Skip to content

Commit

Permalink
use alpine docker builder
Browse files Browse the repository at this point in the history
Signed-off-by: Suntharesan Mohan <[email protected]>
  • Loading branch information
msuntharesan committed Jul 24, 2020
1 parent 23c98ec commit 9f68f85
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@

# But not these files
!build_scripts
!benches
!humanize
!merit-api
!src
!static
!Cargo.toml
!Cargo.lock
34 changes: 19 additions & 15 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 9f68f85

Please sign in to comment.