Merge ~cjwatson/launchpad:charm-debian-importer into launchpad:master

Proposed by Colin Watson
Status: Merged
Approved by: Colin Watson
Approved revision: aecfa0660b443455348c912010e665d9d2df6688
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: ~cjwatson/launchpad:charm-debian-importer
Merge into: launchpad:master
Diff against target: 319 lines (+248/-0)
11 files modified
charm/Makefile (+1/-0)
charm/launchpad-debian-importer/README.md (+13/-0)
charm/launchpad-debian-importer/charmcraft.yaml (+60/-0)
charm/launchpad-debian-importer/config.yaml (+14/-0)
charm/launchpad-debian-importer/layer.yaml (+13/-0)
charm/launchpad-debian-importer/metadata.yaml (+15/-0)
charm/launchpad-debian-importer/reactive/launchpad-debian-importer.py (+62/-0)
charm/launchpad-debian-importer/templates/crontab.j2 (+15/-0)
charm/launchpad-debian-importer/templates/launchpad-debian-importer-lazr.conf (+20/-0)
charm/launchpad-debian-importer/templates/logrotate.conf.j2 (+11/-0)
charm/launchpad-debian-importer/templates/mirror-update.sh.j2 (+24/-0)
Reviewer Review Type Date Requested Status
Simone Pelosi Approve
Review via email: mp+442049@code.launchpad.net

Commit message

charm: Add a launchpad-debian-importer charm

To post a comment you must log in.
Revision history for this message
Simone Pelosi (pelpsi) wrote :

LGTM!

Revision history for this message
Simone Pelosi (pelpsi) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/charm/Makefile b/charm/Makefile
2index d1e4611..857f6b2 100644
3--- a/charm/Makefile
4+++ b/charm/Makefile
5@@ -17,6 +17,7 @@ CHARMS := \
6 launchpad-admin \
7 launchpad-appserver \
8 launchpad-assets \
9+ launchpad-debian-importer \
10 launchpad-librarian
11
12 all: ## alias to build
13diff --git a/charm/launchpad-debian-importer/README.md b/charm/launchpad-debian-importer/README.md
14new file mode 100644
15index 0000000..6ae99ca
16--- /dev/null
17+++ b/charm/launchpad-debian-importer/README.md
18@@ -0,0 +1,13 @@
19+# Launchpad Debian importer
20+
21+This charm runs a job that imports Debian packages into Launchpad.
22+
23+You will need the following relations:
24+
25+ juju relate launchpad-debian-importer:db postgresql:db
26+ juju relate launchpad-debian-importer rabbitmq-server
27+
28+You will also need to set the `librarian_upload_host` and
29+`librarian_upload_port` options to point to a local
30+[launchpad-librarian](https://charmhub.io/launchpad-librarian) instance;
31+this is not currently handled using relations.
32diff --git a/charm/launchpad-debian-importer/charmcraft.yaml b/charm/launchpad-debian-importer/charmcraft.yaml
33new file mode 100644
34index 0000000..1634d67
35--- /dev/null
36+++ b/charm/launchpad-debian-importer/charmcraft.yaml
37@@ -0,0 +1,60 @@
38+type: charm
39+bases:
40+ - build-on:
41+ - name: ubuntu
42+ channel: "20.04"
43+ architectures: [amd64]
44+ run-on:
45+ - name: ubuntu
46+ channel: "20.04"
47+ architectures: [amd64]
48+parts:
49+ charm-wheels:
50+ source: https://git.launchpad.net/~ubuntuone-hackers/ols-charm-deps/+git/wheels
51+ source-commit: "59b32ae07f98051385c96d6d8e7e02ca4f197fe5"
52+ source-submodules: []
53+ source-type: git
54+ plugin: dump
55+ organize:
56+ "*": charm-wheels/
57+ prime:
58+ - "-charm-wheels"
59+ ols-layers:
60+ source: https://git.launchpad.net/ols-charm-deps
61+ source-commit: "56d219f60a293a6c73759b8439ef5fdb11e19d1f"
62+ source-submodules: []
63+ source-type: git
64+ plugin: dump
65+ organize:
66+ "*": layers/
67+ stage:
68+ - layers
69+ prime:
70+ - "-layers"
71+ launchpad-layers:
72+ after:
73+ - ols-layers
74+ source: https://git.launchpad.net/launchpad-layers
75+ source-commit: "6a50917f5f6163069ae1661e3320abb5b48173a3"
76+ source-submodules: []
77+ source-type: git
78+ plugin: dump
79+ organize:
80+ launchpad-base: layers/layer/launchpad-base
81+ stage:
82+ - layers
83+ prime:
84+ - "-layers"
85+ launchpad-debian-importer:
86+ after:
87+ - charm-wheels
88+ - launchpad-layers
89+ source: .
90+ plugin: reactive
91+ build-snaps: [charm/2.x/stable]
92+ build-packages: [libpq-dev]
93+ build-environment:
94+ - CHARM_LAYERS_DIR: $CRAFT_STAGE/layers/layer
95+ - CHARM_INTERFACES_DIR: $CRAFT_STAGE/layers/interface
96+ - PIP_NO_INDEX: "true"
97+ - PIP_FIND_LINKS: $CRAFT_STAGE/charm-wheels
98diff --git a/charm/launchpad-debian-importer/config.yaml b/charm/launchpad-debian-importer/config.yaml
99new file mode 100644
100index 0000000..6b0c325
101--- /dev/null
102+++ b/charm/launchpad-debian-importer/config.yaml
103@@ -0,0 +1,14 @@
104+options:
105+ active:
106+ type: boolean
107+ description: If true, enable jobs that may change the database.
108+ default: true
109+ debian_mirror_host:
110+ type: string
111+ description: Hostname of the Debian mirror to use.
112+ default: "ftp.debian.org"
113+ debian_suites:
114+ type: string
115+ description: YAML-encoded dict mapping Debian suites to components.
116+ default: |
117+ sid: ["main", "contrib", "non-free"]
118diff --git a/charm/launchpad-debian-importer/layer.yaml b/charm/launchpad-debian-importer/layer.yaml
119new file mode 100644
120index 0000000..88e2ce1
121--- /dev/null
122+++ b/charm/launchpad-debian-importer/layer.yaml
123@@ -0,0 +1,13 @@
124+includes:
125+ - layer:launchpad-base
126+repo: https://git.launchpad.net/launchpad
127+options:
128+ apt:
129+ packages:
130+ - debian-archive-keyring
131+ - debmirror
132+ ols-pg:
133+ databases:
134+ db:
135+ name: launchpad_dev
136+ roles: gina
137diff --git a/charm/launchpad-debian-importer/metadata.yaml b/charm/launchpad-debian-importer/metadata.yaml
138new file mode 100644
139index 0000000..ff28cae
140--- /dev/null
141+++ b/charm/launchpad-debian-importer/metadata.yaml
142@@ -0,0 +1,15 @@
143+name: launchpad-debian-importer
144+display-name: launchpad-debian-importer
145+summary: Launchpad Debian importer
146+maintainer: Colin Watson <cjwatson@canonical.com>
147+description: |
148+ Launchpad is an open source suite of tools that help people and teams
149+ to work together on software projects.
150+
151+ This charm runs a job that imports Debian packages into Launchpad.
152+tags:
153+ # https://juju.is/docs/charm-metadata#heading--charm-store-fields
154+ - network
155+series:
156+ - focal
157+subordinate: false
158diff --git a/charm/launchpad-debian-importer/reactive/launchpad-debian-importer.py b/charm/launchpad-debian-importer/reactive/launchpad-debian-importer.py
159new file mode 100644
160index 0000000..f87e95b
161--- /dev/null
162+++ b/charm/launchpad-debian-importer/reactive/launchpad-debian-importer.py
163@@ -0,0 +1,62 @@
164+# Copyright 2023 Canonical Ltd. This software is licensed under the
165+# GNU Affero General Public License version 3 (see the file LICENSE).
166+
167+import os.path
168+
169+import yaml
170+from charmhelpers.core import hookenv, host, templating
171+from charms.launchpad.base import (
172+ configure_cron,
173+ configure_lazr,
174+ get_service_config,
175+)
176+from charms.reactive import set_state, when, when_not
177+from ols import base
178+
179+
180+def configure_logrotate(config):
181+ hookenv.log("Writing logrotate configuration.")
182+ templating.render(
183+ "logrotate.conf.j2",
184+ "/etc/logrotate.d/launchpad-debian-importer",
185+ config,
186+ perms=0o644,
187+ )
188+
189+
190+@when("launchpad.base.configured")
191+@when_not("service.configured")
192+def configure():
193+ config = get_service_config()
194+ config["debian_suites"] = yaml.safe_load(config["debian_suites"])
195+ config["debian_components"] = []
196+ for suite, components in config["debian_suites"].items():
197+ for component in components:
198+ if component not in config["debian_components"]:
199+ config["debian_components"].append(component)
200+ config["mirror_dir"] = os.path.join(base.base_dir(), "mirror")
201+ host.mkdir(
202+ config["mirror_dir"], owner=base.user(), group=base.user(), perms=0o755
203+ )
204+ config["scripts_dir"] = os.path.join(base.base_dir(), "scripts")
205+ host.mkdir(config["scripts_dir"], perms=0o755)
206+ templating.render(
207+ "mirror-update.sh.j2",
208+ os.path.join(config["scripts_dir"], "mirror-update.sh"),
209+ config,
210+ perms=0o755,
211+ )
212+ configure_lazr(
213+ config,
214+ "launchpad-debian-importer-lazr.conf",
215+ "launchpad-debian-importer/launchpad-lazr.conf",
216+ )
217+ configure_logrotate(config)
218+ configure_cron(config, "crontab.j2")
219+
220+ set_state("service.configured")
221+
222+
223+@when("service.configured")
224+def check_is_running():
225+ hookenv.status_set("active", "Ready")
226diff --git a/charm/launchpad-debian-importer/templates/crontab.j2 b/charm/launchpad-debian-importer/templates/crontab.j2
227new file mode 100644
228index 0000000..2f9d7e2
229--- /dev/null
230+++ b/charm/launchpad-debian-importer/templates/crontab.j2
231@@ -0,0 +1,15 @@
232+TZ=UTC
233+MAILFROM={{ bounce_address }}
234+MAILTO={{ cron_mailto }}
235+LPCONFIG=launchpad-debian-importer
236+
237+{% if active -%}
238+# Mirror from Debian and then run the importer. Debian publishes at "52
239+# 1,7,13,19", but we also need to allow time for the above mirror to update.
240+25 4,10,16,22 * * * {{ scripts_dir }}/mirror-update.sh >> {{ logs_dir }}/mirror-update.log 2>&1 && {{ code_dir }}/scripts/gina.py {{ debian_suites.keys()|reverse|join(" ") }} -q --log-file=INFO:{{ logs_dir }}/gina.log
241+
242+{% endif -%}
243+# Catch up with publishing OOPSes that were temporarily spooled to disk due
244+# to RabbitMQ being unavailable.
245+*/15 * * * * {{ code_dir }}/bin/datedir2amqp --exchange oopses --host {{ rabbitmq_host }} --username {{ rabbitmq_username }} --password {{ rabbitmq_password }} --vhost {{ rabbitmq_vhost }} --repo {{ oopses_dir }} --key ""
246+
247diff --git a/charm/launchpad-debian-importer/templates/launchpad-debian-importer-lazr.conf b/charm/launchpad-debian-importer/templates/launchpad-debian-importer-lazr.conf
248new file mode 100644
249index 0000000..2152ea5
250--- /dev/null
251+++ b/charm/launchpad-debian-importer/templates/launchpad-debian-importer-lazr.conf
252@@ -0,0 +1,20 @@
253+# Public configuration data. The contents of this file may be freely shared
254+# with developers if needed for debugging.
255+
256+# A schema's sections, keys, and values are automatically inherited, except
257+# for '.optional' sections. Update this config to override key values.
258+# Values are strings, except for numbers that look like ints. The tokens
259+# true, false, and none are treated as True, False, and None.
260+
261+{% from "macros.j2" import opt -%}
262+
263+[meta]
264+extends: ../launchpad-base-lazr.conf
265+
266+{% for suite, components in debian_suites.items() -%}
267+[gina_target.{{ suite }}]
268+components: {{ components|join(",") }}
269+source_only: True
270+root: {{ mirror_dir }}/
271+
272+{% endfor -%}
273diff --git a/charm/launchpad-debian-importer/templates/logrotate.conf.j2 b/charm/launchpad-debian-importer/templates/logrotate.conf.j2
274new file mode 100644
275index 0000000..51d1421
276--- /dev/null
277+++ b/charm/launchpad-debian-importer/templates/logrotate.conf.j2
278@@ -0,0 +1,11 @@
279+{{ logs_dir }}/*.log
280+{
281+ rotate 21
282+ daily
283+ dateext
284+ delaycompress
285+ compress
286+ notifempty
287+ missingok
288+}
289+
290diff --git a/charm/launchpad-debian-importer/templates/mirror-update.sh.j2 b/charm/launchpad-debian-importer/templates/mirror-update.sh.j2
291new file mode 100644
292index 0000000..446c3af
293--- /dev/null
294+++ b/charm/launchpad-debian-importer/templates/mirror-update.sh.j2
295@@ -0,0 +1,24 @@
296+#! /bin/sh
297+# Copyright 2023 Canonical Ltd. This software is licensed under the
298+# GNU Affero General Public License version 3 (see the file LICENSE).
299+
300+# Part of the launchpad-debian-importer Juju charm.
301+
302+set -e
303+
304+DEST="{{ mirror_dir }}/"
305+HOST="{{ debian_mirror_host }}"
306+DISTS="{{ debian_suites.keys()|join(',') }}"
307+SECTIONS="{{ debian_components|join(',') }}"
308+
309+{% if http_proxy -%}
310+http_proxy="{{ http_proxy }}"
311+ftp_proxy="{{ http_proxy }}"
312+export http_proxy ftp_proxy
313+
314+{% endif -%}
315+echo "Starting Mirror: $(date)"
316+rm -rf "${DEST}/.temp"
317+debmirror --keyring /usr/share/keyrings/debian-archive-keyring.gpg --root=debian --host="$HOST" --method=http --dist="$DISTS" --section="$SECTIONS" --arch=none --diff=none --progress --rsync-extra=none --allow-dist-rename "$DEST"
318+echo "Finished Mirror: $(date)"
319+

Subscribers

People subscribed via source and target branches

to status/vote changes: