Skip to content

Commit

Permalink
Use multi-stage builds for docker image (#434)
Browse files Browse the repository at this point in the history
Previously we used a bunch of dockerfiles to coordinate building
the cernan docker image. The future rolled up on us meanwhile and
we can now make use of multi-stage builds in Docker.

Signed-off-by: Brian L. Troutwine <blt@postmates.com>
  • Loading branch information
blt committed Mar 14, 2018
1 parent 604b337 commit 95db4d7
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 95 deletions.
1 change: 0 additions & 1 deletion Dockerfile

This file was deleted.

51 changes: 51 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
FROM ekidd/rust-musl-builder:1.24.0 as builder

RUN VERS=1.2.11 && \
cd /home/rust/libs && \
curl -LO http://zlib.net/zlib-$VERS.tar.gz && \
tar xzf zlib-$VERS.tar.gz && cd zlib-$VERS && \
CC=musl-gcc CFLAGS=-fPIC ./configure --static --prefix=/usr/local/musl && \
make && sudo make install && \
cd .. && rm -rf zlib-$VERS.tar.gz zlib-$VERS

RUN cd /home/rust/libs && \
curl -LO https://github.com/lz4/lz4/archive/master.tar.gz && \
tar xfz master.tar.gz && \
ls && \
cd lz4-master && \
CC=musl-gcc CFLAGS=-fPIC make prefix=/usr/local/musl && \
sudo make install prefix=/usr/local/musl && \
cd .. && \
rm -rf master.tar.gz lz4-master

RUN sudo apt-get update && \
sudo apt-get install -y python2.7-minimal && \
sudo ln -sf /usr/bin/python2.7 /usr/bin/python

ENV CC=musl-gcc \
CFLAGS=-I/usr/local/musl/include \
LDFLAGS=-L/usr/local/musl/lib

COPY --chown=rust:rust . /source
RUN cd /source && cargo build --release

FROM alpine:3.7

RUN apk update \
&& apk upgrade --no-cache

RUN apk add --no-cache --update \
ca-certificates \
llvm-libunwind \
openssl && \
update-ca-certificates && \
rm -rf /var/cache/apk/* && \
mkdir -p /etc/cernan/scripts

COPY --from=builder /source/target/x86_64-unknown-linux-musl/release/cernan /usr/bin/cernan
COPY examples/configs/quickstart.toml /etc/cernan/cernan.toml

ENV STATSD_PORT 8125

ENTRYPOINT /usr/bin/cernan
CMD ["--config", "/etc/cernan/cernan.toml"]
6 changes: 1 addition & 5 deletions build-container.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,5 @@ cargo clean

VERSION="${1}"

mkdir -p target/bindir
docker build -t cernan-build -f docker/build/Dockerfile .
docker run -v $(pwd):/source -w /source -it cernan-build cargo build --release
docker build -t quay.io/postmates/cernan:latest -t "quay.io/postmates/cernan:$VERSION" -f docker/release/Dockerfile .
docker build -t "quay.io/postmates/cernan:$VERSION" .
docker push "quay.io/postmates/cernan:$VERSION"
docker push "quay.io/postmates/cernan:latest"
27 changes: 0 additions & 27 deletions docker/build/Dockerfile

This file was deleted.

2 changes: 0 additions & 2 deletions docker/release/.gitignore

This file was deleted.

20 changes: 0 additions & 20 deletions docker/release/Dockerfile

This file was deleted.

15 changes: 0 additions & 15 deletions docker/test/Dockerfile

This file was deleted.

10 changes: 0 additions & 10 deletions docker/test/nightly-installs.sh

This file was deleted.

15 changes: 0 additions & 15 deletions push-container.sh

This file was deleted.

0 comments on commit 95db4d7

Please sign in to comment.