summaryrefslogtreecommitdiffstats
path: root/Dockerfile
diff options
context:
space:
mode:
authorMatthew Lemon <y@yulqen.org>2024-04-22 15:10:30 +0100
committerMatthew Lemon <y@yulqen.org>2024-04-22 15:10:30 +0100
commit9d297a6a4b5ab61612d650352ba2bc1b66817def (patch)
treed58385b678998536698100a4abf0dd9f9f89c92a /Dockerfile
parentdab6b649e3a72a21504581de3bfd57006f366427 (diff)
Trying to fix Dockerfile for non-root use
Diffstat (limited to 'Dockerfile')
-rw-r--r--Dockerfile25
1 files changed, 23 insertions, 2 deletions
diff --git a/Dockerfile b/Dockerfile
index 3c01103..f2e71d6 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -1,12 +1,33 @@
FROM docker.io/golang:alpine
+RUN addgroup -S app && adduser -S -g app app
+
WORKDIR /app
RUN apk add --update npm
RUN npm i sass govuk-frontend --save
+
+# Switch to root user
+USER root
+
COPY go.mod ./
RUN go mod download && go mod verify
+
COPY . .
-RUN go build -v -o /usr/local/bin/app ./cmd/web
-CMD ["app"]
+RUN chown -R app:app /app
+
+# Create a directory for the binary
+RUN mkdir /app/bin
+RUN chown app:app /app/bin
+
+# Switch back to app user
+USER app
+
+# Build the Go binary in the /app/bin directory
+RUN go build -v -o /app/bin/app ./cmd/web
+
+# Set the working directory to /app/bin
+WORKDIR /app/bin
+
+CMD ["./app"]
EXPOSE 4000