From 9f68f8523e49c233c061880fb45076c8460011d2 Mon Sep 17 00:00:00 2001 From: Suntharesan Mohan Date: Fri, 24 Jul 2020 00:59:26 -0400 Subject: [PATCH] use alpine docker builder Signed-off-by: Suntharesan Mohan --- .dockerignore | 2 +- Dockerfile | 34 +++++++++++++++++++--------------- 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/.dockerignore b/.dockerignore index 1cfff94..a0c0841 100644 --- a/.dockerignore +++ b/.dockerignore @@ -3,9 +3,9 @@ # But not these files !build_scripts +!benches !humanize !merit-api !src -!static !Cargo.toml !Cargo.lock diff --git a/Dockerfile b/Dockerfile index 528885a..b719986 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,41 +2,45 @@ # Cargo Build Stage # ------------------------------------------------------------------------------ -FROM ekidd/rust-musl-builder:nightly-2020-07-12 as cargo-build +FROM rustlang/rust:nightly-alpine as toolchain -WORKDIR /usr/src/ +RUN adduser -D -h /merit -g "" merit -# Fix permissions on source code. -RUN sudo chown -R rust:rust /home/rust \ - && sudo chown -R rust:rust /usr/src +RUN apk add make zlib-dev openssl-dev musl-dev -COPY . . +USER merit + +ENV USER=merit +ENV PATH=/merit/.cargo/bin:$PATH -RUN mkdir .cargo \ - && cargo vendor > .cargo/config +WORKDIR /merit -RUN rustup target add x86_64-unknown-linux-musl +RUN cargo init --lib --vcs none +RUN cargo new humanize --lib --vcs none +RUN cargo new merit-api --lib --vcs none + +RUN mkdir .cargo +RUN cargo vendor > .cargo/config + +COPY . . RUN OPENSSL_STATIC=true \ - RUSTFLAGS=-Clinker=musl-gcc \ cargo build --release --target=x86_64-unknown-linux-musl -p merit-api # ------------------------------------------------------------------------------ # Final Stage # ------------------------------------------------------------------------------ -FROM alpine:latest +FROM alpine:3.12 ENV PORT=8080 \ LOG_LEVEL="actix_web=info" WORKDIR /home/merit/bin/ -COPY --from=cargo-build /usr/src/target/x86_64-unknown-linux-musl/release/merit-api . +COPY --from=toolchain /merit/target/x86_64-unknown-linux-musl/release/merit-api . -RUN addgroup -g 1000 merit \ - && adduser -D -s /bin/sh -u 1000 -G merit merit \ - && chown merit:merit merit-api +RUN adduser -D -H -g "" merit USER merit