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
diff --git a/charm/Makefile b/charm/Makefile
index d1e4611..857f6b2 100644
--- a/charm/Makefile
+++ b/charm/Makefile
@@ -17,6 +17,7 @@ CHARMS := \
17 launchpad-admin \17 launchpad-admin \
18 launchpad-appserver \18 launchpad-appserver \
19 launchpad-assets \19 launchpad-assets \
20 launchpad-debian-importer \
20 launchpad-librarian21 launchpad-librarian
2122
22all: ## alias to build23all: ## alias to build
diff --git a/charm/launchpad-debian-importer/README.md b/charm/launchpad-debian-importer/README.md
23new file mode 10064424new file mode 100644
index 0000000..6ae99ca
--- /dev/null
+++ b/charm/launchpad-debian-importer/README.md
@@ -0,0 +1,13 @@
1# Launchpad Debian importer
2
3This charm runs a job that imports Debian packages into Launchpad.
4
5You will need the following relations:
6
7 juju relate launchpad-debian-importer:db postgresql:db
8 juju relate launchpad-debian-importer rabbitmq-server
9
10You will also need to set the `librarian_upload_host` and
11`librarian_upload_port` options to point to a local
12[launchpad-librarian](https://charmhub.io/launchpad-librarian) instance;
13this is not currently handled using relations.
diff --git a/charm/launchpad-debian-importer/charmcraft.yaml b/charm/launchpad-debian-importer/charmcraft.yaml
0new file mode 10064414new file mode 100644
index 0000000..1634d67
--- /dev/null
+++ b/charm/launchpad-debian-importer/charmcraft.yaml
@@ -0,0 +1,60 @@
1type: charm
2bases:
3 - build-on:
4 - name: ubuntu
5 channel: "20.04"
6 architectures: [amd64]
7 run-on:
8 - name: ubuntu
9 channel: "20.04"
10 architectures: [amd64]
11parts:
12 charm-wheels:
13 source: https://git.launchpad.net/~ubuntuone-hackers/ols-charm-deps/+git/wheels
14 source-commit: "59b32ae07f98051385c96d6d8e7e02ca4f197fe5"
15 source-submodules: []
16 source-type: git
17 plugin: dump
18 organize:
19 "*": charm-wheels/
20 prime:
21 - "-charm-wheels"
22 ols-layers:
23 source: https://git.launchpad.net/ols-charm-deps
24 source-commit: "56d219f60a293a6c73759b8439ef5fdb11e19d1f"
25 source-submodules: []
26 source-type: git
27 plugin: dump
28 organize:
29 "*": layers/
30 stage:
31 - layers
32 prime:
33 - "-layers"
34 launchpad-layers:
35 after:
36 - ols-layers
37 source: https://git.launchpad.net/launchpad-layers
38 source-commit: "6a50917f5f6163069ae1661e3320abb5b48173a3"
39 source-submodules: []
40 source-type: git
41 plugin: dump
42 organize:
43 launchpad-base: layers/layer/launchpad-base
44 stage:
45 - layers
46 prime:
47 - "-layers"
48 launchpad-debian-importer:
49 after:
50 - charm-wheels
51 - launchpad-layers
52 source: .
53 plugin: reactive
54 build-snaps: [charm/2.x/stable]
55 build-packages: [libpq-dev]
56 build-environment:
57 - CHARM_LAYERS_DIR: $CRAFT_STAGE/layers/layer
58 - CHARM_INTERFACES_DIR: $CRAFT_STAGE/layers/interface
59 - PIP_NO_INDEX: "true"
60 - PIP_FIND_LINKS: $CRAFT_STAGE/charm-wheels
diff --git a/charm/launchpad-debian-importer/config.yaml b/charm/launchpad-debian-importer/config.yaml
0new file mode 10064461new file mode 100644
index 0000000..6b0c325
--- /dev/null
+++ b/charm/launchpad-debian-importer/config.yaml
@@ -0,0 +1,14 @@
1options:
2 active:
3 type: boolean
4 description: If true, enable jobs that may change the database.
5 default: true
6 debian_mirror_host:
7 type: string
8 description: Hostname of the Debian mirror to use.
9 default: "ftp.debian.org"
10 debian_suites:
11 type: string
12 description: YAML-encoded dict mapping Debian suites to components.
13 default: |
14 sid: ["main", "contrib", "non-free"]
diff --git a/charm/launchpad-debian-importer/layer.yaml b/charm/launchpad-debian-importer/layer.yaml
0new file mode 10064415new file mode 100644
index 0000000..88e2ce1
--- /dev/null
+++ b/charm/launchpad-debian-importer/layer.yaml
@@ -0,0 +1,13 @@
1includes:
2 - layer:launchpad-base
3repo: https://git.launchpad.net/launchpad
4options:
5 apt:
6 packages:
7 - debian-archive-keyring
8 - debmirror
9 ols-pg:
10 databases:
11 db:
12 name: launchpad_dev
13 roles: gina
diff --git a/charm/launchpad-debian-importer/metadata.yaml b/charm/launchpad-debian-importer/metadata.yaml
0new file mode 10064414new file mode 100644
index 0000000..ff28cae
--- /dev/null
+++ b/charm/launchpad-debian-importer/metadata.yaml
@@ -0,0 +1,15 @@
1name: launchpad-debian-importer
2display-name: launchpad-debian-importer
3summary: Launchpad Debian importer
4maintainer: Colin Watson <cjwatson@canonical.com>
5description: |
6 Launchpad is an open source suite of tools that help people and teams
7 to work together on software projects.
8
9 This charm runs a job that imports Debian packages into Launchpad.
10tags:
11 # https://juju.is/docs/charm-metadata#heading--charm-store-fields
12 - network
13series:
14 - focal
15subordinate: false
diff --git a/charm/launchpad-debian-importer/reactive/launchpad-debian-importer.py b/charm/launchpad-debian-importer/reactive/launchpad-debian-importer.py
0new file mode 10064416new file mode 100644
index 0000000..f87e95b
--- /dev/null
+++ b/charm/launchpad-debian-importer/reactive/launchpad-debian-importer.py
@@ -0,0 +1,62 @@
1# Copyright 2023 Canonical Ltd. This software is licensed under the
2# GNU Affero General Public License version 3 (see the file LICENSE).
3
4import os.path
5
6import yaml
7from charmhelpers.core import hookenv, host, templating
8from charms.launchpad.base import (
9 configure_cron,
10 configure_lazr,
11 get_service_config,
12)
13from charms.reactive import set_state, when, when_not
14from ols import base
15
16
17def configure_logrotate(config):
18 hookenv.log("Writing logrotate configuration.")
19 templating.render(
20 "logrotate.conf.j2",
21 "/etc/logrotate.d/launchpad-debian-importer",
22 config,
23 perms=0o644,
24 )
25
26
27@when("launchpad.base.configured")
28@when_not("service.configured")
29def configure():
30 config = get_service_config()
31 config["debian_suites"] = yaml.safe_load(config["debian_suites"])
32 config["debian_components"] = []
33 for suite, components in config["debian_suites"].items():
34 for component in components:
35 if component not in config["debian_components"]:
36 config["debian_components"].append(component)
37 config["mirror_dir"] = os.path.join(base.base_dir(), "mirror")
38 host.mkdir(
39 config["mirror_dir"], owner=base.user(), group=base.user(), perms=0o755
40 )
41 config["scripts_dir"] = os.path.join(base.base_dir(), "scripts")
42 host.mkdir(config["scripts_dir"], perms=0o755)
43 templating.render(
44 "mirror-update.sh.j2",
45 os.path.join(config["scripts_dir"], "mirror-update.sh"),
46 config,
47 perms=0o755,
48 )
49 configure_lazr(
50 config,
51 "launchpad-debian-importer-lazr.conf",
52 "launchpad-debian-importer/launchpad-lazr.conf",
53 )
54 configure_logrotate(config)
55 configure_cron(config, "crontab.j2")
56
57 set_state("service.configured")
58
59
60@when("service.configured")
61def check_is_running():
62 hookenv.status_set("active", "Ready")
diff --git a/charm/launchpad-debian-importer/templates/crontab.j2 b/charm/launchpad-debian-importer/templates/crontab.j2
0new file mode 10064463new file mode 100644
index 0000000..2f9d7e2
--- /dev/null
+++ b/charm/launchpad-debian-importer/templates/crontab.j2
@@ -0,0 +1,15 @@
1TZ=UTC
2MAILFROM={{ bounce_address }}
3MAILTO={{ cron_mailto }}
4LPCONFIG=launchpad-debian-importer
5
6{% if active -%}
7# Mirror from Debian and then run the importer. Debian publishes at "52
8# 1,7,13,19", but we also need to allow time for the above mirror to update.
925 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
10
11{% endif -%}
12# Catch up with publishing OOPSes that were temporarily spooled to disk due
13# to RabbitMQ being unavailable.
14*/15 * * * * {{ code_dir }}/bin/datedir2amqp --exchange oopses --host {{ rabbitmq_host }} --username {{ rabbitmq_username }} --password {{ rabbitmq_password }} --vhost {{ rabbitmq_vhost }} --repo {{ oopses_dir }} --key ""
15
diff --git a/charm/launchpad-debian-importer/templates/launchpad-debian-importer-lazr.conf b/charm/launchpad-debian-importer/templates/launchpad-debian-importer-lazr.conf
0new file mode 10064416new file mode 100644
index 0000000..2152ea5
--- /dev/null
+++ b/charm/launchpad-debian-importer/templates/launchpad-debian-importer-lazr.conf
@@ -0,0 +1,20 @@
1# Public configuration data. The contents of this file may be freely shared
2# with developers if needed for debugging.
3
4# A schema's sections, keys, and values are automatically inherited, except
5# for '.optional' sections. Update this config to override key values.
6# Values are strings, except for numbers that look like ints. The tokens
7# true, false, and none are treated as True, False, and None.
8
9{% from "macros.j2" import opt -%}
10
11[meta]
12extends: ../launchpad-base-lazr.conf
13
14{% for suite, components in debian_suites.items() -%}
15[gina_target.{{ suite }}]
16components: {{ components|join(",") }}
17source_only: True
18root: {{ mirror_dir }}/
19
20{% endfor -%}
diff --git a/charm/launchpad-debian-importer/templates/logrotate.conf.j2 b/charm/launchpad-debian-importer/templates/logrotate.conf.j2
0new file mode 10064421new file mode 100644
index 0000000..51d1421
--- /dev/null
+++ b/charm/launchpad-debian-importer/templates/logrotate.conf.j2
@@ -0,0 +1,11 @@
1{{ logs_dir }}/*.log
2{
3 rotate 21
4 daily
5 dateext
6 delaycompress
7 compress
8 notifempty
9 missingok
10}
11
diff --git a/charm/launchpad-debian-importer/templates/mirror-update.sh.j2 b/charm/launchpad-debian-importer/templates/mirror-update.sh.j2
0new file mode 10064412new file mode 100644
index 0000000..446c3af
--- /dev/null
+++ b/charm/launchpad-debian-importer/templates/mirror-update.sh.j2
@@ -0,0 +1,24 @@
1#! /bin/sh
2# Copyright 2023 Canonical Ltd. This software is licensed under the
3# GNU Affero General Public License version 3 (see the file LICENSE).
4
5# Part of the launchpad-debian-importer Juju charm.
6
7set -e
8
9DEST="{{ mirror_dir }}/"
10HOST="{{ debian_mirror_host }}"
11DISTS="{{ debian_suites.keys()|join(',') }}"
12SECTIONS="{{ debian_components|join(',') }}"
13
14{% if http_proxy -%}
15http_proxy="{{ http_proxy }}"
16ftp_proxy="{{ http_proxy }}"
17export http_proxy ftp_proxy
18
19{% endif -%}
20echo "Starting Mirror: $(date)"
21rm -rf "${DEST}/.temp"
22debmirror --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"
23echo "Finished Mirror: $(date)"
24

Subscribers

People subscribed via source and target branches

to status/vote changes: