diff --git a/.travis.yml b/.travis.yml index d6fc01cc..a4f01db4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -118,4 +118,18 @@ matrix: - docker login -u="$DOCKER_USER" -p="$DOCKER_PASSWORD" - ./build_docker.sh after_script: - - docker images + - docker images + + # Snapcraft build configuration + - if: repo = AdguardTeam/AdGuardHome + - name: snapcraft + # if: type != pull_request AND (branch = master OR tag IS present) AND repo = AdguardTeam/AdGuardHome + if: branch = snapcraft + go: + - 1.14.x + os: + - linux + services: + - docker + script: + - ./build_snap.sh diff --git a/build_snap.sh b/build_snap.sh new file mode 100755 index 00000000..2d305a52 --- /dev/null +++ b/build_snap.sh @@ -0,0 +1,81 @@ +#!/usr/bin/env bash + +set -eE +set -o pipefail +set -x + +BUILDER_IMAGE="adguard/snapcraft:1.0" +SNAPCRAFT_TMPL="packaging/snap/snapcraft.yaml" +SNAP_NAME="adguardhometest" +VERSION=`git describe --abbrev=4 --dirty --always --tags` + +if [[ "${TRAVIS_BRANCH}" == "master" ]] +then + CHANNEL="edge" +else + CHANNEL="release" +fi + +# Launchpad oauth tokens data is necessary to run snapcraft remote-build +# +# Here's an instruction on how to generate launchpad OAuth tokens: +# https://uci.readthedocs.io/en/latest/oauth.html +# +# Launchpad credentials are necessary to run snapcraft remote-build command +echo "[1] +consumer_key = ${LAUNCHPAD_KEY} +consumer_secret = +access_token = ${LAUNCHPAD_ACCESS_TOKEN} +access_secret = ${LAUNCHPAD_ACCESS_SECRET} +" > launchpad_credentials + +# Snapcraft login data +# It can be exported using snapcraft export-login command +echo "[login.ubuntu.com] +macaroon = ${SNAPCRAFT_MACAROON} +unbound_discharge = ${SNAPCRAFT_UBUNTU_DISCHARGE} +email = ${SNAPCRAFT_EMAIL}" > snapcraft_login + +# Prepare the snap configuration +cp ${SNAPCRAFT_TMPL} ./snapcraft.yaml +sed -i.bak 's/dev_version/'"${VERSION}"'/g' ./snapcraft.yaml + +build_snap() { + # Run the build + docker run -it -v $(pwd):/build \ + -v $(pwd)/launchpad_credentials:/root/.local/share/snapcraft/provider/launchpad/credentials:ro \ + ${BUILDER_IMAGE} \ + snapcraft remote-build --build-on=${ARCH} --launchpad-accept-public-upload +} + +publish_snap() { + # Check that the snap file exists + snapFile="${SNAP_NAME}_${VERSION}_${ARCH}.snap" + if [ ! -f ${snapFile} ]; then + echo "Snap file ${snapFile} not found!" + exit 1 + fi + + # Login and publish the snap + docker run -it -v $(pwd):/build \ + ${BUILDER_IMAGE} \ + sh -c "snapcraft login --with=/build/snapcraft_login && snapcraft push --release=${CHANNEL} /build/${snapFile}" +} + +# Build snaps +ARCH=i386 build_snap +ARCH=arm64 build_snap +ARCH=armhf build_snap +ARCH=amd64 build_snap + +# Publish snaps +ARCH=i386 publish_snap +ARCH=arm64 publish_snap +ARCH=armhf publish_snap +ARCH=amd64 publish_snap + +# Clean up +rm launchpad_credentials +rm snapcraft.yaml +rm snapcraft.yaml.bak +rm snapcraft_login \ No newline at end of file diff --git a/packaging/snap/README.md b/packaging/snap/README.md new file mode 100644 index 00000000..764100ff --- /dev/null +++ b/packaging/snap/README.md @@ -0,0 +1,5 @@ +## Snapcraft + +Configuration for our snap. + +Check out `build_snap.sh` for more details. \ No newline at end of file diff --git a/packaging/snap/snapcraft.yaml b/packaging/snap/snapcraft.yaml new file mode 100644 index 00000000..ba7a47d0 --- /dev/null +++ b/packaging/snap/snapcraft.yaml @@ -0,0 +1,31 @@ +name: adguardhometest +base: core18 +version: 'dev_version' +summary: Network-wide ads & trackers blocking DNS server +description: | + AdGuard Home is a network-wide software for blocking ads & tracking. After + you set it up, it'll cover ALL your home devices, and you don't need any + client-side software for that. + It operates as a DNS server that re-routes tracking domains to a "black hole," + thus preventing your devices from connecting to those servers. It's based + on software we use for our public AdGuard DNS servers -- both share a lot + of common code. +grade: stable +confinement: strict + +parts: + adguard-home: + plugin: make + source: . + build-snaps: [ node/13/stable, go ] + build-packages: [ git, build-essential ] + override-build: | + make clean + make + cp AdGuardHome ${SNAPCRAFT_PART_INSTALL}/ +apps: + adguard-home: + command: AdGuardHome -c ${SNAP_COMMON}/AdGuardHome.yaml -w ${SNAP_DATA} --no-check-update + plugs: [ network-bind ] + daemon: simple + restart-condition: always \ No newline at end of file