Initial draft of Alpine-based Dockerfile

develop
Jef Roosens 2021-10-10 16:33:07 +02:00
parent 3e9c5e4fe7
commit 924feb662d
Signed by: Jef Roosens
GPG Key ID: B580B976584B5F30
2 changed files with 65 additions and 17 deletions

View File

@ -1,5 +1,6 @@
*
!.cargo/
!Cargo.lock
!Cargo.toml
!Makefile

View File

@ -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