[Patchew-devel] [PATCH] scripts: separate applier and importer

Paolo Bonzini posted 1 patch 2 years, 7 months ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/patchew-ci tags/patchew/20220224075258.316670-1-pbonzini@redhat.com
scripts/deploy                                | 10 +++-
scripts/dockerfiles/applier.docker            | 11 +++++
scripts/dockerfiles/importer.docker           |  8 +---
scripts/patchew-applier                       | 37 ++++++++++++++
scripts/patchew-importer                      | 16 -------
scripts/playbooks/deploy-appliers.yml         | 48 +++++++++++++++++++
scripts/playbooks/deploy-importers.yml        | 13 -----
scripts/playbooks/templates/applier-config.j2 |  4 ++
.../playbooks/templates/importer-config.j2    |  1 -
9 files changed, 110 insertions(+), 38 deletions(-)
create mode 100644 scripts/dockerfiles/applier.docker
create mode 100755 scripts/patchew-applier
create mode 100644 scripts/playbooks/deploy-appliers.yml
create mode 100644 scripts/playbooks/templates/applier-config.j2
[Patchew-devel] [PATCH] scripts: separate applier and importer
Posted by Paolo Bonzini 2 years, 7 months ago
With two different kinds of importer now in existence, separate the
git application and the email import tasks.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 scripts/deploy                                | 10 +++-
 scripts/dockerfiles/applier.docker            | 11 +++++
 scripts/dockerfiles/importer.docker           |  8 +---
 scripts/patchew-applier                       | 37 ++++++++++++++
 scripts/patchew-importer                      | 16 -------
 scripts/playbooks/deploy-appliers.yml         | 48 +++++++++++++++++++
 scripts/playbooks/deploy-importers.yml        | 13 -----
 scripts/playbooks/templates/applier-config.j2 |  4 ++
 .../playbooks/templates/importer-config.j2    |  1 -
 9 files changed, 110 insertions(+), 38 deletions(-)
 create mode 100644 scripts/dockerfiles/applier.docker
 create mode 100755 scripts/patchew-applier
 create mode 100644 scripts/playbooks/deploy-appliers.yml
 create mode 100644 scripts/playbooks/templates/applier-config.j2

diff --git a/scripts/deploy b/scripts/deploy
index 1953e9b..e05984d 100755
--- a/scripts/deploy
+++ b/scripts/deploy
@@ -23,6 +23,8 @@ def parse_args():
                         help="Tester host address")
     parser.add_argument("--importer", "-i", nargs="?",
                         help="Importer host address")
+    parser.add_argument("--applier", "-a", nargs="?",
+                        help="Importer host address")
     parser.add_argument("--debug", "-D", action="store_true",
                         help="Enable debug output")
     return parser.parse_known_args()
@@ -36,6 +38,9 @@ def generate_inventory_file(args):
 [db]
 %s
 
+[appliers]
+%s
+
 [importers]
 %s
 
@@ -43,6 +48,7 @@ def generate_inventory_file(args):
 %s""" \
         % (args.web_server or "",
            args.db_server or "",
+           args.applier or "",
            args.importer or "",
            "\n".join(args.testers or [])))
     f.flush()
@@ -60,10 +66,12 @@ def main():
         playbooks.append("deploy-db.yml")
     if args.testers:
         playbooks.append("deploy-testers.yml")
+    if args.applier:
+        playbooks.append("deploy-appliers.yml")
     if args.importer:
         playbooks.append("deploy-importers.yml")
     if not playbooks:
-        print("At least one host (web server, importer or tester) must be specified")
+        print("At least one host (server/db/applier/importer/tester) must be specified")
         print("Run: '%s -h' for more information" % sys.argv[0])
         return 1
     v = ["-vvv"] if args.debug else []
diff --git a/scripts/dockerfiles/applier.docker b/scripts/dockerfiles/applier.docker
new file mode 100644
index 0000000..dded23a
--- /dev/null
+++ b/scripts/dockerfiles/applier.docker
@@ -0,0 +1,11 @@
+FROM fedora:latest
+RUN dnf install -y python git wget
+RUN git config --global user.email "applier@patchew.org"
+RUN git config --global user.name "Patchew Applier"
+RUN mkdir -p -m 0700 ~/.ssh
+RUN echo IdentityFile=/data/patchew/identity > ~/.ssh/config
+RUN echo StrictHostKeyChecking no >> ~/.ssh/config
+RUN echo UserKnownHostsFile=/dev/null >> ~/.ssh/config
+ENV LC_ALL en_US.UTF-8
+COPY . /opt/patchew/
+CMD /opt/patchew/scripts/patchew-applier
diff --git a/scripts/dockerfiles/importer.docker b/scripts/dockerfiles/importer.docker
index 0021d93..b08b023 100644
--- a/scripts/dockerfiles/importer.docker
+++ b/scripts/dockerfiles/importer.docker
@@ -1,11 +1,5 @@
 FROM fedora:latest
-RUN dnf install -y python offlineimap findutils git wget
-RUN git config --global user.email "importer@patchew.org"
-RUN git config --global user.name "Patchew Importer"
-RUN mkdir -p -m 0700 ~/.ssh
-RUN echo IdentityFile=/data/patchew/identity > ~/.ssh/config
-RUN echo StrictHostKeyChecking no >> ~/.ssh/config
-RUN echo UserKnownHostsFile=/dev/null >> ~/.ssh/config
+RUN dnf install -y python offlineimap findutils wget
 ENV LC_ALL en_US.UTF-8
 COPY . /opt/patchew/
 CMD /opt/patchew/scripts/patchew-importer
diff --git a/scripts/patchew-applier b/scripts/patchew-applier
new file mode 100755
index 0000000..b06b7d2
--- /dev/null
+++ b/scripts/patchew-applier
@@ -0,0 +1,37 @@
+#!/bin/bash
+#
+# Copyright 2016 Red Hat, Inc.
+#
+# Authors:
+#     Fam Zheng <famz@redhat.com>
+#
+# This work is licensed under the MIT License.  Please see the LICENSE file or
+# http://opensource.org/licenses/MIT.
+
+set -e
+
+. /data/patchew/config
+
+BASEDIR="/data/patchew"
+PATCHEW_CLI="/opt/patchew/patchew-cli -s $PATCHEW_SERVER"
+
+while :; do
+    $PATCHEW_CLI login "$PATCHEW_USER" "$PATCHEW_PASS"
+    while :; do
+        wd=$(mktemp -d /var/tmp/patchew-applier.XXXXX)
+	applier_args='--applier-mode '
+	if test "$PATCHEW_TARGET_REPO" != ""; then
+	  applier_args="$applier_args --applier-target $PATCHEW_TARGET_REPO"
+	fi
+        if (cd $wd; $PATCHEW_CLI apply $applier_args); then
+            rm -rf $wd
+        elif [ $? -eq 3 ]; then
+            rm -rf $wd
+            break
+        else
+            rm -rf $wd
+        fi
+    done
+    $PATCHEW_CLI project update
+    sleep 60
+done
diff --git a/scripts/patchew-importer b/scripts/patchew-importer
index 24e0b96..d7754f1 100755
--- a/scripts/patchew-importer
+++ b/scripts/patchew-importer
@@ -107,22 +107,6 @@ offlineimap_import()
 
 while :; do
     $PATCHEW_CLI login "$PATCHEW_USER" "$PATCHEW_PASS"
-    while :; do
-        wd=$(mktemp -d /var/tmp/patchew-applier.XXXXX)
-	applier_args='--applier-mode '
-	if test "$PATCHEW_TARGET_REPO" != ""; then
-	  applier_args="$applier_args --applier-target $PATCHEW_TARGET_REPO"
-	fi
-        if (cd $wd; $PATCHEW_CLI apply $applier_args); then
-            rm -rf $wd
-        elif [ $? -eq 3 ]; then
-            rm -rf $wd
-            break
-        else
-            rm -rf $wd
-        fi
-    done
-    $PATCHEW_CLI project update
     offlineimap_import
     sleep 60
 done
diff --git a/scripts/playbooks/deploy-appliers.yml b/scripts/playbooks/deploy-appliers.yml
new file mode 100644
index 0000000..18edac7
--- /dev/null
+++ b/scripts/playbooks/deploy-appliers.yml
@@ -0,0 +1,48 @@
+- hosts: appliers
+  vars_prompt:
+    - name: instance_name
+      prompt: "The instance name"
+      default: patchew-applier
+      private: no
+    - name: "patchew_server"
+      prompt: "The address of patchew server"
+      default: "https://patchew.org"
+      private: no
+    - name: "applier_user"
+      prompt: "Username for the applier to login to the server"
+      private: no
+      default: "applier"
+    - name: "applier_pass"
+      prompt: "Password for the applier to login to the server"
+      private: yes
+    - name: "applier_identity"
+      prompt: "Path to file containing private key"
+      private: no
+    - name: "applier_repo"
+      prompt: "Target repository allowed by the private key (e.g. git@github.com:youruser)"
+      default: ""
+      private: no
+  vars:
+    base_dir: "/data/{{ instance_name }}"
+    src_dir: "{{ base_dir }}/src"
+    data_dir: "{{ base_dir }}/data"
+    config_file: "{{ data_dir }}/config"
+    identity_file: "{{ data_dir }}/identity"
+  tasks:
+    - name: Create data dir
+      file:
+        path: "{{ data_dir }}"
+        state: directory
+    - name: Store SSH key
+      copy:
+        src: "{{ applier_identity }}"
+        dest: "{{ identity_file }}"
+        validate: test -f %s
+        mode: 0400
+    - name: Create config
+      template:
+        src: "templates/applier-config.j2"
+        dest: "{{ config_file }}"
+    - import_tasks: tasks/docker-deploy.yml
+      vars:
+        instance_role: applier
diff --git a/scripts/playbooks/deploy-importers.yml b/scripts/playbooks/deploy-importers.yml
index 2e45db8..4eb7cbd 100644
--- a/scripts/playbooks/deploy-importers.yml
+++ b/scripts/playbooks/deploy-importers.yml
@@ -15,13 +15,6 @@
     - name: "importer_pass"
       prompt: "Password for the importer to login to the server"
       private: yes
-    - name: "importer_identity"
-      prompt: "Path to file containing private key"
-      private: no
-    - name: "importer_repo"
-      prompt: "Target repository allowed by the private key (e.g. git@github.com:youruser)"
-      default: ""
-      private: no
     - name: "imap_server"
       prompt: "IMAP server address to download patches"
       private: no
@@ -58,12 +51,6 @@
       file:
         path: "{{ data_dir }}"
         state: directory
-    - name: Store SSH key
-      copy:
-        src: "{{ importer_identity }}"
-        dest: "{{ identity_file }}"
-        validate: test -f %s
-        mode: 0400
     - name: Create config
       template:
         src: "templates/importer-config.j2"
diff --git a/scripts/playbooks/templates/applier-config.j2 b/scripts/playbooks/templates/applier-config.j2
new file mode 100644
index 0000000..6a5687e
--- /dev/null
+++ b/scripts/playbooks/templates/applier-config.j2
@@ -0,0 +1,4 @@
+PATCHEW_SERVER={{ patchew_server }}
+PATCHEW_USER={{ applier_user }}
+PATCHEW_PASS={{ applier_pass }}
+PATCHEW_TARGET_REPO={{ applier_repo }}
diff --git a/scripts/playbooks/templates/importer-config.j2 b/scripts/playbooks/templates/importer-config.j2
index 39f1fd9..b6bc844 100644
--- a/scripts/playbooks/templates/importer-config.j2
+++ b/scripts/playbooks/templates/importer-config.j2
@@ -1,7 +1,6 @@
 PATCHEW_SERVER={{ patchew_server }}
 PATCHEW_USER={{ importer_user }}
 PATCHEW_PASS={{ importer_pass }}
-PATCHEW_TARGET_REPO={{ importer_repo }}
 
 IMAP_SERVER={{ imap_server }}
 IMAP_USER={{ imap_user }}
-- 
2.34.1

_______________________________________________
Patchew-devel mailing list
Patchew-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/patchew-devel