From d89e259a90bfce7e3627c16ee159b058f163a9ec Mon Sep 17 00:00:00 2001 From: Greizgh Date: Wed, 27 Mar 2019 10:19:46 +0100 Subject: [PATCH] Do not duplicate Dockerfile The packaging Dockerfile will be generated by patching the one in bitwarden_rs sources. --- .gitignore | 1 + Dockerfile | 85 ------------------------------------------------ Dockerfile.patch | 84 +++++++++++++++++++++++++++++++++++++++++++++++ README.md | 1 + build.sh | 3 ++ 5 files changed, 89 insertions(+), 85 deletions(-) delete mode 100644 Dockerfile create mode 100644 Dockerfile.patch diff --git a/.gitignore b/.gitignore index 7fbcfb9..a54509b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ git/ dist/ debian/config.env +Dockerfile diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index 0fe7bdd..0000000 --- a/Dockerfile +++ /dev/null @@ -1,85 +0,0 @@ -# Using multistage build: -# https://docs.docker.com/develop/develop-images/multistage-build/ -# https://whitfin.io/speeding-up-rust-docker-builds/ -####################### VAULT BUILD IMAGE ####################### -FROM alpine as vault - -ENV VAULT_VERSION "v2.9.0" - -ENV URL "https://github.com/dani-garcia/bw_web_builds/releases/download/$VAULT_VERSION/bw_web_$VAULT_VERSION.tar.gz" - -RUN apk add --update-cache --upgrade \ - curl \ - tar - -RUN mkdir /web-vault -WORKDIR /web-vault - -RUN curl -L $URL | tar xz -RUN ls - - -########################## BUILD IMAGE ########################## -# We need to use the Rust build image, because -# we need the Rust compiler and Cargo tooling -FROM rust as build - -# Using bundled SQLite, no need to install it -# RUN apt-get update && apt-get install -y\ -# sqlite3\ -# --no-install-recommends\ -# && rm -rf /var/lib/apt/lists/* - -# Creates a dummy project used to grab dependencies -RUN USER=root cargo new --bin app -WORKDIR /app - -# Copies over *only* your manifests and build files -COPY git/Cargo.* ./ -COPY git/rust-toolchain ./rust-toolchain -COPY git/build.rs ./build.rs - -# Builds your dependencies and removes the -# dummy project, except the target folder -# This folder contains the compiled dependencies -RUN cargo build --release -RUN find . -not -path "./target*" -delete - -# Copies the complete project -# To avoid copying unneeded files, use .dockerignore -COPY git . - -# Make sure that we actually build the project -RUN touch src/main.rs - -# Builds again, this time it'll just be -# your actual source files being built -RUN cargo build --release - -######################## PACKAGING IMAGE ######################## -# Create a new stage with a minimal image -# because we already have a binary built -FROM debian:stretch-slim - -# Create package directory -RUN mkdir -p /bitwarden_package/DEBIAN -RUN mkdir -p /bitwarden_package/usr/local/bin -RUN mkdir -p /bitwarden_package/usr/lib/systemd/system -RUN mkdir -p /bitwarden_package/etc/bitwarden_rs -RUN mkdir -p /bitwarden_package/usr/share/bitwarden_rs - -WORKDIR /bitwarden_package - -# Copies the files from the context (Rocket.toml file and web-vault) -# and the binary from the "build" stage to the current stage -COPY debian/control /bitwarden_package/DEBIAN/control -COPY debian/postinst /bitwarden_package/DEBIAN/postinst -COPY debian/conffiles /bitwarden_package/DEBIAN/conffiles -COPY git/Rocket.toml /bitwarden_package/etc/bitwarden_rs -COPY debian/config.env /bitwarden_package/etc/bitwarden_rs -COPY debian/bitwarden_rs.service /bitwarden_package/usr/lib/systemd/system -COPY --from=vault /web-vault /bitwarden_package/usr/share/bitwarden_rs/web-vault -COPY --from=build app/target/release/bitwarden_rs /bitwarden_package/usr/local/bin - -# Create the package -RUN dpkg-deb --build . bitwarden-rs.deb diff --git a/Dockerfile.patch b/Dockerfile.patch new file mode 100644 index 0000000..31c4587 --- /dev/null +++ b/Dockerfile.patch @@ -0,0 +1,84 @@ +--- git/Dockerfile 2019-03-27 09:42:06.388326974 +0100 ++++ Dockerfile 2019-03-27 10:13:47.817629003 +0100 +@@ -18,6 +18,7 @@ + RUN curl -L $URL | tar xz + RUN ls + ++ + ########################## BUILD IMAGE ########################## + # We need to use the Rust build image, because + # we need the Rust compiler and Cargo tooling +@@ -34,9 +35,9 @@ + WORKDIR /app + + # Copies over *only* your manifests and build files +-COPY ./Cargo.* ./ +-COPY ./rust-toolchain ./rust-toolchain +-COPY ./build.rs ./build.rs ++COPY git/Cargo.* ./ ++COPY git/rust-toolchain ./rust-toolchain ++COPY git/build.rs ./build.rs + + # Builds your dependencies and removes the + # dummy project, except the target folder +@@ -46,7 +47,7 @@ + + # Copies the complete project + # To avoid copying unneeded files, use .dockerignore +-COPY . . ++COPY git . + + # Make sure that we actually build the project + RUN touch src/main.rs +@@ -55,32 +56,30 @@ + # your actual source files being built + RUN cargo build --release + +-######################## RUNTIME IMAGE ######################## ++######################## PACKAGING IMAGE ######################## + # Create a new stage with a minimal image + # because we already have a binary built + FROM debian:stretch-slim + +-ENV ROCKET_ENV "staging" +-ENV ROCKET_PORT=80 +-ENV ROCKET_WORKERS=10 +- +-# Install needed libraries +-RUN apt-get update && apt-get install -y\ +- openssl\ +- ca-certificates\ +- --no-install-recommends\ +- && rm -rf /var/lib/apt/lists/* +- +-RUN mkdir /data +-VOLUME /data +-EXPOSE 80 +-EXPOSE 3012 ++# Create package directory ++RUN mkdir -p /bitwarden_package/DEBIAN ++RUN mkdir -p /bitwarden_package/usr/local/bin ++RUN mkdir -p /bitwarden_package/usr/lib/systemd/system ++RUN mkdir -p /bitwarden_package/etc/bitwarden_rs ++RUN mkdir -p /bitwarden_package/usr/share/bitwarden_rs ++ ++WORKDIR /bitwarden_package + + # Copies the files from the context (Rocket.toml file and web-vault) + # and the binary from the "build" stage to the current stage +-COPY Rocket.toml . +-COPY --from=vault /web-vault ./web-vault +-COPY --from=build app/target/release/bitwarden_rs . ++COPY debian/control /bitwarden_package/DEBIAN/control ++COPY debian/postinst /bitwarden_package/DEBIAN/postinst ++COPY debian/conffiles /bitwarden_package/DEBIAN/conffiles ++COPY git/Rocket.toml /bitwarden_package/etc/bitwarden_rs ++COPY debian/config.env /bitwarden_package/etc/bitwarden_rs ++COPY debian/bitwarden_rs.service /bitwarden_package/usr/lib/systemd/system ++COPY --from=vault /web-vault /bitwarden_package/usr/share/bitwarden_rs/web-vault ++COPY --from=build app/target/release/bitwarden_rs /bitwarden_package/usr/local/bin + +-# Configures the startup! +-CMD ./bitwarden_rs ++# Create the package ++RUN dpkg-deb --build . bitwarden-rs.deb diff --git a/README.md b/README.md index 50cdd95..2031808 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,7 @@ This repository will help you producing a debian package. Make sure you have the required build dependencies: * docker * git +* patch Then: diff --git a/build.sh b/build.sh index 68f1098..d4464ed 100755 --- a/build.sh +++ b/build.sh @@ -24,6 +24,9 @@ sed -i "s#\# WEB_VAULT_FOLDER=web-vault/#WEB_VAULT_FOLDER=/usr/share/bitwarden_r mkdir -p "$DST" +# Prepare Dockerfile +patch -i "$DIR/Dockerfile.patch" "$SRC/Dockerfile" -o "$DIR/Dockerfile" + docker build -t bitwarden-deb "$DIR" CID=$(docker run -d bitwarden-deb)