添加 GitHub 自动部署 Linux 二进制工作流

- 新增 .github/workflows/deploy-linux.yml 支持自动构建和部署
- 添加 .goreleaser.yml 配置多平台发布
- 支持 build-only/deploy-staging/deploy-production 模式
- 包含 Docker 镜像自动构建
This commit is contained in:
EUForest 2025-11-24 18:10:00 +08:00
parent f0f29deef1
commit 5d18c7bb7d
2 changed files with 139 additions and 18 deletions

View File

@ -3,16 +3,12 @@ name: Build and Deploy Linux Binary
on:
push:
branches: [ main, master ]
paths:
- '**'
- '!.github/workflows/**'
- '.github/workflows/deploy-linux.yml'
workflow_dispatch:
inputs:
mode:
description: 'Operation mode'
required: true
default: 'build'
default: 'build-only'
type: choice
options:
- build-only
@ -32,11 +28,6 @@ permissions:
env:
BINARY_NAME: ppanel-server
CONFIG_PATH: /app/etc/ppanel.yaml
DEPLOY_PATH: /opt/ppanel
SERVICE_NAME: ppanel-server
BACKUP_PATH: /opt/ppanel/backups
LOG_PATH: /opt/ppanel/logs
jobs:
build:
@ -66,7 +57,7 @@ jobs:
if [ "${{ github.event_name }}" = "release" ]; then
VERSION=${GITHUB_REF#refs/tags/}
elif [ -n "${{ github.event.inputs.version }}" ]; then
VERSION=${{ github.event.inputs.version }}
VERSION="${{ github.event.inputs.version }}"
else
VERSION=$(git describe --tags --always --dirty)
fi
@ -213,7 +204,7 @@ jobs:
name: Deploy to Staging
runs-on: ubuntu-latest
needs: build
if: (github.event.inputs.mode == 'deploy-staging' || github.event.inputs.mode == 'build-and-deploy') && env.STAGING_HOST != ''
if: (github.event.inputs.mode == 'deploy-staging' || github.event.inputs.mode == 'build-and-deploy') && secrets.STAGING_HOST != ''
steps:
- name: Download build artifacts
@ -309,8 +300,8 @@ jobs:
deploy-production:
name: Deploy to Production
runs-on: ubuntu-latest
needs: [build, deploy-staging]
if: (github.event.inputs.mode == 'deploy-production' || github.event.inputs.mode == 'build-and-deploy' || github.event_name == 'release') && env.PRODUCTION_HOST != ''
needs: build
if: (github.event.inputs.mode == 'deploy-production' || github.event.inputs.mode == 'build-and-deploy' || github.event_name == 'release') && secrets.PRODUCTION_HOST != ''
steps:
- name: Download build artifacts
@ -415,7 +406,7 @@ jobs:
name: Build Docker Image
runs-on: ubuntu-latest
needs: build
if: (secrets.DOCKER_USERNAME && secrets.DOCKER_PASSWORD) && (github.event_name == 'release' || github.event.inputs.mode == 'build-and-deploy')
if: secrets.DOCKER_USERNAME != '' && secrets.DOCKER_PASSWORD != '' && (github.event_name == 'release' || github.event.inputs.mode == 'build-and-deploy')
steps:
- name: Checkout repository

130
.goreleaser.yml Normal file
View File

@ -0,0 +1,130 @@
version: 2
before:
hooks:
- go mod tidy
- go generate ./...
builds:
- env:
- CGO_ENABLED=0
goos:
- linux
- darwin
- windows
goarch:
- "386"
- amd64
- arm64
ignore:
- goos: darwin
goarch: "386"
binary: ppanel-server
ldflags:
- -s -w
- -X "github.com/perfect-panel/server/pkg/constant.Version={{.Version}}"
- -X "github.com/perfect-panel/server/pkg/constant.BuildTime={{.Date}}"
- -X "github.com/perfect-panel/server/pkg/constant.GitCommit={{.Commit}}"
main: ./ppanel.go
archives:
- format: tar.gz
name_template: >-
{{ .ProjectName }}-
{{- .Version }}-
{{- title .Os }}-
{{- if eq .Arch "amd64" }}x86_64
{{- else if eq .Arch "386" }}i386
{{- else }}{{ .Arch }}{{ end }}
{{- if .Arm }}v{{ .Arm }}{{ end }}
files:
- LICENSE
- etc/*
format_overrides:
- goos: windows
format: zip
checksum:
name_template: "checksums.txt"
snapshot:
name_template: "{{ incpatch .Version }}-next"
changelog:
sort: asc
use: github
filters:
exclude:
- "^docs:"
- "^test:"
- "^chore:"
- Merge pull request
groups:
- title: Features
regexp: "^.*feat[(\\w)]*:+.*$"
order: 0
- title: 'Bug fixes'
regexp: "^.*fix[(\\w)]*:+.*$"
order: 1
- title: Others
order: 999
dockers:
- image_templates:
- "{{ .Env.DOCKER_USERNAME }}/ppanel-server:{{ .Tag }}"
- "{{ .Env.DOCKER_USERNAME }}/ppanel-server:v{{ .Major }}"
- "{{ .Env.DOCKER_USERNAME }}/ppanel-server:v{{ .Major }}.{{ .Minor }}"
- "{{ .Env.DOCKER_USERNAME }}/ppanel-server:latest"
dockerfile: Dockerfile
build_flag_templates:
- "--pull"
- "--label=org.opencontainers.image.created={{.Date}}"
- "--label=org.opencontainers.image.title={{.ProjectName}}"
- "--label=org.opencontainers.image.revision={{.FullCommit}}"
- "--label=org.opencontainers.image.version={{.Version}}"
- "--platform=linux/amd64"
use: docker
extra_files:
- etc/
- image_templates:
- "{{ .Env.DOCKER_USERNAME }}/ppanel-server:{{ .Tag }}-arm64"
- "{{ .Env.DOCKER_USERNAME }}/ppanel-server:v{{ .Major }}.{{ .Minor }}-arm64"
dockerfile: Dockerfile
build_flag_templates:
- "--pull"
- "--label=org.opencontainers.image.created={{.Date}}"
- "--label=org.opencontainers.image.title={{.ProjectName}}"
- "--label=org.opencontainers.image.revision={{.FullCommit}}"
- "--label=org.opencontainers.image.version={{.Version}}"
- "--platform=linux/arm64"
use: docker
goarch: arm64
extra_files:
- etc/
docker_signs:
- cmd: cosign
args:
- "sign"
- "${artifact}@${digest}"
env:
- COSIGN_EXPERIMENTAL=1
release:
github:
owner: perfect-panel
name: server
draft: false
prerelease: auto
name_template: "{{.ProjectName}} v{{.Version}}"
header: |
## ppanel-server {{.Version}}
Welcome to this new release!
footer: |
Docker images are available at:
- `{{ .Env.DOCKER_USERNAME }}/ppanel-server:{{ .Tag }}`
- `{{ .Env.DOCKER_USERNAME }}/ppanel-server:latest`
For more information, visit our documentation.