Skip to content

Commit 63ec908

Browse files
committed
bring fix/remove-root-access-when-building-docker-img Dockerfile changes
1 parent 1ec49d8 commit 63ec908

File tree

1 file changed

+33
-19
lines changed

1 file changed

+33
-19
lines changed

Dockerfile

Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,45 @@
1-
# CONTAINER FOR BUILDING BINARY
2-
FROM --platform=${BUILDPLATFORM} golang:1.24.4 AS build
1+
# ================================
2+
# STAGE 1: Build binary
3+
# ================================
4+
FROM --platform=${BUILDPLATFORM} golang:1.24.4-alpine AS builder
5+
6+
# Install build dependencies
7+
RUN apk add --no-cache gcc musl-dev make sqlite-dev
38

49
WORKDIR /app
510

6-
# INSTALL DEPENDENCIES
11+
# Download Go dependencies
712
COPY go.mod go.sum ./
813
RUN go mod download
914

10-
# BUILD BINARY
15+
# Copy source and build
1116
COPY . .
12-
RUN make build-aggkit build-tools
13-
14-
# CONTAINER FOR RUNNING BINARY
15-
FROM --platform=${BUILDPLATFORM} debian:bookworm-slim
16-
RUN apt-get update && \
17-
apt-get install -y --no-install-recommends \
18-
ca-certificates \
19-
sqlite3 \
20-
procps \
21-
libssl-dev && \
22-
rm -rf /var/lib/apt/lists/*
23-
COPY --from=build /app/target/aggkit /usr/local/bin/
24-
25-
# ADD NON-ROOT USER
26-
RUN addgroup --system appgroup && adduser --system --ingroup appgroup appuser
17+
18+
# Compile binary
19+
RUN make build-aggkit
20+
21+
# ================================
22+
# STAGE 2: Final runtime image
23+
# ================================
24+
FROM alpine:3.22
25+
26+
# Install runtime dependencies and remove shell
27+
RUN apk add --no-cache sqlite-libs ca-certificates
28+
29+
# Add non-root user with home and nologin shell
30+
RUN addgroup appgroup && \
31+
adduser -D -G appgroup -h /home/appuser -s /sbin/nologin appuser && \
32+
mkdir -p /home/appuser && \
33+
chown -R appuser:appgroup /home/appuser
34+
35+
# Set the working directory and user
36+
# This ensures that the application runs as a non-root user
37+
WORKDIR /home/appuser
2738
USER appuser
2839

40+
# Copy the built binary from the builder stage
41+
COPY --from=builder /app/target/aggkit /usr/local/bin/aggkit
42+
2943
EXPOSE 5576/tcp
3044

3145
ENTRYPOINT ["/usr/local/bin/aggkit"]

0 commit comments

Comments
 (0)