Created
July 25, 2019 11:01
-
-
Save popey/c14d5a9ded832d931b12777ca4279e98 to your computer and use it in GitHub Desktop.
Script to rebuild a bunch of snaps using lxd or multipass
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash -x | |
DATESTAMP="$(date +%Y%m%d)-$(date +%H%M%S)" | |
SNAPCRAFT_CHANNEL="--candidate" | |
GHUSER=snapcrafters | |
LXDIMAGE="ubuntu:16.04" | |
TEMPDIR=$(pwd)/build-$DATESTAMP | |
RESULTSDIR="$TEMPDIR"/results | |
REPORT=$RESULTSDIR/report | |
mkdir -p $TEMPDIR/results | |
check_for_lxd() { | |
if ! [ -x "$(command -v lxc version)" ]; then | |
echo "Error: lxc is not installed" | |
exit 1 | |
fi | |
} | |
check_for_multipass() { | |
if ! [ -x "$(command -v multipass version)" ]; then | |
echo "Error: multipass is not installed" | |
exit | |
fi | |
} | |
check_tools() { | |
check_for_lxd | |
check_for_multipass | |
} | |
get_repos() { | |
## This is too much, we don't want to build all of snapcrafters | |
## especially as some of them will never build like signal-desktop | |
## and others take far too long like ffmpeg | |
#echo "**** Get repo list from $GHUSER github" | |
#GITREPOS=$(curl -q "https://api.github.com/users/$GHUSER/repos?per_page=100" | grep -o 'git@[^"]*' | sed 's|git@github.com:|https://github.com/|g') | |
GITREPOS+=("https://github.com/snapcrafters/android-studio.git") | |
GITREPOS+=("https://github.com/snapcrafters/android-studio-canary.git") | |
GITREPOS+=("https://github.com/snapcrafters/atom.git") | |
GITREPOS+=("https://github.com/snapcrafters/axel.git") | |
GITREPOS+=("https://github.com/snapcrafters/brackets.git") | |
GITREPOS+=("https://github.com/snapcrafters/brave.git") | |
GITREPOS+=("https://github.com/snapcrafters/corsixth.git") | |
GITREPOS+=("https://github.com/snapcrafters/cumulonimbus.git") | |
GITREPOS+=("https://github.com/snapcrafters/ddgr.git") | |
GITREPOS+=("https://github.com/snapcrafters/discord.git") | |
GITREPOS+=("https://github.com/snapcrafters/discord-ptb.git") | |
GITREPOS+=("https://github.com/snapcrafters/dosbox-x.git") | |
GITREPOS+=("https://github.com/snapcrafters/duckmarines.git") | |
GITREPOS+=("https://github.com/snapcrafters/eclipse.git") | |
GITREPOS+=("https://github.com/snapcrafters/fkill.git") | |
GITREPOS+=("https://github.com/snapcrafters/get-iplayer.git") | |
GITREPOS+=("https://github.com/snapcrafters/ghost-desktop.git") | |
GITREPOS+=("https://github.com/snapcrafters/gitter-desktop.git") | |
GITREPOS+=("https://github.com/snapcrafters/googler.git") | |
GITREPOS+=("https://github.com/snapcrafters/helm.git") | |
GITREPOS+=("https://github.com/snapcrafters/inadyn.git") | |
GITREPOS+=("https://github.com/snapcrafters/irccloud-desktop.git") | |
GITREPOS+=("https://github.com/snapcrafters/irssi.git") | |
GITREPOS+=("https://github.com/snapcrafters/jenkins.git") | |
GITREPOS+=("https://github.com/snapcrafters/links.git") | |
GITREPOS+=("https://github.com/snapcrafters/magic-wormhole.git") | |
GITREPOS+=("https://github.com/snapcrafters/mattermost-desktop.git") | |
GITREPOS+=("https://github.com/snapcrafters/mdl.git") | |
GITREPOS+=("https://github.com/snapcrafters/minetest.git") | |
GITREPOS+=("https://github.com/snapcrafters/mosaic.git") | |
GITREPOS+=("https://github.com/snapcrafters/mrrescue.git") | |
GITREPOS+=("https://github.com/snapcrafters/mumble.git") | |
GITREPOS+=("https://github.com/snapcrafters/mumble-stable.git") | |
GITREPOS+=("https://github.com/snapcrafters/mutt.git") | |
GITREPOS+=("https://github.com/snapcrafters/nano.git") | |
GITREPOS+=("https://github.com/snapcrafters/newsboat.git") | |
GITREPOS+=("https://github.com/snapcrafters/obs-studio.git") | |
GITREPOS+=("https://github.com/snapcrafters/offlineimap.git") | |
GITREPOS+=("https://github.com/snapcrafters/opentoonz.git") | |
GITREPOS+=("https://github.com/snapcrafters/opentoonz-morevna.git") | |
GITREPOS+=("https://github.com/snapcrafters/opentyrian.git") | |
GITREPOS+=("https://github.com/snapcrafters/photoscape.git") | |
GITREPOS+=("https://github.com/snapcrafters/pypy.git") | |
GITREPOS+=("https://github.com/snapcrafters/pypy3.git") | |
GITREPOS+=("https://github.com/snapcrafters/pyradio.git") | |
GITREPOS+=("https://github.com/snapcrafters/scummvm.git") | |
GITREPOS+=("https://github.com/snapcrafters/sdlpop.git") | |
GITREPOS+=("https://github.com/snapcrafters/sentry.git") | |
GITREPOS+=("https://github.com/snapcrafters/signal-desktop.git") | |
GITREPOS+=("https://github.com/snapcrafters/simplenote.git") | |
GITREPOS+=("https://github.com/snapcrafters/slack-term.git") | |
GITREPOS+=("https://github.com/snapcrafters/spelunky.git") | |
GITREPOS+=("https://github.com/snapcrafters/steamforwindows.git") | |
GITREPOS+=("https://github.com/snapcrafters/storjshare-gui.git") | |
GITREPOS+=("https://github.com/snapcrafters/sublime-text.git") | |
GITREPOS+=("https://github.com/snapcrafters/tcpie.git") | |
GITREPOS+=("https://github.com/snapcrafters/teleconsole.git") | |
GITREPOS+=("https://github.com/snapcrafters/term2048.git") | |
GITREPOS+=("https://github.com/snapcrafters/thelounge.git") | |
GITREPOS+=("https://github.com/snapcrafters/tmnationsforever.git") | |
GITREPOS+=("https://github.com/snapcrafters/uber-cli.git") | |
GITREPOS+=("https://github.com/snapcrafters/vagrant.git") | |
GITREPOS+=("https://github.com/snapcrafters/vault.git") | |
GITREPOS+=("https://github.com/snapcrafters/vscode.git") | |
GITREPOS+=("https://github.com/snapcrafters/warzone2100.git") | |
GITREPOS+=("https://github.com/snapcrafters/wethr.git") | |
GITREPOS+=("https://github.com/snapcrafters/wire.git") | |
GITREPOS+=("https://github.com/snapcrafters/wordpress-desktop.git") | |
GITREPOS+=("https://github.com/snapcrafters/xonotic.git") | |
GITREPOS+=("https://github.com/snapcrafters/yakyak.git") | |
GITREPOS=("https://github.com/jacobzimmermann/dosbox-jz-snap.git" "${GITREPOS[@]}") | |
BZRREPOS+=("lp:~ubuntu-desktop/gnome-system-monitor/snap") | |
BZRREPOS+=("lp:~ubuntu-desktop/evince/snap") | |
BZRREPOS+=("lp:~ubuntu-desktop/gedit/snap") | |
BZRREPOS+=("lp:~ubuntu-desktop/eog/snap") | |
BZRREPOS+=("lp:~ubuntu-desktop/quadrapassel/snap") | |
} | |
install_snapcraft() { | |
if ! [ -x "$(command -v snapcraft version)" ]; then | |
echo "**** snapcraft is not installed, installing" | |
sudo snap install snapcraft --classic $SNAPCRAFT_CHANNEL | |
else | |
echo "**** snapcraft is already installed, refreshing" | |
sudo snap refresh snapcraft $SNAPCRAFT_CHANNEL | |
fi | |
} | |
initialise_report() { | |
echo "snapcraft on host:" > "$REPORT" | |
snapcraft version >> "$REPORT" | |
echo "multipass on host:" >> "$REPORT" | |
multipass version >> "$REPORT" | |
echo "lxd on host:" >> "$REPORT" | |
lxd version >> "$REPORT" | |
} | |
build_in_multipass() { | |
cd "$TEMPDIR"/"$DIR" | |
SNAPCRAFT_BUILD_ENVIRONMENT=multipass | |
snapcraft 2>&1 | tee -a $RESULTSDIR/$DIR.log | |
cp *.snap "$RESULTSDIR" | |
if [ "$?" == "0" ]; then | |
echo "✓ - $DIR (multipass) - $RESULTSDIR/$DIR.log" >> "$REPORT" | |
else | |
echo "🗙 - $DIR (multipass) - $RESULTSDIR/$DIR.log" >> "$REPORT" | |
fi | |
cleanup | |
} | |
create_lxd_container() { | |
echo "**** Starting $CONTAINER" | |
lxc launch "$LXDIMAGE" $CONTAINER | |
echo "**** Waiting" | |
sleep 10 | |
} | |
push_source_to_container() { | |
echo "**** Push source from $TEMPDIR/$DIR to $CONTAINER" | |
lxc file push -r "$TEMPDIR"/"$DIR" "$CONTAINER"/root/ | |
} | |
install_snapcraft_in_container() { | |
echo "**** Install snapcraft in $CONTAINER" | |
/snap/bin/lxc exec "$CONTAINER" -- snap install snapcraft --classic $SNAPCRAFT_CHANNEL | |
} | |
create_build_script() { | |
echo "**** Prepare script" | |
SCRIPT="$TEMPDIR"/build.sh | |
echo "#!/bin/bash" > "$SCRIPT" | |
echo "apt update -y" >> "$SCRIPT" | |
echo "apt dist-upgrade -y" >> "$SCRIPT" | |
echo "cd /root/$DIR" >> "$SCRIPT" | |
echo "export SNAPCRAFT_BUILD_ENVIRONMENT=host" >> "$SCRIPT" | |
echo "snapcraft 2>&1 | tee -a /root/$DIR.log" >> "$SCRIPT" | |
echo "ls -1 *.snap > /root/snapfilename" >> "$SCRIPT" | |
chmod +x "$SCRIPT" | |
lxc file push "$SCRIPT" "$CONTAINER"/root/ | |
} | |
run_snapcraft_in_container() { | |
echo "**** Run snapcraft in $CONTAINER" | |
/snap/bin/lxc exec "$CONTAINER" -- /root/build.sh | |
} | |
pull_snap_from_container() { | |
echo "**** Pull log from container" | |
lxc file pull "$CONTAINER"/root/"$DIR".log "$RESULTSDIR" | |
echo "**** Pull snap from container" | |
lxc file pull "$CONTAINER"/root/snapfilename "$TEMPDIR"/snapfilename | |
FILENAME=$(cat "$TEMPDIR"/snapfilename) | |
lxc file pull "$CONTAINER"/root/"$DIR"/"$FILENAME" "$RESULTSDIR" | |
if [ "$?" == "0" ]; then | |
echo "✓ - $DIR (lxd) - $RESULTSDIR/$DIR.log" >> "$REPORT" | |
else | |
echo "🗙 - $DIR (lxd) - $RESULTSDIR/$DIR.log" >> "$REPORT" | |
fi | |
rm "$TEMPDIR"/snapfilename | |
} | |
pull_log_from_container() { | |
echo "**** Pull log from container" | |
lxc file pull "$CONTAINER"/root/"$DIR".log "$RESULTSDIR" | |
} | |
delete_container() { | |
lxc delete --force "$CONTAINER" | |
} | |
cleanup() { | |
echo "**** Clean up source dir for $DIR" | |
rm -rf "$TEMPDIR"/"$DIR" | |
} | |
build_in_lxd() { | |
CONTAINER="snapcraft-$DATESTAMP-$DIR" | |
create_lxd_container | |
push_source_to_container | |
install_snapcraft_in_container | |
create_build_script | |
run_snapcraft_in_container | |
pull_snap_from_container | |
pull_log_from_container | |
cleanup | |
delete_container | |
} | |
build_all_snaps() { | |
for i in ${BZRREPOS[@]}; do | |
echo "$i" | |
cd $TEMPDIR | |
DIR=$(echo $i | awk -F '/' '{ print $2}') | |
bzr branch "$i" $DIR | |
grep -R ^base "$DIR"/* | |
if [ "$?" == "0" ]; then | |
build_in_multipass | |
else | |
build_in_lxd | |
fi | |
rm -rf "$TEMPDIR"/"$DIR" | |
done | |
for i in ${GITREPOS[@]}; do | |
echo "$i" | |
cd $TEMPDIR | |
DIR=$(basename $i | cut -d'.' -f1) | |
git clone "$i" | |
grep ^base "$DIR"/snap/snapcraft.yaml | |
if [ "$?" == "0" ]; then | |
build_in_multipass | |
else | |
build_in_lxd | |
fi | |
rm -rf "$TEMPDIR"/"$DIR" | |
done | |
} | |
list_results() { | |
echo "**** Results in $RESULTSDIR" | |
ls -l "$RESULTSDIR"/*.snap | |
} | |
check_tools | |
install_snapcraft | |
initialise_report | |
get_repos | |
build_all_snaps | |
list_results |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment