替换图片链接 #11
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/ | |
# 设置目录及其子文件的所有权和权限 | |
chown -R 1000:1000 /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 |