This commit is contained in:
Tomas Dvorak
2025-11-21 08:44:44 +01:00
parent c941313fd5
commit f5b6f83974
108 changed files with 8642 additions and 5871 deletions
+31 -8
View File
@@ -1,32 +1,55 @@
# Build stage
FROM golang:1.24.5-alpine AS builder
FROM golang:1.24.5-bullseye AS builder
ARG REMBG_ENABLED=true
WORKDIR /app
# Install dependencies
RUN apk add --no-cache git
# Install build dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
git \
build-essential \
&& if [ "$REMBG_ENABLED" = "true" ]; then apt-get install -y --no-install-recommends python3 python3-pip python3-dev; fi \
&& rm -rf /var/lib/apt/lists/*
# Download dependencies
# Download Go dependencies
COPY go.mod go.sum ./
RUN go mod download
# Copy source code
COPY . .
# Install Python dependencies for rembg
COPY scripts/requirements-rembg.txt .
RUN --mount=type=cache,target=/root/.cache/pip \
if [ "$REMBG_ENABLED" = "true" ]; then pip3 install -r requirements-rembg.txt; else echo "REMBG disabled, skipping pip install"; fi
# Build the application
RUN CGO_ENABLED=0 GOOS=linux go build -o fotbal-club
# Final stage
FROM alpine:latest
FROM debian:bullseye-slim
ARG REMBG_ENABLED=true
WORKDIR /app
# Install runtime dependencies (TLS certs, timezone data) and create non-root user
RUN apk add --no-cache ca-certificates tzdata \
&& addgroup -S app && adduser -S app -G app \
# Install runtime dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
ca-certificates \
tzdata \
&& if [ "$REMBG_ENABLED" = "true" ]; then apt-get install -y --no-install-recommends python3 python3-pip python3-dev libgl1-mesa-glx libglib2.0-0; fi \
&& rm -rf /var/lib/apt/lists/*
# Create non-root user
RUN addgroup --system app && adduser --system --ingroup app app \
&& mkdir -p /app/uploads /app/cache \
&& chown -R app:app /app
# Install rembg and its dependencies
COPY --from=builder /app/requirements-rembg.txt .
RUN --mount=type=cache,target=/root/.cache/pip \
if [ "$REMBG_ENABLED" = "true" ]; then pip3 install -r requirements-rembg.txt; fi \
&& rm -f requirements-rembg.txt
# Copy the binary from builder
COPY --from=builder /app/fotbal-club ./fotbal-club