build: add docker image build entrypoint

This commit is contained in:
hy 2026-04-20 15:47:04 +08:00
parent 2fb3a1e5f5
commit e25b6acae3
3 changed files with 45 additions and 0 deletions

8
.dockerignore Normal file
View File

@ -0,0 +1,8 @@
.git
.gitignore
target
tmp
bin
dist
coverage
**/.DS_Store

22
Dockerfile Normal file
View File

@ -0,0 +1,22 @@
FROM golang:1.24 AS builder
ARG APP_VERSION="dev"
ENV CGO_ENABLED=0 GOOS=linux GOARCH=amd64
WORKDIR /src
COPY . .
RUN go build -trimpath -ldflags="-s -w" -o /out/week-star-job ./cmd/week-star-job
FROM alpine:3.20
ARG APP_VERSION="dev"
RUN apk add --no-cache ca-certificates wget
WORKDIR /application
COPY --from=builder /out/week-star-job /application/service
LABEL org.opencontainers.image.version="${APP_VERSION}"
RUN chmod +x /application/service
ENTRYPOINT ["/application/service"]

15
ci/build-image.sh Executable file
View File

@ -0,0 +1,15 @@
#!/usr/bin/env bash
set -euo pipefail
ROOT_DIR="$(CDPATH= cd -- "$(dirname -- "${BASH_SOURCE[0]}")/.." && pwd)"
IMAGE_REF="${1:-}"
APP_VERSION="${APP_VERSION:-${2:-dev}}"
DOCKER_PLATFORM="${DOCKER_PLATFORM:-linux/amd64}"
if [ -z "${IMAGE_REF}" ]; then
echo "usage: ci/build-image.sh <image-ref> [app-version]" >&2
exit 1
fi
cd "${ROOT_DIR}"
docker build --platform "${DOCKER_PLATFORM}" --build-arg "APP_VERSION=${APP_VERSION}" -t "${IMAGE_REF}" .