From a025bcd7db2b4ff456ce0cd9def55fc6184f240b Mon Sep 17 00:00:00 2001 From: Jonathan White Date: Sun, 8 Jul 2018 11:41:00 -0400 Subject: [PATCH] Build snaps using custom Docker image * Added --snapcraft option to release-tool build command --- ci/snapcraft/Dockerfile | 51 +++++++++++++++++++++++++++++++++++++++++ release-tool | 51 ++++++++++++++++++++++++++++------------- snapcraft.yaml | 34 +++++++++++++-------------- 3 files changed, 102 insertions(+), 34 deletions(-) create mode 100644 ci/snapcraft/Dockerfile diff --git a/ci/snapcraft/Dockerfile b/ci/snapcraft/Dockerfile new file mode 100644 index 000000000..37b3742dd --- /dev/null +++ b/ci/snapcraft/Dockerfile @@ -0,0 +1,51 @@ +# KeePassXC Linux Release Build Dockerfile +# Copyright (C) 2017-2018 KeePassXC team +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 2 or (at your option) +# version 3 of the License. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +FROM snapcore/snapcraft + +ENV REBUILD_COUNTER=1 + +ENV QT5_VERSION=510 +ENV QT5_PPA_VERSION=5.10.1 + +RUN set -x \ + && apt update -y \ + && apt -y install software-properties-common + +RUN set -x \ + && add-apt-repository ppa:phoerious/keepassxc + +RUN set -x \ + && apt update -y \ + && apt-get -y --no-install-recommends install \ + build-essential \ + cmake \ + libgcrypt20-18-dev \ + libargon2-0-dev \ + libsodium-dev \ + qtbase5-dev \ + qttools5-dev \ + qttools5-dev-tools \ + zlib1g-dev \ + libyubikey-dev \ + libykpers-1-dev \ + libxi-dev \ + libxtst-dev \ + xvfb + +RUN set -x \ + && apt-get autoremove --purge + diff --git a/release-tool b/release-tool index 74f205900..f2a7b8116 100755 --- a/release-tool +++ b/release-tool @@ -41,6 +41,7 @@ BUILD_PLUGINS="all" INSTALL_PREFIX="/usr/local" BUILD_SOURCE_TARBALL=true BUILD_SNAPSHOT=false +BUILD_SNAPCRAFT=false ORIG_BRANCH="" ORIG_CWD="$(pwd)" @@ -106,6 +107,8 @@ Options: This option has no effect if --build is not set. --container-name Docker container name (default: '${DOCKER_CONTAINER_NAME}') The container must not exist already + --snapcraft Create and use docker image to build snapcraft distribution. + This option has no effect if --docker-image is not set. -c, --cmake-options Additional CMake options for compiling the sources --compiler Compiler to use (default: '${COMPILER}') -m, --make-options Make options for compiling sources (default: '${MAKE_OPTIONS}') @@ -542,6 +545,10 @@ build() { --container-name) DOCKER_CONTAINER_NAME="$2" shift ;; + + --snapcraft) + BUILD_SNAPCRAFT=true + shift ;; -c|--cmake-options) CMAKE_OPTIONS="$2" @@ -703,22 +710,34 @@ build() { ${SRC_DIR}/AppImage-Recipe.sh "$APP_NAME" "$RELEASE_NAME" fi else - mkdir -p "${OUTPUT_DIR}/bin-release" - - logInfo "Launching Docker container to compile sources..." - - docker run --name "$DOCKER_CONTAINER_NAME" --rm \ - --cap-add SYS_ADMIN --security-opt apparmor:unconfined --device /dev/fuse \ - -e "CC=${CC}" -e "CXX=${CXX}" \ - -v "$(realpath "$SRC_DIR"):/keepassxc/src:ro" \ - -v "$(realpath "$OUTPUT_DIR"):/keepassxc/out:rw" \ - "$DOCKER_IMAGE" \ - bash -c "cd /keepassxc/out/build-release && \ - cmake -DCMAKE_BUILD_TYPE=Release -DWITH_TESTS=Off $CMAKE_OPTIONS \ - -DCMAKE_INSTALL_PREFIX=\"${INSTALL_PREFIX}\" \ - -DKEEPASSXC_DIST_TYPE=AppImage /keepassxc/src && \ - make $MAKE_OPTIONS && make DESTDIR=/keepassxc/out/bin-release install/strip && \ - /keepassxc/src/AppImage-Recipe.sh "$APP_NAME" "$RELEASE_NAME"" + if [ BUILD_SNAPCRAFT ]; then + logInfo "Building snapcraft docker image..." + + sudo docker image build -t "$DOCKER_IMAGE" "$(realpath "$SRC_DIR")/ci/snapcraft" + + logInfo "Launching Docker contain to compile snapcraft..." + + sudo docker run --name "$DOCKER_CONTAINER_NAME" --rm \ + -v "$(realpath "$SRC_DIR"):/keepassxc" -w "/keepassxc" \ + "$DOCKER_IMAGE" snapcraft + else + mkdir -p "${OUTPUT_DIR}/bin-release" + + logInfo "Launching Docker container to compile sources..." + + docker run --name "$DOCKER_CONTAINER_NAME" --rm \ + --cap-add SYS_ADMIN --security-opt apparmor:unconfined --device /dev/fuse \ + -e "CC=${CC}" -e "CXX=${CXX}" \ + -v "$(realpath "$SRC_DIR"):/keepassxc/src:ro" \ + -v "$(realpath "$OUTPUT_DIR"):/keepassxc/out:rw" \ + "$DOCKER_IMAGE" \ + bash -c "cd /keepassxc/out/build-release && \ + cmake -DCMAKE_BUILD_TYPE=Release -DWITH_TESTS=Off $CMAKE_OPTIONS \ + -DCMAKE_INSTALL_PREFIX=\"${INSTALL_PREFIX}\" \ + -DKEEPASSXC_DIST_TYPE=AppImage /keepassxc/src && \ + make $MAKE_OPTIONS && make DESTDIR=/keepassxc/out/bin-release install/strip && \ + /keepassxc/src/AppImage-Recipe.sh "$APP_NAME" "$RELEASE_NAME"" + fi if [ 0 -ne $? ]; then exitError "Docker build failed!" diff --git a/snapcraft.yaml b/snapcraft.yaml index 5a3597c30..83f003aea 100644 --- a/snapcraft.yaml +++ b/snapcraft.yaml @@ -27,6 +27,8 @@ parts: configflags: - -DCMAKE_BUILD_TYPE=Release - -DCMAKE_INSTALL_PREFIX=/usr + - -DCMAKE_LIBRARY_PATH=/opt/keepassxc-libs/lib/x86_64-linux-gnu + - -DCMAKE_INCLUDE_PATH=/opt/keepassxc-libs/include - -DKEEPASSXC_DIST_TYPE=Snap - -DKEEPASSXC_BUILD_TYPE=Release - -DWITH_TESTS=OFF @@ -43,29 +45,25 @@ parts: - libxtst-dev - libyubikey-dev - libykpers-1-dev - - libcurl4-openssl-dev - libsodium-dev stage-packages: - dbus - qttranslations5-l10n # common translations - install: | + - libgcrypt20-18 + - libykpers-1-1 + - libargon2-0 + - libsodium23 + - libxtst6 + - libqt5x11extras5 + - libusb-1.0-0 + override-build: | + snapcraftctl build sed -i 's|Icon=keepassxc|Icon=${SNAP}/usr/share/icons/hicolor/256x256/apps/keepassxc.png|g' $SNAPCRAFT_PART_INSTALL/usr/share/applications/org.keepassxc.KeePassXC.desktop organize: usr/share/qt5/translations/*.qm: usr/share/keepassxc/translations/ + opt/keepassxc-libs/lib/x86_64-linux-gnu/*: usr/lib/x86_64-linux-gnu/ + opt/keepassxc-libs/share/locale/*: usr/share/locale/ + stage: + - -opt after: [desktop-qt5] - - # Redefine desktop-qt5 stage packages to work with Ubuntu 17.04 - desktop-qt5: - stage-packages: - - libxkbcommon0 - - ttf-ubuntu-font-family - - dmz-cursor-theme - - light-themes - - adwaita-icon-theme - - gnome-themes-standard - - shared-mime-info - - libqt5gui5 - - libgdk-pixbuf2.0-0 - - libqt5svg5 # for loading icon themes which are svg - - locales-all - - xdg-user-dirs +