-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
44 lines (32 loc) · 1.19 KB
/
Dockerfile
File metadata and controls
44 lines (32 loc) · 1.19 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
# Build stage
FROM --platform=$BUILDPLATFORM golang:1.21-alpine AS builder
WORKDIR /app
# Copy go mod file (go.sum may not exist for projects with no external deps)
COPY go.mod* go.sum* ./
# Download dependencies
RUN go mod download
# Copy source code
COPY main.go healthcheck.go ./
COPY json/ ./json/
COPY images/ ./images/
# Build the binaries with optimizations for the target platform
ARG TARGETOS TARGETARCH BASE_FQDN=coollabs.io
RUN CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH go build -a -installsuffix cgo -o coollabs-cdn main.go
RUN CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH go build -a -installsuffix cgo -o healthcheck healthcheck.go
# Final stage
FROM scratch
# Copy CA certificates for HTTPS requests
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
# Copy the binaries from builder stage
COPY --from=builder /app/coollabs-cdn /coollabs-cdn
COPY --from=builder /app/healthcheck /healthcheck
# Set the base FQDN environment variable
ARG BASE_FQDN=coollabs.io
ENV BASE_FQDN=$BASE_FQDN
# Expose port 80
EXPOSE 80
# Add healthcheck
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
CMD ["/healthcheck"]
# Run the binary
CMD ["/coollabs-cdn"]