summaryrefslogtreecommitdiffstats
path: root/Dockerfile
diff options
context:
space:
mode:
authorYulqen <246857+yulqen@users.noreply.github.com>2024-04-22 15:16:32 +0100
committerGitHub <noreply@github.com>2024-04-22 15:16:32 +0100
commitf2209833a4c16ba32f91db9f2fbf2e7b22d99f79 (patch)
treee216c259656f4058a4d60c747e447b1e1170913b /Dockerfile
parente546c7103da64e1b4cbda9c400926370f66b8c22 (diff)
parent05bef10708775eb608dd68bedd3bb4b796ba6920 (diff)
Merge pull request #19 from defencedigital/change-dockerfile
Trying to fix Dockerfile for non-root use
Diffstat (limited to 'Dockerfile')
-rw-r--r--Dockerfile26
1 files changed, 24 insertions, 2 deletions
diff --git a/Dockerfile b/Dockerfile
index 0b159f0..f2e71d6 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -1,11 +1,33 @@
-FROM registry.redhat.io/rhel9/go-toolset:1.20.12-3.1712567214
+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 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
-CMD ["./bin/app"]
+
+# Set the working directory to /app/bin
+WORKDIR /app/bin
+
+CMD ["./app"]
EXPOSE 4000