-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDockerfile
More file actions
51 lines (36 loc) · 1.28 KB
/
Dockerfile
File metadata and controls
51 lines (36 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# ================================
# Stage 1: Build
# ================================
FROM golang:1.24-alpine AS builder
RUN apk add --no-cache git ca-certificates tzdata
# Install swag for Swagger generation
RUN go install github.com/swaggo/swag/cmd/swag@latest
WORKDIR /src
# Cache dependencies
COPY go.mod go.sum ./
RUN go mod download
# Copy source and build
COPY . .
ARG VERSION=dev
ARG GIT_COMMIT=unknown
ARG BUILD_TIME=unknown
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build \
-ldflags="-s -w -X main.Version=${VERSION} -X main.BuildTime=${BUILD_TIME} -X main.GitCommit=${GIT_COMMIT}" \
-o /bin/osdl .
# ================================
# Stage 2: Runtime
# ================================
FROM alpine:3.21
RUN apk add --no-cache ca-certificates tzdata wget \
&& cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
&& echo "Asia/Shanghai" > /etc/timezone \
&& apk del tzdata
RUN addgroup -S osdl && adduser -S -G osdl osdl
COPY --from=builder /bin/osdl /usr/local/bin/osdl
USER osdl
# Default ports: HTTP 8080, Schedule 8081, gRPC 9090
EXPOSE 8080 8081 9090
HEALTHCHECK --interval=15s --timeout=3s --start-period=10s --retries=3 \
CMD wget --quiet --tries=1 --spider http://localhost:8080/api/health/live || exit 1
ENTRYPOINT ["osdl"]
CMD ["apiserver"]