|
| 1 | +name: deploy React App |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_run: |
| 5 | + workflows: ["check React App"] |
| 6 | + types: |
| 7 | + - completed |
| 8 | + |
| 9 | +jobs: |
| 10 | + client-docker-build-push: |
| 11 | + if: ${{ github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.head_branch == 'main' }} |
| 12 | + runs-on: ubuntu-latest |
| 13 | + permissions: |
| 14 | + packages: write |
| 15 | + contents: read |
| 16 | + steps: |
| 17 | + - uses: actions/checkout@v4 |
| 18 | + |
| 19 | + - name: Set up Docker Buildx |
| 20 | + uses: docker/setup-buildx-action@v3 |
| 21 | + |
| 22 | + - name: Log in to GitHub Container Registry |
| 23 | + uses: docker/login-action@v3 |
| 24 | + with: |
| 25 | + registry: ghcr.io |
| 26 | + username: ${{ github.actor }} |
| 27 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 28 | + |
| 29 | + - name: Build and push Docker image |
| 30 | + uses: docker/build-push-action@v5 |
| 31 | + with: |
| 32 | + context: ./client |
| 33 | + file: ./client/Dockerfile |
| 34 | + push: true |
| 35 | + tags: | |
| 36 | + ghcr.io/aet-devops25/team-cache-me-if-you-can/client:latest |
| 37 | + ghcr.io/aet-devops25/team-cache-me-if-you-can/client:${{ github.sha }} |
| 38 | + labels: | |
| 39 | + org.opencontainers.image.source=https://github.com/${{ github.repository }} |
| 40 | + org.opencontainers.image.revision=${{ github.sha }} |
| 41 | +
|
| 42 | + aws-client-docker-build-push: |
| 43 | + if: ${{ github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.head_branch == 'main' }} |
| 44 | + runs-on: ubuntu-latest |
| 45 | + permissions: |
| 46 | + packages: write |
| 47 | + contents: read |
| 48 | + steps: |
| 49 | + - uses: actions/checkout@v4 |
| 50 | + |
| 51 | + - name: Set up Docker Buildx |
| 52 | + uses: docker/setup-buildx-action@v3 |
| 53 | + |
| 54 | + - name: Log in to GitHub Container Registry |
| 55 | + uses: docker/login-action@v3 |
| 56 | + with: |
| 57 | + registry: ghcr.io |
| 58 | + username: ${{ github.actor }} |
| 59 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 60 | + |
| 61 | + - name: Build and push Docker image |
| 62 | + uses: docker/build-push-action@v5 |
| 63 | + with: |
| 64 | + context: ./client |
| 65 | + file: ./client/Dockerfile.prod |
| 66 | + push: true |
| 67 | + tags: | |
| 68 | + ghcr.io/aet-devops25/team-cache-me-if-you-can/client-prod:latest |
| 69 | + ghcr.io/aet-devops25/team-cache-me-if-you-can/client-prod:${{ github.sha }} |
| 70 | + labels: | |
| 71 | + org.opencontainers.image.source=https://github.com/${{ github.repository }} |
| 72 | + org.opencontainers.image.revision=${{ github.sha }} |
| 73 | +
|
| 74 | + client-deploy: |
| 75 | + name: Deploy to Kubernetes |
| 76 | + runs-on: ubuntu-latest |
| 77 | + needs: [client-check-format, client-run-tests, client-docker-build-push] |
| 78 | + if: github.ref == 'refs/heads/main' && github.event_name == 'push' |
| 79 | + |
| 80 | + steps: |
| 81 | + - name: Checkout Code |
| 82 | + uses: actions/checkout@v4 |
| 83 | + |
| 84 | + - name: Set up Terraform |
| 85 | + uses: hashicorp/setup-terraform@v3 |
| 86 | + |
| 87 | + - name: Set up Kubernetes tools |
| 88 | + uses: azure/setup-kubectl@v3 |
| 89 | + |
| 90 | + - name: Configure kubeconfig |
| 91 | + run: | |
| 92 | + mkdir -p ~/.kube |
| 93 | + echo "${{ secrets.KUBE_CONFIG_DATA }}" > ~/.kube/config |
| 94 | + chmod 600 ~/.kube/config |
| 95 | +
|
| 96 | + - name: Terraform Init |
| 97 | + run: terraform init |
| 98 | + working-directory: ./client/terraform |
| 99 | + |
| 100 | + - name: Terraform Plan |
| 101 | + run: terraform plan -var="redeploy_id=${{ github.sha }}" |
| 102 | + working-directory: ./client/terraform |
| 103 | + |
| 104 | + - name: Terraform Apply |
| 105 | + run: terraform apply -auto-approve -var="redeploy_id=${{ github.sha }}" |
| 106 | + working-directory: ./client/terraform |
| 107 | + env: |
| 108 | + KUBECONFIG: $HOME/.kube/config |
0 commit comments