Colin Watson has proposed merging ~cjwatson/launchpad:charm-layers into launchpad:master.
Commit message: Split some charm code into a layer Requested reviews: Launchpad code reviewers (launchpad-reviewers) For more details, see: https://code.launchpad.net/~cjwatson/launchpad/+git/launchpad/+merge/428107 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. -- Your team Launchpad code reviewers is requested to review the proposed merge of ~cjwatson/launchpad:charm-layers into launchpad:master.
diff --git a/charm/.gitignore b/charm/.gitignore index da831d3..de07da3 100644 --- a/charm/.gitignore +++ b/charm/.gitignore @@ -1,4 +1,5 @@ *.charm bundle.yaml dist +layer/*/codetree-collect-info.yaml tmp diff --git a/charm/Makefile b/charm/Makefile index de55a73..5bb96fe 100644 --- a/charm/Makefile +++ b/charm/Makefile @@ -45,12 +45,13 @@ build-launchpad: ## build the launchpad charm build-launchpad: dist/$(call charm_file,launchpad) dist/%_ubuntu-$(CHARM_SERIES)-$(ARCH).charm: $(CHARM_DEPS) | $(BUILDDIR) - @echo "Building $*..." - @rm -rf $*/tmp - @cp -a tmp $*/tmp - @cd $* && charmcraft pack - @cp -a $*/$(call charm_file,$*) dist/ - @rm -rf $*/tmp + echo "Building $*..." + rm -rf $*/tmp + cp -a tmp $*/tmp + cp -a layer/launchpad-base $*/tmp/deps/ols-layers/layer/ + cd $* && charmcraft pack + cp -a $*/$(call charm_file,$*) dist/ + rm -rf $*/tmp clean: ## clean the build environment clean: $(foreach charm,$(CHARMS),clean-$(charm)) diff --git a/charm/launchpad/layer.yaml b/charm/launchpad/layer.yaml index ae16aa0..bcff867 100644 --- a/charm/launchpad/layer.yaml +++ b/charm/launchpad/layer.yaml @@ -1,15 +1,3 @@ includes: - - layer:basic - - layer:ols -options: - apt: - packages: - - launchpad-dependencies - ols: - service_name: launchpad - config_filename: service.conf - user: launchpad - tarball_payload: true - symlink_switch_payload: true - python_bin: /usr/bin/python3 + - layer:launchpad-base repo: https://git.launchpad.net/launchpad diff --git a/charm/launchpad/reactive/launchpad.py b/charm/launchpad/reactive/launchpad.py index 076a8c9..5b4222b 100644 --- a/charm/launchpad/reactive/launchpad.py +++ b/charm/launchpad/reactive/launchpad.py @@ -1,23 +1,8 @@ # Copyright 2022 Canonical Ltd. This software is licensed under the # GNU Affero General Public License version 3 (see the file LICENSE). -import subprocess - from charmhelpers.core import hookenv -from charms.reactive import remove_state, set_state, when, when_not -from ols import base - - -# Monkey-patch layer:ols. -def create_virtualenv(wheels_dir, codedir, python_exe): - subprocess.run( - ["make", "compile", "PYTHON={}".format(python_exe)], - cwd=codedir, - check=True, - ) - - -base.create_virtualenv = create_virtualenv +from charms.reactive import set_state, when, when_not @when("ols.configured") @@ -30,15 +15,3 @@ def configure(): @when("service.configured") def check_is_running(): hookenv.status_set("active", "Ready") - - -@when("config.changed.build_label") -def build_label_changed(): - remove_state("ols.service.installed") - remove_state("ols.configured") - remove_state("service.configured") - - -@when("config.changed") -def config_changed(): - remove_state("service.configured") diff --git a/charm/launchpad/config.yaml b/charm/layer/launchpad-base/config.yaml similarity index 100% rename from charm/launchpad/config.yaml rename to charm/layer/launchpad-base/config.yaml diff --git a/charm/launchpad/icon.svg b/charm/layer/launchpad-base/icon.svg similarity index 100% rename from charm/launchpad/icon.svg rename to charm/layer/launchpad-base/icon.svg diff --git a/charm/layer/launchpad-base/layer.yaml b/charm/layer/launchpad-base/layer.yaml new file mode 100644 index 0000000..ae16aa0 --- /dev/null +++ b/charm/layer/launchpad-base/layer.yaml @@ -0,0 +1,15 @@ +includes: + - layer:basic + - layer:ols +options: + apt: + packages: + - launchpad-dependencies + ols: + service_name: launchpad + config_filename: service.conf + user: launchpad + tarball_payload: true + symlink_switch_payload: true + python_bin: /usr/bin/python3 +repo: https://git.launchpad.net/launchpad diff --git a/charm/layer/launchpad-base/reactive/launchpad-base.py b/charm/layer/launchpad-base/reactive/launchpad-base.py new file mode 100644 index 0000000..88a6f5b --- /dev/null +++ b/charm/layer/launchpad-base/reactive/launchpad-base.py @@ -0,0 +1,31 @@ +# Copyright 2022 Canonical Ltd. This software is licensed under the +# GNU Affero General Public License version 3 (see the file LICENSE). + +import subprocess + +from charms.reactive import remove_state, when +from ols import base + + +# Monkey-patch layer:ols. +def create_virtualenv(wheels_dir, codedir, python_exe): + subprocess.run( + ["make", "compile", "PYTHON={}".format(python_exe)], + cwd=codedir, + check=True, + ) + + +base.create_virtualenv = create_virtualenv + + +@when("config.changed.build_label") +def build_label_changed(): + remove_state("ols.service.installed") + remove_state("ols.configured") + remove_state("service.configured") + + +@when("config.changed") +def config_changed(): + remove_state("service.configured")
_______________________________________________ Mailing list: https://launchpad.net/~launchpad-reviewers Post to : [email protected] Unsubscribe : https://launchpad.net/~launchpad-reviewers More help : https://help.launchpad.net/ListHelp

