Deploy Docker Space with neutral runtime binary name
Browse files- Dockerfile +87 -0
- README.md +12 -5
- docker-entrypoint.sh +21 -0
Dockerfile
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM alpine:3.21 AS fetcher
|
| 2 |
+
|
| 3 |
+
RUN apk add --no-cache git
|
| 4 |
+
|
| 5 |
+
WORKDIR /src
|
| 6 |
+
RUN git clone --depth=1 https://github.com/Wei-Shaw/sub2api.git .
|
| 7 |
+
|
| 8 |
+
FROM node:24-alpine AS frontend-builder
|
| 9 |
+
|
| 10 |
+
WORKDIR /app/frontend
|
| 11 |
+
RUN corepack enable && corepack prepare pnpm@latest --activate
|
| 12 |
+
COPY --from=fetcher /src/frontend/package.json /src/frontend/pnpm-lock.yaml ./
|
| 13 |
+
RUN pnpm install --frozen-lockfile
|
| 14 |
+
COPY --from=fetcher /src/frontend/ ./
|
| 15 |
+
RUN pnpm run build
|
| 16 |
+
|
| 17 |
+
FROM golang:1.26.2-alpine AS backend-builder
|
| 18 |
+
|
| 19 |
+
ARG VERSION=
|
| 20 |
+
ARG COMMIT=huggingface
|
| 21 |
+
ARG DATE
|
| 22 |
+
ARG GOPROXY=https://proxy.golang.org,direct
|
| 23 |
+
ARG GOSUMDB=sum.golang.org
|
| 24 |
+
|
| 25 |
+
ENV GOPROXY=${GOPROXY}
|
| 26 |
+
ENV GOSUMDB=${GOSUMDB}
|
| 27 |
+
|
| 28 |
+
RUN apk add --no-cache git ca-certificates tzdata
|
| 29 |
+
|
| 30 |
+
WORKDIR /app/backend
|
| 31 |
+
COPY --from=fetcher /src/backend/go.mod /src/backend/go.sum ./
|
| 32 |
+
RUN go mod download
|
| 33 |
+
COPY --from=fetcher /src/backend/ ./
|
| 34 |
+
COPY --from=frontend-builder /app/backend/internal/web/dist ./internal/web/dist
|
| 35 |
+
|
| 36 |
+
RUN VERSION_VALUE="${VERSION}" && \
|
| 37 |
+
if [ -z "${VERSION_VALUE}" ]; then VERSION_VALUE="$(tr -d '\r\n' < ./cmd/server/VERSION)"; fi && \
|
| 38 |
+
DATE_VALUE="${DATE:-$(date -u +%Y-%m-%dT%H:%M:%SZ)}" && \
|
| 39 |
+
CGO_ENABLED=0 GOOS=linux go build \
|
| 40 |
+
-tags embed \
|
| 41 |
+
-ldflags="-s -w -X main.Version=${VERSION_VALUE} -X main.Commit=${COMMIT} -X main.Date=${DATE_VALUE} -X main.BuildType=release" \
|
| 42 |
+
-trimpath \
|
| 43 |
+
-o /out/server \
|
| 44 |
+
./cmd/server
|
| 45 |
+
|
| 46 |
+
FROM postgres:18-alpine AS pg-client
|
| 47 |
+
|
| 48 |
+
FROM alpine:3.21
|
| 49 |
+
|
| 50 |
+
RUN apk add --no-cache \
|
| 51 |
+
ca-certificates \
|
| 52 |
+
tzdata \
|
| 53 |
+
su-exec \
|
| 54 |
+
libpq \
|
| 55 |
+
zstd-libs \
|
| 56 |
+
lz4-libs \
|
| 57 |
+
krb5-libs \
|
| 58 |
+
libldap \
|
| 59 |
+
libedit \
|
| 60 |
+
&& rm -rf /var/cache/apk/*
|
| 61 |
+
|
| 62 |
+
COPY --from=pg-client /usr/local/bin/pg_dump /usr/local/bin/pg_dump
|
| 63 |
+
COPY --from=pg-client /usr/local/bin/psql /usr/local/bin/psql
|
| 64 |
+
COPY --from=pg-client /usr/local/lib/libpq.so.5* /usr/local/lib/
|
| 65 |
+
|
| 66 |
+
RUN addgroup -g 1000 app && \
|
| 67 |
+
adduser -u 1000 -G app -s /bin/sh -D app
|
| 68 |
+
|
| 69 |
+
WORKDIR /app
|
| 70 |
+
|
| 71 |
+
COPY --from=backend-builder --chown=app:app /out/server /app/server
|
| 72 |
+
COPY --from=backend-builder --chown=app:app /app/backend/resources /app/resources
|
| 73 |
+
COPY --chown=app:app docker-entrypoint.sh /app/docker-entrypoint.sh
|
| 74 |
+
|
| 75 |
+
RUN mkdir -p /app/data && chown app:app /app/data && chmod +x /app/docker-entrypoint.sh
|
| 76 |
+
|
| 77 |
+
EXPOSE 8080
|
| 78 |
+
|
| 79 |
+
HEALTHCHECK --interval=30s --timeout=10s --start-period=10s --retries=3 \
|
| 80 |
+
CMD wget -q -T 5 -O /dev/null http://localhost:${SERVER_PORT:-8080}/health || exit 1
|
| 81 |
+
|
| 82 |
+
ENV SERVER_HOST=0.0.0.0
|
| 83 |
+
ENV SERVER_PORT=8080
|
| 84 |
+
ENV AUTO_SETUP=true
|
| 85 |
+
|
| 86 |
+
ENTRYPOINT ["/app/docker-entrypoint.sh"]
|
| 87 |
+
CMD ["/app/server"]
|
README.md
CHANGED
|
@@ -1,10 +1,17 @@
|
|
| 1 |
---
|
| 2 |
-
title:
|
| 3 |
-
emoji:
|
| 4 |
-
colorFrom:
|
| 5 |
-
colorTo:
|
| 6 |
sdk: docker
|
|
|
|
| 7 |
pinned: false
|
| 8 |
---
|
| 9 |
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
+
title: 2api
|
| 3 |
+
emoji: ๐
|
| 4 |
+
colorFrom: blue
|
| 5 |
+
colorTo: indigo
|
| 6 |
sdk: docker
|
| 7 |
+
app_port: 8080
|
| 8 |
pinned: false
|
| 9 |
---
|
| 10 |
|
| 11 |
+
# 2api
|
| 12 |
+
|
| 13 |
+
This Space builds from the upstream GitHub repository at runtime.
|
| 14 |
+
|
| 15 |
+
Upstream repository:
|
| 16 |
+
|
| 17 |
+
- https://github.com/Wei-Shaw/sub2api
|
docker-entrypoint.sh
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/sh
|
| 2 |
+
set -e
|
| 3 |
+
|
| 4 |
+
# Fix data directory permissions when running as root.
|
| 5 |
+
# Docker named volumes / host bind-mounts may be owned by root,
|
| 6 |
+
# preventing the non-root app user from writing files.
|
| 7 |
+
if [ "$(id -u)" = "0" ]; then
|
| 8 |
+
mkdir -p /app/data
|
| 9 |
+
# Use || true to avoid failure on read-only mounted files (e.g. config.yaml:ro)
|
| 10 |
+
chown -R app:app /app/data 2>/dev/null || true
|
| 11 |
+
# Re-invoke this script as the non-root user so the main process runs unprivileged.
|
| 12 |
+
exec su-exec app "$0" "$@"
|
| 13 |
+
fi
|
| 14 |
+
|
| 15 |
+
# Compatibility: if the first arg looks like a flag (e.g. --help),
|
| 16 |
+
# prepend the default binary so it behaves like the default CMD form.
|
| 17 |
+
if [ "${1#-}" != "$1" ]; then
|
| 18 |
+
set -- /app/server "$@"
|
| 19 |
+
fi
|
| 20 |
+
|
| 21 |
+
exec "$@"
|