-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile
39 lines (26 loc) · 920 Bytes
/
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
FROM golang:1.23-alpine AS build
WORKDIR /app
# pre-copy/cache go.mod for pre-downloading dependencies and only redownloading them in subsequent builds if they change
COPY go.mod go.sum ./
RUN --mount=type=cache,target=/go/pkg/mod \
--mount=type=cache,target=/root/.cache/go-build \
go mod download && go mod verify
FROM build AS development
# Install : Air = hot-reload ; Delve = debugger
RUN go install github.com/air-verse/air@latest && \
go install github.com/go-delve/delve/cmd/dlv@latest
COPY . .
# Run the application with Air for hot-reloading
CMD ["air", "-c", ".air.toml"]
FROM build AS build-production
WORKDIR /app
COPY . .
# Build the Go app
RUN go build -v -o server
FROM scratch AS production
# Start a new ligthwheight stage from scratch
WORKDIR /
# Copy the binary from the build stage
COPY --from=build-production /app/server /server
# Run the compiled binary
CMD ["/server"]