Hotfix: Improve final docker image
This commit is contained in:
58
Dockerfile
58
Dockerfile
@@ -1,49 +1,55 @@
|
|||||||
FROM --platform=$BUILDPLATFORM golang:1.22 as builder
|
# Stage 1: Build binaries
|
||||||
|
FROM --platform=$BUILDPLATFORM golang:1.22-alpine as builder
|
||||||
|
|
||||||
ARG TARGETPLATFORM
|
ARG TARGETOS
|
||||||
ARG BUILDPLATFORM
|
ARG TARGETARCH
|
||||||
ARG VERSION
|
ARG VERSION
|
||||||
ARG CHANNEL
|
ARG CHANNEL
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
COPY go.mod go.sum ./
|
COPY go.mod go.sum ./
|
||||||
RUN go mod download
|
RUN --mount=type=cache,target=/go/pkg/mod \
|
||||||
|
go mod download -x
|
||||||
|
|
||||||
ADD . .
|
COPY . .
|
||||||
|
|
||||||
RUN CGO_ENABLED=0 GOOS=$(echo $TARGETPLATFORM | cut -d '/' -f1) GOARCH=$(echo $TARGETPLATFORM | cut -d '/' -f2) go build \
|
# Build main binary
|
||||||
-ldflags="-X github.com/sirrobot01/debrid-blackhole/pkg/version.Version=${VERSION} -X github.com/sirrobot01/debrid-blackhole/pkg/version.Channel=${CHANNEL}" \
|
RUN --mount=type=cache,target=/go/pkg/mod \
|
||||||
|
--mount=type=cache,target=/root/.cache/go-build \
|
||||||
|
CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH \
|
||||||
|
go build -trimpath \
|
||||||
|
-ldflags="-w -s -X github.com/sirrobot01/debrid-blackhole/pkg/version.Version=${VERSION} -X github.com/sirrobot01/debrid-blackhole/pkg/version.Channel=${CHANNEL}" \
|
||||||
-o /blackhole
|
-o /blackhole
|
||||||
|
|
||||||
RUN CGO_ENABLED=0 GOOS=$(echo $TARGETPLATFORM | cut -d '/' -f1) GOARCH=$(echo $TARGETPLATFORM | cut -d '/' -f2) go build \
|
# Build healthcheck (optimized)
|
||||||
|
RUN --mount=type=cache,target=/go/pkg/mod \
|
||||||
|
--mount=type=cache,target=/root/.cache/go-build \
|
||||||
|
CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH \
|
||||||
|
go build -trimpath -ldflags="-w -s" \
|
||||||
-o /healthcheck cmd/healthcheck/main.go
|
-o /healthcheck cmd/healthcheck/main.go
|
||||||
|
|
||||||
FROM alpine as logsetup
|
# Stage 2: Create directory structure
|
||||||
ARG PUID=1000
|
FROM alpine:3.19 as dirsetup
|
||||||
ARG PGID=1000
|
RUN mkdir -p /logs && \
|
||||||
RUN addgroup -g $PGID appuser && \
|
|
||||||
adduser -D -u $PUID -G appuser appuser && \
|
|
||||||
mkdir -p /logs && \
|
|
||||||
chmod 777 /logs && \
|
chmod 777 /logs && \
|
||||||
touch /logs/decypharr.log && \
|
touch /logs/decypharr.log && \
|
||||||
chmod 666 /logs/decypharr.log
|
chmod 666 /logs/decypharr.log
|
||||||
|
|
||||||
FROM gcr.io/distroless/static-debian12:latest
|
# Stage 3: Final image
|
||||||
COPY --from=builder /blackhole /blackhole
|
FROM gcr.io/distroless/static-debian12:nonroot
|
||||||
COPY --from=builder /healthcheck /healthcheck
|
|
||||||
COPY --from=logsetup /etc/passwd /etc/passwd
|
|
||||||
COPY --from=logsetup /etc/group /etc/group
|
|
||||||
COPY --from=logsetup /logs /logs
|
|
||||||
|
|
||||||
|
# Copy binaries
|
||||||
|
COPY --from=builder --chown=nonroot:nonroot /blackhole /blackhole
|
||||||
|
COPY --from=builder --chown=nonroot:nonroot /healthcheck /healthcheck
|
||||||
|
|
||||||
|
# Copy pre-made directory structure
|
||||||
|
COPY --from=dirsetup --chown=nonroot:nonroot /logs /logs
|
||||||
|
|
||||||
|
# Metadata
|
||||||
ENV LOG_PATH=/logs
|
ENV LOG_PATH=/logs
|
||||||
|
|
||||||
EXPOSE 8181 8282
|
EXPOSE 8181 8282
|
||||||
|
|
||||||
VOLUME ["/app"]
|
VOLUME ["/app"]
|
||||||
|
USER nonroot:nonroot
|
||||||
USER appuser
|
|
||||||
|
|
||||||
HEALTHCHECK CMD ["/healthcheck"]
|
HEALTHCHECK CMD ["/healthcheck"]
|
||||||
|
|
||||||
CMD ["/blackhole", "--config", "/app/config.json"]
|
CMD ["/blackhole", "--config", "/app/config.json"]
|
||||||
Reference in New Issue
Block a user