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