-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathDockerfile.crystal
More file actions
90 lines (81 loc) · 3.36 KB
/
Dockerfile.crystal
File metadata and controls
90 lines (81 loc) · 3.36 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
87
88
89
90
ARG alpine_version=latest
FROM alpine:$alpine_version AS builder
ARG llvm_version=20
# add dependencies required for building crystal from source
RUN apk add --update --no-cache \
crystal shards \
llvm${llvm_version}-dev llvm${llvm_version}-static \
zlib-static yaml-static pcre2-dev zstd-static libxml2-static pcre2-static \
libffi-dev git g++ make automake libtool autoconf curl abuild asciidoctor
WORKDIR /usr/src
# Build libgc
ARG gc_version=8.2.8
ADD https://github.com/ivmai/bdwgc/archive/v${gc_version}.tar.gz bdwgc.tar.gz
RUN tar zxf bdwgc.tar.gz && \
cd bdwgc-${gc_version} && \
source /usr/share/abuild/default.conf && \
./autogen.sh && \
./configure --disable-debug --disable-shared --enable-large-config --prefix=/usr && \
make -j$(nproc) && \
make install
# Build crystal
ARG crystal_version=1.19.1
ADD https://github.com/crystal-lang/crystal/archive/${crystal_version}.tar.gz crystal.tar.gz
RUN tar zxf crystal.tar.gz && \
cd crystal-${crystal_version} && \
source /usr/share/abuild/default.conf && \
make release=1 static=1 CRYSTAL_CONFIG_LIBRARY_PATH=/usr/lib/crystal LDFLAGS="$LDFLAGS -s -w" && \
make install PREFIX=/usr
# Build shards
WORKDIR /usr/src/shards
ARG shards_version=0.20.0
ADD https://github.com/crystal-lang/shards/archive/refs/tags/v${shards_version}.tar.gz shards.tar.gz
RUN tar zxf shards.tar.gz && \
cd shards-${shards_version} && \
source /usr/share/abuild/default.conf && \
make release=1 static=1 CRYSTAL_CONFIG_LIBRARY_PATH=/usr/lib/crystal FLAGS="--link-flags=\"$LDFLAGS -s -w\"" && \
make install PREFIX=/usr
# start from a clean image
FROM alpine:$alpine_version
# Get package updates since image release
RUN apk update && apk --no-cache --quiet upgrade
# add dependencies commonly required for building crystal applications
RUN apk add --update --no-cache musl-dev gcc pcre2-dev openssl-dev openssl-libs-static libxml2-dev zlib-dev zlib-static git make yaml-dev libxml2-static gmp-dev xz-static yaml-static pcre2-static
# copy the binaries + stdlib + libgc from the build stage
COPY --from=builder /usr/share/man/man1/crystal.1.gz /usr/share/man/man1/
COPY --from=builder /usr/share/man/man1/shards.1.gz /usr/share/man/man1/
COPY --from=builder /usr/share/man/man5/shard.yml.5.gz /usr/share/man/man5/
COPY --from=builder /usr/share/crystal /usr/share/crystal
COPY --from=builder /usr/bin/crystal /usr/bin/
COPY --from=builder /usr/bin/shards /usr/bin/
COPY --from=builder /usr/lib/libgc.a /usr/lib/crystal/
# Add dependencies commonly required for building PlaceOS applications
# hadolint ignore=DL3018
RUN apk add \
--update \
--no-cache \
autoconf \
automake \
libtool \
patch \
ca-certificates \
bash \
iputils \
libelf \
gmp-dev \
gmp-static \
lz4-dev \
lz4-static \
tzdata \
curl \
xz-libs \
xz-dev \
xz-static
RUN apk add --no-cache --repository=http://dl-cdn.alpinelinux.org/alpine/edge/main libssh2-static
RUN update-ca-certificates
# These provide certificate chain validation where communicating with external services over TLS
ENV SSL_CERT_FILE=/etc/ssl/certs/ca-certificates.crt
ENV GIT_SSL_CAINFO=/etc/ssl/certs/ca-certificates.crt
RUN git config --system http.sslCAInfo /etc/ssl/certs/ca-certificates.crt
# set the default cmd, example usage: docker run --rm 84codes/crystal eval 'puts "hello world"'
ENTRYPOINT ["/usr/bin/crystal"]