← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] ~cjwatson/launchpad-layers:payload-layer into launchpad-layers:main

 

Colin Watson has proposed merging ~cjwatson/launchpad-layers:payload-layer into launchpad-layers:main.

Commit message:
Move part of launchpad-base into a new launchpad-payload layer

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~cjwatson/launchpad-layers/+git/launchpad-layers/+merge/442013

Some charms - at least the prospective `launchpad-assets`, which publishes CSS/JS etc. assets for use by frontends - only really need an unpacked Launchpad payload, and don't need the rest of `launchpad-base`.  Extract that part into a separate layer.
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~cjwatson/launchpad-layers:payload-layer into launchpad-layers:main.
diff --git a/launchpad-base/config.yaml b/launchpad-base/config.yaml
index 14feeca..826cdc4 100644
--- a/launchpad-base/config.yaml
+++ b/launchpad-base/config.yaml
@@ -274,10 +274,3 @@ options:
     type: string
     description: Outbound webhook request proxy URL.
     default:
-  # layer-apt
-  install_sources:
-    default: |
-      - ppa:launchpad/ppa
-  install_keys:
-    default: |
-      - null  # PPA keys securely added via Launchpad.
diff --git a/launchpad-base/layer.yaml b/launchpad-base/layer.yaml
index 32c0987..5abc6ac 100644
--- a/launchpad-base/layer.yaml
+++ b/launchpad-base/layer.yaml
@@ -2,15 +2,5 @@ includes:
   - layer:basic
   - layer:ols-pg
   - interface:rabbitmq
-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-payload
 repo: https://git.launchpad.net/launchpad-layers
diff --git a/launchpad-base/reactive/launchpad-base.py b/launchpad-base/reactive/launchpad-base.py
index adc40d7..50293c8 100644
--- a/launchpad-base/reactive/launchpad-base.py
+++ b/launchpad-base/reactive/launchpad-base.py
@@ -1,8 +1,6 @@
 # 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.launchpad.base import (
     change_shell,
@@ -27,18 +25,6 @@ from charms.reactive import (
 from ols import base, postgres
 
 
-# Monkey-patch layer:ols.
-def create_virtualenv(wheels_dir, codedir, python_exe):
-    subprocess.run(
-        ["make", "compile", f"PYTHON={python_exe}"],
-        cwd=codedir,
-        check=True,
-    )
-
-
-base.create_virtualenv = create_virtualenv
-
-
 @when("rabbitmq.connected")
 def prepare_rabbitmq():
     rabbitmq = endpoint_from_flag("rabbitmq.connected")
@@ -120,23 +106,6 @@ def deconfigure():
     clear_flag("service.configured")
 
 
-@hook("upgrade-charm")
-def upgrade_charm():
-    # The ols layer takes care of removing the ols.service.installed,
-    # ols.configured, and service.configured states.  Remove
-    # launchpad.base.configured as well so that we have an opportunity to
-    # rewrite base configuration files.
-    clear_flag("launchpad.base.configured")
-
-
-@when("config.changed.build_label")
-def build_label_changed():
-    clear_flag("ols.service.installed")
-    clear_flag("ols.configured")
-    clear_flag("launchpad.base.configured")
-    clear_flag("service.configured")
-
-
 @when("config.changed")
 def config_changed():
     clear_flag("launchpad.base.configured")
diff --git a/launchpad-payload/config.yaml b/launchpad-payload/config.yaml
new file mode 100644
index 0000000..adc4e2c
--- /dev/null
+++ b/launchpad-payload/config.yaml
@@ -0,0 +1,8 @@
+options:
+  # layer-apt
+  install_sources:
+    default: |
+      - ppa:launchpad/ppa
+  install_keys:
+    default: |
+      - null  # PPA keys securely added via Launchpad.
diff --git a/launchpad-base/icon.svg b/launchpad-payload/icon.svg
similarity index 100%
rename from launchpad-base/icon.svg
rename to launchpad-payload/icon.svg
diff --git a/launchpad-payload/layer.yaml b/launchpad-payload/layer.yaml
new file mode 100644
index 0000000..970a981
--- /dev/null
+++ b/launchpad-payload/layer.yaml
@@ -0,0 +1,17 @@
+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
+  launchpad-payload:
+    build_target: compile
+repo: https://git.launchpad.net/launchpad-layers
diff --git a/launchpad-payload/reactive/launchpad-payload.py b/launchpad-payload/reactive/launchpad-payload.py
new file mode 100644
index 0000000..dc3f153
--- /dev/null
+++ b/launchpad-payload/reactive/launchpad-payload.py
@@ -0,0 +1,29 @@
+# Copyright 2022-2023 Canonical Ltd.  This software is licensed under the
+# GNU Affero General Public License version 3 (see the file LICENSE).
+
+import subprocess
+
+from charms.layer import options
+from charms.reactive import clear_flag, when
+from ols import base
+
+
+# Monkey-patch layer:ols.
+def create_virtualenv(wheels_dir, codedir, python_exe):
+    build_target = (
+        options().get("launchpad-payload", {}).get("build_target", "compile")
+    )
+    subprocess.run(
+        ["make", build_target, f"PYTHON={python_exe}"],
+        cwd=codedir,
+        check=True,
+    )
+
+
+base.create_virtualenv = create_virtualenv
+
+
+@when("config.changed.build_label")
+def build_label_changed():
+    clear_flag("ols.service.installed")
+    clear_flag("ols.configured")