Skip to content

Commit 9888495

Browse files
committed
chore: fix for docker-deploy
1 parent 6b950c5 commit 9888495

File tree

2 files changed

+88
-59
lines changed

2 files changed

+88
-59
lines changed

.github/workflows/docker-deploy.yml

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
name: deploy to docker hub
2+
3+
on:
4+
push:
5+
tags:
6+
- "v*.*.*"
7+
branches:
8+
- 'master'
9+
10+
jobs:
11+
docker-deploy:
12+
runs-on: ubuntu-latest
13+
steps:
14+
-
15+
name: Checkout
16+
uses: actions/checkout@v4
17+
-
18+
name: Set up QEMU
19+
uses: docker/setup-qemu-action@v3
20+
-
21+
name: Set up Docker Buildx
22+
uses: docker/setup-buildx-action@v3
23+
# 提供 docker 元数据,构建 docker images tag 时使用
24+
-
25+
name: Extract Docker metadata
26+
id: meta
27+
uses: docker/metadata-action@v4
28+
with:
29+
images: ${{ env.IMAGE_NAME }}
30+
tags: |
31+
# set latest tag for default branch
32+
type=raw,value=latest,enable={{is_default_branch}}
33+
# tag event
34+
type=ref,enable=true,priority=600,prefix=,suffix=,event=tag
35+
36+
# -
37+
# name: Login to Docker Hub
38+
# uses: docker/login-action@v3
39+
# with:
40+
# # registry: ghcr.io # 声明镜像源
41+
# username: ${{ secrets.DOCKER_USERNAME }}
42+
# password: ${{ secrets.DOCKER_PASSWORD }} # ${{ secrets.HUB_GITHUB_TOKEN }}
43+
# -
44+
# name: Build and push
45+
# uses: docker/build-push-action@v5
46+
# with:
47+
# push: true
48+
# tags: ${{ steps.meta.outputs.tags }}:latest
49+
50+
-
51+
name: Build and push Docker Image
52+
run: |
53+
docker build -t ${{ env.REGISTRY }}/${{ steps.meta.outputs.tags }} -f Dockerfile .
54+
docker login --username=${{ secrets.DOCKER_USERNAME }} --password ${{ secrets.DOCKER_PASSWORD }} ${{ env.REGISTRY }}
55+
docker push ${{ env.REGISTRY }}/${{ steps.meta.outputs.tags }}
56+
57+
# -
58+
# name: Deploy Docker App
59+
# uses: appleboy/ssh-action@master
60+
# env:
61+
# TZ: Asia/Shanghai
62+
# with:
63+
# host: ${{ secrets.HOST }}
64+
# username: ${{ secrets.HOST_USERNAME }}
65+
# key: ${{ secrets.HOST_SSHKEY }}
66+
# port: ${{ secrets.PORT }}
67+
# script: |
68+
# wget https://raw.githubusercontent.com/${{ env.IMAGE_NAME }}/master/docker/docker-compose.yml
69+
# ls
70+
# cat docker-compose.yml
71+
# docker-compose down -v
72+
# docker-compose up -d
Lines changed: 16 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# see: https://help.github.com/actions/language-and-framework-guides/publishing-nodejs-packages
22

3-
name: Publish Package to npmjs
3+
name: Publish to NPM
44

55
on:
66
push:
@@ -23,39 +23,40 @@ jobs:
2323
concurrency:
2424
group: ${{ github.workflow }}-${{ github.ref }}
2525
steps:
26-
- name: Checkout
27-
uses: actions/checkout@v3
26+
-
27+
name: Checkout
28+
uses: actions/checkout@v4
2829
with:
2930
submodules: 'recursive'
30-
31-
- name: Install Node.js
31+
-
32+
name: Install Node.js
3233
uses: actions/setup-node@v3
3334
with:
3435
node-version: 18
3536
registry-url: https://registry.npmjs.com
36-
37-
- uses: pnpm/action-setup@v2
37+
-
3838
name: Install pnpm
39+
uses: pnpm/action-setup@v2
3940
id: pnpm-install
4041
with:
4142
version: 8
4243
run_install: false
43-
44-
- name: Get pnpm store directory
44+
-
45+
name: Get pnpm store directory
4546
id: pnpm-cache
4647
shell: bash
4748
run: |
4849
echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT
49-
50-
- uses: actions/cache@v3
50+
-
5151
name: Setup pnpm cache
52+
uses: actions/cache@v3
5253
with:
5354
path: ${{ steps.pnpm-cache.outputs.STORE_PATH }}
5455
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
5556
restore-keys: |
5657
${{ runner.os }}-pnpm-store-
57-
58-
- name: Install dependencies
58+
-
59+
name: Install dependencies
5960
run: pnpm install --no-frozen-lockfile --ignore-scripts
6061

6162
# - name: Build and npm-publish
@@ -74,8 +75,8 @@ jobs:
7475
# with:
7576
# github_token: ${{ secrets.GITHUB_TOKEN }}
7677
# publish_dir: ./docs
77-
78-
- name: Github Release
78+
-
79+
name: Github Release
7980
uses: softprops/action-gh-release@v1
8081
if: startsWith(github.ref, 'refs/tags/')
8182
with:
@@ -88,47 +89,3 @@ jobs:
8889
# ${{ secrets.ReleaseZipName }}.zip
8990
# LICENSE
9091

91-
docker-deploy:
92-
runs-on: ubuntu-latest
93-
steps:
94-
95-
# 提供 docker 元数据,构建 docker images tag 时使用
96-
- name: Extract Docker metadata
97-
id: meta
98-
uses: docker/metadata-action@v4
99-
with:
100-
images: ${{ env.IMAGE_NAME }}
101-
tags: |
102-
# set latest tag for default branch
103-
type=raw,value=latest,enable={{is_default_branch}}
104-
# tag event
105-
type=ref,enable=true,priority=600,prefix=,suffix=,event=tag
106-
107-
# 构建镜像 使用 docker/Build-And-push@v5 插件有问题
108-
- uses: actions/checkout@v2
109-
- name: Build Docker Image
110-
run: |
111-
docker build -t ${{ env.REGISTRY }}/${{ steps.meta.outputs.tags }} -f ./docker/nginx/Dockerfile .
112-
- name: Push Docker Image
113-
run: |
114-
docker login --username=${{ secrets.DOCKER_USERNAME }} --password ${{ secrets.DOCKER_PASSWORD }} ${{ env.REGISTRY }}
115-
docker push ${{ env.REGISTRY }}/${{ steps.meta.outputs.tags }}
116-
117-
# 运行 docker 服务
118-
# 另外一种选择是通过 scp 将文件传到指定服务器,完成 docker-compose 启动
119-
# - name: Deploy Docker App
120-
# uses: appleboy/ssh-action@master
121-
# env:
122-
# TZ: Asia/Shanghai
123-
# with:
124-
# host: ${{ secrets.HOST }}
125-
# username: ${{ secrets.HOST_USERNAME }}
126-
# key: ${{ secrets.HOST_SSHKEY }}
127-
# port: ${{ secrets.PORT }}
128-
# script: |
129-
# # 获取 docker-compose 文件
130-
# wget https://raw.githubusercontent.com/${{ env.IMAGE_NAME }}/master/docker/docker-compose.yml
131-
# ls
132-
# cat docker-compose.yml
133-
# docker-compose down -v
134-
# docker-compose up -d

0 commit comments

Comments
 (0)