feat(ci/cd):自动构建镜像推送到docker hub

This commit is contained in:
qian committed 2026-05-25 23:57:19 +08:00
1 parent 5193e971fa
commit ded149ed2f
2 files changed
+56 -1

No files matched your search

+54
View File
@@ -0,0 +1,54 @@
name: Docker
on:
release:
types: [published]
env:
REGISTRY: docker.io
IMAGE_NAME: qianfree/team-api
jobs:
build-push:
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- uses: actions/checkout@v4
- 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: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Extract version
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=raw,value=latest
- name: Build and push
uses: docker/build-push-action@v6
with:
context: .
file: manifest/docker/Dockerfile
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
VERSION=${{ github.ref_name }}
cache-from: type=gha
cache-to: type=gha,mode=max
+2 -1
View File
@@ -47,7 +47,8 @@ COPY --from=frontend /build/web/admin/dist ./web/admin/dist
COPY --from=frontend /build/web/tenant/dist ./web/tenant/dist
ARG VERSION=dev
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 \
ARG TARGETARCH
RUN CGO_ENABLED=0 GOOS=linux GOARCH=${TARGETARCH} \
go build -tags embedweb -ldflags="-s -w -X github.com/qianfree/team-api/internal/consts.Version=${VERSION}" \
-o /app/team-api main.go