From 924feb662d81388e75b892266d38aa753b613ee0 Mon Sep 17 00:00:00 2001 From: Jef Roosens Date: Sun, 10 Oct 2021 16:33:07 +0200 Subject: [PATCH] Initial draft of Alpine-based Dockerfile --- .dockerignore | 1 + Dockerfile | 81 ++++++++++++++++++++++++++++++++++++++++----------- 2 files changed, 65 insertions(+), 17 deletions(-) diff --git a/.dockerignore b/.dockerignore index 04c13db..5ad583d 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,5 +1,6 @@ * +!.cargo/ !Cargo.lock !Cargo.toml !Makefile diff --git a/Dockerfile b/Dockerfile index 7a7ee23..72638d3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,19 +1,66 @@ -FROM rust:1.54 - -ENV PREFIX="/usr/src/out/prefix" \ - CC="musl-gcc -fPIC -pie -static" \ - LD_LIBRARY_PATH="$PREFIX" \ - PKG_CONFIG_PATH="/usr/local/lib/pkgconfig" \ - PATH="/usr/local/bin:/root/.cargo/bin:$PATH" - -RUN apt update && \ - apt install -y --no-install-recommends \ - musl-dev \ - musl-tools \ - libpq-dev \ - libssl-dev && \ - rustup target add x86_64-unknown-linux-musl && \ - mkdir "$PREFIX" && \ - echo "$PREFIX/lib" >> /etc/ld-musl-x86_64.path +# Build frontend files +FROM node:16 AS fbuilder WORKDIR /usr/src/app + +COPY web/ ./ + +RUN yarn install && \ + yarn build + + +# Build backend & backend docs +FROM rust:1.55-alpine AS builder + +ARG DI_VER=1.2.5 + +# ENV OPENSSL_STATIC=1 \ +# PQ_LIB_STATIC=1 + +RUN apk update && \ + apk add --no-cache \ + postgresql \ + postgresql-dev \ + openssl-dev \ + build-base + +WORKDIR /usr/src/app + +# Build backend +COPY .cargo/ ./.cargo +COPY src/ ./src +COPY migrations/ ./migrations +COPY Cargo.toml Cargo.lock ./ + +RUN cargo build --release && \ + cargo doc --no-deps + +# Build dumb-init +RUN curl -sSL "https://github.com/Yelp/dumb-init/archive/refs/tags/v$DI_VER.tar.gz" | \ + tar -xzf - && \ + cd "dumb-init-$DI_VER" && \ + make build && \ + mv dumb-init .. + + +FROM alpine:3.14.2 + +RUN mkdir -p /var/www/html + +COPY --from=fbuilder /usr/src/app/dist /var/www/html/site +COPY --from=builder /usr/src/app/out/target/doc /var/www/html/doc +COPY --from=builder /usr/src/app/out/target/release/rbd /usr/bin/rbd +COPY --from=builder /usr/src/app/dumb-init /usr/bin/dumb-init + +ENTRYPOINT [ "dumb-init", "--" ] +CMD [ "/usr/bin/rbd" ] + +# RUN apt update && \ +# apt install -y --no-install-recommends \ +# musl-dev \ +# musl-tools \ +# libpq-dev \ +# libssl-dev && \ +# rustup target add x86_64-unknown-linux-musl && \ +# mkdir "$PREFIX" && \ +# echo "$PREFIX/lib" >> /etc/ld-musl-x86_64.path