-
-
Notifications
You must be signed in to change notification settings - Fork 761
159 lines (139 loc) · 5.39 KB
/
docker-alpha-push.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
name: Build and Push Alpha Image
on:
pull_request:
types: [opened, synchronize, reopened]
workflow_dispatch:
inputs:
pr_number:
description: 'PR number to build'
required: false
type: string
permissions:
pull-requests: write
contents: read
env:
INSTANCE_NAME: pr-${{ github.event.pull_request.number || github.event.inputs.pr_number }}
INSTANCE_DOMAIN: pr-${{ github.event.pull_request.number || github.event.inputs.pr_number }}
DISPLAY_NAME: "teable-pr-${{ github.event.pull_request.number || github.event.inputs.pr_number }}"
MAIN_IMAGE_REPOSITORY: registry.cn-shenzhen.aliyuncs.com/teable/teable
DB_MIGRATE_IMAGE_REPOSITORY: registry.cn-shenzhen.aliyuncs.com/teable/teable-db-migrate
IMAGE_TAG: alpha-pr-${{ github.event.pull_request.number || github.event.inputs.pr_number }}
jobs:
create-deployment-button:
if: github.event_name == 'pull_request'
runs-on: ubuntu-latest
steps:
- name: Create deployment comment
uses: actions/github-script@v6
with:
script: |
const prNumber = context.payload.pull_request.number;
const commentBody = `
## 🚀 Deploy Preview Environment
Click the button below to deploy a preview environment for this PR:
[![Deploy Preview](https://img.shields.io/badge/Deploy-Preview-blue?style=for-the-badge)](${process.env.GITHUB_SERVER_URL}/${context.repo.owner}/${context.repo.name}/actions/workflows/${context.workflow.replace('.github/workflows/','')}/trigger?ref=${context.ref})
`;
const comments = await github.rest.issues.listComments({
...context.repo,
issue_number: prNumber
});
const existingComment = comments.data.find(comment =>
comment.body.includes('Deploy Preview Environment')
);
if (existingComment) {
await github.rest.issues.updateComment({
...context.repo,
comment_id: existingComment.id,
body: commentBody
});
} else {
await github.rest.issues.createComment({
...context.repo,
issue_number: prNumber,
body: commentBody
});
}
build-push:
if: github.event_name == 'workflow_dispatch'
runs-on: ubuntu-latest
strategy:
matrix:
include:
- image: teable
file: Dockerfile
- image: teable-db-migrate
file: Dockerfile.migrate
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Login to Ali container registry
uses: docker/login-action@v3
with:
registry: registry.cn-shenzhen.aliyuncs.com
username: ${{ secrets.ALI_DOCKER_USERNAME }}
password: ${{ secrets.ALI_DOCKER_PASSWORD }}
- uses: actions/setup-node@v4
with:
node-version: 20.9.0
- name: ⚙️ Install zx
run: npm install -g zx
- name: ⚙️ Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: |
registry.cn-shenzhen.aliyuncs.com/teable/${{ matrix.image }}
tags: |
type=raw,value=alpha-pr-${{ github.event.inputs.pr_number }}
type=sha,format=long
- name: 📦 Build and push
run: |
zx scripts/build-image.mjs --file=dockers/teable/${{ matrix.file }} \
--build-arg="ENABLE_CSP=false" \
--tag="${{ steps.meta.outputs.tags }}" \
--platform="linux/amd64" \
--push
deploy:
needs: build-push
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Create deployment YAML
run: |
cp .github/workflows/templates/preview-template.yaml deploy.yaml
sed -i "s/__INSTANCE_NAME__/${{ env.INSTANCE_NAME }}/g" deploy.yaml
sed -i "s/__INSTANCE_DOMAIN__/${{ env.INSTANCE_DOMAIN }}/g" deploy.yaml
sed -i "s/__MAIN_IMAGE_REPOSITORY__/${{ env.MAIN_IMAGE_REPOSITORY }}/g" deploy.yaml
sed -i "s/__IMAGE_TAG__/${{ env.IMAGE_TAG }}/g" deploy.yaml
sed -i "s/__DISPLAY_NAME__/${{ env.DISPLAY_NAME }}/g" deploy.yaml
- name: Apply deploy job
uses: actions-hub/kubectl@master
env:
KUBE_CONFIG: ${{ secrets.KUBE_CONFIG }}
with:
args: apply -f deploy.yaml
- name: Rollout status
uses: actions-hub/kubectl@master
env:
KUBE_CONFIG: ${{ secrets.KUBE_CONFIG }}
with:
args: rollout status deployment/teable-${{ env.INSTANCE_NAME }} --timeout=300s
- name: Create deployment status comment
if: always()
uses: actions/github-script@v6
with:
script: |
const success = ${{ job.status == 'success' }};
const deploymentUrl = 'https://${{ env.INSTANCE_DOMAIN }}.sealosgzg.site';
const status = success ? '✅ Success' : '❌ Failed';
const commentBody = `
## Deployment Status: ${status}
${success ? `🔗 Preview URL: ${deploymentUrl}` : ''}
`;
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.name,
issue_number: ${{ github.event.inputs.pr_number }},
body: commentBody
});