-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
86 lines (72 loc) · 1.65 KB
/
Dockerfile
File metadata and controls
86 lines (72 loc) · 1.65 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
###########
# CRYSTAL #
###########
FROM alpine:3.23 AS crystal
RUN apk add --update --no-cache \
make \
crystal=~1.18 \
shards \
gc-dev \
gc-static \
git \
libxml2-dev \
libxml2-static \
openssl-dev \
openssl-libs-static \
gmp-dev \
gmp-static \
pcre2-dev \
pcre2-static \
xz-dev \
xz-static \
yaml-dev \
yaml-static \
zlib-dev \
zlib-static \
upx
#########
# BUILD #
#########
FROM crystal AS build-binary-file
# Fetch platforms variables from ARGS
ARG TARGETPLATFORM
ARG TARGETOS
ARG TARGETARCH
ARG TARGETVARIANT
# Export them to build binary files with the right name: squarectl-linux-amd64
ENV \
TARGETPLATFORM=${TARGETPLATFORM} \
TARGETOS=${TARGETOS} \
TARGETARCH=${TARGETARCH} \
TARGETVARIANT=${TARGETVARIANT}
# Set build environment
WORKDIR /build
COPY .git/ /build/.git/
COPY shard.yml shard.lock /build/
COPY Makefile.release /build/Makefile
COPY src/ /build/src/
COPY completion/ /build/completion/
RUN mkdir /build/bin
# Build the binary
RUN make release
# Extract binary from Docker image
FROM scratch AS binary-file
ARG TARGETOS
ARG TARGETARCH
COPY --from=build-binary-file /build/bin/squarectl-${TARGETOS}-${TARGETARCH} /
###########
# RUNTIME #
###########
# Build distroless images \o/
FROM gcr.io/distroless/static-debian12 AS docker-image
# Fetch platforms variables from ARGS
ARG TARGETOS
ARG TARGETARCH
# Grab squarectl binary from **binary-file** step and inject it in the final image
COPY --from=binary-file /build/bin/squarectl-${TARGETOS}-${TARGETARCH} /usr/bin/squarectl
# Set runtime environment
USER nonroot
ENV USER nonroot
ENV HOME /home/nonroot
WORKDIR /home/nonroot
ENTRYPOINT ["squarectl"]