feat: 更新 Dockerfile 和工作流以支持手动触发构建和版本解析
This commit is contained in:
24
.github/workflows/docker-release.yml
vendored
24
.github/workflows/docker-release.yml
vendored
@@ -4,6 +4,12 @@ on:
|
||||
push:
|
||||
tags:
|
||||
- "v*"
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
image_tag:
|
||||
description: "Tag to apply when running manually (e.g. dev-build)"
|
||||
required: false
|
||||
default: dev-build
|
||||
|
||||
env:
|
||||
GHCR_IMAGE: ghcr.io/${{ github.repository_owner }}/any-hub
|
||||
@@ -21,6 +27,17 @@ jobs:
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Resolve version tag
|
||||
id: vars
|
||||
env:
|
||||
INPUT_TAG: ${{ inputs.image_tag }}
|
||||
run: |
|
||||
VERSION="$GITHUB_REF_NAME"
|
||||
if [ "$GITHUB_REF_TYPE" != "tag" ] || [ -z "$VERSION" ]; then
|
||||
VERSION="${INPUT_TAG:-manual-${GITHUB_RUN_NUMBER}}"
|
||||
fi
|
||||
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
|
||||
|
||||
- name: Set up QEMU
|
||||
uses: docker/setup-qemu-action@v3
|
||||
|
||||
@@ -49,8 +66,9 @@ jobs:
|
||||
${{ env.DOCKERHUB_IMAGE }}
|
||||
tags: |
|
||||
type=ref,event=tag
|
||||
type=semver,pattern={{version}}
|
||||
type=semver,pattern={{major}}.{{minor}}
|
||||
type=semver,pattern={{version}},event=tag
|
||||
type=semver,pattern={{major}}.{{minor}},event=tag
|
||||
type=raw,value=${{ steps.vars.outputs.version }},enable=${{ github.event_name == 'workflow_dispatch' }}
|
||||
labels: |
|
||||
org.opencontainers.image.source=${{ github.repository }}
|
||||
|
||||
@@ -63,5 +81,5 @@ jobs:
|
||||
tags: ${{ steps.meta.outputs.tags }}
|
||||
labels: ${{ steps.meta.outputs.labels }}
|
||||
build-args: |
|
||||
VERSION=${{ github.ref_name }}
|
||||
VERSION=${{ steps.vars.outputs.version }}
|
||||
COMMIT=${{ github.sha }}
|
||||
|
||||
@@ -6,10 +6,12 @@ ARG TARGETARCH=amd64
|
||||
ARG VERSION=dev
|
||||
ARG COMMIT=dev
|
||||
WORKDIR /src
|
||||
COPY go.mod go.sum ./
|
||||
RUN --mount=type=cache,target=/go/pkg/mod go mod download
|
||||
COPY . .
|
||||
RUN go mod download \
|
||||
RUN --mount=type=cache,target=/root/.cache/go-build \
|
||||
CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH \
|
||||
go build -trimpath -ldflags "-s -w -X github.com/any-hub/any-hub/internal/version.Version=${VERSION} -X github.com/any-hub/any-hub/internal/version.Commit=${COMMIT}" -o /out/any-hub /src/cmd/any-hub
|
||||
go build -trimpath -ldflags "-s -w -X github.com/any-hub/any-hub/internal/version.Version=${VERSION} -X github.com/any-hub/any-hub/internal/version.Commit=${COMMIT}" -o /out/any-hub ./cmd/any-hub
|
||||
|
||||
FROM gcr.io/distroless/static-debian12:nonroot
|
||||
COPY --from=builder /out/any-hub /usr/local/bin/any-hub
|
||||
|
||||
Reference in New Issue
Block a user