t
This commit is contained in:
@@ -5,7 +5,7 @@ on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
# 定义工作流
|
||||
|
||||
jobs:
|
||||
build-and-deploy:
|
||||
runs-on: ubuntu
|
||||
@@ -13,9 +13,7 @@ jobs:
|
||||
image: catthehacker/ubuntu:act-latest
|
||||
steps:
|
||||
- name: 检出代码
|
||||
run: |
|
||||
pwd
|
||||
ls -la
|
||||
uses: actions/checkout@v3
|
||||
|
||||
# 1. 登录 Docker Registry (已跳过,无密码模式)1
|
||||
# - name: 登录到私有 Registry
|
||||
@@ -27,31 +25,48 @@ jobs:
|
||||
|
||||
# 2. 构建并推送镜像
|
||||
- name: 配置 Buildx
|
||||
run: |
|
||||
cat > buildkitd.toml << 'EOF'
|
||||
[registry."docker.io"]
|
||||
mirrors = ["https://docker.m.daocloud.io", "https://dockerproxy.com"]
|
||||
[registry."121.43.104.161:6500"]
|
||||
http = true
|
||||
insecure = true
|
||||
EOF
|
||||
docker buildx create --name ci-builder --use --driver docker-container --driver-opt network=host --buildkitd-flags "--allow-insecure-entitlement security.insecure --allow-insecure-entitlement network.host" --config ./buildkitd.toml
|
||||
docker buildx inspect --bootstrap
|
||||
uses: docker/setup-buildx-action@v2
|
||||
with:
|
||||
driver-opts: network=host
|
||||
buildkitd-flags: --allow-insecure-entitlement security.insecure --allow-insecure-entitlement network.host
|
||||
config-inline: |
|
||||
[registry."docker.io"]
|
||||
mirrors = ["https://docker.m.daocloud.io", "https://dockerproxy.com"]
|
||||
[registry."121.43.104.161:6500"]
|
||||
http = true
|
||||
insecure = true
|
||||
|
||||
- name: 构建并推送 Docker 镜像
|
||||
run: |
|
||||
docker buildx build --push --tag 121.43.104.161:6500/quant-speed-page:latest --allow security.insecure --allow network.host .
|
||||
uses: docker/build-push-action@v4
|
||||
with:
|
||||
context: .
|
||||
push: true
|
||||
# 镜像标签,推送到私有 Registry
|
||||
tags: 121.43.104.161:6500/quant-speed-page:latest
|
||||
|
||||
# 3. 部署到服务器
|
||||
- name: 部署到服务器
|
||||
# uses: appleboy/ssh-action@master
|
||||
# 换用 garygrossgarten/github-action-ssh,它不依赖外部下载
|
||||
uses: garygrossgarten/github-action-ssh@release
|
||||
env:
|
||||
QUANT_PASSWORD: ${{ secrets.QUANT_PASSWORD }}
|
||||
run: |
|
||||
apt-get update -y
|
||||
apt-get install -y sshpass
|
||||
sshpass -p "$QUANT_PASSWORD" ssh -o StrictHostKeyChecking=no -p 22 root@121.40.192.128 '
|
||||
with:
|
||||
host: 121.40.192.128
|
||||
port: 22
|
||||
username: root
|
||||
password: ${{ secrets.QUANT_PASSWORD }}
|
||||
command: |
|
||||
# 停止并删除旧容器
|
||||
docker stop quant-speed-page || true
|
||||
docker rm quant-speed-page || true
|
||||
|
||||
# 拉取最新镜像
|
||||
docker pull 121.43.104.161:6500/quant-speed-page:latest
|
||||
docker run -d --name quant-speed-page --restart unless-stopped -p 8080:80 121.43.104.161:6500/quant-speed-page:latest
|
||||
'
|
||||
|
||||
# 启动新容器/
|
||||
docker run -d \
|
||||
--name quant-speed-page \
|
||||
--restart unless-stopped \
|
||||
-p 8080:80 \
|
||||
121.43.104.161:6500/quant-speed-page:latest
|
||||
|
||||
Reference in New Issue
Block a user