-
Notifications
You must be signed in to change notification settings - Fork 0
86 lines (68 loc) · 2.23 KB
/
docker.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
name: Docker
on:
push:
branches:
- main
tags:
- v*
env:
IMAGE_NAME: random-api-go
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: woodchen
password: ${{ secrets.ACCESS_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v5
with:
context: .
file: Dockerfile
push: true
tags: woodchen/${{ env.IMAGE_NAME }}:latest
platforms: linux/amd64,linux/arm64
- name: Create artifact
run: |
zip -r public.zip public
- name: Deploy public directory to server
uses: appleboy/scp-action@master
with:
host: ${{ secrets.SERVER_HOST }}
username: root
key: ${{ secrets.SERVER_SSH_KEY }}
source: "public.zip"
target: "/tmp"
- name: Execute deployment commands
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.SERVER_HOST }}
username: root
key: ${{ secrets.SERVER_SSH_KEY }}
script: |
# 解压文件
unzip -o /tmp/public.zip -d /tmp/public_temp
# 删除目标目录中的现有文件
rm -rf /opt/1panel/docker/compose/random-api-go/public/*
# 移动新文件到目标目录
mv -f /tmp/public_temp/public/* /opt/1panel/docker/compose/random-api-go/public/
# 设置目录及其子文件的所有权和权限
chmod -R 0755 /opt/1panel/docker/compose/random-api-go/public
# 清理临时文件
rm /tmp/public.zip
rm -rf /tmp/public_temp
# 拉取镜像
docker pull woodchen/random-api-go:latest
# 停止并删除容器
docker stop random-api-go || true
docker rm random-api-go || true
# 启动容器
docker compose -f /opt/1panel/docker/compose/random-api-go/docker-compose.yml up -d