-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathDockerfile
More file actions
36 lines (23 loc) · 808 Bytes
/
Dockerfile
File metadata and controls
36 lines (23 loc) · 808 Bytes
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
# syntax=docker/dockerfile:1
ARG app_dir="/home/go/app"
# * Building the application
FROM golang:1.25-alpine3.22 AS build
ARG app_dir
ARG build_string=pretendo.friends.docker
WORKDIR ${app_dir}
RUN --mount=type=cache,target=/go/pkg/mod/ \
--mount=type=bind,source=go.sum,target=go.sum \
--mount=type=bind,source=go.mod,target=go.mod \
go mod download -x
COPY . .
RUN --mount=type=cache,target=/go/pkg/mod/ \
CGO_ENABLED=0 go build -v -o ${app_dir}/build/server -ldflags "-X 'main.serverBuildString=${build_string}'"
# * Running the final application
FROM alpine:3.22 AS final
ARG app_dir
WORKDIR ${app_dir}
RUN addgroup go && adduser -D -G go go
RUN mkdir -p ${app_dir}/log && chown go:go ${app_dir}/log
USER go
COPY --from=build ${app_dir}/build/server ${app_dir}/server
CMD [ "./server" ]