forked from inflection-zone/rean-admin
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b1660ac
commit 69538b0
Showing
1 changed file
with
115 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
# 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: PROD-CI-CD | ||
|
||
# Controls when the workflow will run | ||
on: | ||
# Triggers the workflow on push events but only for the develop branch | ||
push: | ||
branches: [main] | ||
|
||
jobs: | ||
|
||
Publish-Release: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: New Release Publish | ||
id: new_publish | ||
uses: release-drafter/release-drafter@v5 | ||
with: | ||
publish : true | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.PAT_GITHUB }} | ||
|
||
outputs: | ||
release_id: ${{ steps.new_publish.outputs.id }} | ||
release_name: ${{ steps.new_publish.outputs.tag_name }} | ||
|
||
|
||
Deploy-ECS: | ||
needs: Publish-Release | ||
environment: prod | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
|
||
- 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: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v2 | ||
|
||
- name: Login to Amazon ECR | ||
run: | | ||
aws ecr-public get-login-password --region us-east-1 | docker login --username AWS --password-stdin public.ecr.aws | ||
- name: Cache Docker layers | ||
uses: actions/cache@v3 | ||
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@v3 | ||
with: | ||
context: ./ | ||
file: ./Dockerfile | ||
builder: ${{ steps.buildx.outputs.name }} | ||
push: true | ||
tags: public.ecr.aws/i9y2d4u3/reancare:${{ needs.Publish-Release.outputs.release_name }}_${{ needs.Publish-Release.outputs.release_id }} | ||
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: public.ecr.aws/i9y2d4u3/reancare:${{ needs.Publish-Release.outputs.release_name }}_${{ needs.Publish-Release.outputs.release_id }} | ||
|
||
- 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 "task_definition_arn=$(aws ecs describe-task-definition --task-definition ${{ secrets.TASK_DEFINTION_NAME }} | jq '.[] | .taskDefinitionArn')" >> $GITHUB_OUTPUT | ||
- 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": ""}' | ||
bearerToken: ${{ secrets.DUPLOCLOUD_TOKEN }} |