From 9989534983e0b81b33d52f4fcff097235c44104c Mon Sep 17 00:00:00 2001 From: Christian Eriksson Date: Tue, 10 Nov 2020 11:08:37 +0100 Subject: [PATCH] Support for arm32v7 (#25) * Move Dockerfile.patch files to architecture dependent directories Need a way to distinguish between patches when we implement support for other architectures. Putting them in different paths seems simple and straight forward enough. * Add -a option to support arm32v7 and amd64 architectures Previous releases lacked support for compiling for arm32v7 architecture. In order to keep previous behaviour the default is set to amd64. Using the -a option, users can now choose between arm32v7 and amd64. If arm32v7 is used only the Buster release of debian is supported. The limitation is due to the libmariadb3:armhf dependency not being avaliable in earlier debian releases. * Update documentation to detail the -a option * Remove reference to local dirs * Set debian package to report correct architecture for arm32v7 build * Format arm32v7 Dockerfile.patch to match the amd64 * Handle architecture property in control file dynamically Similar to version, the architecture property in the control file should be handled dynamically. The build script will now replace the architecture prop from control.dist to match the choosen architecture. --- README.md | 4 +- build.sh | 12 +- control.dist | 2 +- .../amd64/Dockerfile.patch | 0 patch/arm32v7/Dockerfile.patch | 116 ++++++++++++++++++ 5 files changed, 128 insertions(+), 6 deletions(-) rename Dockerfile.patch => patch/amd64/Dockerfile.patch (100%) create mode 100644 patch/arm32v7/Dockerfile.patch diff --git a/README.md b/README.md index ea98b20..754c7c1 100644 --- a/README.md +++ b/README.md @@ -17,11 +17,11 @@ Then: ``` git clone https://github.com/greizgh/bitwarden_rs-debian.git cd bitwarden_rs-debian -./build.sh -r 1.10.0 +./build.sh -r 1.17.0 ``` The `build.sh` script will build bitwarden_rs for the same Debian version which targets bitwarden_rs. -To compile for a different Debian version, specify the release name (e.g. Stretch, Buster) using the `-o` option. +To compile for a different Debian version, specify the release name (e.g. Stretch, Buster) using the `-o` option. You can compile for arm32v7 or amd64 architecture using the `-a` option, only the Buster (default) release of debian is supported by arm32v7. ``` ./build.sh -o stretch diff --git a/build.sh b/build.sh index df17e82..09247ad 100755 --- a/build.sh +++ b/build.sh @@ -6,7 +6,7 @@ DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" SRC="$DIR/git" DST="$DIR/dist" -while getopts ":r:o:d:" opt; do +while getopts ":r:o:d:a:" opt; do case $opt in r) REF="$OPTARG" ;; @@ -14,6 +14,8 @@ while getopts ":r:o:d:" opt; do ;; d) DB_TYPE="$OPTARG" ;; + a) ARCH_DIR="$OPTARG" + ;; \?) echo "Invalid option -$OPTARG" >&2 ;; esac @@ -21,6 +23,9 @@ done if [ -z "$REF" ]; then REF=$(curl -s https://api.github.com/repos/dani-garcia/bitwarden_rs/releases/latest | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/' | cut -c 1-); fi if [ -z "$OS_VERSION_NAME" ]; then OS_VERSION_NAME='buster'; fi if [ -z "$DB_TYPE" ]; then DB_TYPE="sqlite"; fi +if [ -z "$ARCH_DIR" ]; then ARCH_DIR="amd64"; fi +ARCH=$ARCH_DIR +if [[ "$ARCH" =~ ^arm ]]; then ARCH="armhf"; fi # Clone bitwarden_rs if [ ! -d "$SRC" ]; then @@ -47,7 +52,7 @@ sed -i "s/Uncomment any of the following lines to change the defaults/Uncomment mkdir -p "$DST" # Prepare Dockerfile -patch -i "$DIR/Dockerfile.patch" "$SRC/docker/amd64/Dockerfile" --verbose -o "$DIR/Dockerfile" || exit +patch -i "$DIR/patch/$ARCH_DIR/Dockerfile.patch" "$SRC/docker/$ARCH_DIR/Dockerfile" --verbose -o "$DIR/Dockerfile" || exit sed -E "s/(FROM[[:space:]]*rust:)[^[:space:]]+(.+)/\1${OS_VERSION_NAME}\2/g" -i "$DIR/Dockerfile" sed -E "s/(FROM[[:space:]]*debian:)[^-]+(-.+)/\1${OS_VERSION_NAME}\2/g" -i "$DIR/Dockerfile" @@ -55,6 +60,7 @@ sed -E "s/(FROM[[:space:]]*debian:)[^-]+(-.+)/\1${OS_VERSION_NAME}\2/g" -i "$DIR CONTROL="$DIR/debian/control" cp "$DIR/control.dist" "$CONTROL" sed -i "s/Version:.*/Version: $REF-1/" "$CONTROL" +sed -i "s/Architecture:.*/Architecture: $ARCH/" "$CONTROL" # Prepare Systemd-unit SYSTEMD_UNIT="$DIR/debian/bitwarden_rs.service" @@ -68,5 +74,5 @@ echo "[INFO] docker build -t bitwarden-deb "$DIR" --build-arg DB=$DB_TYPE" docker build -t bitwarden-deb "$DIR" --build-arg DB=$DB_TYPE CID=$(docker run -d bitwarden-deb) -docker cp "$CID":/bitwarden_package/bitwarden-rs.deb "$DST/bitwarden_rs-${OS_VERSION_NAME}-${REF}-${DB_TYPE}.deb" +docker cp "$CID":/bitwarden_package/bitwarden-rs.deb "$DST/bitwarden_rs-${OS_VERSION_NAME}-${REF}-${DB_TYPE}-${ARCH_DIR}.deb" docker rm "$CID" diff --git a/control.dist b/control.dist index b6527cb..4a0aebc 100644 --- a/control.dist +++ b/control.dist @@ -1,5 +1,5 @@ Package: bitwarden-rs -Architecture: amd64 +Architecture: - Maintainer: Greizgh Priority: optional Version: - diff --git a/Dockerfile.patch b/patch/amd64/Dockerfile.patch similarity index 100% rename from Dockerfile.patch rename to patch/amd64/Dockerfile.patch diff --git a/patch/arm32v7/Dockerfile.patch b/patch/arm32v7/Dockerfile.patch new file mode 100644 index 0000000..b383136 --- /dev/null +++ b/patch/arm32v7/Dockerfile.patch @@ -0,0 +1,116 @@ +--- ./git/docker/arm32v7/Dockerfile 2020-10-31 15:04:00.786589801 +0100 ++++ ./Dockerfile 2020-11-06 17:44:35.204501362 +0100 +@@ -54,23 +54,23 @@ + && echo 'rustflags = ["-L/usr/lib/arm-linux-gnueabihf"]' >> ~/.cargo/config + + ENV CARGO_HOME "/root/.cargo" + ENV USER "root" + + # 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 ./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 + + # NOTE: This should be the last apt-get/dpkg for this stage, since after this it will fail because of broken dependencies. + # For Diesel-RS migrations_macros to compile with MySQL/MariaDB we need to do some magic. + # We at least need libmariadb3:amd64 installed for the x86_64 version of libmariadb.so (client) + # We also need the libmariadb-dev-compat:amd64 but it can not be installed together with the :armhf version. + # What we can do is a force install, because nothing important is overlapping each other. + RUN apt-get install -y libmariadb3:amd64 && \ + mkdir -pv /tmp/dpkg && \ + cd /tmp/dpkg && \ + apt-get download libmariadb-dev-compat:amd64 && \ +@@ -90,64 +90,45 @@ + RUN rustup target add armv7-unknown-linux-gnueabihf + + # Builds your dependencies and removes the + # dummy project, except the target folder + # This folder contains the compiled dependencies + RUN cargo build --features ${DB} --release --target=armv7-unknown-linux-gnueabihf + RUN find . -not -path "./target*" -delete + + # 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 + + # Builds again, this time it'll just be + # your actual source files being built + RUN cargo build --features ${DB} --release --target=armv7-unknown-linux-gnueabihf + + ######################## RUNTIME IMAGE ######################## + # Create a new stage with a minimal image + # because we already have a binary built +-FROM balenalib/armv7hf-debian:buster ++FROM debian:buster-slim + +-ENV ROCKET_ENV "staging" +-ENV ROCKET_PORT=80 +-ENV ROCKET_WORKERS=10 +- +-RUN [ "cross-build-start" ] +- +-# Install needed libraries +-RUN apt-get update && apt-get install -y \ +- --no-install-recommends \ +- openssl \ +- ca-certificates \ +- curl \ +- sqlite3 \ +- libmariadb-dev-compat \ +- libpq5 \ +- && rm -rf /var/lib/apt/lists/* +- +-RUN mkdir /data +- +-RUN [ "cross-build-end" ] +- +-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 +-COPY Rocket.toml . +-COPY --from=vault /web-vault ./web-vault +-COPY --from=build /app/target/armv7-unknown-linux-gnueabihf/release/bitwarden_rs . +- +-COPY docker/healthcheck.sh /healthcheck.sh +-COPY docker/start.sh /start.sh +- +-HEALTHCHECK --interval=60s --timeout=10s CMD ["/healthcheck.sh"] +- +-# Configures the startup! +-WORKDIR / +-CMD ["/start.sh"] ++# 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 ++ ++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/armv7-unknown-linux-gnueabihf/release/bitwarden_rs /bitwarden_package/usr/local/bin ++ ++# Create the package ++RUN dpkg-deb --build . bitwarden-rs.deb +