mirror of
https://github.com/LiteyukiStudio/spage.git
synced 2026-01-25 21:22:10 +00:00
✨ 优化构建流程,调整 Dockerfile 以支持多架构二进制复制
This commit is contained in:
20
.github/workflows/build-aio.yaml
vendored
20
.github/workflows/build-aio.yaml
vendored
@@ -6,12 +6,8 @@ on:
|
||||
tags: [v*]
|
||||
|
||||
env:
|
||||
REGISTRY: ghcr.io
|
||||
IMAGE_NAME: <your-image-name>
|
||||
REPO_OWNER: ${{ github.repository_owner }}
|
||||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
BIN_OUT: build
|
||||
|
||||
REGISTRY_URLS: ghcr.io docker.io reg.liteyuki.org
|
||||
REGISTRY_USERS: ${{ secrets.GHCR_USER }} ${{ secrets.DOCKERHUB_USER }} ${{ secrets.LITEYUKIHARBOR_USER }}
|
||||
REGISTRY_TOKENS: ${{ secrets.GHCR_TOKEN }} ${{ secrets.DOCKERHUB_TOKEN }} ${{ secrets.LITEYUKIHARBOR_TOKEN }}
|
||||
@@ -66,19 +62,27 @@ jobs:
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: spage-${{ matrix.goos }}-${{ matrix.goarch }}
|
||||
path: ${{ env.BIN_OUT }}/${{ matrix.goos }}-${{ matrix.goarch }}/spage
|
||||
path: ${{ env.BIN_OUT }}/${{ matrix.goos }}-${{ matrix.goarch }}/spage*
|
||||
|
||||
publish:
|
||||
name: Publish Artifacts & Images
|
||||
runs-on: ubuntu-latest
|
||||
needs: build
|
||||
steps:
|
||||
- name: Download all artifacts
|
||||
# 下载所有产物用于 Release
|
||||
- name: Download all artifacts for release
|
||||
uses: actions/download-artifact@v4
|
||||
with:
|
||||
pattern: spage-*
|
||||
path: ${{ env.BIN_OUT }}
|
||||
|
||||
# 只下载 linux 产物用于镜像构建
|
||||
- name: Download linux artifacts for image
|
||||
uses: actions/download-artifact@v4
|
||||
with:
|
||||
pattern: spage-linux-*
|
||||
path: ${{ env.BIN_OUT }}
|
||||
|
||||
- name: Set version/tag
|
||||
id: version
|
||||
run: |
|
||||
@@ -108,7 +112,7 @@ jobs:
|
||||
IFS=' ' read -r -a tokens <<< "$REGISTRY_TOKENS"
|
||||
IFS=' ' read -r -a namespaces <<< "$REGISTRY_NAMESPACES"
|
||||
|
||||
# 只build一次镜像
|
||||
# 只build一次镜像,Dockerfile 只 COPY linux 产物
|
||||
docker build -t tmpimg:${TAG} .
|
||||
|
||||
for i in "${!urls[@]}"; do
|
||||
@@ -137,4 +141,4 @@ jobs:
|
||||
Release ${{ steps.version.outputs.tag }}
|
||||
Built from tag ${{ steps.version.outputs.tag }}
|
||||
files: |
|
||||
${{ env.BIN_OUT }}/**/spage
|
||||
${{ env.BIN_OUT }}/**/spage*
|
||||
31
Dockerfile
31
Dockerfile
@@ -1,32 +1,17 @@
|
||||
# build
|
||||
FROM golang:1.24.2-alpine3.21 AS builder
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
RUN apk --no-cache add build-base git tzdata
|
||||
|
||||
COPY go.mod go.sum ./
|
||||
|
||||
RUN go mod download
|
||||
|
||||
COPY . .
|
||||
|
||||
RUN CGO_ENABLED=1 GOOS=linux GOARCH=amd64 go build -o server \
|
||||
-ldflags="-X './config.CommitHash=$(git rev-parse HEAD)' \
|
||||
-X './config.BuildTime=$(date "+%Y-%m-%d %H:%M:%S")'" \
|
||||
./cmd/server
|
||||
|
||||
# production
|
||||
FROM alpine:latest AS prod
|
||||
FROM alpine:latest
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
RUN apk --no-cache add tzdata ca-certificates
|
||||
|
||||
COPY --from=builder /app/server /app/server
|
||||
# 使用 buildx 时自动注入 TARGETARCH 变量
|
||||
ARG TARGETARCH
|
||||
|
||||
# 复制对应架构的二进制
|
||||
COPY build/linux-${TARGETARCH}/spage /app/server
|
||||
|
||||
EXPOSE 8888
|
||||
|
||||
RUN chmod +x ./server
|
||||
RUN chmod +x /app/server
|
||||
|
||||
ENTRYPOINT ["./server"]
|
||||
ENTRYPOINT ["/app/server"]
|
||||
Reference in New Issue
Block a user