|
1 | | -name: Deploy to Kubernetes |
| 1 | +name: Deploy build |
2 | 2 |
|
3 | 3 | on: |
4 | 4 | push: |
5 | 5 | branches: |
6 | 6 | - main |
7 | | - - canary |
8 | 7 | - staging |
9 | | - - td-nature |
10 | | - - td-book |
11 | 8 | - td-art |
12 | 9 |
|
| 10 | + workflow_dispatch: |
| 11 | + inputs: |
| 12 | + ref_name: |
| 13 | + description: "Branch or tag" |
| 14 | + required: true |
| 15 | + type: string |
| 16 | + |
| 17 | + workflow_call: |
| 18 | + inputs: |
| 19 | + ref_name: |
| 20 | + required: true |
| 21 | + type: string |
| 22 | + |
13 | 23 | jobs: |
14 | 24 | build: |
15 | | - runs-on: ubuntu-latest |
16 | | - environment: "${{ github.ref == 'refs/heads/main' && 'production' || github.ref == 'refs/heads/canary' && 'canary' || github.ref == 'refs/heads/staging' && 'staging' || startsWith(github.ref, 'refs/heads/td-') && 'testing' || 'unknown' }}" |
17 | | - env: |
18 | | - JOB_ENV: "${{ github.ref == 'refs/heads/main' && 'production' || github.ref == 'refs/heads/canary' && 'canary' || github.ref == 'refs/heads/staging' && 'staging' || startsWith(github.ref, 'refs/heads/td-') && 'testing' || 'unknown' }}" |
19 | | - APP_ENV: "${{ github.ref == 'refs/heads/main' && 'production' || github.ref == 'refs/heads/canary' && 'canary' || github.ref == 'refs/heads/staging' && 'staging' || startsWith(github.ref, 'refs/heads/td-') && format('{0}{1}', 'testing-', github.ref_name) || 'unknown' }}" |
20 | | - APP_DOMAIN: "${{ startsWith(github.ref, 'refs/heads/td-') && format('{0}{1}', github.ref_name, vars.APP_DOMAIN_TESTING) || github.ref == 'refs/heads/staging' && vars.APP_DOMAIN_STAGING || vars.APP_DOMAIN }}" |
21 | | - concurrency: |
22 | | - group: ${{ github.workflow }}-${{ github.ref }} |
23 | | - cancel-in-progress: false |
24 | | - |
| 25 | + uses: ./.github/workflows/build.yml |
| 26 | + secrets: inherit |
25 | 27 | permissions: |
26 | 28 | packages: write |
27 | 29 | contents: read |
| 30 | + with: |
| 31 | + ref_name: ${{ inputs.ref_name || github.ref_name }} |
28 | 32 |
|
| 33 | + deploy: |
| 34 | + needs: build |
| 35 | + runs-on: ubuntu-latest |
29 | 36 | steps: |
30 | | - - name: Checkout code |
31 | | - uses: actions/checkout@v4 |
32 | | - |
33 | | - - name: Configure AWS Credentials |
34 | | - uses: aws-actions/configure-aws-credentials@v4 |
35 | | - with: |
36 | | - aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} |
37 | | - aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} |
38 | | - aws-region: ${{ vars.AWS_REGION }} |
39 | | - |
40 | | - - name: Log in to GitHub Container Registry |
41 | | - uses: docker/login-action@v3 |
42 | | - with: |
43 | | - registry: ghcr.io |
44 | | - username: ${{ github.actor }} |
45 | | - password: ${{ secrets.GITHUB_TOKEN }} |
46 | | - |
47 | | - - name: Set sha-short |
48 | | - run: echo "GITHUB_SHA_SHORT=$(echo $GITHUB_SHA | cut -c 1-7)" >> $GITHUB_ENV |
49 | | - |
50 | | - - id: lower-repo |
51 | | - name: Repository to lowercase |
52 | | - run: | |
53 | | - echo "repository=${GITHUB_REPOSITORY@L}" >> $GITHUB_OUTPUT |
54 | | -
|
55 | | - - name: Extract metadata (tags, labels) for Docker |
56 | | - id: meta |
57 | | - uses: docker/metadata-action@v5 |
| 37 | + - name: Run deployment wf |
| 38 | + uses: the-actions-org/workflow-dispatch@v4 |
58 | 39 | with: |
59 | | - images: ghcr.io/${{ steps.lower-repo.outputs.repository }} |
60 | | - github-token: ${{ secrets.GITHUB_TOKEN }} |
61 | | - tags: | |
62 | | - type=sha |
63 | | - type=sha,format=long |
64 | | - type=ref,event=branch |
65 | | -
|
66 | | - - name: Build and push Docker image ${{ steps.lower-repo.outputs.repository }}:${{ env.APP_ENV }} |
67 | | - uses: docker/build-push-action@v6 |
68 | | - with: |
69 | | - context: . |
70 | | - push: true |
71 | | - tags: ghcr.io/${{ steps.lower-repo.outputs.repository }}:${{ env.GITHUB_SHA_SHORT }},ghcr.io/${{ steps.lower-repo.outputs.repository }}:${{ env.APP_ENV }} |
72 | | - build-args: | |
73 | | - sha=${{ github.sha }} |
74 | | - sha_short=${{ env.GITHUB_SHA_SHORT }} |
75 | | - app_env=${{ vars.APP_ENV }} |
76 | | - REACT_APP_PROXY_KEY=${{ secrets.REACT_APP_PROXY_KEY }} |
77 | | - REACT_APP_MIXPANEL_TOKEN=${{ secrets.REACT_APP_MIXPANEL_TOKEN }} |
78 | | - REACT_APP_ANALYTICS_ENABLED=${{ secrets.REACT_APP_ANALYTICS_ENABLED }} |
79 | | -
|
80 | | - - name: Apply AWS k8s config |
81 | | - run: aws eks update-kubeconfig --name ${{ vars.AWS_CLUSTER }} --region ${{ vars.AWS_REGION }} |
82 | | - |
83 | | - - name: Create namespace |
84 | | - run: | |
85 | | - kubectl create ns ${{ vars.APP_NAME }}-${{ env.APP_ENV }} || echo "Namespace already exists" |
86 | | -
|
87 | | - - name: Deploy ${{ vars.APP_NAME }} to Kubernetes |
88 | | - run: | |
89 | | - helm upgrade --install ${{ vars.APP_NAME }} ./helm/app \ |
90 | | - --namespace ${{ vars.APP_NAME }}-${{ env.APP_ENV }} \ |
91 | | - --values ./helm/app/values.yaml \ |
92 | | - --values ./helm/app/values-${{ env.JOB_ENV }}.yaml \ |
93 | | - --set imageRepo="ghcr.io/${{ steps.lower-repo.outputs.repository }}" \ |
94 | | - --set imageTag="${{ env.GITHUB_SHA_SHORT }}" \ |
95 | | - --set host=${{ env.APP_DOMAIN }} \ |
96 | | - --set appName=${{ vars.APP_NAME }} \ |
97 | | - --set ghcrSecret=${{ secrets.GHCR_SECRET }} |
98 | | -
|
99 | | - - name: Verify deployment |
100 | | - run: | |
101 | | - kubectl -n ${{ vars.APP_NAME }}-${{ env.APP_ENV }} rollout status deployment/${{ vars.APP_NAME }}-${{ env.JOB_ENV }} |
102 | | -
|
103 | | - - name: Telegram Notify (Success) |
104 | | - |
105 | | - if: success() && contains('${{ vars.ENABLE_DEPLOY_BOT }}', 1) |
106 | | - with: |
107 | | - to: ${{ secrets.TELEGRAM_DEPLOY_CHAT_ID }} |
108 | | - token: ${{ secrets.TELEGRAM_DEPLOY_TOKEN }} |
109 | | - format: markdown |
110 | | - message: | |
111 | | - 🚂 The application from repository [${{ steps.lower-repo.outputs.repository }}](https://github.com/${{ steps.lower-repo.outputs.repository }}) has been successfully deployed by [${{ github.actor }}](https://github.com/users/${{ github.actor }}) on ${{ env.APP_ENV }}. |
112 | | -
|
113 | | - 🏗️ [GitHub Actions Build](https://github.com/${{ steps.lower-repo.outputs.repository }}/actions/runs/${{ github.run_id }}) |
114 | | - 🐳 [Image](https://ghcr.io/${{ steps.lower-repo.outputs.repository }}:${{ env.GITHUB_SHA_SHORT }}) |
115 | | - 🔗 [Link](https://${{ env.APP_DOMAIN }}) |
116 | | -
|
117 | | - - name: Telegram Notify (Failure) |
118 | | - |
119 | | - if: failure() |
120 | | - with: |
121 | | - to: ${{ secrets.TELEGRAM_DEPLOY_CHAT_ID }} |
122 | | - token: ${{ secrets.TELEGRAM_DEPLOY_TOKEN }} |
123 | | - format: markdown |
124 | | - message: | |
125 | | - 🚨 Deploy of the application from repository [${{ steps.lower-repo.outputs.repository }}](https://github.com/${{ steps.lower-repo.outputs.repository }}) on ${{ env.APP_ENV }} has failed. |
126 | | -
|
127 | | - 🏗️ [GitHub Actions Build](https://github.com/${{ steps.lower-repo.outputs.repository }}/actions/runs/${{ github.run_id }}) |
128 | | - 🐳 [Image](https://ghcr.io/${{ steps.lower-repo.outputs.repository }}:${{ env.GITHUB_SHA_SHORT }}) |
129 | | - 🔗 [Link](https://${{ env.APP_DOMAIN }}) |
| 40 | + workflow: deploy-v2.yml |
| 41 | + ref: main |
| 42 | + repo: ${{ vars.DEPLOY_REPO }} |
| 43 | + token: ${{ secrets.DEPLOY_REPO_TOKEN }} |
| 44 | + inputs: | |
| 45 | + { |
| 46 | + "app_name": "${{ vars.APP_NAME }}", |
| 47 | + "image_tag": "${{ needs.build.outputs.image_tag }}", |
| 48 | + "image_digest": "${{ needs.build.outputs.image_digest }}" |
| 49 | + } |
0 commit comments