Merge ~cjwatson/launchpad:charm-layers into launchpad:master

Proposed by Colin Watson
Status: Merged
Approved by: Colin Watson
Approved revision: ac269298eae5a97bfa9b998698917c848074913b
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: ~cjwatson/launchpad:charm-layers
Merge into: launchpad:master
Diff against target: 166 lines (+56/-47)
6 files modified
charm/.gitignore (+1/-0)
charm/Makefile (+7/-6)
charm/launchpad/layer.yaml (+1/-13)
charm/launchpad/reactive/launchpad.py (+1/-28)
charm/layer/launchpad-base/layer.yaml (+15/-0)
charm/layer/launchpad-base/reactive/launchpad-base.py (+31/-0)
Reviewer Review Type Date Requested Status
Ioana Lasc (community) Approve
Review via email: mp+428107@code.launchpad.net

Commit message

Split some charm code into a layer

Description of the change

At the moment there isn't much of this beyond `layer:ols`, but this should make it a little easier to develop multiple charms for different Launchpad deployments.

To post a comment you must log in.
Revision history for this message
Ioana Lasc (ilasc) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/charm/.gitignore b/charm/.gitignore
2index da831d3..de07da3 100644
3--- a/charm/.gitignore
4+++ b/charm/.gitignore
5@@ -1,4 +1,5 @@
6 *.charm
7 bundle.yaml
8 dist
9+layer/*/codetree-collect-info.yaml
10 tmp
11diff --git a/charm/Makefile b/charm/Makefile
12index de55a73..5bb96fe 100644
13--- a/charm/Makefile
14+++ b/charm/Makefile
15@@ -45,12 +45,13 @@ build-launchpad: ## build the launchpad charm
16 build-launchpad: dist/$(call charm_file,launchpad)
17
18 dist/%_ubuntu-$(CHARM_SERIES)-$(ARCH).charm: $(CHARM_DEPS) | $(BUILDDIR)
19- @echo "Building $*..."
20- @rm -rf $*/tmp
21- @cp -a tmp $*/tmp
22- @cd $* && charmcraft pack
23- @cp -a $*/$(call charm_file,$*) dist/
24- @rm -rf $*/tmp
25+ echo "Building $*..."
26+ rm -rf $*/tmp
27+ cp -a tmp $*/tmp
28+ cp -a layer/launchpad-base $*/tmp/deps/ols-layers/layer/
29+ cd $* && charmcraft pack
30+ cp -a $*/$(call charm_file,$*) dist/
31+ rm -rf $*/tmp
32
33 clean: ## clean the build environment
34 clean: $(foreach charm,$(CHARMS),clean-$(charm))
35diff --git a/charm/launchpad/layer.yaml b/charm/launchpad/layer.yaml
36index ae16aa0..bcff867 100644
37--- a/charm/launchpad/layer.yaml
38+++ b/charm/launchpad/layer.yaml
39@@ -1,15 +1,3 @@
40 includes:
41- - layer:basic
42- - layer:ols
43-options:
44- apt:
45- packages:
46- - launchpad-dependencies
47- ols:
48- service_name: launchpad
49- config_filename: service.conf
50- user: launchpad
51- tarball_payload: true
52- symlink_switch_payload: true
53- python_bin: /usr/bin/python3
54+ - layer:launchpad-base
55 repo: https://git.launchpad.net/launchpad
56diff --git a/charm/launchpad/reactive/launchpad.py b/charm/launchpad/reactive/launchpad.py
57index 076a8c9..5b4222b 100644
58--- a/charm/launchpad/reactive/launchpad.py
59+++ b/charm/launchpad/reactive/launchpad.py
60@@ -1,23 +1,8 @@
61 # Copyright 2022 Canonical Ltd. This software is licensed under the
62 # GNU Affero General Public License version 3 (see the file LICENSE).
63
64-import subprocess
65-
66 from charmhelpers.core import hookenv
67-from charms.reactive import remove_state, set_state, when, when_not
68-from ols import base
69-
70-
71-# Monkey-patch layer:ols.
72-def create_virtualenv(wheels_dir, codedir, python_exe):
73- subprocess.run(
74- ["make", "compile", "PYTHON={}".format(python_exe)],
75- cwd=codedir,
76- check=True,
77- )
78-
79-
80-base.create_virtualenv = create_virtualenv
81+from charms.reactive import set_state, when, when_not
82
83
84 @when("ols.configured")
85@@ -30,15 +15,3 @@ def configure():
86 @when("service.configured")
87 def check_is_running():
88 hookenv.status_set("active", "Ready")
89-
90-
91-@when("config.changed.build_label")
92-def build_label_changed():
93- remove_state("ols.service.installed")
94- remove_state("ols.configured")
95- remove_state("service.configured")
96-
97-
98-@when("config.changed")
99-def config_changed():
100- remove_state("service.configured")
101diff --git a/charm/launchpad/config.yaml b/charm/layer/launchpad-base/config.yaml
102similarity index 100%
103rename from charm/launchpad/config.yaml
104rename to charm/layer/launchpad-base/config.yaml
105diff --git a/charm/launchpad/icon.svg b/charm/layer/launchpad-base/icon.svg
106similarity index 100%
107rename from charm/launchpad/icon.svg
108rename to charm/layer/launchpad-base/icon.svg
109diff --git a/charm/layer/launchpad-base/layer.yaml b/charm/layer/launchpad-base/layer.yaml
110new file mode 100644
111index 0000000..ae16aa0
112--- /dev/null
113+++ b/charm/layer/launchpad-base/layer.yaml
114@@ -0,0 +1,15 @@
115+includes:
116+ - layer:basic
117+ - layer:ols
118+options:
119+ apt:
120+ packages:
121+ - launchpad-dependencies
122+ ols:
123+ service_name: launchpad
124+ config_filename: service.conf
125+ user: launchpad
126+ tarball_payload: true
127+ symlink_switch_payload: true
128+ python_bin: /usr/bin/python3
129+repo: https://git.launchpad.net/launchpad
130diff --git a/charm/layer/launchpad-base/reactive/launchpad-base.py b/charm/layer/launchpad-base/reactive/launchpad-base.py
131new file mode 100644
132index 0000000..88a6f5b
133--- /dev/null
134+++ b/charm/layer/launchpad-base/reactive/launchpad-base.py
135@@ -0,0 +1,31 @@
136+# Copyright 2022 Canonical Ltd. This software is licensed under the
137+# GNU Affero General Public License version 3 (see the file LICENSE).
138+
139+import subprocess
140+
141+from charms.reactive import remove_state, when
142+from ols import base
143+
144+
145+# Monkey-patch layer:ols.
146+def create_virtualenv(wheels_dir, codedir, python_exe):
147+ subprocess.run(
148+ ["make", "compile", "PYTHON={}".format(python_exe)],
149+ cwd=codedir,
150+ check=True,
151+ )
152+
153+
154+base.create_virtualenv = create_virtualenv
155+
156+
157+@when("config.changed.build_label")
158+def build_label_changed():
159+ remove_state("ols.service.installed")
160+ remove_state("ols.configured")
161+ remove_state("service.configured")
162+
163+
164+@when("config.changed")
165+def config_changed():
166+ remove_state("service.configured")

Subscribers

People subscribed via source and target branches

to status/vote changes: