summaryrefslogtreecommitdiffstats
path: root/Dockerfile
blob: 71171cc0c322c602672172c5c22ce64d732c71cd (plain) (blame)
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
39
40
41
42
43
44
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

# instead of doing COPY . . here, I want to be specific about the files I want to copy
# this way if I add a new file to the project, it will not be copied over

# Can this be refactored?
COPY ./cmd ./cmd
COPY ./internal ./internal
COPY ./postgresql ./postgresql
COPY ./ui ./ui
COPY go.sum .
COPY go.mod .
COPY sonar-project.properties .

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