Merge ~prometheus-charmers/charm-prometheus2:core-resource into ~prometheus-charmers/charm-prometheus2:master

Proposed by Kevin W Monroe
Status: Merged
Approved by: Kevin W Monroe
Approved revision: d7199e79fa9c95561a2750a1c6bca0da0619d403
Merged at revision: 89dc19ff15b5b7dfcd268c2027e0ff7e0530d607
Proposed branch: ~prometheus-charmers/charm-prometheus2:core-resource
Merge into: ~prometheus-charmers/charm-prometheus2:master
Diff against target: 96 lines (+51/-3)
4 files modified
Makefile (+42/-0)
README.md (+4/-3)
metadata.yaml (+4/-0)
reactive/prometheus.py (+1/-0)
Reviewer Review Type Date Requested Status
Stuart Bishop (community) Approve
Review via email: mp+367206@code.launchpad.net

Commit message

lp:1828063 add a core.snap resource to facilitate offline installs

Description of the change

The core snap is required by the prometheus snap. To facilitate offline deployment, users need the ability to attach a core.snap resource in addition to the prometheus.snap resource.

A downside of this is that future prometheus2 charm releases will need to have a zero-byte core.snap resource attached, as in:

rm /tmp/core.snap && touch /tmp/core.snap
charm push /path/to/prometheus2-charm --resource core=/tmp/core.snap
charm release <prometheus2-X> --resource core-0 --resource prometheus-Y

For normal deployments, layer-snap will recognize that core.snap is a 0-byte resource and will fall back to installing from the snap store. For offline deployments, users will need to attach the desired core.snap, as in:

juju deploy /path/to/prometheus2-charm \
  --resource core=/path/to/real/core.snap \
  --resource prometheus=/path/to/real/prometheus.snap

Also in offline deployments, we need to ensure the core.snap is installed prior to prometheus.snap, hence this is dependent on:

https://github.com/stub42/layer-snap/pull/22.

To post a comment you must log in.
Revision history for this message
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote :

This merge proposal is being monitored by mergebot. Change the status to Approved to merge.

Revision history for this message
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote :

Unable to determine commit message from repository - please click "Set commit message" and enter the commit message manually.

Revision history for this message
George Kraft (cynerva) wrote :

LGTM

> Also in offline deployments, we need to ensure the core.snap is installed prior to prometheus.snap, hence this is dependent on: https://github.com/stub42/layer-snap/pull/22.

I don't think that layer-snap PR is a dependency for this, since it only applies to charms that use the layer.yaml snap options.

Revision history for this message
Stuart Bishop (stub) wrote :

Looks good.

I would like to request a brief developer's readme/howto or at least a Makefile rule which details how to build and publish the snap, while you are here making this more complex than it already is.

The snap layer PR has been merged and released.

review: Approve
Revision history for this message
Kevin W Monroe (kwmonroe) wrote :

@stub, I added a makefile target with some helpful text for developers:

$ make charmrelease
---------------------------------------------------------------------
prometheus2 supports core and prometheus snap resources.

Attached resources will be processed during charm deployment. If a
zero-byte resource is found, the charm will install the relevant snap
from the store. This provides flexibility in choosing which snaps will
be installed by the charm.

For example, release a charm that uses the core snap from the store
(0-byte resource attached) along with a specific prometheus snap:

cd /tmp
rm empty-core.snap && touch empty-core.snap
snap download --channel=2/stable prometheus
charm push /Users/kwmonroe/charms/builds/prometheus2 --resource core=/tmp/empty-core.snap --resource prometheus=/tmp/prometheus_*.snap
charm release <revision> --resource core-<m> --resource prometheus-<n>

If the resources you want already exist in the charm store, omit the
declarations during 'charm push' and specify resource revisions
during 'charm release':

charm push /Users/kwmonroe/charms/builds/prometheus2
charm release <revision> --resource core-0 --resource prometheus-0
---------------------------------------------------------------------

Revision history for this message
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote :

Change successfully merged at revision 89dc19ff15b5b7dfcd268c2027e0ff7e0530d607

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/Makefile b/Makefile
2index 76b37de..ab0dbb3 100644
3--- a/Makefile
4+++ b/Makefile
5@@ -1,3 +1,45 @@
6+BUILDDEST:=$(if $(JUJU_REPOSITORY),$(JUJU_REPOSITORY),"../prometheus2-built")
7+BUILTCHARMDIR:="$(BUILDDEST)/builds/prometheus2"
8+
9+.PHONY: charmbuild
10+charmbuild:
11+ charm build --output-dir $(BUILDDEST) --report --no-local-layers
12+
13+.PHONY: charmrelease
14+charmrelease:
15+ @echo ---------------------------------------------------------------------
16+ @echo prometheus2 supports 'core' and 'prometheus' snap resources.
17+ @echo
18+ @echo Attached resources will be processed during charm deployment. If a
19+ @echo zero-byte resource is found, the charm will install the relevant snap
20+ @echo from the store. This provides flexibility in choosing which snaps will
21+ @echo be installed by the charm.
22+ @echo
23+ @echo For example, release a charm that uses the core snap from the store
24+ @echo \(0-byte resource attached\) along with a specific prometheus snap:
25+ @echo
26+ @echo cd /tmp
27+ @echo rm empty-core.snap \&\& touch empty-core.snap
28+ @echo snap download --channel=2/stable prometheus
29+ @echo charm push $(BUILTCHARMDIR) --resource core=/tmp/empty-core.snap --resource prometheus=/tmp/prometheus_*.snap
30+ @echo charm release \<revision\> --resource core-\<m\> --resource prometheus-\<n\>
31+ @echo
32+ @echo If the resources you want already exist in the charm store, omit the
33+ @echo declarations during \'charm push\' and specify resource revisions
34+ @echo during \'charm release\':
35+ @echo
36+ @echo charm push $(BUILTCHARMDIR)
37+ @echo charm release \<revision\> --resource core-0 --resource prometheus-0
38+ @echo ---------------------------------------------------------------------
39+
40+.PHONY: clean
41+clean:
42+ @echo "Cleaning files"
43+ @rm -f .coverage .unit-state.db
44+ @find . -name "*.pyc" -type f -exec rm -f '{}' \;
45+ @find . -name "__pycache__" -type d -prune -exec rm -rf '{}' \;
46+ @rm -rf ./.tox
47+
48 .PHONY: test
49 test: unittest
50
51diff --git a/README.md b/README.md
52index f9bfa85..0581e89 100644
53--- a/README.md
54+++ b/README.md
55@@ -41,10 +41,11 @@ For example to deploy with local filesystem run:
56
57 ## Juju resources support
58
59-The charm support juju resources, which is handy in offline deployments. Prefetch the snap:
60+The charm support juju resources, which is handy in offline deployments. Prefetch the snaps:
61
62+ snap download --channel=stable core
63 snap download --channel=2/stable prometheus
64
65-Provide downloaded snap (prometheus_20.snap) as a resource to the application:
66+Provide downloaded snaps as resources to the application:
67
68- juju deploy cs:prometheus2 --resource prometheus=prometheus_20.snap
69+ juju deploy cs:prometheus2 --resource core=core_6818.snap --resource prometheus=prometheus_20.snap
70diff --git a/metadata.yaml b/metadata.yaml
71index bc054ac..7b72d5c 100644
72--- a/metadata.yaml
73+++ b/metadata.yaml
74@@ -36,6 +36,10 @@ requires:
75 prometheus-rules:
76 interface: prometheus-rules
77 resources:
78+ core:
79+ type: file
80+ filename: core.snap
81+ description: Snap package of core
82 prometheus:
83 type: file
84 filename: prometheus.snap
85diff --git a/reactive/prometheus.py b/reactive/prometheus.py
86index 32796b7..e06bdc0 100644
87--- a/reactive/prometheus.py
88+++ b/reactive/prometheus.py
89@@ -198,6 +198,7 @@ def install_packages():
90
91 if not os.path.exists('/usr/sbin/sendmail'):
92 fetch.apt_install('sendmail-bin') # Needed for cronjob email notifications
93+ snap.install('core') # Needed for offline deploy; falls back to store as needed
94 snap.install(pkgname, channel=channel, force_dangerous=False)
95 if config.get('prometheus_registration_listen', False):
96 channel = config.get('promreg_snap_channel', 'stable')

Subscribers

People subscribed via source and target branches

to all changes: