-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathDockerfile
More file actions
75 lines (56 loc) · 2.5 KB
/
Dockerfile
File metadata and controls
75 lines (56 loc) · 2.5 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# Multi-stage build for Synkronus
# Stage 1: Build the Go application
# Pure Go build (PostgreSQL only, SQLite/CGO disabled by default)
FROM golang:1.26.0-alpine AS builder
# Install build dependencies (no C toolchain needed for pure Go build)
RUN apk add --no-cache git
# Set working directory
WORKDIR /app
# Copy go mod files
COPY go.mod go.sum ./
# Download dependencies
RUN go mod download
# Copy source code
COPY . .
# Build the application with version from build arg
# Version is automatically derived from git tags in CI and passed as build arg
# Defaults to a semantic version for local builds without tags (middleware requires semver)
ARG SYNKRONUS_VERSION=1.0.0
ENV CGO_ENABLED=0 GOOS=linux
RUN echo "Building Synkronus with version: ${SYNKRONUS_VERSION}" && \
go build -a -ldflags="-w -s -X github.com/opendataensemble/synkronus/pkg/version.version=${SYNKRONUS_VERSION}" -o synkronus ./cmd/synkronus
# Stage 2: Create minimal runtime image
FROM alpine:latest
# Install runtime dependencies (wget needed for container healthcheck)
RUN apk --no-cache add ca-certificates tzdata wget
# Create non-root user for security
RUN addgroup -g 1000 synkronus && \
adduser -D -u 1000 -G synkronus synkronus
# Set working directory
WORKDIR /app
# Copy binary from builder
COPY --from=builder /app/synkronus .
# Copy openapi directory for Swagger UI
COPY --from=builder /app/openapi /app/openapi
# Copy static directory for static files
COPY --from=builder /app/static /app/static
# Mount a volume at /app/data. Subdirs also created at runtime.
RUN mkdir -p /app/data/app-bundle/active /app/data/app-bundle/versions /app/data/attachments && \
chown -R synkronus:synkronus /app
# Switch to non-root user
USER synkronus
# Expose port (default 8080, configurable via PORT env var)
EXPOSE 8080
# Optional attachment image-processing defaults (override at runtime as needed):
# - SYNKRONUS_IMAGE_COMPRESSION_LEVEL: 0..10 (0 disables compression)
# - SYNKRONUS_IMAGE_MAX_WIDTH_PX / SYNKRONUS_IMAGE_MAX_HEIGHT_PX: bounding box (0 disables axis)
# - SYNKRONUS_IMAGE_APPLY_EXIF_ORIENTATION: true/false
ENV SYNKRONUS_IMAGE_COMPRESSION_LEVEL=0 \
SYNKRONUS_IMAGE_MAX_WIDTH_PX=0 \
SYNKRONUS_IMAGE_MAX_HEIGHT_PX=0 \
SYNKRONUS_IMAGE_APPLY_EXIF_ORIENTATION=true
# Health check
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
CMD wget --no-verbose --tries=1 -O - http://127.0.0.1:8080/health || wget --no-verbose --tries=1 -O - http://localhost:8080/health || exit 1
# Run the application
CMD ["./synkronus"]