name: Api Gateway concurrency: group: api_gateway cancel-in-progress: true on: push: tags: - '*standardnotes/api-gateway*' workflow_dispatch: jobs: test: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - uses: actions/setup-node@v1 with: node-version: '16.x' - run: yarn lint:api-gateway publish-aws-ecr: needs: test runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - name: Build locally run: yarn build:api-gateway - 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: api-gateway IMAGE_TAG: ${{ github.sha }} run: | yarn docker build @standardnotes/api-gateway -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG docker tag $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG $ECR_REGISTRY/$ECR_REPOSITORY:latest docker push $ECR_REGISTRY/$ECR_REPOSITORY:latest publish-docker-hub: needs: test runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - name: Build locally run: yarn build:api-gateway - name: Login to Docker Hub uses: docker/login-action@v2 with: username: ${{ secrets.DOCKER_USERNAME }} password: ${{ secrets.DOCKER_PASSWORD }} - name: Build, tag, and push image to Docker Hub run: | yarn docker build @standardnotes/api-gateway -t standardnotes/api-gateway:${{ github.sha }} docker push standardnotes/api-gateway:${{ github.sha }} docker tag standardnotes/api-gateway:${{ github.sha }} standardnotes/api-gateway:latest docker push standardnotes/api-gateway:latest 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 - name: DEV - Download task definition run: | aws ecs describe-task-definition --task-definition api-gateway-dev --query taskDefinition > task-definition.json - name: DEV - Fill in the new version in the Amazon ECS task definition run: | jq '(.containerDefinitions[] | select(.name=="api-gateway-dev") | .environment[] | select(.name=="VERSION")).value = "${{ github.sha }}"' task-definition.json > tmp.json && mv tmp.json task-definition.json - name: DEV - Fill in the new image ID in the Amazon ECS task definition id: task-def-dev uses: aws-actions/amazon-ecs-render-task-definition@v1 with: task-definition: task-definition.json container-name: api-gateway-dev image: ${{ secrets.AWS_ECR_REGISTRY }}/api-gateway:${{ github.sha }} - name: DEV - Deploy Amazon ECS task definition uses: aws-actions/amazon-ecs-deploy-task-definition@v1 with: task-definition: ${{ steps.task-def-dev.outputs.task-definition }} service: api-gateway-dev cluster: dev wait-for-service-stability: true - name: PROD - Download task definition run: | aws ecs describe-task-definition --task-definition api-gateway-prod --query taskDefinition > task-definition.json - name: PROD - Fill in the new version in the Amazon ECS task definition run: | jq '(.containerDefinitions[] | select(.name=="api-gateway-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 id: task-def-prod uses: aws-actions/amazon-ecs-render-task-definition@v1 with: task-definition: task-definition.json container-name: api-gateway-prod image: ${{ secrets.AWS_ECR_REGISTRY }}/api-gateway:${{ github.sha }} - name: PROD - Deploy Amazon ECS task definition uses: aws-actions/amazon-ecs-deploy-task-definition@v1 with: task-definition: ${{ steps.task-def-prod.outputs.task-definition }} service: api-gateway-prod cluster: prod wait-for-service-stability: true newrelic: needs: deploy-web runs-on: ubuntu-latest steps: - name: Create New Relic deployment marker for Web 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_API_GATEWAY_WEB_PROD }} revision: "${{ github.sha }}" description: "Automated Deployment via Github Actions" user: "${{ github.actor }}"