-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wip!: progress towards static musl builds
- Loading branch information
Showing
3 changed files
with
124 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,108 @@ | ||
ARG CRYSTAL_VERSION=1.0.0 | ||
FROM crystallang/crystal:${CRYSTAL_VERSION} | ||
|
||
# Digest CLI | ||
############################################################################### | ||
FROM crystallang/crystal:${CRYSTAL_VERSION} as digest | ||
|
||
ARG CRYSTAL_VERSION=1.0.0 | ||
ARG PLACE_COMMIT="DEV" | ||
|
||
WORKDIR /app | ||
|
||
RUN apt update | ||
RUN apt install --no-install-recommends -y \ | ||
RUN apt-get update && \ | ||
apt-get install -y apt-transport-https && \ | ||
apt-get update && \ | ||
DEBIAN_FRONTEND=noninteractive \ | ||
apt install --no-install-recommends -y \ | ||
bash \ | ||
ca-certificates \ | ||
curl \ | ||
libssh2-1 libssh2-1-dev \ | ||
llvm-10 llvm-10-dev \ | ||
|
||
# Install watchexec | ||
RUN curl -sLO https://github.com/watchexec/watchexec/releases/download/cli-v1.16.0/watchexec-1.16.0-x86_64-unknown-linux-gnu.deb && \ | ||
dpkg -i watchexec-1.16.0-x86_64-unknown-linux-gnu.deb && \ | ||
rm -rf ./*.deb | ||
|
||
# Add trusted CAs for communicating with external services | ||
RUN update-ca-certificates | ||
libssh2-1 libssh2-1-dev \ | ||
libyaml-dev \ | ||
&& apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* | ||
|
||
# Install shards before adding source. | ||
COPY shard.yml /app | ||
COPY shard.lock /app | ||
RUN shards install --ignore-crystal-version | ||
|
||
# Build digest tool before copying rest of source for better caching. | ||
RUN mkdir /app/src | ||
COPY src/digest_cli.cr /app/src/digest_cli.cr | ||
|
||
RUN CRYSTAL_PATH=lib:/usr/share/crystal/src/ \ | ||
LLVM_CONFIG=$(/usr/share/crystal/src/llvm/ext/find-llvm-config) \ | ||
shards build digest_cli --ignore-crystal-version --no-debug | ||
shards build digest_cli -Dpreview_mt --ignore-crystal-version --no-debug --production | ||
|
||
COPY src/digest_cli.cr /app/src/digest_cli.cr | ||
# Extract dependencies | ||
RUN ldd /app/bin/digest_cli | tr -s '[:blank:]' '\n' | grep '^/' | xargs -I % sh -c 'mkdir -p $(dirname deps%); cp % deps%;' | ||
|
||
COPY scripts /app/scripts | ||
COPY src /app/sr | ||
# Build | ||
############################################################################### | ||
|
||
FROM crystallang/crystal:${CRYSTAL_VERSION}-alpine as build | ||
|
||
ARG CRYSTAL_VERSION=1.0.0 | ||
ARG PLACE_COMMIT="DEV" | ||
|
||
WORKDIR /app | ||
|
||
# Install the latest version of LibSSH2, ping, etc | ||
RUN apk add --no-cache \ | ||
bash \ | ||
ca-certificates \ | ||
curl \ | ||
iputils \ | ||
libssh2-static \ | ||
yaml-static | ||
|
||
RUN mkdir -p /app/bin/drivers | ||
# Add a glibc shim | ||
# NOTE: Once musl builds are a supported target, `asdf` should be updated to use those builds | ||
RUN mkdir keys && (cd keys && curl -slO https://alpine-pkgs.sgerrand.com/sgerrand.rsa.pub) && \ | ||
curl -sLO https://github.com/sgerrand/alpine-pkg-glibc/releases/download/2.33-r0/glibc-2.33-r0.apk && \ | ||
curl -sLO https://github.com/sgerrand/alpine-pkg-glibc/releases/download/2.33-r0/glibc-i18n-2.33-r0.apk && \ | ||
curl -sLO https://github.com/sgerrand/alpine-pkg-glibc/releases/download/2.33-r0/glibc-bin-2.33-r0.apk && \ | ||
curl -sLO https://github.com/sgerrand/alpine-pkg-glibc/releases/download/2.33-r0/glibc-dev-2.33-r0.apk && \ | ||
apk add --allow-untrusted --keys-dir keys glibc-2.33-r0.apk && \ | ||
apk add --allow-untrusted --keys-dir keys glibc-dev-2.33-r0.apk && \ | ||
apk add --allow-untrusted --keys-dir keys glibc-bin-2.33-r0.apk && \ | ||
apk add --allow-untrusted --keys-dir keys glibc-i18n-2.33-r0.apk && \ | ||
rm -r keys *.apk | ||
|
||
# Add trusted CAs for communicating with external services | ||
RUN update-ca-certificates | ||
|
||
# Add watchexec | ||
RUN apk add --no-cache -X http://dl-cdn.alpinelinux.org/alpine/edge/testing watchexec | ||
|
||
# Install shards before adding source. | ||
COPY shard.yml /app | ||
COPY shard.lock /app | ||
RUN shards install --ignore-crystal-version | ||
|
||
# Copy the `digest_cli` binary, and all of its runtime dependencies | ||
COPY --from=digest /app/deps / | ||
COPY --from=digest /app/bin/digest_cli /app/bin | ||
|
||
COPY scripts /app/scripts | ||
COPY src /app/src | ||
|
||
# These provide certificate chain validation where communicating with external services over TLS | ||
ENV SSL_CERT_FILE=/etc/ssl/certs/ca-certificates.crt | ||
|
||
# Install asdf version manager | ||
###############################################3############################### | ||
|
||
ENV CRYSTAL_PATH=lib:/usr/share/crystal/src | ||
ENV CRYSTAL_LIBRARY_PATH=/usr/local/lib | ||
ENV CRYSTAL_VERSION=${CRYSTAL_VERSION} | ||
|
||
ENV HOME="/app" | ||
SHELL ["/bin/bash", "-l", "-c"] | ||
RUN git clone https://github.com/asdf-vm/asdf.git $HOME/.asdf --branch v0.8.0 && \ | ||
|
||
# Install asdf version manager | ||
RUN git clone --depth 1 https://github.com/asdf-vm/asdf.git $HOME/.asdf --branch v0.8.0 && \ | ||
$HOME/.asdf/bin/asdf plugin-add crystal https://github.com/asdf-community/asdf-crystal.git && \ | ||
echo -e '\n. $HOME/.asdf/asdf.sh' >> ~/.bashrc && \ | ||
echo -e '\n. $HOME/.asdf/asdf.sh' >> ~/.profile && \ | ||
echo -e '\n. $HOME/.asdf/asdf.sh' >> $HOME/.bashrc && \ | ||
echo -e '\n. $HOME/.asdf/asdf.sh' >> $HOME/.profile && \ | ||
source ~/.bashrc | ||
|
||
CMD /app/scripts/entrypoint-test.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters