Permalink
Browse files

Minimize docker api image

- Use alpine image
- Make sure images build on systems on which remapping of user IDs is enabled
  • Loading branch information...
schrieveslaach committed Jan 28, 2019
1 parent 2ec729d commit a101f0fa2ee6b3146c55fd044c0b233e11853050
Showing with 20 additions and 21 deletions.
  1. +1 −0 api/.dockerignore
  2. +9 −13 api/Dockerfile
  3. +8 −6 frontend/Dockerfile
  4. +2 −2 frontend/webpack.config.js
@@ -0,0 +1 @@
target/
@@ -1,23 +1,19 @@
FROM docker.io/library/rust:1.31.0-slim as builder
RUN apt update ; \
apt install -y libssl-dev pkg-config ; \
rustup default nightly
WORKDIR /usr/src/api
FROM docker.io/ekidd/rust-musl-builder as builder
USER root
RUN rustup default nightly && rustup target add x86_64-unknown-linux-musl
COPY Cargo.toml Cargo.lock /usr/src/api/
COPY src /usr/src/api/src
RUN cargo install --path . ; \
chown root:root /usr/local/cargo/bin/api
WORKDIR /usr/src/api
RUN cargo build --release --target x86_64-unknown-linux-musl

FROM docker.io/library/debian:stretch-slim
FROM docker.io/library/alpine
LABEL maintainer="marc.schreiber@aixigo.de"

RUN set -eux ; \
apt-get update ; \
apt-get install -y openssl ca-certificates
RUN adduser -D -u 1000 api
COPY --chown=api --from=builder /usr/src/api/target/x86_64-unknown-linux-musl/release/api /app/api
COPY --chown=api res/Rocket.toml res/config.toml /app/

WORKDIR /app
COPY --from=builder /usr/local/cargo/bin/api .
COPY res/Rocket.toml res/config.toml /app/
EXPOSE 80
ENV ROCKET_ENV=staging
ENV RUST_LOG=info
@@ -7,20 +7,22 @@ RUN npm ci && npm run build


FROM docker.io/ekidd/rust-musl-builder as http-backend-builder
USER root
RUN rustup default nightly && rustup target add x86_64-unknown-linux-musl
COPY --chown=rust Cargo.lock Cargo.toml /usr/src/frontend/
COPY --chown=rust src/*.rs /usr/src/frontend/src/
COPY Cargo.lock Cargo.toml /usr/src/frontend/
COPY src/*.rs /usr/src/frontend/src/
WORKDIR /usr/src/frontend/
RUN cargo build --release --target x86_64-unknown-linux-musl



FROM alpine
FROM docker.io/library/alpine
LABEL maintainer="marc.schreiber@aixigo.de"

COPY --from=http-backend-builder /usr/src/frontend/target/x86_64-unknown-linux-musl/release/frontend /app/frontend
COPY --from=frontend-builder /usr/src/frontend/dist/* /app/static/
COPY index.html favicon.svg /app/static/
RUN adduser -D -u 1000 frontend
COPY --chown=frontend --from=http-backend-builder /usr/src/frontend/target/x86_64-unknown-linux-musl/release/frontend /app/frontend
COPY --chown=frontend --from=frontend-builder /usr/src/frontend/target/* /app/static/
COPY --chown=frontend index.html favicon.svg /app/static/

EXPOSE 8000
WORKDIR /app/
@@ -13,8 +13,8 @@ module.exports = {
},

output: {
path: path.resolve(__dirname, './dist'),
publicPath: '/dist/',
path: path.resolve(__dirname, './target'),
publicPath: '/',
filename: 'app.js'
},

0 comments on commit a101f0f

Please sign in to comment.