2021-09-13 06:00:52 -04:00
|
|
|
# syntax=docker/dockerfile:1
|
|
|
|
|
2020-02-29 20:38:26 -05:00
|
|
|
# This file was generated using a Jinja2 template.
|
2023-10-22 18:18:38 -04:00
|
|
|
# Please make your changes in `DockerSettings.yaml` or `Dockerfile.j2` and then `make`
|
|
|
|
# This will generate two Dockerfile's `Dockerfile.debian` and `Dockerfile.alpine`
|
|
|
|
|
2020-02-29 20:38:26 -05:00
|
|
|
# Using multistage build:
|
|
|
|
# https://docs.docker.com/develop/develop-images/multistage-build/
|
|
|
|
# https://whitfin.io/speeding-up-rust-docker-builds/
|
2023-10-22 18:18:38 -04:00
|
|
|
|
|
|
|
####################### VAULT BUILD IMAGE #######################
|
2021-01-24 20:26:25 -05:00
|
|
|
# The web-vault digest specifies a particular web-vault build on Docker Hub.
|
|
|
|
# Using the digest instead of the tag name provides better security,
|
|
|
|
# as the digest of an image is immutable, whereas a tag name can later
|
|
|
|
# be changed to point to a malicious image.
|
2020-03-16 17:34:59 -04:00
|
|
|
#
|
2021-01-24 20:26:25 -05:00
|
|
|
# To verify the current digest for a given tag name:
|
2021-04-27 17:18:32 -04:00
|
|
|
# - From https://hub.docker.com/r/vaultwarden/web-vault/tags,
|
2021-01-24 20:26:25 -05:00
|
|
|
# click the tag name to view the digest of the image it currently points to.
|
|
|
|
# - From the command line:
|
2023-05-03 12:31:28 -04:00
|
|
|
# $ docker pull docker.io/vaultwarden/web-vault:{{ vault_version }}
|
|
|
|
# $ docker image inspect --format "{{ '{{' }}.RepoDigests}}" docker.io/vaultwarden/web-vault:{{ vault_version }}
|
|
|
|
# [docker.io/vaultwarden/web-vault@{{ vault_image_digest }}]
|
2021-01-24 20:26:25 -05:00
|
|
|
#
|
|
|
|
# - Conversely, to get the tag name from the digest:
|
2023-05-03 12:31:28 -04:00
|
|
|
# $ docker image inspect --format "{{ '{{' }}.RepoTags}}" docker.io/vaultwarden/web-vault@{{ vault_image_digest }}
|
|
|
|
# [docker.io/vaultwarden/web-vault:{{ vault_version }}]
|
2021-01-24 20:26:25 -05:00
|
|
|
#
|
2023-10-22 18:18:38 -04:00
|
|
|
FROM --platform=linux/amd64 docker.io/vaultwarden/web-vault@{{ vault_image_digest }} as vault
|
|
|
|
|
|
|
|
{% if base == "debian" %}
|
|
|
|
########################## Cross Compile Docker Helper Scripts ##########################
|
|
|
|
## We use the linux/amd64 no matter which Build Platform, since these are all bash scripts
|
|
|
|
## And these bash scripts do not have any significant difference if at all
|
|
|
|
FROM --platform=linux/amd64 docker.io/tonistiigi/xx@{{ xx_image_digest }} AS xx
|
|
|
|
{% elif base == "alpine" %}
|
|
|
|
########################## ALPINE BUILD IMAGES ##########################
|
|
|
|
## NOTE: The Alpine Base Images do not support other platforms then linux/amd64
|
|
|
|
## And for Alpine we define all build images here, they will only be loaded when actually used
|
|
|
|
{% for arch in build_stage_image[base].arch_image %}
|
|
|
|
FROM --platform={{ build_stage_image[base].platform }} {{ build_stage_image[base].arch_image[arch] }} as build_{{ arch }}
|
|
|
|
{% endfor %}
|
|
|
|
{% endif %}
|
|
|
|
|
|
|
|
########################## BUILD IMAGE ##########################
|
|
|
|
# hadolint ignore=DL3006
|
|
|
|
FROM --platform={{ build_stage_image[base].platform }} {{ build_stage_image[base].image }} as build
|
|
|
|
{% if base == "debian" %}
|
|
|
|
COPY --from=xx / /
|
|
|
|
{% endif %}
|
|
|
|
ARG TARGETARCH
|
|
|
|
ARG TARGETVARIANT
|
|
|
|
ARG TARGETPLATFORM
|
2019-12-28 16:52:01 -05:00
|
|
|
|
2023-10-22 18:18:38 -04:00
|
|
|
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
|
2019-12-28 16:52:01 -05:00
|
|
|
|
2019-12-31 10:20:04 -05:00
|
|
|
# Build time options to avoid dpkg warnings and help with reproducible builds.
|
2021-09-13 06:00:52 -04:00
|
|
|
ENV DEBIAN_FRONTEND=noninteractive \
|
|
|
|
LANG=C.UTF-8 \
|
|
|
|
TZ=UTC \
|
|
|
|
TERM=xterm-256color \
|
|
|
|
CARGO_HOME="/root/.cargo" \
|
|
|
|
USER="root"
|
2023-10-22 18:18:38 -04:00
|
|
|
{%- if base == "alpine" %} \
|
|
|
|
# Use PostgreSQL v15 during Alpine/MUSL builds instead of the default v11
|
|
|
|
# Debian Bookworm already contains libpq v15
|
|
|
|
PQ_LIB_DIR="/usr/local/musl/pq15/lib"
|
|
|
|
{% endif %}
|
2019-12-31 10:20:04 -05:00
|
|
|
|
2023-10-22 18:18:38 -04:00
|
|
|
{% if base == "debian" %}
|
2019-12-28 16:52:01 -05:00
|
|
|
|
2023-10-22 18:18:38 -04:00
|
|
|
# Install clang to get `xx-cargo` working
|
|
|
|
# Install pkg-config to allow amd64 builds to find all libraries
|
|
|
|
# Install git so build.rs can determine the correct version
|
|
|
|
# Install the libc cross packages based upon the debian-arch
|
|
|
|
RUN apt-get update && \
|
|
|
|
apt-get install -y \
|
2019-12-31 09:17:31 -05:00
|
|
|
--no-install-recommends \
|
2023-10-22 18:18:38 -04:00
|
|
|
clang \
|
|
|
|
pkg-config \
|
|
|
|
git \
|
|
|
|
"libc6-$(xx-info debian-arch)-cross" \
|
|
|
|
"libc6-dev-$(xx-info debian-arch)-cross" \
|
|
|
|
"linux-libc-dev-$(xx-info debian-arch)-cross" && \
|
2024-05-19 14:32:36 -04:00
|
|
|
xx-apt-get install -y \
|
2021-09-13 06:00:52 -04:00
|
|
|
--no-install-recommends \
|
2023-10-22 18:18:38 -04:00
|
|
|
gcc \
|
|
|
|
libmariadb3 \
|
|
|
|
libpq-dev \
|
|
|
|
libpq5 \
|
2023-12-09 17:04:33 -05:00
|
|
|
libssl-dev \
|
|
|
|
zlib1g-dev && \
|
2023-10-22 18:18:38 -04:00
|
|
|
# Force install arch dependend mariadb dev packages
|
|
|
|
# Installing them the normal way breaks several other packages (again)
|
|
|
|
apt-get download "libmariadb-dev-compat:$(xx-info debian-arch)" "libmariadb-dev:$(xx-info debian-arch)" && \
|
2024-05-19 14:32:36 -04:00
|
|
|
dpkg --force-all -i ./libmariadb-dev*.deb && \
|
|
|
|
# Run xx-cargo early, since it sometimes seems to break when run at a later stage
|
|
|
|
echo "export CARGO_TARGET=$(xx-cargo --print-target-triple)" >> /env-cargo
|
2019-12-28 16:52:01 -05:00
|
|
|
{% endif %}
|
2020-08-18 18:02:14 -04:00
|
|
|
|
2023-10-22 18:18:38 -04:00
|
|
|
# Create CARGO_HOME folder and don't download rust docs
|
2024-05-19 14:32:36 -04:00
|
|
|
RUN mkdir -pv "${CARGO_HOME}" && \
|
|
|
|
rustup set profile minimal
|
2023-10-22 18:18:38 -04:00
|
|
|
|
2019-12-28 16:52:01 -05:00
|
|
|
# Creates a dummy project used to grab dependencies
|
2019-12-31 09:31:01 -05:00
|
|
|
RUN USER=root cargo new --bin /app
|
2019-12-28 16:52:01 -05:00
|
|
|
WORKDIR /app
|
|
|
|
|
2023-10-22 18:18:38 -04:00
|
|
|
{% if base == "debian" %}
|
2024-04-27 15:51:14 -04:00
|
|
|
# Environment variables for Cargo on Debian based builds
|
|
|
|
ARG ARCH_OPENSSL_LIB_DIR \
|
|
|
|
ARCH_OPENSSL_INCLUDE_DIR
|
|
|
|
|
2023-10-22 18:18:38 -04:00
|
|
|
RUN source /env-cargo && \
|
|
|
|
if xx-info is-cross ; then \
|
2024-04-27 15:51:14 -04:00
|
|
|
# Some special variables if needed to override some build paths
|
|
|
|
if [[ -n "${ARCH_OPENSSL_LIB_DIR}" && -n "${ARCH_OPENSSL_INCLUDE_DIR}" ]]; then \
|
|
|
|
echo "export $(echo "${CARGO_TARGET}" | tr '[:lower:]' '[:upper:]' | tr - _)_OPENSSL_LIB_DIR=${ARCH_OPENSSL_LIB_DIR}" >> /env-cargo && \
|
|
|
|
echo "export $(echo "${CARGO_TARGET}" | tr '[:lower:]' '[:upper:]' | tr - _)_OPENSSL_INCLUDE_DIR=${ARCH_OPENSSL_INCLUDE_DIR}" >> /env-cargo ; \
|
|
|
|
fi && \
|
2023-10-22 18:18:38 -04:00
|
|
|
# We can't use xx-cargo since that uses clang, which doesn't work for our libraries.
|
|
|
|
# Because of this we generate the needed environment variables here which we can load in the needed steps.
|
|
|
|
echo "export CC_$(echo "${CARGO_TARGET}" | tr '[:upper:]' '[:lower:]' | tr - _)=/usr/bin/$(xx-info)-gcc" >> /env-cargo && \
|
|
|
|
echo "export CARGO_TARGET_$(echo "${CARGO_TARGET}" | tr '[:lower:]' '[:upper:]' | tr - _)_LINKER=/usr/bin/$(xx-info)-gcc" >> /env-cargo && \
|
|
|
|
echo "export PKG_CONFIG=/usr/bin/$(xx-info)-pkg-config" >> /env-cargo && \
|
|
|
|
echo "export CROSS_COMPILE=1" >> /env-cargo && \
|
|
|
|
echo "export OPENSSL_INCLUDE_DIR=/usr/include/$(xx-info)" >> /env-cargo && \
|
|
|
|
echo "export OPENSSL_LIB_DIR=/usr/lib/$(xx-info)" >> /env-cargo ; \
|
|
|
|
fi && \
|
|
|
|
# Output the current contents of the file
|
|
|
|
cat /env-cargo
|
2020-09-21 18:39:39 -04:00
|
|
|
|
2023-10-22 18:18:38 -04:00
|
|
|
{% elif base == "alpine" %}
|
2024-04-27 15:51:14 -04:00
|
|
|
# Environment variables for Cargo on Alpine based builds
|
2023-10-22 18:18:38 -04:00
|
|
|
RUN echo "export CARGO_TARGET=${RUST_MUSL_CROSS_TARGET}" >> /env-cargo && \
|
|
|
|
# To be able to build the armv6 image with mimalloc we need to tell the linker to also look for libatomic
|
|
|
|
if [[ "${TARGETARCH}${TARGETVARIANT}" == "armv6" ]] ; then echo "export RUSTFLAGS='-Clink-arg=-latomic'" >> /env-cargo ; fi && \
|
|
|
|
# Output the current contents of the file
|
|
|
|
cat /env-cargo
|
|
|
|
|
2022-03-20 13:51:24 -04:00
|
|
|
{% endif %}
|
2023-10-22 18:18:38 -04:00
|
|
|
RUN source /env-cargo && \
|
|
|
|
rustup target add "${CARGO_TARGET}"
|
|
|
|
|
2024-05-19 14:32:36 -04:00
|
|
|
# Copies over *only* your manifests and build files
|
|
|
|
COPY ./Cargo.* ./rust-toolchain.toml ./build.rs ./
|
|
|
|
|
2023-10-22 18:18:38 -04:00
|
|
|
ARG CARGO_PROFILE=release
|
|
|
|
|
2024-05-19 14:32:36 -04:00
|
|
|
# Configure the DB ARG as late as possible to not invalidate the cached layers above
|
|
|
|
{% if base == "debian" %}
|
|
|
|
ARG DB=sqlite,mysql,postgresql
|
|
|
|
{% elif base == "alpine" %}
|
|
|
|
# Enable MiMalloc to improve performance on Alpine builds
|
|
|
|
ARG DB=sqlite,mysql,postgresql,enable_mimalloc
|
|
|
|
{% endif %}
|
2023-10-22 18:18:38 -04:00
|
|
|
|
2019-12-28 16:52:01 -05:00
|
|
|
# Builds your dependencies and removes the
|
|
|
|
# dummy project, except the target folder
|
|
|
|
# This folder contains the compiled dependencies
|
2023-10-22 18:18:38 -04:00
|
|
|
RUN source /env-cargo && \
|
|
|
|
cargo build --features ${DB} --profile "${CARGO_PROFILE}" --target="${CARGO_TARGET}" && \
|
|
|
|
find . -not -path "./target*" -delete
|
2019-12-28 16:52:01 -05:00
|
|
|
|
|
|
|
# Copies the complete project
|
|
|
|
# To avoid copying unneeded files, use .dockerignore
|
|
|
|
COPY . .
|
|
|
|
|
2024-05-19 14:32:36 -04:00
|
|
|
ARG VW_VERSION
|
|
|
|
|
2023-10-22 18:18:38 -04:00
|
|
|
# Builds again, this time it will be the actual source files being build
|
|
|
|
RUN source /env-cargo && \
|
|
|
|
# Make sure that we actually build the project by updating the src/main.rs timestamp
|
2023-12-09 17:04:33 -05:00
|
|
|
# Also do this for build.rs to ensure the version is rechecked
|
|
|
|
touch build.rs src/main.rs && \
|
2023-10-22 18:18:38 -04:00
|
|
|
# Create a symlink to the binary target folder to easy copy the binary in the final stage
|
|
|
|
cargo build --features ${DB} --profile "${CARGO_PROFILE}" --target="${CARGO_TARGET}" && \
|
|
|
|
if [[ "${CARGO_PROFILE}" == "dev" ]] ; then \
|
|
|
|
ln -vfsr "/app/target/${CARGO_TARGET}/debug" /app/target/final ; \
|
|
|
|
else \
|
|
|
|
ln -vfsr "/app/target/${CARGO_TARGET}/${CARGO_PROFILE}" /app/target/final ; \
|
|
|
|
fi
|
2019-12-28 16:52:01 -05:00
|
|
|
|
|
|
|
|
|
|
|
######################## RUNTIME IMAGE ########################
|
|
|
|
# Create a new stage with a minimal image
|
|
|
|
# because we already have a binary built
|
2023-10-22 18:18:38 -04:00
|
|
|
#
|
|
|
|
# To build these images you need to have qemu binfmt support.
|
|
|
|
# See the following pages to help install these tools locally
|
|
|
|
# Ubuntu/Debian: https://wiki.debian.org/QemuUserEmulation
|
|
|
|
# Arch Linux: https://wiki.archlinux.org/title/QEMU#Chrooting_into_arm/arm64_environment_from_x86_64
|
|
|
|
#
|
|
|
|
# Or use a Docker image which modifies your host system to support this.
|
|
|
|
# The GitHub Actions Workflow uses the same image as used below.
|
|
|
|
# See: https://github.com/tonistiigi/binfmt
|
|
|
|
# Usage: docker run --privileged --rm tonistiigi/binfmt --install arm64,arm
|
|
|
|
# To uninstall: docker run --privileged --rm tonistiigi/binfmt --uninstall 'qemu-*'
|
|
|
|
#
|
|
|
|
# We need to add `--platform` here, because of a podman bug: https://github.com/containers/buildah/issues/4742
|
|
|
|
FROM --platform=$TARGETPLATFORM {{ runtime_stage_image[base] }}
|
2019-12-28 16:52:01 -05:00
|
|
|
|
2022-02-07 16:26:22 -05:00
|
|
|
ENV ROCKET_PROFILE="release" \
|
|
|
|
ROCKET_ADDRESS=0.0.0.0 \
|
|
|
|
ROCKET_PORT=80
|
2023-10-22 18:18:38 -04:00
|
|
|
{%- if base == "debian" %} \
|
|
|
|
DEBIAN_FRONTEND=noninteractive
|
|
|
|
{% elif base == "alpine" %} \
|
2021-12-26 06:40:12 -05:00
|
|
|
SSL_CERT_DIR=/etc/ssl/certs
|
2019-12-28 16:52:01 -05:00
|
|
|
{% endif %}
|
|
|
|
|
2021-05-08 10:48:48 -04:00
|
|
|
# Create data folder and Install needed libraries
|
2023-10-22 18:18:38 -04:00
|
|
|
RUN mkdir /data && \
|
|
|
|
{% if base == "debian" %}
|
|
|
|
apt-get update && apt-get install -y \
|
|
|
|
--no-install-recommends \
|
|
|
|
ca-certificates \
|
|
|
|
curl \
|
|
|
|
libmariadb-dev-compat \
|
|
|
|
libpq5 \
|
|
|
|
openssl && \
|
|
|
|
apt-get clean && \
|
|
|
|
rm -rf /var/lib/apt/lists/*
|
|
|
|
{% elif base == "alpine" %}
|
|
|
|
apk --no-cache add \
|
2023-01-19 00:50:29 -05:00
|
|
|
ca-certificates \
|
2019-12-28 16:52:01 -05:00
|
|
|
curl \
|
2023-01-19 00:50:29 -05:00
|
|
|
openssl \
|
|
|
|
tzdata
|
2019-12-28 16:52:01 -05:00
|
|
|
{% endif %}
|
2021-05-08 10:48:48 -04:00
|
|
|
|
2019-12-28 16:52:01 -05:00
|
|
|
VOLUME /data
|
|
|
|
EXPOSE 80
|
|
|
|
EXPOSE 3012
|
|
|
|
|
|
|
|
# Copies the files from the context (Rocket.toml file and web-vault)
|
|
|
|
# and the binary from the "build" stage to the current stage
|
2021-03-30 15:45:10 -04:00
|
|
|
WORKDIR /
|
2019-12-28 16:52:01 -05:00
|
|
|
|
2024-05-19 14:32:36 -04:00
|
|
|
COPY docker/healthcheck.sh docker/start.sh /
|
2019-12-28 16:52:01 -05:00
|
|
|
|
2023-10-22 18:18:38 -04:00
|
|
|
COPY --from=vault /web-vault ./web-vault
|
|
|
|
COPY --from=build /app/target/final/vaultwarden .
|
|
|
|
|
2020-03-25 23:13:36 -04:00
|
|
|
HEALTHCHECK --interval=60s --timeout=10s CMD ["/healthcheck.sh"]
|
2019-12-28 16:52:01 -05:00
|
|
|
|
2020-07-05 18:26:20 -04:00
|
|
|
CMD ["/start.sh"]
|