-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathDockerfile
46 lines (31 loc) · 1.09 KB
/
Dockerfile
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
45
46
FROM golang:1.22.4-alpine as base
# Adds version as a build argument
ARG VERSION=latest
ENV VERSION=${VERSION}
# Install git for VCS build information
RUN apk add --no-cache git
# Create another stage called "dev" that is based off of our "base" stage (so we have golang available to us)
FROM base as dev
# Install the air binary so we get live code-reloading when we save files
RUN go install github.com/air-verse/air@latest
# Run the air command in the directory where our code will live
WORKDIR /opt/mensatt
RUN git config --global --add safe.directory /opt/mensatt
# Start air hot-reload server
CMD ["air"]
FROM base as built
WORKDIR /opt/mensatt
RUN git config --global --add safe.directory /opt/mensatt
# Install required dependencies here for better cache utilization
COPY go.mod go.sum ./
RUN go mod download
# Copy the rest of the code and build the binary
COPY . .
RUN go build -o ./build/mensatt ./cmd/mensatt
FROM alpine:3.20 as prod
ARG VERSION=latest
ENV VERSION=${VERSION}
COPY --from=built /opt/mensatt/build/mensatt /usr/bin/mensatt
USER nobody:nobody
EXPOSE 4000
CMD ["mensatt"]