mirror of
https://github.com/woodchen-ink/Q58Bot.git
synced 2025-07-18 05:42:06 +08:00
78 lines
2.0 KiB
YAML
78 lines
2.0 KiB
YAML
name: Build and Push Docker Image
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- main
|
|
tags:
|
|
- v*
|
|
|
|
env:
|
|
IMAGE_NAME: q58bot
|
|
|
|
jobs:
|
|
build:
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Set up Go
|
|
uses: actions/setup-go@v4
|
|
with:
|
|
go-version: '1.23' # 使用你项目需要的 Go 版本
|
|
|
|
- name: Build for amd64
|
|
run: CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o main-amd64 .
|
|
|
|
- name: Build for arm64
|
|
run: CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -o main-arm64 .
|
|
|
|
- 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 Docker image
|
|
uses: docker/build-push-action@v5
|
|
with:
|
|
context: .
|
|
file: Dockerfile.multi
|
|
platforms: linux/amd64,linux/arm64
|
|
push: true
|
|
tags: |
|
|
woodchen/${{ env.IMAGE_NAME }}:latest
|
|
woodchen/${{ env.IMAGE_NAME }}:${{ github.sha }}
|
|
|
|
- name: Update Docker Hub description
|
|
uses: peter-evans/dockerhub-description@v4
|
|
with:
|
|
username: woodchen
|
|
password: ${{ secrets.ACCESS_TOKEN }}
|
|
repository: woodchen/${{ env.IMAGE_NAME }}
|
|
short-description: ${{ github.event.repository.description }}
|
|
|
|
- name: 部署到服务器
|
|
uses: appleboy/ssh-action@master
|
|
env:
|
|
DOCKER_IMAGE: woodchen/${{ env.IMAGE_NAME }}:latest
|
|
PROJECT_PATH: ${{ secrets.PROJECT_PATH }}
|
|
with:
|
|
host: ${{ secrets.SERVER_IP }}
|
|
username: root
|
|
key: ${{ secrets.SERVER_SSH_KEY }}
|
|
envs: DOCKER_IMAGE,PROJECT_PATH
|
|
script: |
|
|
docker pull $DOCKER_IMAGE
|
|
cd $PROJECT_PATH
|
|
docker compose down
|
|
docker compose up -d
|