Skip to content

Commit 6682ae4

Browse files
authored
chore: update deployment pipelines (#418)
1 parent fbe5f38 commit 6682ae4

File tree

4 files changed

+127
-218
lines changed

4 files changed

+127
-218
lines changed

.github/workflows/build.yml

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
name: Build
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
ref_name:
7+
required: true
8+
type: string
9+
image_file:
10+
required: false
11+
default: './Dockerfile'
12+
type: string
13+
component:
14+
required: false
15+
type: string
16+
outputs:
17+
image_repo:
18+
value: ${{ jobs.build.outputs.image_repo }}
19+
image_tag:
20+
value: ${{ jobs.build.outputs.image_tag }}
21+
image_digest:
22+
value: ${{ jobs.build.outputs.image_digest }}
23+
component:
24+
value: ${{ jobs.build.outputs.component }}
25+
26+
27+
jobs:
28+
build:
29+
runs-on: ubuntu-latest
30+
31+
permissions:
32+
packages: write
33+
contents: read
34+
35+
env:
36+
REF_NAME: ${{ inputs.ref_name || github.ref_name }}
37+
38+
outputs:
39+
image_repo: ghcr.io/${{ steps.params.outputs.repository }}
40+
image_tag: ${{ steps.params.outputs.tag }}
41+
image_digest: ${{ steps.build.outputs.digest }}
42+
component: ${{ steps.params.outputs.component }}
43+
44+
steps:
45+
- name: Compute params
46+
uses: actions/github-script@v7
47+
id: params
48+
env:
49+
COMPONENT: ${{ inputs.component }}
50+
with:
51+
script: |
52+
core.setOutput('tag', process.env.REF_NAME);
53+
core.setOutput('component', process.env.COMPONENT);
54+
let repository = process.env.GITHUB_REPOSITORY.toLowerCase();
55+
if (process.env.COMPONENT) {
56+
repository += '/' + process.env.COMPONENT
57+
}
58+
core.setOutput('repository', repository);
59+
60+
- name: Checkout code
61+
uses: actions/checkout@v4
62+
with:
63+
fetch-depth: 0
64+
submodules: recursive
65+
ref: ${{ env.REF_NAME }}
66+
67+
- name: Log in to GitHub Container Registry
68+
uses: docker/login-action@v3
69+
with:
70+
registry: ghcr.io
71+
username: ${{ github.actor }}
72+
password: ${{ secrets.GITHUB_TOKEN }}
73+
74+
- name: Extract metadata (tags, labels) for Docker
75+
id: meta
76+
uses: docker/metadata-action@v5
77+
with:
78+
images: ghcr.io/${{ steps.params.outputs.repository }}
79+
github-token: ${{ secrets.GITHUB_TOKEN }}
80+
context: 'git'
81+
tags: |
82+
type=sha
83+
type=sha,format=long
84+
type=raw,value=${{ steps.params.outputs.tag }}
85+
86+
- name: Build and push Docker image
87+
uses: docker/build-push-action@v6
88+
id: build
89+
with:
90+
context: .
91+
file: ${{ inputs.image_file }}
92+
push: true
93+
tags: ${{ steps.meta.outputs.tags }}
94+
labels: ${{ steps.meta.outputs.labels }}

.github/workflows/deploy.yml

Lines changed: 33 additions & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -1,129 +1,49 @@
1-
name: Deploy to Kubernetes
1+
name: Deploy build
22

33
on:
44
push:
55
branches:
66
- main
7-
- canary
87
- staging
9-
- td-nature
10-
- td-book
118
- td-art
129

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+
1323
jobs:
1424
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
2527
permissions:
2628
packages: write
2729
contents: read
30+
with:
31+
ref_name: ${{ inputs.ref_name || github.ref_name }}
2832

33+
deploy:
34+
needs: build
35+
runs-on: ubuntu-latest
2936
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
5839
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-
uses: appleboy/[email protected]
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-
uses: appleboy/[email protected]
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+
}

.github/workflows/remove-td.yml

Lines changed: 0 additions & 42 deletions
This file was deleted.

.github/workflows/rollback.yml

Lines changed: 0 additions & 63 deletions
This file was deleted.

0 commit comments

Comments
 (0)