Skip to content

Commit 6f0a05a

Browse files
authored
snap: v0: build fixes & updates (#3999)
* snap: drop sudo Fixes #3989 * snap: ci: fix builds * snap: ci: developer notifications * snap: minimise size * debug commit * Revert "snap: minimise size" This reverts commit 77b41a9. * fix image info * Revert "debug commit" This reverts commit 232baf0. * snap: v1 channels Related: #3872 * snap: v0 channels Related #3990 Related #3989 * snap: auto-version (major) detect * ci: fetch --tags explanation & error checking * snap: update warning framework * hardocde warning * add deprecation dev comment * remove warning on explicit v0 channel * tidy comment * fix py2
1 parent e798a57 commit 6f0a05a

File tree

5 files changed

+106
-5
lines changed

5 files changed

+106
-5
lines changed

.travis.yml

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,15 @@ jobs:
101101
- name: lxd
102102
channel: stable
103103
env:
104-
- SNAPCRAFT_IMAGE_INFO: '{"build_url": "$TRAVIS_BUILD_URL"}'
104+
- SNAPCRAFT_IMAGE_INFO: |
105+
'{"build_url": "$TRAVIS_JOB_WEB_URL"}'
106+
- SNAPCRAFT_BUILD_ENVIRONMENT: lxd
107+
- SNAPCRAFT_BUILD_INFO: 1 # https://snapcraft.io/blog/introducing-developer-notifications-for-snap-security-updates
105108
install:
109+
- sudo usermod --append --groups lxd $USER
106110
- sudo /snap/bin/lxd.migrate -yes
107111
- sudo /snap/bin/lxd waitready
108112
- sudo /snap/bin/lxd init --auto
109-
- git fetch --tags
110113
script:
111114
- ./scripts/build_snap.sh
112115
after_failure:
@@ -157,6 +160,14 @@ deploy:
157160
script: "(echo $SNAP_TOKEN | snapcraft login --with -) && timeout 600 snapcraft push dvc_*.snap --release $SNAP_CHANNEL || echo timed out"
158161
on:
159162
all_branches: true
160-
condition: "$(./scripts/ci/deploy_condition.sh dvc_*.snap) && ($TRAVIS_BRANCH = master || -n $TRAVIS_TAG)"
163+
condition: "$(./scripts/ci/deploy_condition.sh dvc_*.snap) && ($TRAVIS_BRANCH = master || -n $TRAVIS_TAG) && -n $SNAP_CHANNEL"
164+
repo: iterative/dvc
165+
stage: build
166+
- provider: script
167+
skip_cleanup: true
168+
script: "(echo $SNAP_TOKEN | snapcraft login --with -) && timeout 600 snapcraft push nowarn_update_dvc_*.snap --release $SNAP_CHANNEL_MAJOR || echo timed out"
169+
on:
170+
all_branches: true
171+
condition: "$(./scripts/ci/deploy_condition.sh nowarn_update_dvc_*.snap) && ($TRAVIS_BRANCH = master || -n $TRAVIS_TAG) && -n $SNAP_CHANNEL_MAJOR"
161172
repo: iterative/dvc
162173
stage: build

dvc/updater.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,15 @@ def _with_lock(self, func, action):
4848
logger.debug(msg.format(self.lock.lockfile, action))
4949

5050
def check(self):
51-
if os.getenv("CI") or env2bool("DVC_TEST") or PKG == "snap":
51+
if os.getenv("CI") or env2bool("DVC_TEST"):
52+
return
53+
54+
if PKG == "snap":
55+
# hardcoded transition message
56+
version_major = version.parse(self.current).major
57+
self.current = "v{}".format(version_major)
58+
self.latest = "v{}".format(version_major + 1)
59+
self._notify()
5260
return
5361

5462
self._with_lock(self._check, "checking")
@@ -138,6 +146,17 @@ def _get_update_instructions(self):
138146
),
139147
"conda": "Run `{yellow}conda{reset} update dvc`",
140148
"choco": "Run `{yellow}choco{reset} upgrade dvc`",
149+
"snap": (
150+
"To upgrade to the latest major release,\n"
151+
"run `{yellow}snap{reset} refresh --channel=latest/beta`, or\n"
152+
"to stay on the current major release track,\n"
153+
"run `{yellow}snap{reset} refresh --channel={current}/stable`"
154+
"\n\n"
155+
"{red}WARNING{reset}: ignoring this message will result in\n"
156+
"snap automatically performing an upgrade soon.\n"
157+
"More information can be found at\n"
158+
"{blue}https://github.com/iterative/dvc/issues/3872{reset}"
159+
),
141160
None: (
142161
"Find the latest release at\n"
143162
"{blue}https://github.com/iterative/dvc/releases/latest{reset}"

scripts/build_snap.sh

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,14 @@ if [ ! -d "dvc" ]; then
77
exit 1
88
fi
99

10-
sudo snapcraft --use-lxd
10+
sg lxd -c snapcraft
11+
original_snap_name="$(ls dvc_*.snap)"
12+
mv "$original_snap_name" original.snap
13+
14+
git apply scripts/remove_update_warning.patch
15+
sg lxd -c snapcraft
16+
mv dvc_*.snap nowarn_update_"$original_snap_name".snap
17+
mv original.snap "$original_snap_name"
1118

1219
pip uninstall -y dvc
1320
if which dvc; then

scripts/ci/before_install.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,25 @@ elif [[ "$TRAVIS_OS_NAME" == "osx" ]]; then
5151
ln -s -f /usr/local/bin/pip3 /usr/local/bin/pip
5252
fi
5353

54+
# fetch tags for `git-describe`, since
55+
# - can't rely on $TRAVIS_TAG for `edge` (master) releases, and
56+
# - `snapcraft` also uses `git-describe` for version detection
57+
git fetch --tags
58+
TAG_MAJOR="$(git describe --tags | sed -r 's/^v?([0-9]+)\.[0-9]+\.[0-9]+.*/\1/')"
59+
[[ -n "$TAG_MAJOR" ]] || exit 1 # failed to detect major version
60+
5461
if [[ -n "$TRAVIS_TAG" ]]; then
5562
if [[ $(echo "$TRAVIS_TAG" | grep -E '^[0-9]+\.[0-9]+\.[0-9]+$') ]]; then
5663
echo "export SNAP_CHANNEL=stable" >>env.sh
64+
echo "export SNAP_CHANNEL_MAJOR=v$TAG_MAJOR/stable" >>env.sh
5765
else
5866
echo "export SNAP_CHANNEL=beta" >>env.sh
67+
echo "export SNAP_CHANNEL_MAJOR=v$TAG_MAJOR/beta" >>env.sh
5968
fi
6069
else
6170
echo "export SNAP_CHANNEL=edge" >>env.sh
71+
echo "export SNAP_CHANNEL_MAJOR=v$TAG_MAJOR/edge" >>env.sh
6272
fi
73+
74+
# NOTE: after deprecating this branch, uncomment this line
75+
# echo "unset SNAP_CHANNEL" >>env.sh

scripts/remove_update_warning.patch

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
diff --git a/dvc/updater.py b/dvc/updater.py
2+
index d6dc372..cfa416f 100644
3+
--- a/dvc/updater.py
4+
+++ b/dvc/updater.py
5+
@@ -48,15 +48,7 @@ class Updater(object): # pragma: no cover
6+
logger.debug(msg.format(self.lock.lockfile, action))
7+
8+
def check(self):
9+
- if os.getenv("CI") or env2bool("DVC_TEST"):
10+
- return
11+
-
12+
- if PKG == "snap":
13+
- # hardcoded transition message
14+
- version_major = version.parse(self.current).major
15+
- self.current = "v{}".format(version_major)
16+
- self.latest = "v{}".format(version_major + 1)
17+
- self._notify()
18+
+ if os.getenv("CI") or env2bool("DVC_TEST") or PKG == "snap":
19+
return
20+
21+
self._with_lock(self._check, "checking")
22+
@@ -146,17 +138,6 @@ class Updater(object): # pragma: no cover
23+
),
24+
"conda": "Run `{yellow}conda{reset} update dvc`",
25+
"choco": "Run `{yellow}choco{reset} upgrade dvc`",
26+
- "snap": (
27+
- "To upgrade to the latest major release,\n"
28+
- "run `{yellow}snap{reset} refresh --channel=latest/beta`, or\n"
29+
- "to stay on the current major release track,\n"
30+
- "run `{yellow}snap{reset} refresh --channel={current}/stable`"
31+
- "\n\n"
32+
- "{red}WARNING{reset}: ignoring this message will result in\n"
33+
- "snap automatically performing an upgrade soon.\n"
34+
- "More information can be found at\n"
35+
- "{blue}https://github.com/iterative/dvc/issues/3872{reset}"
36+
- ),
37+
None: (
38+
"Find the latest release at\n"
39+
"{blue}https://github.com/iterative/dvc/releases/latest{reset}"
40+
diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml
41+
index 75d0f7d..996db8c 100644
42+
--- a/snap/snapcraft.yaml
43+
+++ b/snap/snapcraft.yaml
44+
@@ -30,7 +30,6 @@ parts:
45+
override-pull: |
46+
snapcraftctl pull
47+
snapcraftctl set-version $(cd $SNAPCRAFT_PART_SRC && git describe --tags)
48+
- git diff --quiet || error_dirty_build
49+
echo 'PKG = "snap"' > $SNAPCRAFT_PART_SRC/dvc/utils/build.py
50+
# install all optional extras
51+
sed -ri 's/(=install_requires)/\1+all_remotes+hdfs/' $SNAPCRAFT_PART_SRC/setup.py

0 commit comments

Comments
 (0)