CI/CD - Prod (AWS) #24
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 - Prod (AWS) | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| branch: | |
| description: 'Branch' | |
| required: true | |
| default: 'develop' | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v3 | |
| with: | |
| ref: ${{ github.event.inputs.branch }} | |
| - uses: actions/setup-java@v3 | |
| with: | |
| distribution: 'temurin' | |
| java-version: '17' | |
| - uses: gradle/actions/setup-gradle@v3 | |
| with: | |
| gradle-version: '8.14.2' | |
| - name: Generate Production Configs | |
| shell: bash | |
| run: | | |
| mkdir -p ./src/main/resources | |
| cat <<'EOF' > ./src/main/resources/application.yml | |
| ${{ secrets.CD_APPLICATION }} | |
| EOF | |
| cat <<'EOF' > ./src/main/resources/application-aws.yml | |
| ${{ secrets.CD_APPLICATION_AWS }} | |
| EOF | |
| cat <<'EOF' > ./src/main/resources/application-oauth.yml | |
| ${{ secrets.CD_APPLICATION_OAUTH }} | |
| EOF | |
| - name: Build & Push | |
| run: | | |
| chmod +x ./gradlew | |
| ./gradlew clean build -x test | |
| echo "${{ secrets.DOCKER_PASSWORD }}" | docker login -u "${{ secrets.DOCKER_USERNAME }}" --password-stdin | |
| docker build --no-cache -t "${{ secrets.DOCKER_USERNAME }}/doki-prod:latest" . | |
| docker push "${{ secrets.DOCKER_USERNAME }}/doki-prod:latest" | |
| deploy: | |
| needs: build | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Deploy to AWS EC2 via SSH | |
| uses: appleboy/ssh-action@v1.0.3 | |
| with: | |
| host: ${{ secrets.PROD_EC2_PUBLIC_IP }} | |
| username: ubuntu | |
| key: ${{ secrets.PROD_EC2_SSH_KEY }} | |
| script: | | |
| echo "📦 Pulling latest doki-prod image..." | |
| sudo docker pull ${{ secrets.DOCKER_USERNAME }}/doki-prod:latest | |
| echo "🚀 Running Blue-Green deployment..." | |
| cd /home/ubuntu | |
| chmod +x deploy.sh | |
| ./deploy.sh | |
| echo "✅ AWS Prod Blue-Green Deployment Complete!" |