*: update build_snap.sh
This commit is contained in:
parent
3ae6043748
commit
093617e6bd
170
build_snap.sh
170
build_snap.sh
|
@ -7,6 +7,7 @@ set -x
|
||||||
BUILDER_IMAGE="adguard/snapcraft:1.0"
|
BUILDER_IMAGE="adguard/snapcraft:1.0"
|
||||||
SNAPCRAFT_TMPL="packaging/snap/snapcraft.yaml"
|
SNAPCRAFT_TMPL="packaging/snap/snapcraft.yaml"
|
||||||
SNAP_NAME="adguardhometest"
|
SNAP_NAME="adguardhometest"
|
||||||
|
LAUNCHPAD_CREDENTIALS_DIR=".local/share/snapcraft/provider/launchpad"
|
||||||
VERSION=`git describe --abbrev=4 --dirty --always --tags`
|
VERSION=`git describe --abbrev=4 --dirty --always --tags`
|
||||||
|
|
||||||
if [[ "${TRAVIS_BRANCH}" == "master" ]]
|
if [[ "${TRAVIS_BRANCH}" == "master" ]]
|
||||||
|
@ -22,6 +23,43 @@ if [ -t 0 ] ; then
|
||||||
INTERACTIVE="-it"
|
INTERACTIVE="-it"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
function usage() {
|
||||||
|
cat <<EOF
|
||||||
|
Usage: ${0##*/} command [options]
|
||||||
|
|
||||||
|
Please note that in order for the builds to work properly, you need to setup some env variables.
|
||||||
|
|
||||||
|
These are necessary for "remote-build' command.
|
||||||
|
Read this doc on how to generate them: https://uci.readthedocs.io/en/latest/oauth.html
|
||||||
|
|
||||||
|
* LAUNCHPAD_KEY -- launchpad CI key
|
||||||
|
* LAUNCHPAD_ACCESS_TOKEN -- launchpad access token
|
||||||
|
* LAUNCHPAD_ACCESS_SECRET -- launchpad access secret
|
||||||
|
|
||||||
|
These are necessary for snapcraft publish command to work.
|
||||||
|
They can be exported using "snapcraft export-login"
|
||||||
|
|
||||||
|
* SNAPCRAFT_MACAROON
|
||||||
|
* SNAPCRAFT_UBUNTU_DISCHARGE
|
||||||
|
* SNAPCRAFT_EMAIL
|
||||||
|
|
||||||
|
Examples:
|
||||||
|
${0##*/} build-docker - builds snaps using remote-build inside a Docker environment
|
||||||
|
${0##*/} build - builds snaps using remote-build
|
||||||
|
${0##*/} publish-docker-beta - publishes snaps to the beta channel using Docker environment
|
||||||
|
${0##*/} publish-docker-release - publishes snaps to the release channel using Docker environment
|
||||||
|
${0##*/} publish-beta - publishes snaps to the beta channel
|
||||||
|
${0##*/} publish-release - publishes snaps to the release channel
|
||||||
|
${0##*/} cleanup - clean up temporary files that were created by the builds
|
||||||
|
EOF
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
#######################################
|
||||||
|
# helper functions
|
||||||
|
#######################################
|
||||||
|
|
||||||
|
function prepare() {
|
||||||
# Launchpad oauth tokens data is necessary to run snapcraft remote-build
|
# Launchpad oauth tokens data is necessary to run snapcraft remote-build
|
||||||
#
|
#
|
||||||
# Here's an instruction on how to generate launchpad OAuth tokens:
|
# Here's an instruction on how to generate launchpad OAuth tokens:
|
||||||
|
@ -45,17 +83,67 @@ email = ${SNAPCRAFT_EMAIL}" > snapcraft_login
|
||||||
# Prepare the snap configuration
|
# Prepare the snap configuration
|
||||||
cp ${SNAPCRAFT_TMPL} ./snapcraft.yaml
|
cp ${SNAPCRAFT_TMPL} ./snapcraft.yaml
|
||||||
sed -i.bak 's/dev_version/'"${VERSION}"'/g' ./snapcraft.yaml
|
sed -i.bak 's/dev_version/'"${VERSION}"'/g' ./snapcraft.yaml
|
||||||
|
rm -f snapcraft.yaml.bak
|
||||||
|
}
|
||||||
|
|
||||||
build_snap() {
|
build_snap() {
|
||||||
# Run the build
|
# prepare credentials
|
||||||
|
prepare
|
||||||
|
|
||||||
|
# copy them to the directory where snapcraft will be able to read them
|
||||||
|
mkdir -p ~/${LAUNCHPAD_CREDENTIALS_DIR}
|
||||||
|
cp -f snapcraft_login ~/${LAUNCHPAD_CREDENTIALS_DIR}/credentials
|
||||||
|
chmod 600 ~/${LAUNCHPAD_CREDENTIALS_DIR}/credentials
|
||||||
|
|
||||||
|
# run the build
|
||||||
|
snapcraft remote-build --build-on=${ARCH} --launchpad-accept-public-upload
|
||||||
|
|
||||||
|
# remove the credentials - we don't need them anymore
|
||||||
|
rm -rf ~/${LAUNCHPAD_CREDENTIALS_DIR}
|
||||||
|
|
||||||
|
# cleanup credentials
|
||||||
|
cleanup
|
||||||
|
}
|
||||||
|
|
||||||
|
build_snap_docker() {
|
||||||
|
# prepare credentials
|
||||||
|
prepare
|
||||||
|
|
||||||
docker run ${INTERACTIVE} --rm \
|
docker run ${INTERACTIVE} --rm \
|
||||||
-v $(pwd):/build \
|
-v $(pwd):/build \
|
||||||
-v $(pwd)/launchpad_credentials:/root/.local/share/snapcraft/provider/launchpad/credentials:ro \
|
-v $(pwd)/launchpad_credentials:/root/${LAUNCHPAD_CREDENTIALS_DIR}/credentials:ro \
|
||||||
${BUILDER_IMAGE} \
|
${BUILDER_IMAGE} \
|
||||||
snapcraft remote-build --build-on=${ARCH} --launchpad-accept-public-upload
|
snapcraft remote-build --build-on=${ARCH} --launchpad-accept-public-upload
|
||||||
|
|
||||||
|
# cleanup credentials
|
||||||
|
cleanup
|
||||||
}
|
}
|
||||||
|
|
||||||
publish_snap() {
|
publish_snap() {
|
||||||
|
# prepare credentials
|
||||||
|
prepare
|
||||||
|
|
||||||
|
# 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 if necessary
|
||||||
|
snapcraft login --with=snapcraft_login
|
||||||
|
|
||||||
|
# Push to the channel
|
||||||
|
snapcraft push --release=${CHANNEL} ${snapFile}
|
||||||
|
|
||||||
|
# cleanup credentials
|
||||||
|
cleanup
|
||||||
|
}
|
||||||
|
|
||||||
|
publish_snap_docker() {
|
||||||
|
# prepare credentials
|
||||||
|
prepare
|
||||||
|
|
||||||
# Check that the snap file exists
|
# Check that the snap file exists
|
||||||
snapFile="${SNAP_NAME}_${VERSION}_${ARCH}.snap"
|
snapFile="${SNAP_NAME}_${VERSION}_${ARCH}.snap"
|
||||||
if [ ! -f ${snapFile} ]; then
|
if [ ! -f ${snapFile} ]; then
|
||||||
|
@ -68,22 +156,86 @@ publish_snap() {
|
||||||
-v $(pwd):/build \
|
-v $(pwd):/build \
|
||||||
${BUILDER_IMAGE} \
|
${BUILDER_IMAGE} \
|
||||||
sh -c "snapcraft login --with=/build/snapcraft_login && snapcraft push --release=${CHANNEL} /build/${snapFile}"
|
sh -c "snapcraft login --with=/build/snapcraft_login && snapcraft push --release=${CHANNEL} /build/${snapFile}"
|
||||||
|
|
||||||
|
# cleanup credentials
|
||||||
|
cleanup
|
||||||
}
|
}
|
||||||
|
|
||||||
# Build snaps
|
#######################################
|
||||||
|
# main functions
|
||||||
|
#######################################
|
||||||
|
|
||||||
|
build() {
|
||||||
ARCH=i386 build_snap
|
ARCH=i386 build_snap
|
||||||
ARCH=arm64 build_snap
|
ARCH=arm64 build_snap
|
||||||
ARCH=armhf build_snap
|
ARCH=armhf build_snap
|
||||||
ARCH=amd64 build_snap
|
ARCH=amd64 build_snap
|
||||||
|
}
|
||||||
|
|
||||||
|
build_docker() {
|
||||||
|
ARCH=i386 build_snap_docker
|
||||||
|
ARCH=arm64 build_snap_docker
|
||||||
|
ARCH=armhf build_snap_docker
|
||||||
|
ARCH=amd64 build_snap_docker
|
||||||
|
}
|
||||||
|
|
||||||
|
publish_docker() {
|
||||||
|
if [[ -z $1 ]]; then
|
||||||
|
echo "No channel specified"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
CHANNEL="${1}"
|
||||||
|
if [ "$CHANNEL" != "release" ] && [ "$CHANNEL" != "beta" ]; then
|
||||||
|
echo "$CHANNEL is an invalid value for the update channel!"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
ARCH=i386 publish_snap_docker
|
||||||
|
ARCH=arm64 publish_snap_docker
|
||||||
|
ARCH=armhf publish_snap_docker
|
||||||
|
ARCH=amd64 publish_snap_docker
|
||||||
|
}
|
||||||
|
|
||||||
|
publish() {
|
||||||
|
if [[ -z $1 ]]; then
|
||||||
|
echo "No channel specified"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
CHANNEL="${1}"
|
||||||
|
if [ "$CHANNEL" != "release" ] && [ "$CHANNEL" != "beta" ]; then
|
||||||
|
echo "$CHANNEL is an invalid value for the update channel!"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
# Publish snaps
|
|
||||||
ARCH=i386 publish_snap
|
ARCH=i386 publish_snap
|
||||||
ARCH=arm64 publish_snap
|
ARCH=arm64 publish_snap
|
||||||
ARCH=armhf publish_snap
|
ARCH=armhf publish_snap
|
||||||
ARCH=amd64 publish_snap
|
ARCH=amd64 publish_snap
|
||||||
|
}
|
||||||
|
|
||||||
# Clean up
|
cleanup() {
|
||||||
rm launchpad_credentials
|
rm -f launchpad_credentials
|
||||||
rm snapcraft.yaml
|
rm -f snapcraft.yaml
|
||||||
rm snapcraft.yaml.bak
|
rm -f snapcraft.yaml.bak
|
||||||
rm snapcraft_login
|
rm -f snapcraft_login
|
||||||
|
}
|
||||||
|
|
||||||
|
#######################################
|
||||||
|
# main
|
||||||
|
#######################################
|
||||||
|
if [[ -z $1 || $1 == "--help" || $1 == "-h" ]]; then
|
||||||
|
usage
|
||||||
|
fi
|
||||||
|
|
||||||
|
case "$1" in
|
||||||
|
"build-docker") build_docker ;;
|
||||||
|
"build") build ;;
|
||||||
|
"publish-docker-beta") publish_docker beta ;;
|
||||||
|
"publish-docker-release") publish_docker release ;;
|
||||||
|
"publish-beta") publish beta ;;
|
||||||
|
"publish-release") publish release ;;
|
||||||
|
"cleanup") cleanup ;;
|
||||||
|
*) usage ;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
exit 0
|
Loading…
Reference in New Issue