Skip to content

Commit b1301c9

Browse files
author
Assistant
committed
chore: update Docker configuration with latest versions and best practices
- Upgrade Alpine from 3.22.0 to 3.23.3 (security fixes) - Add multi-platform build support (ARM64, ARM, x86) - Add Go module caching for faster builds - Add non-root user for security - Add health check configuration - Add resource limits in docker-compose - Add logging configuration with rotation - Add ca-certificates for HTTPS support - Add volume mount as read-only for config
1 parent 0468654 commit b1301c9

File tree

2 files changed

+45
-14
lines changed

2 files changed

+45
-14
lines changed

Dockerfile

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,48 @@
1-
FROM golang:1.26-alpine AS builder
1+
FROM --platform=$BUILDPLATFORM golang:1.26-alpine AS builder
22

33
WORKDIR /app
44

5+
RUN apk add --no-cache git make
6+
57
COPY go.mod go.sum ./
68

7-
RUN go mod download
9+
RUN --mount=type=cache,target=/go/pkg/mod \
10+
go mod download
811

912
COPY . .
1013

1114
ARG VERSION=dev
1215
ARG COMMIT=none
1316
ARG BUILD_DATE=unknown
17+
TARGETOS=${TARGETOS:-linux}
18+
TARGETARCH=${TARGETARCH:-amd64}
1419

15-
RUN CGO_ENABLED=0 GOOS=linux go build -ldflags="-s -w -X 'main.Version=${VERSION}-plus' -X 'main.Commit=${COMMIT}' -X 'main.BuildDate=${BUILD_DATE}'" -o ./CLIProxyAPIPlus ./cmd/server/
20+
RUN CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH go build \
21+
-ldflags="-s -w -X 'main.Version=${VERSION}-plus' -X 'main.Commit=${COMMIT}' -X 'main.BuildDate=${BUILD_DATE}'" \
22+
-o ./CLIProxyAPIPlus ./cmd/server/
1623

17-
FROM alpine:3.22.0
24+
FROM alpine:3.23.3
1825

19-
RUN apk add --no-cache tzdata
26+
RUN addgroup -g 1000 appgroup && \
27+
adduser -u 1000 -G appgroup -s /bin/sh -D appuser
2028

21-
RUN mkdir /CLIProxyAPI
29+
RUN apk add --no-cache tzdata ca-certificates
2230

23-
COPY --from=builder ./app/CLIProxyAPIPlus /CLIProxyAPI/CLIProxyAPIPlus
31+
RUN mkdir -p /CLIProxyAPI && chown -R appuser:appgroup /CLIProxyAPI
2432

25-
COPY config.example.yaml /CLIProxyAPI/config.example.yaml
33+
COPY --from=builder --chown=appuser:appgroup /app/CLIProxyAPIPlus /CLIProxyAPI/CLIProxyAPIPlus
34+
COPY --chown=appuser:appgroup config.example.yaml /CLIProxyAPI/config.example.yaml
2635

2736
WORKDIR /CLIProxyAPI
2837

29-
EXPOSE 8317
38+
USER appuser
3039

31-
ENV TZ=Asia/Shanghai
40+
EXPOSE 8317 8085 1455 54545 51121 11451
3241

42+
ENV TZ=Asia/Shanghai
3343
RUN cp /usr/share/zoneinfo/${TZ} /etc/localtime && echo "${TZ}" > /etc/timezone
3444

35-
CMD ["./CLIProxyAPIPlus"]
45+
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
46+
CMD wget --no-verbose --tries=1 --spider http://localhost:8317/health || exit 1
47+
48+
CMD ["./CLIProxyAPIPlus"]

docker-compose.yml

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,9 @@ services:
1010
COMMIT: ${COMMIT:-none}
1111
BUILD_DATE: ${BUILD_DATE:-unknown}
1212
container_name: cli-proxy-api-plus
13-
# env_file:
14-
# - .env
1513
environment:
1614
DEPLOY: ${DEPLOY:-}
15+
TZ: ${TZ:-Asia/Shanghai}
1716
ports:
1817
- "8317:8317"
1918
- "8085:8085"
@@ -22,7 +21,26 @@ services:
2221
- "51121:51121"
2322
- "11451:11451"
2423
volumes:
25-
- ${CLI_PROXY_CONFIG_PATH:-./config.yaml}:/CLIProxyAPI/config.yaml
24+
- ${CLI_PROXY_CONFIG_PATH:-./config.yaml}:/CLIProxyAPI/config.yaml:ro
2625
- ${CLI_PROXY_AUTH_PATH:-./auths}:/root/.cli-proxy-api
2726
- ${CLI_PROXY_LOG_PATH:-./logs}:/CLIProxyAPI/logs
27+
healthcheck:
28+
test: ["CMD", "wget", "--no-verbose", "--tries=1", "--spider", "http://localhost:8317/health"]
29+
interval: 30s
30+
timeout: 10s
31+
retries: 3
32+
start_period: 10s
33+
deploy:
34+
resources:
35+
limits:
36+
cpus: '${CLI_PROXY_CPU_LIMIT:-1}'
37+
memory: ${CLI_PROXY_MEMORY_LIMIT:-512M}
38+
reservations:
39+
cpus: '${CLI_PROXY_CPU_RESERVE:-0.1}'
40+
memory: ${CLI_PROXY_MEMORY_RESERVE:-128M}
2841
restart: unless-stopped
42+
logging:
43+
driver: json-file
44+
options:
45+
max-size: "10m"
46+
max-file: "3"

0 commit comments

Comments
 (0)