16
16
pull_request :
17
17
branches : ['master']
18
18
19
+ env :
20
+ REGISTRY : ghcr.io
21
+ IMAGE_REPOSITORY : $(echo ${{ github.repository }} | tr '[:upper:]' '[:lower:]')
22
+ DOCKER_COMPOSE_DIR : /opt/pomelo
23
+
24
+ permissions :
25
+ contents : read
26
+ packages : write
27
+
19
28
jobs :
20
29
cache :
21
30
runs-on : ubuntu-latest
52
61
- name : Build Submodules
53
62
if : steps.submodules-cache.outputs.cache-hit != 'true'
54
63
run : yarn build:submodules
55
- build :
64
+ docker- build :
56
65
needs : cache
57
66
runs-on : ubuntu-latest
58
67
environment :
65
74
- name : Login to GitHub Container Registry
66
75
uses : docker/login-action@v1
67
76
with :
68
- registry : ghcr.io # 声明镜像源
77
+ registry : ${{ env.REGISTRY }} # 声明镜像源
69
78
username : ${{ github.actor }} # 当前github 用户名
70
- password : ${{ secrets.GITHUB_TOKEN }} # 需要去 https://github.com/settings/tokens 生成一个 名为 token,注意此token 需要读写 packages 等权限
79
+ password : ${{ secrets.GITHUB_TOKEN }} # 当前github token
71
80
- name : Set up Node.js
72
81
uses : actions/setup-node@v2
73
82
with :
@@ -91,13 +100,11 @@ jobs:
91
100
- name : Build the Docker image
92
101
run :
93
102
| # 使用 上一步写的 Dockerfile 构建镜像并发布到私有仓库; 发布完成可以去 https://github.com/aceHubert?tab=packages 查看
94
- docker build . --file Dockerfile --target deploy --cache-from ghcr.io/${{ env.IMAGE_REPOSITORY }}:latest --build-arg BUILD_IGNORE=true --build-arg BUILDKIT_INLINE_CACHE=1 --tag ghcr.io/${{ env.IMAGE_REPOSITORY }}:latest --tag ghcr.io/${{ env.IMAGE_REPOSITORY }}:${{ github.run_id }}-${{ github.ref_name }}
95
- docker push ghcr.io/${{ env.IMAGE_REPOSITORY }}:${{ github.run_id }}-${{ github.ref_name }}
96
- docker push ghcr.io/${{ env.IMAGE_REPOSITORY }}:latest
97
- env :
98
- IMAGE_REPOSITORY : $(echo ${{ github.repository }} | tr '[:upper:]' '[:lower:]')
99
- deploy :
100
- # needs: build
103
+ docker build . --file Dockerfile --target deploy --cache-from ${{ env.REGISTRY }}/${{ env.IMAGE_REPOSITORY }}:latest --build-arg BUILD_IGNORE=true --build-arg BUILDKIT_INLINE_CACHE=1 --tag ${{ env.REGISTRY }}/${{ env.IMAGE_REPOSITORY }}:latest --tag ${{ env.REGISTRY }}/${{ env.IMAGE_REPOSITORY }}:${{ github.run_id }}
104
+ docker push ${{ env.REGISTRY }}/${{ env.IMAGE_REPOSITORY }}:${{ github.run_id }}
105
+ docker push ${{ env.REGISTRY }}/${{ env.IMAGE_REPOSITORY }}:latest
106
+ ssh-deploy :
107
+ needs : docker-build
101
108
runs-on : ubuntu-latest
102
109
environment :
103
110
name : ' production'
@@ -110,10 +117,8 @@ jobs:
110
117
key : ${{ secrets.SSH_KEY }} # 服务器密码;需要去仓库的 settings/secrets/actions 去创建
111
118
port : ${{ secrets.SSH_PORT }} # 服务器端口,默认22;需要去仓库的 settings/secrets/actions 去创建
112
119
script : | # 重启更新镜像
113
- cd ${{ env.CONTENT_DIR }}
114
- echo "IMAGE_REPOSITORY=ghcr.io/ ${{ env.IMAGE_REPOSITORY }}: ${{ github.run_id }}- ${{ github.ref_name }}" > .env.${{ github.run_id }}
115
- docker login -u ${{ github.actor }} -p ${{ secrets.GITHUB_TOKEN }} https://ghcr.io
120
+ cd ${{ env.DOCKER_COMPOSE_DIR }}
121
+ echo "IMAGE_REPOSITORY=${{ env.REGISTRY }}/ ${{ env.IMAGE_REPOSITORY }}: ${{ github.run_id }}" > .env.${{ github.run_id }}
122
+ docker login -u ${{ github.actor }} -p ${{ secrets.GITHUB_TOKEN }} https://${{ env.REGISTRY }}
116
123
docker compose --env-file .env.${{ github.run_id }} up --force-recreate -d
117
- env :
118
- CONTENT_DIR : /opt/pomelo
119
- IMAGE_REPOSITORY : $(echo ${{ github.repository }} | tr '[:upper:]' '[:lower:]')
124
+ rm -f .env.${{ github.run_id }}
0 commit comments