Merge pull request #110 from Team-Senifit/release-1.0.1 #65
This file contains hidden or 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
| name: CI/CD Deploy | |
| on: | |
| push: | |
| branches: ["develop"] | |
| workflow_dispatch: {} | |
| concurrency: | |
| group: deploy-develop | |
| cancel-in-progress: true | |
| permissions: | |
| contents: read | |
| packages: write | |
| jobs: | |
| build-and-deploy: | |
| runs-on: ubuntu-latest | |
| env: | |
| IMAGE_NAME: ghcr.io/team-senifit/web | |
| IMAGE_TAG: ${{ github.sha }} | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Log in to GHCR | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.repository_owner }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Build and push image | |
| uses: docker/build-push-action@v6 | |
| with: | |
| context: . | |
| file: Dockerfile | |
| push: true | |
| tags: ${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG }} | |
| build-args: | | |
| NEXT_PUBLIC_SITE_URL=${{ secrets.NEXT_PUBLIC_SITE_URL }} | |
| NEXT_PUBLIC_API_URL=${{ secrets.NEXT_PUBLIC_API_URL }} | |
| SITE_URL=${{ secrets.NEXT_PUBLIC_SITE_URL }} | |
| - name: Configure AWS credentials | |
| uses: aws-actions/configure-aws-credentials@v4 | |
| 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: Deploy via SSM | |
| env: | |
| SSM_INSTANCE_ID: ${{ secrets.SSM_INSTANCE_ID }} | |
| IMAGE_TAG: ${{ env.IMAGE_TAG }} | |
| IMAGE_NAME: ${{ env.IMAGE_NAME }} | |
| run: | | |
| set -euo pipefail | |
| COMMAND_ID=$(aws ssm send-command \ | |
| --instance-ids "$SSM_INSTANCE_ID" \ | |
| --document-name "AWS-RunShellScript" \ | |
| --comment "Deploy web image $IMAGE_NAME:$IMAGE_TAG" \ | |
| --parameters 'commands=["cd /srv","export IMAGE_TAG='\"$IMAGE_TAG\"'","docker compose down","docker compose pull","docker compose up -d"]' \ | |
| --query "Command.CommandId" \ | |
| --output text) | |
| aws ssm wait command-executed \ | |
| --command-id "$COMMAND_ID" \ | |
| --instance-id "$SSM_INSTANCE_ID" | |
| aws ssm get-command-invocation \ | |
| --command-id "$COMMAND_ID" \ | |
| --instance-id "$SSM_INSTANCE_ID" |