ci/cd optimization

Signed-off-by: jagger <cossjie@foxmail.com>
This commit is contained in:
jagger 2024-11-11 20:22:29 +08:00
parent 44aca8bc0e
commit b95b65aaf1
2 changed files with 2 additions and 16 deletions

View File

@ -43,14 +43,6 @@ jobs:
run: |
echo "::set-output name=build_time::$(date +'%Y%m%d%H%M%S')"
- name: Cache Go modules
uses: actions/cache@v3
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Build and push multi-arch image
run: |
docker buildx build \

View File

@ -1,22 +1,16 @@
# 第一阶段:构建二进制文件
FROM --platform=$BUILDPLATFORM golang:alpine AS builder
WORKDIR /app
COPY go.mod go.sum ./
COPY . .
# 缓存依赖项
ENV GO111MODULE=on GOPROXY=https://goproxy.cn,direct
RUN go mod download
COPY . .
ARG TARGETOS
ARG TARGETARCH
# 使用 GOOS 和 GOARCH 环境变量来构建不同架构的二进制文件
RUN CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH go build -ldflags="-w -s" -o pcm-core-api
# 第二阶段:构建最终镜像
FROM --platform=$TARGETPLATFORM alpine:latest
WORKDIR /app