Skip to content

Commit

Permalink
setup cicd pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
raymondhtet committed Sep 9, 2024
1 parent 83af1ba commit 6179ec1
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 0 deletions.
99 changes: 99 additions & 0 deletions .github/workflows/cicd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
name: Gen AI Microservice CICD

on:
push:
branches:
- main
pull_request:
types: [opened, synchronize, reopened]

permissions: write-all

env:
AWS_REGION: ${{ secrets.AWS_REGION }}
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
ECR_REPOSITORY_URL: ${{ secrets.ECR_REPOSITORY_URL }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
IMAGE_NAME: ${{ secrets.ECR_REPOSITORY_URL }}:${{ github.sha }}
LATEST_IMAGE_NAME: ${{ secrets.ECR_REPOSITORY_URL }}:latest
API_GATEWAY_URL: ${{ secrets.API_GATEWAY_URL }}

jobs:
build_and_push_image:
needs: code_scan
name: Push Docker Image to ECR
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ env.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ env.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ env.AWS_REGION }}

- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v2

- name: Build and Push Image
uses: docker/build-push-action@v6
with:
context: .
file: ./Dockerfile
push: true
tags: |
${{ env.IMAGE_NAME }}
${{ env.LATEST_IMAGE_NAME }}
deploy_to_ecs:
name: Deploy to ECS
needs: build_and_push_image
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ env.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ env.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ env.AWS_REGION }}

- name: Fill in the new image ID in the Amazon ECS task definition
id: task-def
uses: aws-actions/amazon-ecs-render-task-definition@v1
with:
task-definition: aws/task-definition.json
container-name: genai_ms
image: ${{ env.IMAGE_NAME }}

- name: Deploy Amazon ECS task definition
uses: aws-actions/amazon-ecs-deploy-task-definition@v1
with:
task-definition: ${{ steps.task-def.outputs.task-definition }}
service: genai-ms
cluster: quemistry-ms
wait-for-service-stability: false

zap_scan:
if: false
permissions: write-all
needs: deploy_to_ecs
runs-on: ubuntu-latest
name: Zap Scan
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: main

- name: ZAP Scan
uses: zaproxy/[email protected]
with:
target: ${{ env.API_GATEWAY_URL }}
Empty file added aws/task-definition.json
Empty file.

0 comments on commit 6179ec1

Please sign in to comment.