fix: add versioning support to Docker build process
This commit is contained in:
parent
3800d1034d
commit
65c130f538
4
.github/workflows/release.yml
vendored
4
.github/workflows/release.yml
vendored
@ -48,6 +48,8 @@ jobs:
|
|||||||
file: Dockerfile
|
file: Dockerfile
|
||||||
platforms: linux/amd64,linux/arm64
|
platforms: linux/amd64,linux/arm64
|
||||||
push: true
|
push: true
|
||||||
|
build-args: |
|
||||||
|
VERSION=${{ env.VERSION }}
|
||||||
tags: |
|
tags: |
|
||||||
${{ secrets.DOCKER_USERNAME }}/${{ env.IMAGE_NAME }}:latest
|
${{ secrets.DOCKER_USERNAME }}/${{ env.IMAGE_NAME }}:latest
|
||||||
${{ secrets.DOCKER_USERNAME }}/${{ env.IMAGE_NAME }}:${{ env.VERSION }}-${{ env.GIT_SHA }}
|
${{ secrets.DOCKER_USERNAME }}/${{ env.IMAGE_NAME }}:${{ env.VERSION }}-${{ env.GIT_SHA }}
|
||||||
@ -60,6 +62,8 @@ jobs:
|
|||||||
file: Dockerfile
|
file: Dockerfile
|
||||||
platforms: linux/amd64,linux/arm64
|
platforms: linux/amd64,linux/arm64
|
||||||
push: true
|
push: true
|
||||||
|
build-args: |
|
||||||
|
VERSION=${{ env.VERSION }}
|
||||||
tags: |
|
tags: |
|
||||||
${{ secrets.DOCKER_USERNAME }}/${{ env.IMAGE_NAME }}:beta
|
${{ secrets.DOCKER_USERNAME }}/${{ env.IMAGE_NAME }}:beta
|
||||||
${{ secrets.DOCKER_USERNAME }}/${{ env.IMAGE_NAME }}:${{ env.VERSION }}-${{ env.GIT_SHA }}
|
${{ secrets.DOCKER_USERNAME }}/${{ env.IMAGE_NAME }}:${{ env.VERSION }}-${{ env.GIT_SHA }}
|
||||||
|
|||||||
10
Dockerfile
10
Dockerfile
@ -4,6 +4,7 @@ FROM golang:alpine AS builder
|
|||||||
LABEL stage=gobuilder
|
LABEL stage=gobuilder
|
||||||
|
|
||||||
ARG TARGETARCH
|
ARG TARGETARCH
|
||||||
|
ARG VERSION
|
||||||
ENV CGO_ENABLED=0 GOOS=linux GOARCH=${TARGETARCH}
|
ENV CGO_ENABLED=0 GOOS=linux GOARCH=${TARGETARCH}
|
||||||
|
|
||||||
# Combine apk commands into one to reduce layer size
|
# Combine apk commands into one to reduce layer size
|
||||||
@ -18,8 +19,9 @@ RUN go mod download
|
|||||||
# Copy the rest of the application code
|
# Copy the rest of the application code
|
||||||
COPY . .
|
COPY . .
|
||||||
|
|
||||||
# Build the binary with optimization flags to reduce binary size
|
# Build the binary with version and build time
|
||||||
RUN go build -ldflags="-s -w" -o /app/ppanel ppanel.go
|
RUN BUILD_TIME=$(date -u +"%Y-%m-%dT%H:%M:%SZ") && \
|
||||||
|
go build -ldflags="-s -w -X 'github.com/perfect-panel/server/pkg/constant.Version=${VERSION}' -X 'github.com/perfect-panel/server/pkg/constant.BuildTime=${BUILD_TIME}'" -o /app/ppanel ppanel.go
|
||||||
|
|
||||||
# Final minimal image
|
# Final minimal image
|
||||||
FROM scratch
|
FROM scratch
|
||||||
@ -34,11 +36,11 @@ ENV TZ=Asia/Shanghai
|
|||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
COPY --from=builder /app/ppanel /app/ppanel
|
COPY --from=builder /app/ppanel /app/ppanel
|
||||||
COPY --from=builder /etc /app/etc
|
COPY --from=builder /build/etc /app/etc
|
||||||
|
|
||||||
# Expose the port (optional)
|
# Expose the port (optional)
|
||||||
EXPOSE 8080
|
EXPOSE 8080
|
||||||
|
|
||||||
# Specify entry point
|
# Specify entry point
|
||||||
ENTRYPOINT ["/app/ppanel"]
|
ENTRYPOINT ["/app/ppanel"]
|
||||||
CMD ["run", "--config", "etc/ppanel.yaml"]
|
CMD ["run", "--config", "etc/ppanel.yaml"]
|
||||||
Loading…
x
Reference in New Issue
Block a user