Skip to content

Merge pull request #123 from REAN-Foundation/snyk-fix-9da7ed0952c6aa8… #60

Merge pull request #123 from REAN-Foundation/snyk-fix-9da7ed0952c6aa8…

Merge pull request #123 from REAN-Foundation/snyk-fix-9da7ed0952c6aa8… #60

Workflow file for this run

# This workflow will trigger pull requests and apply a label based on the
# paths that are modified in the pull request.
#
# To use this workflow, you will need to set up a .github/labeler.yml
# file with configuration. For more information, see:
# https://github.com/actions/labeler
name: Dev-CI-CD
# Controls when the workflow will run
on:
# Triggers the workflow on push events but only for the develop branch
push:
branches: [develop]
workflow_dispatch:
jobs:
Deploy-ECS:
environment: dev
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- 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: ${{ secrets.AWS_REGION }}
- name: Declare some variables
id: vars
shell: bash
run: |
echo "##[set-output name=branch;]$(echo ${GITHUB_REF#refs/heads/} | sed "s/\\//-/g")"
echo "::set-output name=sha_short::$(git rev-parse --short HEAD)"
echo "::set-output name=repo_name::$(echo "$GITHUB_REPOSITORY" | awk -F / '{print $2}')"
- name: Another step
run: |
echo "Branch: ${{ steps.vars.outputs.branch }}"
echo "Sha: ${{ steps.vars.outputs.sha_short }}"
echo "Repo: ${{ steps.vars.outputs.repo_name }}"
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1
- name: Cache Docker layers
uses: actions/cache@v2
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
- name: Build and push
id: docker_build
uses: docker/build-push-action@v2
with:
context: ./
file: ./Dockerfile
builder: ${{ steps.buildx.outputs.name }}
push: true
tags: ${{ steps.login-ecr.outputs.registry }}/careplan-service-dev-uat:${{ steps.vars.outputs.branch }}_${{ steps.vars.outputs.sha_short }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache
- name: Image digest
run: echo ${{ steps.docker_build.outputs.digest }}
- name: Download task definition
run: |
aws ecs describe-task-definition --task-definition ${{ secrets.TASK_DEFINTION_NAME }} \
--query taskDefinition > task-definition.json
- name: New image ID in the Amazon ECS task definition
id: task-def
uses: aws-actions/amazon-ecs-render-task-definition@v1
with:
task-definition: task-definition.json
container-name: default
image: ${{ steps.login-ecr.outputs.registry }}/careplan-service-dev-uat:${{ steps.vars.outputs.branch }}_${{ steps.vars.outputs.sha_short }}
- name: Sleep for 30 seconds
uses: jakejarvis/wait-action@master
with:
time: '40s'
- name: Deploy Amazon ECS task definition
uses: aws-actions/amazon-ecs-deploy-task-definition@v1
with:
task-definition: ${{ steps.task-def.outputs.task-definition }}
wait-for-service-stability: true
- name: Task Definition Variable
id: taskdefintionvar
shell: bash
run: |
echo "::set-output name=task_definition_arn::$(aws ecs describe-task-definition --task-definition ${{ secrets.TASK_DEFINTION_NAME }} | jq '.[] | .taskDefinitionArn')"
- name: Task Defintion ARN
run: |
echo "Task Defintion: ${{ steps.taskdefintionvar.outputs.task_definition_arn }}"
- name: Deploy Amazon ECS task definition using Duplo API
uses: fjogeleit/http-request-action@master
with:
url: 'https://reanfoundation.duplocloud.net/subscriptions/${{ secrets.DUPLO_ID }}/UpdateEcsService'
method: 'POST'
data: '{"TaskDefinition":${{ steps.taskdefintionvar.outputs.task_definition_arn }},"Name": "${{ secrets.SERVICE_NAME }}","Replicas":1, "HealthCheckGracePeriodSeconds": 1200, "DnsPrfx": "", "IsTargetGroupOnly": true }'
bearerToken: ${{ secrets.DUPLOCLOUD_TOKEN }}