Merge ~morphis/snappy-hwe-snaps/+git/build-scripts:feature/snap-release-job into ~snappy-hwe-team/snappy-hwe-snaps/+git/build-scripts:master

Proposed by Simon Fels
Status: Merged
Approved by: Jim Hodapp
Approved revision: 235cb09d6d273e61dfc95f6a104aa949d1279a47
Merged at revision: d94715fe5278700bbcdf52230dd71390118bd093
Proposed branch: ~morphis/snappy-hwe-snaps/+git/build-scripts:feature/snap-release-job
Merge into: ~snappy-hwe-team/snappy-hwe-snaps/+git/build-scripts:master
Diff against target: 238 lines (+194/-6)
4 files modified
jobs/generic-release-snap (+63/-0)
scripts/se_utils/__init__.py (+22/-0)
scripts/snap-build (+9/-6)
scripts/trigger-lp-build.py (+100/-0)
Reviewer Review Type Date Requested Status
Jim Hodapp (community) Approve
System Enablement Bot continuous-integration Approve
Review via email: mp+316129@code.launchpad.net

Description of the change

To post a comment you must log in.
Revision history for this message
System Enablement Bot (system-enablement-ci-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
System Enablement Bot (system-enablement-ci-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
System Enablement Bot (system-enablement-ci-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
System Enablement Bot (system-enablement-ci-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
System Enablement Bot (system-enablement-ci-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
System Enablement Bot (system-enablement-ci-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
System Enablement Bot (system-enablement-ci-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
System Enablement Bot (system-enablement-ci-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
System Enablement Bot (system-enablement-ci-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
Jim Hodapp (jhodapp) wrote :

Just a few changes needed, see inline below.

review: Needs Fixing (code)
Revision history for this message
System Enablement Bot (system-enablement-ci-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
System Enablement Bot (system-enablement-ci-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
Jim Hodapp (jhodapp) wrote :

LGTM

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
diff --git a/jobs/generic-release-snap b/jobs/generic-release-snap
0new file mode 1007550new file mode 100755
index 0000000..4c05499
--- /dev/null
+++ b/jobs/generic-release-snap
@@ -0,0 +1,63 @@
1#!/bin/sh
2#
3# Copyright (C) 2017 Canonical Ltd
4#
5# This program is free software: you can redistribute it and/or modify
6# it under the terms of the GNU General Public License version 3 as
7# published by the Free Software Foundation.
8#
9# This program is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12# GNU General Public License for more details.
13#
14# You should have received a copy of the GNU General Public License
15# along with this program. If not, see <http://www.gnu.org/licenses/>.
16
17set -ex
18
19if [ -z "$VERSION" ]; then
20 echo "ERROR: No version specified"
21 exit 1
22fi
23
24echo "Snap to be release: $SNAP_NAME"
25echo "Version to be released: $VERSION"
26
27GIT_USER=system-enablement-ci-bot
28REPOSITORY_URL="git+ssh://$GIT_USER@git.launchpad.net/~snappy-hwe-team/snappy-hwe-snaps/+git/$SNAP_NAME"
29
30if [ -e $SNAP_NAME ]; then
31 rm -rf $SNAP_NAME
32fi
33
34git clone -b master $REPOSITORY_URL $SNAP_NAME
35cd $SNAP_NAME
36
37if [ ! -e snapcraft.yaml ]; then
38 echo "ERROR: No top-level snapcraft.yaml file!"
39 exit 1
40fi
41
42git config user.name "System Enablement CI Bot"
43git config user.email "ce-system-enablement@lists.canonical.com"
44
45sed -i -e "s/version:.*/version: $VERSION/g" snapcraft.yaml
46git add snapcraft.yaml
47git commit -m "Bump version to $VERSION"
48
49git tag -a -m "$VERSION" $VERSION HEAD
50if ! git branch -r | grep origin/stable ; then
51 git checkout -b stable origin/master
52else
53 git checkout -b stable origin/stable
54fi
55git merge master
56
57git push origin stable
58git push origin master
59git push origin $VERSION
60
61
62
63exec $WORKSPACE/build-scripts/scripts/trigger-lp-build.py -s $SNAP_NAME -p
diff --git a/scripts/se_utils/__init__.py b/scripts/se_utils/__init__.py
index fcb95d7..280450c 100644
--- a/scripts/se_utils/__init__.py
+++ b/scripts/se_utils/__init__.py
@@ -20,6 +20,7 @@ import sys
20import time20import time
21import logging21import logging
22import os22import os
23import yaml
23from shutil import rmtree24from shutil import rmtree
24from launchpadlib.credentials import RequestTokenAuthorizationEngine25from launchpadlib.credentials import RequestTokenAuthorizationEngine
25from lazr.restfulclient.errors import HTTPError26from lazr.restfulclient.errors import HTTPError
@@ -98,3 +99,24 @@ def get_launchpad(launchpadlib_dir=None, credential_store_path=None, lp_app=None
98 authorization_engine=authorization_engine,99 authorization_engine=authorization_engine,
99 launchpadlib_dir=lib_dir,100 launchpadlib_dir=lib_dir,
100 version='devel')101 version='devel')
102
103# Load configuration for the current agent we're running on. All agents were
104# provisioned when they were setup with a proper configuration. See
105# https://wiki.canonical.com/InformationInfrastructure/Jenkaas/UserDocs for
106# more details.
107def load_config():
108 files = [os.path.expanduser('~/.jlp/jlp.config'), 'jlp.config']
109 for config_file in files:
110 try:
111 config = yaml.safe_load(open(config_file, 'r'))
112 return config
113 except IOError:
114 pass
115 print("ERROR: No config file found")
116 sys.exit(1)
117
118# Return a configuration option from the agent configuration specified by the
119# name argument.
120def get_config_option(name):
121 config = load_config()
122 return config[name]
diff --git a/scripts/snap-build b/scripts/snap-build
index b597ab6..abe40b4 100755
--- a/scripts/snap-build
+++ b/scripts/snap-build
@@ -79,12 +79,15 @@ cd /build/src
7979
80git config user.name "System Enablement CI Bot"80git config user.name "System Enablement CI Bot"
81git config user.email "ce-system-enablement@lists.canonical.com"81git config user.email "ce-system-enablement@lists.canonical.com"
82git remote add other $SOURCE_GIT_REPO82
83git fetch other83if [ -n "$SOURCE_GIT_REPO" ]; then
84git merge \84 git remote add other $SOURCE_GIT_REPO
85 --no-ff \85 git fetch other
86 -m "Merge remote tracking branch other/$SOURCE_GIT_REPO_BRANCH" \86 git merge \
87 $REVISION87 --no-ff \
88 -m "Merge remote tracking branch other/$SOURCE_GIT_REPO_BRANCH" \
89 $REVISION
90fi
8891
89# Only attempt to build projects where we have a valid snapcraft project.92# Only attempt to build projects where we have a valid snapcraft project.
90# For all others we just make sure we can merge source to target.93# For all others we just make sure we can merge source to target.
diff --git a/scripts/trigger-lp-build.py b/scripts/trigger-lp-build.py
91new file mode 10075594new file mode 100755
index 0000000..842acd5
--- /dev/null
+++ b/scripts/trigger-lp-build.py
@@ -0,0 +1,100 @@
1#! /usr/bin/python
2
3import os
4import sys
5import time
6import smtplib
7
8from datetime import datetime
9from os.path import basename
10from launchpadlib.launchpad import Launchpad
11
12from argparse import ArgumentParser
13
14import se_utils
15
16parser = ArgumentParser(description="Build a specific snap on launchpad")
17parser.add_argument('-s', '--snap', required=True,
18 help="Name of the snap to build")
19parser.add_argument('-p', '--publish', action='store_true',
20 help="Trigger a publish build instead of a daily (default)")
21
22args = vars(parser.parse_args())
23
24arches = ['amd64', 'i386', 'armhf', 'arm64']
25series = 'xenial'
26
27lp_app = se_utils.get_config_option("lp_app")
28lp_env = se_utils.get_config_option("lp_env")
29credential_store_path = se_utils.get_config_option('credential_store_path')
30launchpad = se_utils.get_launchpad(None, credential_store_path, lp_app, lp_env)
31
32team = launchpad.people['snappy-hwe-team']
33
34build_name = "%s-daily" % args["snap"]
35if args["publish"] == True:
36 build_name = "%s-publish" % args["snap"]
37
38snap = launchpad.snaps.getByName(name=build_name, owner=team)
39ubuntu = launchpad.distributions['ubuntu']
40release = ubuntu.getSeries(name_or_version=series)
41primary_archive = ubuntu.getArchive(name='primary')
42
43# Add a big fat warning that we don't really care about fixing things when
44# the job will be canceled after the following lines are printed out.
45print("!!!!!!! POINT OF NO RETURN !!!!!!!")
46print("DO NOT CANCEL THIS JOB AFTER THIS OR BAD THINGS WILL HAPPEN")
47print("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!")
48
49stamp = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
50print("Trying to trigger builds at: {}".format(stamp))
51
52# We will now trigger a build for each whitelisted architecture, collect the
53# build job url and the wait for all builds to finish and collect their results
54# to vote for a successful or failed build.
55triggered_builds = []
56for build_arch in arches:
57 arch = release.getDistroArchSeries(archtag=build_arch)
58 request = snap.requestBuild(archive=primary_archive, distro_arch_series=arch, pocket='Proposed')
59 build_id = str(request).rsplit('/', 1)[-1]
60 triggered_builds.append(build_id)
61 print("Arch: {} is building under: {}".format(build_arch, request))
62
63failures = []
64while len(triggered_builds):
65 for build in triggered_builds:
66 try:
67 response = snap.getBuildSummariesForSnapBuildIds(snap_build_ids=[build])
68 except:
69 print("Could not get response for {} (was there an LP timeout?)".format(build))
70 continue
71 status = response[build]['status']
72 if status == "FULLYBUILT":
73 triggered_builds.remove(build)
74 continue
75 elif status == "FAILEDTOBUILD":
76 failures.append(build)
77 triggered_builds.remove(build)
78 continue
79 elif status == "CANCELLED":
80 triggered_builds.remove(build)
81 continue
82 time.sleep(60)
83
84if len(failures):
85 for failure in failures:
86 try:
87 response = snap.getBuildSummariesForSnapBuildIds(snap_build_ids=[failure])
88 except:
89 print ("Could not get failure data for {} (was there an LP timeout?)".format(build))
90 continue
91 buildlog = response[build]['build_log_url']
92 if buildlog != 'None':
93 print(buildlog)
94 arch = str(buildlog).split('_')[4]
95 print("{} snap {} build at {} failed for id: {} log: {}".format(args["snap"], arch, stamp, failure, buildlog))
96
97 # Let the build fail as at least a single snap has failed to build
98 sys.exit(1)
99
100print("Done!")

Subscribers

People subscribed via source and target branches

to all changes: