-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathDockerfile
50 lines (37 loc) · 1.17 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
47
48
49
50
# syntax=docker/dockerfile:1
ARG GO_VERSION=1.22.2-alpine3.19
FROM --platform=$BUILDPLATFORM golang:${GO_VERSION} AS builder
WORKDIR /src
RUN --mount=type=cache,target=/var/cache/apk apk update && apk upgrade && apk add --no-cache build-base
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
ARG TARGETARCH
# RUN --mount=type=cache,target=/go/pkg/mod/ \
# --mount=type=bind,target=. \
# GOARCH=$TARGETARCH go build -ldflags="-linkmode external -extldflags -static" -o indexer main.go
COPY . .
RUN set -eux; \
GOARCH=$TARGETARCH go build -ldflags="-linkmode external -extldflags -static" -o indexer main.go
FROM alpine:3.19 AS production
RUN --mount=type=cache,target=/var/cache/apk \
apk --update add \
ca-certificates \
tzdata \
&& \
update-ca-certificates
WORKDIR /srv/app
COPY --from=builder /src/indexer ./indexer
ARG UID=10001
RUN adduser \
--disabled-password \
--gecos "" \
--home "/nonexistent" \
--shell "/sbin/nologin" \
--no-create-home \
--uid "${UID}" \
appuser
USER appuser
EXPOSE 8080
ENTRYPOINT [ "/srv/app/indexer" ]