Skip to content

Commit

Permalink
Merge pull request #28 from canyongbs/feature/AIDAPP-30-prod-ci-cd
Browse files Browse the repository at this point in the history
[AIDAPP-30]: Setup CI/CD for production
  • Loading branch information
Orrison authored Apr 2, 2024
2 parents 0262329 + 8db3587 commit 002e064
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 4 deletions.
67 changes: 67 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
name: Deploy to Production Environment

on:
release:
types: [released]

env:
AWS_REGION: "us-west-2"
ECR_REPOSITORY: "aidingapp"

jobs:
deploy:
name: Deploy
runs-on: ubuntu-22.04
environment: production

steps:
- name: Checkout
uses: actions/checkout@v4
with:
submodules: true
ref: ${{ github.head_ref }}
token: ${{ secrets.PAT }}

- name: Configure AWS credentials
# SHA of release v4.0.2
uses: aws-actions/configure-aws-credentials@e3dd6a429d7300a6a4c196c26e071d42e0343502
with:
aws-access-key-id: ${{ secrets.PROD_AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.PROD_AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ env.AWS_REGION }}

- name: Login to Amazon ECR
id: login-ecr
# SHA of release v2.0.1
uses: aws-actions/amazon-ecr-login@062b18b96a7aff071d4dc91bc00c4c1a7945b076

- name: Build, tag, and push image to Amazon ECR
id: build-image
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
IMAGE_TAG: ${{ github.event.release.tag_name }}
run: |
# Build a docker container and
# push it to ECR so that it can
# be deployed to ECS.
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG --target deploy --platform linux/amd64 --build-arg USER_ID=9999 --build-arg GROUP_ID=9999 .
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
echo "image=$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG" >> $GITHUB_OUTPUT
- name: Fill in the new image ID in the Amazon ECS task definition
id: task-def
# SHA of release v1.2.0
uses: aws-actions/amazon-ecs-render-task-definition@4225e0b507142a2e432b018bc3ccb728559b437a
with:
task-definition: "docker/devops/ecs/aidingapp/aidingapp-prod-task-definition.json"
container-name: "app"
image: ${{ steps.build-image.outputs.image }}

- name: Deploy Amazon ECS task definition
# SHA of release v1.4.11
uses: aws-actions/amazon-ecs-deploy-task-definition@df9643053eda01f169e64a0e60233aacca83799a
with:
task-definition: ${{ steps.task-def.outputs.task-definition }}
service: "aidingapp-prod-service"
cluster: "aidingapp-prod"
wait-for-service-stability: true
2 changes: 1 addition & 1 deletion docker/devops
5 changes: 2 additions & 3 deletions docker/s6-overlay/s6-rc.d/nginx/data/check
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#!/command/with-contenv bash
response=$(curl -I --location --insecure --silent http://localhost | awk '/^HTTP/{print $2}')
response=$(curl -s -o /dev/null -w "%{http_code}" -L --insecure http://localhost)

if [[ $response == "302
200" ]] || [[ $response == "302" ]]; then
if [[ $response == "200" ]]; then
exit 0
else
echo "❌ There seems to be a failure in checking the web server. Here's the response:"
Expand Down

0 comments on commit 002e064

Please sign in to comment.