Hardening the container
This commit is contained in:
parent
f4e6924bbb
commit
c3457011b1
1 changed files with 20 additions and 6 deletions
|
@ -4,7 +4,7 @@
|
||||||
# make it available in the public directory.
|
# make it available in the public directory.
|
||||||
FROM docker.io/node:alpine as client
|
FROM docker.io/node:alpine as client
|
||||||
WORKDIR /build
|
WORKDIR /build
|
||||||
ADD frontend /build
|
ADD frontend ./
|
||||||
RUN npm install
|
RUN npm install
|
||||||
RUN npm run build
|
RUN npm run build
|
||||||
|
|
||||||
|
@ -13,31 +13,45 @@ FROM docker.io/golang:alpine as go
|
||||||
RUN apk add gcompat
|
RUN apk add gcompat
|
||||||
RUN apk add gcc
|
RUN apk add gcc
|
||||||
RUN apk add musl-dev
|
RUN apk add musl-dev
|
||||||
ADD backend /build
|
RUN apk add make
|
||||||
|
RUN apk add sqlite
|
||||||
WORKDIR /build
|
WORKDIR /build
|
||||||
|
ADD backend/go.mod backend/go.sum ./
|
||||||
|
|
||||||
# Get the dependencies
|
# Get the dependencies
|
||||||
RUN go mod download
|
RUN go mod download
|
||||||
|
|
||||||
|
# Add the source code
|
||||||
|
ADD backend .
|
||||||
|
|
||||||
|
RUN make migrate
|
||||||
|
|
||||||
# RUN go build -o server
|
# RUN go build -o server
|
||||||
RUN CGO_ENABLED=1 GOOS=linux go build -a -installsuffix cgo -o ./server ./cmd/
|
RUN CGO_ENABLED=1 GOOS=linux go build -a -installsuffix cgo -o ./server ./cmd/
|
||||||
|
|
||||||
|
# Strip the binary for a smaller image
|
||||||
RUN strip ./server
|
RUN strip ./server
|
||||||
|
|
||||||
# The final stage for building a minimal image
|
# The final stage for building a minimal image
|
||||||
FROM docker.io/alpine:latest as runner
|
FROM docker.io/alpine:latest as runner
|
||||||
|
RUN adduser -D nonroot
|
||||||
|
RUN addgroup nonroot nonroot
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
# Copy the frontend SPA build into public
|
# Copy the frontend SPA build into public
|
||||||
COPY --from=client /build/dist /app/static
|
COPY --from=client /build/dist static
|
||||||
|
|
||||||
# Copy the server binary
|
# Copy the server binary
|
||||||
COPY --from=go /build/server /app/server
|
COPY --from=go /build/server server
|
||||||
|
|
||||||
# Copy the migration scripts
|
# Copy the database
|
||||||
COPY --from=go /build/migrations /app/migrations
|
COPY --from=go /build/db.sqlite3 db.sqlite3
|
||||||
|
|
||||||
# Expose port 8080
|
# Expose port 8080
|
||||||
EXPOSE 8080
|
EXPOSE 8080
|
||||||
|
|
||||||
|
# Set the user to nonroot
|
||||||
|
USER nonroot:nonroot
|
||||||
|
|
||||||
# Run the server
|
# Run the server
|
||||||
CMD ["./server"]
|
CMD ["./server"]
|
Loading…
Reference in a new issue