2022-06-23 12:11:23 +00:00
|
|
|
name: Syncing Server
|
2022-06-22 14:16:03 +00:00
|
|
|
|
|
|
|
concurrency:
|
2022-06-23 12:11:23 +00:00
|
|
|
group: syncing_server
|
2022-06-22 14:16:03 +00:00
|
|
|
cancel-in-progress: true
|
|
|
|
|
|
|
|
on:
|
|
|
|
push:
|
|
|
|
tags:
|
2022-06-23 12:11:23 +00:00
|
|
|
- '*standardnotes/syncing-server*'
|
2022-06-22 14:16:03 +00:00
|
|
|
workflow_dispatch:
|
|
|
|
|
|
|
|
jobs:
|
|
|
|
test:
|
|
|
|
runs-on: ubuntu-latest
|
|
|
|
|
|
|
|
steps:
|
|
|
|
- uses: actions/checkout@v3
|
|
|
|
- uses: actions/setup-node@v1
|
|
|
|
with:
|
|
|
|
node-version: '16.x'
|
2022-06-23 10:22:59 +00:00
|
|
|
- run: yarn install --immutable
|
2022-06-22 14:16:03 +00:00
|
|
|
- run: yarn lint:syncing-server
|
|
|
|
- run: yarn test:syncing-server
|
|
|
|
|
|
|
|
publish-aws-ecr:
|
|
|
|
needs: test
|
|
|
|
|
|
|
|
runs-on: ubuntu-latest
|
|
|
|
|
|
|
|
steps:
|
2022-06-23 09:40:52 +00:00
|
|
|
- uses: actions/checkout@v3
|
|
|
|
- name: Build locally
|
|
|
|
run: yarn build:syncing-server
|
2022-06-22 14:16:03 +00:00
|
|
|
- name: Configure AWS credentials
|
|
|
|
uses: aws-actions/configure-aws-credentials@v1
|
|
|
|
with:
|
|
|
|
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
|
|
|
|
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
|
|
|
|
aws-region: us-east-1
|
|
|
|
- name: Login to Amazon ECR
|
|
|
|
id: login-ecr
|
|
|
|
uses: aws-actions/amazon-ecr-login@v1
|
|
|
|
- name: Build, tag, and push image to Amazon ECR
|
|
|
|
id: build-image
|
|
|
|
env:
|
|
|
|
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
|
|
|
|
ECR_REPOSITORY: syncing-server-js
|
|
|
|
IMAGE_TAG: ${{ github.sha }}
|
|
|
|
run: |
|
|
|
|
yarn docker build @standardnotes/syncing-server -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
|
|
|
|
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
|
2022-06-23 12:11:23 +00:00
|
|
|
docker tag $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG $ECR_REGISTRY/$ECR_REPOSITORY:latest
|
|
|
|
docker push $ECR_REGISTRY/$ECR_REPOSITORY:latest
|
2022-06-22 14:16:03 +00:00
|
|
|
|
|
|
|
publish-docker-hub:
|
|
|
|
needs: test
|
|
|
|
|
|
|
|
runs-on: ubuntu-latest
|
|
|
|
|
|
|
|
steps:
|
2022-06-23 09:40:52 +00:00
|
|
|
- uses: actions/checkout@v3
|
|
|
|
- name: Build locally
|
|
|
|
run: yarn build:syncing-server
|
2022-06-23 09:47:43 +00:00
|
|
|
- name: Login to Docker Hub
|
|
|
|
uses: docker/login-action@v2
|
2022-06-22 14:16:03 +00:00
|
|
|
with:
|
|
|
|
username: ${{ secrets.DOCKER_USERNAME }}
|
|
|
|
password: ${{ secrets.DOCKER_PASSWORD }}
|
2022-06-23 09:47:43 +00:00
|
|
|
- name: Build, tag, and push image to Docker Hub
|
|
|
|
run: |
|
|
|
|
yarn docker build @standardnotes/syncing-server -t standardnotes/syncing-server-js:${{ github.sha }}
|
|
|
|
docker push standardnotes/syncing-server-js:${{ github.sha }}
|
2022-06-23 12:11:23 +00:00
|
|
|
docker tag standardnotes/syncing-server-js:${{ github.sha }} standardnotes/syncing-server-js:latest
|
|
|
|
docker push standardnotes/syncing-server-js:latest
|
2022-06-22 14:16:03 +00:00
|
|
|
|
|
|
|
deploy-web:
|
|
|
|
needs: publish-aws-ecr
|
|
|
|
|
|
|
|
runs-on: ubuntu-latest
|
|
|
|
|
|
|
|
steps:
|
|
|
|
- name: Configure AWS credentials
|
|
|
|
uses: aws-actions/configure-aws-credentials@v1
|
|
|
|
with:
|
|
|
|
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
|
|
|
|
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
|
|
|
|
aws-region: us-east-1
|
2022-06-23 12:11:23 +00:00
|
|
|
- name: DEV - Download task definition
|
2022-06-22 14:16:03 +00:00
|
|
|
run: |
|
|
|
|
aws ecs describe-task-definition --task-definition syncing-server-js-dev --query taskDefinition > task-definition.json
|
2022-06-23 16:47:13 +00:00
|
|
|
- name: DEV - Fill in the new version in the Amazon ECS task definition
|
2022-06-22 14:16:03 +00:00
|
|
|
run: |
|
|
|
|
jq '(.containerDefinitions[] | select(.name=="syncing-server-js-dev") | .environment[] | select(.name=="VERSION")).value = "${{ github.sha }}"' task-definition.json > tmp.json && mv tmp.json task-definition.json
|
2022-06-23 12:11:23 +00:00
|
|
|
- name: DEV - Fill in the new image ID in the Amazon ECS task definition
|
2022-06-23 16:34:03 +00:00
|
|
|
id: task-def-dev
|
2022-06-22 14:16:03 +00:00
|
|
|
uses: aws-actions/amazon-ecs-render-task-definition@v1
|
|
|
|
with:
|
|
|
|
task-definition: task-definition.json
|
|
|
|
container-name: syncing-server-js-dev
|
|
|
|
image: ${{ secrets.AWS_ECR_REGISTRY }}/syncing-server-js:${{ github.sha }}
|
2022-06-23 12:11:23 +00:00
|
|
|
- name: DEV - Deploy Amazon ECS task definition
|
2022-06-22 14:16:03 +00:00
|
|
|
uses: aws-actions/amazon-ecs-deploy-task-definition@v1
|
|
|
|
with:
|
2022-06-23 16:34:03 +00:00
|
|
|
task-definition: ${{ steps.task-def-dev.outputs.task-definition }}
|
2022-06-22 14:16:03 +00:00
|
|
|
service: syncing-server-js-dev
|
|
|
|
cluster: dev
|
|
|
|
wait-for-service-stability: true
|
2022-06-23 12:11:23 +00:00
|
|
|
- name: PROD - Download task definition
|
|
|
|
run: |
|
|
|
|
aws ecs describe-task-definition --task-definition syncing-server-js-prod --query taskDefinition > task-definition.json
|
2022-06-23 16:47:13 +00:00
|
|
|
- name: PROD - Fill in the new version in the Amazon ECS task definition
|
2022-06-23 12:11:23 +00:00
|
|
|
run: |
|
|
|
|
jq '(.containerDefinitions[] | select(.name=="syncing-server-js-prod") | .environment[] | select(.name=="VERSION")).value = "${{ github.sha }}"' task-definition.json > tmp.json && mv tmp.json task-definition.json
|
|
|
|
- name: PROD - Fill in the new image ID in the Amazon ECS task definition
|
2022-06-23 16:34:03 +00:00
|
|
|
id: task-def-prod
|
2022-06-23 12:11:23 +00:00
|
|
|
uses: aws-actions/amazon-ecs-render-task-definition@v1
|
|
|
|
with:
|
|
|
|
task-definition: task-definition.json
|
|
|
|
container-name: syncing-server-js-prod
|
|
|
|
image: ${{ secrets.AWS_ECR_REGISTRY }}/syncing-server-js:${{ github.sha }}
|
|
|
|
- name: PROD - Deploy Amazon ECS task definition
|
|
|
|
uses: aws-actions/amazon-ecs-deploy-task-definition@v1
|
|
|
|
with:
|
2022-06-23 16:34:03 +00:00
|
|
|
task-definition: ${{ steps.task-def-prod.outputs.task-definition }}
|
2022-06-23 12:11:23 +00:00
|
|
|
service: syncing-server-js-prod
|
|
|
|
cluster: prod
|
|
|
|
wait-for-service-stability: true
|
2022-06-22 14:16:03 +00:00
|
|
|
|
|
|
|
deploy-worker:
|
|
|
|
needs: publish-aws-ecr
|
|
|
|
|
|
|
|
runs-on: ubuntu-latest
|
|
|
|
|
|
|
|
steps:
|
|
|
|
- name: Configure AWS credentials
|
|
|
|
uses: aws-actions/configure-aws-credentials@v1
|
|
|
|
with:
|
|
|
|
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
|
|
|
|
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
|
|
|
|
aws-region: us-east-1
|
2022-06-23 12:11:23 +00:00
|
|
|
- name: DEV - Download task definition
|
2022-06-22 14:16:03 +00:00
|
|
|
run: |
|
|
|
|
aws ecs describe-task-definition --task-definition syncing-server-js-worker-dev --query taskDefinition > task-definition.json
|
2022-06-23 16:47:13 +00:00
|
|
|
- name: DEV - Fill in the new version in the Amazon ECS task definition
|
2022-06-22 14:16:03 +00:00
|
|
|
run: |
|
|
|
|
jq '(.containerDefinitions[] | select(.name=="syncing-server-js-worker-dev") | .environment[] | select(.name=="VERSION")).value = "${{ github.sha }}"' task-definition.json > tmp.json && mv tmp.json task-definition.json
|
2022-06-23 12:11:23 +00:00
|
|
|
- name: DEV - Fill in the new image ID in the Amazon ECS task definition
|
2022-06-23 16:34:03 +00:00
|
|
|
id: task-def-dev
|
2022-06-22 14:16:03 +00:00
|
|
|
uses: aws-actions/amazon-ecs-render-task-definition@v1
|
|
|
|
with:
|
|
|
|
task-definition: task-definition.json
|
|
|
|
container-name: syncing-server-js-worker-dev
|
|
|
|
image: ${{ secrets.AWS_ECR_REGISTRY }}/syncing-server-js:${{ github.sha }}
|
2022-06-23 12:11:23 +00:00
|
|
|
- name: DEV - Deploy Amazon ECS task definition
|
2022-06-22 14:16:03 +00:00
|
|
|
uses: aws-actions/amazon-ecs-deploy-task-definition@v1
|
|
|
|
with:
|
2022-06-23 16:34:03 +00:00
|
|
|
task-definition: ${{ steps.task-def-dev.outputs.task-definition }}
|
2022-06-22 14:16:03 +00:00
|
|
|
service: syncing-server-js-worker-dev
|
|
|
|
cluster: dev
|
|
|
|
wait-for-service-stability: true
|
2022-06-23 12:11:23 +00:00
|
|
|
- name: PROD - Download task definition
|
|
|
|
run: |
|
|
|
|
aws ecs describe-task-definition --task-definition syncing-server-js-worker-prod --query taskDefinition > task-definition.json
|
2022-06-23 16:47:13 +00:00
|
|
|
- name: PROD - Fill in the new version in the Amazon ECS task definition
|
2022-06-23 12:11:23 +00:00
|
|
|
run: |
|
|
|
|
jq '(.containerDefinitions[] | select(.name=="syncing-server-js-worker-prod") | .environment[] | select(.name=="VERSION")).value = "${{ github.sha }}"' task-definition.json > tmp.json && mv tmp.json task-definition.json
|
|
|
|
- name: PROD - Fill in the new image ID in the Amazon ECS task definition
|
2022-06-23 16:34:03 +00:00
|
|
|
id: task-def-prod
|
2022-06-23 12:11:23 +00:00
|
|
|
uses: aws-actions/amazon-ecs-render-task-definition@v1
|
|
|
|
with:
|
|
|
|
task-definition: task-definition.json
|
|
|
|
container-name: syncing-server-js-worker-prod
|
|
|
|
image: ${{ secrets.AWS_ECR_REGISTRY }}/syncing-server-js:${{ github.sha }}
|
|
|
|
- name: PROD - Deploy Amazon ECS task definition
|
|
|
|
uses: aws-actions/amazon-ecs-deploy-task-definition@v1
|
|
|
|
with:
|
2022-06-23 16:34:03 +00:00
|
|
|
task-definition: ${{ steps.task-def-prod.outputs.task-definition }}
|
2022-06-23 12:11:23 +00:00
|
|
|
service: syncing-server-js-worker-prod
|
|
|
|
cluster: prod
|
|
|
|
wait-for-service-stability: true
|
2022-06-22 14:16:03 +00:00
|
|
|
|
|
|
|
newrelic:
|
|
|
|
needs: [ deploy-web, deploy-worker ]
|
|
|
|
|
|
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
2022-06-23 17:42:23 +00:00
|
|
|
- name: Create New Relic deployment marker for Web
|
2022-06-23 12:11:23 +00:00
|
|
|
uses: newrelic/deployment-marker-action@v1
|
|
|
|
with:
|
|
|
|
accountId: ${{ secrets.NEW_RELIC_ACCOUNT_ID }}
|
|
|
|
apiKey: ${{ secrets.NEW_RELIC_API_KEY }}
|
|
|
|
applicationId: ${{ secrets.NEW_RELIC_APPLICATION_ID_SYNCING_SERVER_WEB_PROD }}
|
|
|
|
revision: "${{ github.sha }}"
|
|
|
|
description: "Automated Deployment via Github Actions"
|
|
|
|
user: "${{ github.actor }}"
|
2022-06-23 17:42:23 +00:00
|
|
|
- name: Create New Relic deployment marker for Worker
|
2022-06-23 12:11:23 +00:00
|
|
|
uses: newrelic/deployment-marker-action@v1
|
|
|
|
with:
|
|
|
|
accountId: ${{ secrets.NEW_RELIC_ACCOUNT_ID }}
|
|
|
|
apiKey: ${{ secrets.NEW_RELIC_API_KEY }}
|
|
|
|
applicationId: ${{ secrets.NEW_RELIC_APPLICATION_ID_SYNCING_SERVER_WORKER_PROD }}
|
|
|
|
revision: "${{ github.sha }}"
|
|
|
|
description: "Automated Deployment via Github Actions"
|
|
|
|
user: "${{ github.actor }}"
|