Repository navigation
Expand file tree
/
Copy pathDockerfile
More file actions
58 lines (40 loc) · 1.5 KB
/
Copy pathDockerfile
File metadata and controls
58 lines (40 loc) · 1.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
# Use Debian-based Golang image for building
FROM golang:bookworm AS builder
# Install git and set working directory
RUN apt-get update && apt-get install -y --no-install-recommends git ca-certificates && \
rm -rf /var/lib/apt/lists/*
WORKDIR /app
# Build determinism and cache paths
RUN go env -w GOCACHE=/go-cache
RUN go env -w GOMODCACHE=/gomod-cache
# Copy local source code
COPY . .
# Pre-download modules so Go can populate go.sum entries for the new nostr module.
RUN --mount=type=cache,target=/gomod-cache --mount=type=cache,target=/go-cache \
go mod download
# Build the app; VERSION stamps the version the relay reports over NIP-11
ARG VERSION=dev
RUN --mount=type=cache,target=/gomod-cache --mount=type=cache,target=/go-cache \
go build -a -tags netgo -ldflags "-w -s -extldflags \"-static\" -X main.buildVersion=${VERSION}" -o sanctum .
# Final Alpine image (keeps latest tag intentionally)
FROM alpine:latest
ENV IMPORT_FLAG=false
# Add non-root user specification
RUN adduser -D -g '' nonroot
WORKDIR /app
# Copy Go application
COPY --from=builder /app/sanctum .
# Ensure the main executable has the correct permissions
RUN chmod +x /app/sanctum
# Copy the httml templates
COPY --from=builder /app/templates /app/templates
# Copy the entrypoint script
COPY entrypoint.sh /entrypoint.sh
# Ensure the entrypoint script has the correct permissions
RUN chmod +x /entrypoint.sh
# Set the entrypoint
ENTRYPOINT ["/entrypoint.sh"]
# Switch to non-root user
USER nonroot
# Expose port
EXPOSE 3355