friends/Dockerfile
William Oldham 7455c84512
Some checks failed
Build and Publish Docker Image / Build and Publish Docker Image (amd64) (push) Has been cancelled
Build and Publish Docker Image / Build and Publish Docker Image (arm64) (push) Has been cancelled
chore: move go files to copy so readonly fs isn't errored
2026-02-06 21:40:45 +00:00

37 lines
733 B
Docker

# 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}
COPY go.mod go.mod ./
RUN --mount=type=cache,target=/go/pkg/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" ]