-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
38 lines (28 loc) · 1 KB
/
Dockerfile
File metadata and controls
38 lines (28 loc) · 1 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
FROM golang:1-alpine AS build
RUN apk add --update --no-cache make git
WORKDIR /build
# Copy go.mod and go.sum first for better layer caching
COPY go.mod go.sum ./
# Download dependencies with cache mount for go modules
# This layer only rebuilds when go.mod or go.sum changes
RUN --mount=type=cache,target=/go/pkg/mod \
go mod download
# Copy source code (this invalidates cache only when code changes)
COPY . .
# Build with cache mount for go build cache
# This dramatically speeds up rebuilds by caching compiled packages
RUN --mount=type=cache,target=/go/pkg/mod \
--mount=type=cache,target=/root/.cache/go-build \
CGO_ENABLED=0 GOOS=linux make
FROM alpine:3
LABEL org.opencontainers.image.source=https://github.com/thorsager/surl
WORKDIR /
# Create non-root user
RUN addgroup -g 10001 -S appgroup && \
adduser -u 10001 -S appuser -G appgroup
COPY --from=build --chown=appuser:appgroup /build/bin/surl /
# Switch to non-root user
USER appuser
EXPOSE 8080
ENTRYPOINT [ "/surl" ]
CMD [ ":8080" ]