-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathDockerfile
More file actions
57 lines (43 loc) · 1.69 KB
/
Copy pathDockerfile
File metadata and controls
57 lines (43 loc) · 1.69 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
52
53
54
55
56
57
# syntax=docker/dockerfile:1.7
FROM --platform=$BUILDPLATFORM golang:1.22-alpine AS build
WORKDIR /src
ARG TARGETOS
ARG TARGETARCH
ARG TARGETVARIANT
ARG VERSION=dev
ARG COMMIT=none
ARG DATE=unknown
COPY go.mod go.sum ./
RUN go mod download
COPY *.go ./
COPY static ./static
RUN set -eux; \
if [ "$TARGETARCH" = "arm" ]; then export GOARM="${TARGETVARIANT#v}"; fi; \
CGO_ENABLED=0 GOOS="$TARGETOS" GOARCH="$TARGETARCH" \
go build -trimpath \
-ldflags "-s -w -X main.version=$VERSION -X main.commit=$COMMIT -X main.date=$DATE" \
-o /out/opencode2api .
FROM alpine:3.20
RUN set -eux; \
apk add --no-cache ca-certificates su-exec tzdata wget; \
addgroup -S opencode2api; \
adduser -S -G opencode2api -h /data opencode2api; \
mkdir -p /app /data; \
chown -R opencode2api:opencode2api /data; \
wget -qO /tmp/sing-box.tar.gz "https://github.com/SagerNet/sing-box/releases/download/v1.13.16/sing-box-1.13.16-linux-amd64-musl.tar.gz"; \
tar -xzf /tmp/sing-box.tar.gz -C /tmp; \
cp /tmp/sing-box-1.13.16-linux-amd64-musl/sing-box /usr/local/bin/sing-box; \
chmod +x /usr/local/bin/sing-box; \
rm -rf /tmp/sing-box.tar.gz /tmp/sing-box-1.13.16-linux-amd64-musl
WORKDIR /data
COPY --from=build /out/opencode2api /usr/local/bin/opencode2api
COPY config.example.json /app/config.example.json
COPY docker/entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh
ENV OPENCODE2API_PORT=52000 \
OPENCODE2API_CONFIG=/data/config.json \
OPENCODE2API_PASSWORD=123456
EXPOSE 52000
HEALTHCHECK --interval=30s --timeout=5s --start-period=15s --retries=3 \
CMD wget -qO- "http://127.0.0.1:${OPENCODE2API_PORT}/health" >/dev/null || exit 1
ENTRYPOINT ["/entrypoint.sh"]