Skip to content

pref:完善 deploy.yml #2

pref:完善 deploy.yml

pref:完善 deploy.yml #2

Workflow file for this run

name: Deploy to Server
on:
push:
branches:
- main
env:
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: 设置 Docker Buildx
uses: docker/setup-buildx-action@v3
- name: 登录 Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: 构建 & 推送镜像
id: build-and-push
uses: docker/build-push-action@v6
with:
push: true
tags: lihazi/weilai:latest
- name: 拉取镜像 & 部署
run: |
ssh -o StrictHostKeyChecking=no [email protected] << 'EOF'
docker pull lihazi/weilai:latest
docker stop weilai-container || true
docker rm weilai-container || true
docker run -d --name weilai-container -p 80:80 lihazi/weilai:latest
EOF