Created
January 12, 2019 10:20
-
-
Save denibertovic/01f0bfd2f16c81fb487430558324745a to your computer and use it in GitHub Desktop.
Dockerfile with buildkit (experimental support)
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
# syntax = docker/dockerfile:experimental | |
FROM ubuntu:18.04 as build | |
# This is phase1: the build phase | |
# where we build our project and output a binary | |
ENV DEBIAN_FRONTEND=noninteractive | |
RUN apt-get update && apt-get install -y \ | |
apt-transport-https \ | |
apt-utils \ | |
build-essential \ | |
ca-certificates \ | |
curl \ | |
iputils-ping \ | |
iputils-tracepath \ | |
jq \ | |
libgmp-dev \ | |
lsb-release \ | |
make \ | |
netbase \ | |
software-properties-common \ | |
unzip \ | |
xz-utils \ | |
zlib1g-dev | |
# Install latest version of Stack | |
ENV STACK_VERSION=1.9.3 | |
RUN curl -sSL https://github.com/commercialhaskell/stack/releases/download/v$STACK_VERSION/stack-$STACK_VERSION-linux-x86_64.tar.gz | tar xz --wildcards --strip-components=1 -C /usr/local/bin '*/stack' | |
# Ideally all of the above would go into a "build image" from which we can inherit here | |
# and just do the stuff below | |
# Make build directory and copy source | |
RUN mkdir -p /opt/build | |
RUN mkdir -p /tmp/out | |
COPY . /opt/build | |
# Run the build but make sure to cache .stack and .stack-work | |
RUN --mount=type=cache,target=/root/.stack \ | |
--mount=type=cache,target=/opt/build/.stack-work \ | |
cd /opt/build && \ | |
stack build --copy-bins --local-bin-path=/tmp/out | |
FROM fpco/pid1:0.1.2.0 | |
# In this phase we just copy over the prebuilt binary from the above build phase | |
ENV DEBIAN_FRONTEND=noninteractive | |
# Some common dependencies we might need with our app | |
RUN apt-get update && apt-get install -y \ | |
ca-certificates \ | |
netbase \ | |
libgmp-dev | |
COPY entrypoint.sh /usr/local/bin/entrypoint.sh | |
RUN chmod +x /usr/local/bin/entrypoint.sh | |
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"] | |
RUN mkdir -p /opt/app | |
COPY --from=build /tmp/out/my-binary /opt/app/ | |
CMD ["/opt/app/my-binary"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Build using:
DOCKER_BUILDKIT=1 docker build -t test .
This requires docker
v18.06
(or newer).See here for more info.