You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
80 lines
1.9 KiB
80 lines
1.9 KiB
6 years ago
|
# Using multistage build:
|
||
|
# https://docs.docker.com/develop/develop-images/multistage-build/
|
||
|
# https://whitfin.io/speeding-up-rust-docker-builds/
|
||
|
####################### VAULT BUILD IMAGE #######################
|
||
6 years ago
|
FROM alpine as vault
|
||
6 years ago
|
|
||
6 years ago
|
ENV VAULT_VERSION "v2.10.1"
|
||
6 years ago
|
|
||
6 years ago
|
ENV URL "https://github.com/dani-garcia/bw_web_builds/releases/download/$VAULT_VERSION/bw_web_$VAULT_VERSION.tar.gz"
|
||
6 years ago
|
|
||
|
RUN apk add --update-cache --upgrade \
|
||
|
curl \
|
||
|
tar
|
||
|
|
||
6 years ago
|
RUN mkdir /web-vault
|
||
|
WORKDIR /web-vault
|
||
6 years ago
|
|
||
6 years ago
|
RUN curl -L $URL | tar xz
|
||
|
RUN ls
|
||
6 years ago
|
|
||
|
########################## BUILD IMAGE ##########################
|
||
|
# Musl build image for statically compiled binary
|
||
6 years ago
|
FROM clux/muslrust:nightly-2018-12-01 as build
|
||
6 years ago
|
|
||
6 years ago
|
# set sqlite as default for DB ARG for backward comaptibility
|
||
|
ARG DB=sqlite
|
||
|
|
||
6 years ago
|
ENV USER "root"
|
||
6 years ago
|
|
||
6 years ago
|
# Install needed libraries
|
||
|
RUN apt-get update && apt-get install -y\
|
||
|
libmysqlclient-dev\
|
||
|
--no-install-recommends\
|
||
|
&& rm -rf /var/lib/apt/lists/*
|
||
|
|
||
6 years ago
|
WORKDIR /app
|
||
6 years ago
|
|
||
|
# Copies the complete project
|
||
|
# To avoid copying unneeded files, use .dockerignore
|
||
|
COPY . .
|
||
|
|
||
6 years ago
|
RUN rustup target add x86_64-unknown-linux-musl
|
||
|
|
||
6 years ago
|
# Make sure that we actually build the project
|
||
|
RUN touch src/main.rs
|
||
|
|
||
6 years ago
|
# Build
|
||
6 years ago
|
RUN cargo build --features ${DB} --release
|
||
6 years ago
|
|
||
|
######################## RUNTIME IMAGE ########################
|
||
|
# Create a new stage with a minimal image
|
||
|
# because we already have a binary built
|
||
6 years ago
|
FROM alpine:3.9
|
||
6 years ago
|
|
||
|
ENV ROCKET_ENV "staging"
|
||
6 years ago
|
ENV ROCKET_PORT=80
|
||
6 years ago
|
ENV ROCKET_WORKERS=10
|
||
|
ENV SSL_CERT_DIR=/etc/ssl/certs
|
||
|
|
||
|
# Install needed libraries
|
||
|
RUN apk add \
|
||
6 years ago
|
openssl \
|
||
|
mariadb-connector-c \
|
||
6 years ago
|
ca-certificates \
|
||
|
&& rm /var/cache/apk/*
|
||
|
|
||
|
RUN mkdir /data
|
||
|
VOLUME /data
|
||
|
EXPOSE 80
|
||
6 years ago
|
EXPOSE 3012
|
||
6 years ago
|
|
||
6 years ago
|
# Copies the files from the context (Rocket.toml file and web-vault)
|
||
6 years ago
|
# and the binary from the "build" stage to the current stage
|
||
|
COPY Rocket.toml .
|
||
|
COPY --from=vault /web-vault ./web-vault
|
||
6 years ago
|
COPY --from=build /app/target/x86_64-unknown-linux-musl/release/bitwarden_rs .
|
||
6 years ago
|
|
||
|
# Configures the startup!
|
||
|
CMD ./bitwarden_rs
|