From nobody Thu Apr 25 01:32:41 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=patchew-devel-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=patchew-devel-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1540949961219926.1919350399241; Tue, 30 Oct 2018 18:39:21 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2A12C3084259; Wed, 31 Oct 2018 01:39:20 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1F5CF1001640; Wed, 31 Oct 2018 01:39:20 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 10BF41804750; Wed, 31 Oct 2018 01:39:20 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w9V1T3KZ012160 for ; Tue, 30 Oct 2018 21:29:03 -0400 Received: by smtp.corp.redhat.com (Postfix) id 493D861B92; Wed, 31 Oct 2018 01:29:03 +0000 (UTC) Received: from magic.redhat.com (ovpn-12-37.pek2.redhat.com [10.72.12.37]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0C6B061B7B; Wed, 31 Oct 2018 01:29:01 +0000 (UTC) From: Fam Zheng To: patchew-devel@redhat.com Date: Wed, 31 Oct 2018 09:28:51 +0800 Message-Id: <20181031012856.30125-2-famz@redhat.com> In-Reply-To: <20181031012856.30125-1-famz@redhat.com> References: <20181031012856.30125-1-famz@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: patchew-devel@redhat.com Subject: [Patchew-devel] [PATCH 1/6] ansible: Install the right pip X-BeenThere: patchew-devel@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Patchew development and discussion list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: patchew-devel-bounces@redhat.com Errors-To: patchew-devel-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Wed, 31 Oct 2018 01:39:20 +0000 (UTC) Content-Type: text/plain; charset="utf-8" The Ansible pip module seems to prefer pip2 to pip3. So simplify the preparation step a bit. (the when: check is deprecated). Signed-off-by: Fam Zheng --- scripts/playbooks/tasks/docker-deploy.yml | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/scripts/playbooks/tasks/docker-deploy.yml b/scripts/playbooks/= tasks/docker-deploy.yml index 5b04b59..2a11893 100644 --- a/scripts/playbooks/tasks/docker-deploy.yml +++ b/scripts/playbooks/tasks/docker-deploy.yml @@ -1,16 +1,7 @@ --- -- name: Install Python 3 +- name: Install pip package: - name: python34 -- name: Install pip3 (python3-pip) - package: - name: python3-pip - register: pip3_result - ignore_errors: yes -- name: Install pip3 (python34-pip) - package: - name: python34-pip - when: pip3_result|failed + name: python-pip - name: Install docker package: name: docker --=20 2.17.2 _______________________________________________ Patchew-devel mailing list Patchew-devel@redhat.com https://www.redhat.com/mailman/listinfo/patchew-devel From nobody Thu Apr 25 01:32:41 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=patchew-devel-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=patchew-devel-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1540949961414561.5631484701179; Tue, 30 Oct 2018 18:39:21 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 42B0585550; Wed, 31 Oct 2018 01:39:20 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 326C686FD5; Wed, 31 Oct 2018 01:39:20 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 270F31808841; Wed, 31 Oct 2018 01:39:20 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w9V1T5uY012170 for ; Tue, 30 Oct 2018 21:29:05 -0400 Received: by smtp.corp.redhat.com (Postfix) id 8465861B92; Wed, 31 Oct 2018 01:29:05 +0000 (UTC) Received: from magic.redhat.com (ovpn-12-37.pek2.redhat.com [10.72.12.37]) by smtp.corp.redhat.com (Postfix) with ESMTP id D36B761B7B; Wed, 31 Oct 2018 01:29:03 +0000 (UTC) From: Fam Zheng To: patchew-devel@redhat.com Date: Wed, 31 Oct 2018 09:28:52 +0800 Message-Id: <20181031012856.30125-3-famz@redhat.com> In-Reply-To: <20181031012856.30125-1-famz@redhat.com> References: <20181031012856.30125-1-famz@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: patchew-devel@redhat.com Subject: [Patchew-devel] [PATCH 2/6] deploy: Deploy a Dockerized postgres DB X-BeenThere: patchew-devel@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Patchew development and discussion list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: patchew-devel-bounces@redhat.com Errors-To: patchew-devel-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Wed, 31 Oct 2018 01:39:20 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Signed-off-by: Fam Zheng --- scripts/deploy | 10 +++++++++- scripts/dockerfiles/db.docker | 6 ++++++ scripts/playbooks/deploy-db.yml | 18 ++++++++++++++++++ 3 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 scripts/dockerfiles/db.docker create mode 100644 scripts/playbooks/deploy-db.yml diff --git a/scripts/deploy b/scripts/deploy index 0fc61ff..1953e9b 100755 --- a/scripts/deploy +++ b/scripts/deploy @@ -17,11 +17,13 @@ def parse_args(): parser =3D argparse.ArgumentParser() parser.add_argument("--server", "-s", dest=3D"web_server", help=3D"Web server host address") + parser.add_argument("--db", "-d", dest=3D"db_server", + help=3D"Database host address") parser.add_argument("--tester", "-t", nargs=3D"*", dest=3D"testers", help=3D"Tester host address") parser.add_argument("--importer", "-i", nargs=3D"?", help=3D"Importer host address") - parser.add_argument("--debug", "-d", action=3D"store_true", + parser.add_argument("--debug", "-D", action=3D"store_true", help=3D"Enable debug output") return parser.parse_known_args() =20 @@ -31,12 +33,16 @@ def generate_inventory_file(args): [servers] %s =20 +[db] +%s + [importers] %s =20 [testers] %s""" \ % (args.web_server or "", + args.db_server or "", args.importer or "", "\n".join(args.testers or []))) f.flush() @@ -50,6 +56,8 @@ def main(): playbooks =3D [] if args.web_server: playbooks.append("deploy-servers.yml") + if args.db_server: + playbooks.append("deploy-db.yml") if args.testers: playbooks.append("deploy-testers.yml") if args.importer: diff --git a/scripts/dockerfiles/db.docker b/scripts/dockerfiles/db.docker new file mode 100644 index 0000000..80a34e5 --- /dev/null +++ b/scripts/dockerfiles/db.docker @@ -0,0 +1,6 @@ +FROM postgres:11 +EXPOSE 5432 +ENV POSTGRES_USER patchew +ENV POSTGRES_PASSWORD patchew +ENV POSTGRES_DB patchew +ENV PGDATA /data/patchew/db diff --git a/scripts/playbooks/deploy-db.yml b/scripts/playbooks/deploy-db.= yml new file mode 100644 index 0000000..2b69995 --- /dev/null +++ b/scripts/playbooks/deploy-db.yml @@ -0,0 +1,18 @@ +- hosts: db + vars_prompt: + - name: instance_name + prompt: "Instance name of the patchew postgres db" + default: patchew-server-db + private: no + vars: + base_dir: "/data/{{ instance_name }}" + src_dir: "{{ base_dir }}/src" + data_dir: "{{ base_dir }}/data" + tasks: + - name: Create data dir + file: + path: "{{ data_dir }}" + state: directory + - import_tasks: tasks/docker-deploy.yml + vars: + instance_role: db --=20 2.17.2 _______________________________________________ Patchew-devel mailing list Patchew-devel@redhat.com https://www.redhat.com/mailman/listinfo/patchew-devel From nobody Thu Apr 25 01:32:41 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=patchew-devel-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=patchew-devel-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 15409498744234.640540125915322; Tue, 30 Oct 2018 18:37:54 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0E9D9308402C; Wed, 31 Oct 2018 01:37:53 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 01D681001F53; Wed, 31 Oct 2018 01:37:53 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id E815F1808841; Wed, 31 Oct 2018 01:37:52 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w9V1T7nX012180 for ; Tue, 30 Oct 2018 21:29:07 -0400 Received: by smtp.corp.redhat.com (Postfix) id A14855D9D6; Wed, 31 Oct 2018 01:29:07 +0000 (UTC) Received: from magic.redhat.com (ovpn-12-37.pek2.redhat.com [10.72.12.37]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2305C61B98; Wed, 31 Oct 2018 01:29:05 +0000 (UTC) From: Fam Zheng To: patchew-devel@redhat.com Date: Wed, 31 Oct 2018 09:28:53 +0800 Message-Id: <20181031012856.30125-4-famz@redhat.com> In-Reply-To: <20181031012856.30125-1-famz@redhat.com> References: <20181031012856.30125-1-famz@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: patchew-devel@redhat.com Subject: [Patchew-devel] [PATCH 3/6] settings: Drop dead code for openshift X-BeenThere: patchew-devel@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Patchew development and discussion list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: patchew-devel-bounces@redhat.com Errors-To: patchew-devel-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Wed, 31 Oct 2018 01:37:53 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Signed-off-by: Fam Zheng --- patchew/settings.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/patchew/settings.py b/patchew/settings.py index 65a3b29..16f60a5 100644 --- a/patchew/settings.py +++ b/patchew/settings.py @@ -101,9 +101,6 @@ def env_detect(): if "PATCHEW_DATA_DIR" in os.environ: # Docker deployment return False, os.environ.get("PATCHEW_DATA_DIR") - elif "OPENSHIFT_DATA_DIR" in os.environ: - # OpenShift deployment - return False, os.environ.get("OPENSHIFT_DATA_DIR") elif "VIRTUAL_ENV" in os.environ or os.environ.get("PATCHEW_DEBUG", Fa= lse): # Development setup return True, os.path.join(os.environ.get("VIRTUAL_ENV", --=20 2.17.2 _______________________________________________ Patchew-devel mailing list Patchew-devel@redhat.com https://www.redhat.com/mailman/listinfo/patchew-devel From nobody Thu Apr 25 01:32:41 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=patchew-devel-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=patchew-devel-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1540949961502667.1893997724029; Tue, 30 Oct 2018 18:39:21 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 57B88356D3; Wed, 31 Oct 2018 01:39:20 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 440D219495; Wed, 31 Oct 2018 01:39:20 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 3620D180B5B7; Wed, 31 Oct 2018 01:39:20 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w9V1TAsH012191 for ; Tue, 30 Oct 2018 21:29:10 -0400 Received: by smtp.corp.redhat.com (Postfix) id 0745D6590E; Wed, 31 Oct 2018 01:29:10 +0000 (UTC) Received: from magic.redhat.com (ovpn-12-37.pek2.redhat.com [10.72.12.37]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8FD225D9D6; Wed, 31 Oct 2018 01:29:08 +0000 (UTC) From: Fam Zheng To: patchew-devel@redhat.com Date: Wed, 31 Oct 2018 09:28:54 +0800 Message-Id: <20181031012856.30125-5-famz@redhat.com> In-Reply-To: <20181031012856.30125-1-famz@redhat.com> References: <20181031012856.30125-1-famz@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: patchew-devel@redhat.com Subject: [Patchew-devel] [PATCH 4/6] Make default group creation a migration X-BeenThere: patchew-devel@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Patchew development and discussion list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: patchew-devel-bounces@redhat.com Errors-To: patchew-devel-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Wed, 31 Oct 2018 01:39:20 +0000 (UTC) Content-Type: text/plain; charset="utf-8" The ready hook isn't the right point to use DB. Signed-off-by: Fam Zheng --- api/apps.py | 14 ++---------- .../0037_populate_default_groups.py | 22 +++++++++++++++++++ 2 files changed, 24 insertions(+), 12 deletions(-) create mode 100644 api/migrations/0037_populate_default_groups.py diff --git a/api/apps.py b/api/apps.py index c7fc162..1210091 100644 --- a/api/apps.py +++ b/api/apps.py @@ -13,19 +13,9 @@ from django.apps import AppConfig import mod =20 -_default_groups =3D ['maintainers', 'testers', 'importers'] - -def create_default_groups(): - from django.contrib.auth.models import Group - for grp in _default_groups: - Group.objects.get_or_create(name=3Dgrp) - class ApiConfig(AppConfig): name =3D 'api' verbose_name =3D "Patchew Core" def ready(self): - try: - mod.load_modules() - create_default_groups() - except Exception as e: - print("Error while loading modules:", e) + from mod import load_modules + load_modules() diff --git a/api/migrations/0037_populate_default_groups.py b/api/migration= s/0037_populate_default_groups.py new file mode 100644 index 0000000..c0befa6 --- /dev/null +++ b/api/migrations/0037_populate_default_groups.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations +from django.db.models import Count +import json + + +def populate_default_groups(apps, schema_editor): + from django.contrib.auth.models import Group + for grp in ['maintainers', 'testers', 'importers']: + Group.objects.get_or_create(name=3Dgrp) + +class Migration(migrations.Migration): + + dependencies =3D [ + ('api', '0036_populate_message_tags'), + ] + + operations =3D [ + migrations.RunPython(populate_default_groups), + ] --=20 2.17.2 _______________________________________________ Patchew-devel mailing list Patchew-devel@redhat.com https://www.redhat.com/mailman/listinfo/patchew-devel From nobody Thu Apr 25 01:32:41 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=patchew-devel-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=patchew-devel-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1540949961589131.4849067941136; Tue, 30 Oct 2018 18:39:21 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6BD7B83F3D; Wed, 31 Oct 2018 01:39:20 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 57AB260C7A; Wed, 31 Oct 2018 01:39:20 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 4970218005B3; Wed, 31 Oct 2018 01:39:20 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w9V1TOv3012202 for ; Tue, 30 Oct 2018 21:29:24 -0400 Received: by smtp.corp.redhat.com (Postfix) id D11136591C; Wed, 31 Oct 2018 01:29:24 +0000 (UTC) Received: from magic.redhat.com (ovpn-12-37.pek2.redhat.com [10.72.12.37]) by smtp.corp.redhat.com (Postfix) with ESMTP id DACF25D9D6; Wed, 31 Oct 2018 01:29:10 +0000 (UTC) From: Fam Zheng To: patchew-devel@redhat.com Date: Wed, 31 Oct 2018 09:28:55 +0800 Message-Id: <20181031012856.30125-6-famz@redhat.com> In-Reply-To: <20181031012856.30125-1-famz@redhat.com> References: <20181031012856.30125-1-famz@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: patchew-devel@redhat.com Subject: [Patchew-devel] [PATCH 5/6] mod: Lazy access module config from DB X-BeenThere: patchew-devel@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Patchew development and discussion list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: patchew-devel-bounces@redhat.com Errors-To: patchew-devel-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Wed, 31 Oct 2018 01:39:20 +0000 (UTC) Content-Type: text/plain; charset="utf-8" _init_module is called in app.ready where DB access is bad: the tables may not be ready yet. Also we always wanted the module config to be effective so there isn't much point in loading it here. Signed-off-by: Fam Zheng --- mod.py | 30 ++++++++++-------------------- 1 file changed, 10 insertions(+), 20 deletions(-) diff --git a/mod.py b/mod.py index 90880ea..4446171 100644 --- a/mod.py +++ b/mod.py @@ -29,6 +29,13 @@ class PatchewModule(object): _module_init_config(self.__class__) return PC.objects.get(name=3Dself.name) =20 + def enabled(self): + try: + m =3D self.get_model() + return m.enabled + except: + return True + def get_config_raw(self): return self.get_model().config or "" =20 @@ -164,18 +171,6 @@ def _module_init_config(cls): pc.save() return pc =20 -def _init_module(cls): - name =3D cls.name - if name in _loaded_modules: - raise Exception("The module named '%s' is already loaded" % name) - pc =3D _module_init_config(cls) - if not pc.enabled: - return None - i =3D cls() - # TODO: let i.enabled follows pc.enabled - i.enabled =3D pc.enabled - return i - def load_modules(): _module_path =3D settings.MODULE_DIR sys.path.append(_module_path) @@ -187,17 +182,12 @@ def load_modules(): except: traceback.print_exc() for cls in PatchewModule.__subclasses__(): - try: - i =3D _init_module(cls) - if not i: - continue - _loaded_modules[cls.name] =3D i + if cls.name not in _loaded_modules: + _loaded_modules[cls.name] =3D cls() print("Loaded module:", cls.name) - except Exception as e: - print("Cannot load module '%s':" % cls, e) =20 def dispatch_module_hook(hook_name, **params): - for i in [x for x in list(_loaded_modules.values()) if x.enabled]: + for i in [x for x in list(_loaded_modules.values()) if x.enabled()]: if hasattr(i, hook_name): try: getattr(i, hook_name)(**params) --=20 2.17.2 _______________________________________________ Patchew-devel mailing list Patchew-devel@redhat.com https://www.redhat.com/mailman/listinfo/patchew-devel From nobody Thu Apr 25 01:32:41 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=patchew-devel-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=patchew-devel-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 15409499616441010.8068668860946; Tue, 30 Oct 2018 18:39:21 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 763A1C05680E; Wed, 31 Oct 2018 01:39:20 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 669E560851; Wed, 31 Oct 2018 01:39:20 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 599C24CA94; Wed, 31 Oct 2018 01:39:20 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w9V1TZiZ012213 for ; Tue, 30 Oct 2018 21:29:35 -0400 Received: by smtp.corp.redhat.com (Postfix) id EC5DB67C6F; Wed, 31 Oct 2018 01:29:34 +0000 (UTC) Received: from magic.redhat.com (ovpn-12-37.pek2.redhat.com [10.72.12.37]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7F85565921; Wed, 31 Oct 2018 01:29:25 +0000 (UTC) From: Fam Zheng To: patchew-devel@redhat.com Date: Wed, 31 Oct 2018 09:28:56 +0800 Message-Id: <20181031012856.30125-7-famz@redhat.com> In-Reply-To: <20181031012856.30125-1-famz@redhat.com> References: <20181031012856.30125-1-famz@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: patchew-devel@redhat.com Subject: [Patchew-devel] [PATCH 6/6] server: Use postgres in Docker deploy X-BeenThere: patchew-devel@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Patchew development and discussion list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: patchew-devel-bounces@redhat.com Errors-To: patchew-devel-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Wed, 31 Oct 2018 01:39:20 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Signed-off-by: Fam Zheng --- patchew/settings.py | 39 +++++++++++-------- requirements.txt | 1 + scripts/playbooks/deploy-servers.yml | 1 + scripts/playbooks/templates/docker.service.j2 | 1 + 4 files changed, 26 insertions(+), 16 deletions(-) diff --git a/patchew/settings.py b/patchew/settings.py index 16f60a5..b11da54 100644 --- a/patchew/settings.py +++ b/patchew/settings.py @@ -98,21 +98,35 @@ WSGI_APPLICATION =3D 'patchew.wsgi.application' # https://docs.djangoproject.com/en/1.9/ref/settings/#databases =20 def env_detect(): - if "PATCHEW_DATA_DIR" in os.environ: + if "PATCHEW_DB_PORT_5432_TCP_ADDR" in os.environ: # Docker deployment - return False, os.environ.get("PATCHEW_DATA_DIR") + return (False, os.environ.get("PATCHEW_DATA_DIR"), + { + 'default': { + 'ENGINE': 'django.db.backends.postgresql', + 'NAME': 'patchew', + 'USER': 'patchew', + 'PASSWORD': 'patchew', + 'HOST': os.environ.get('PATCHEW_DB_PORT_5432_TCP_ADDR'= ), + 'PORT': '5432', + } + }) elif "VIRTUAL_ENV" in os.environ or os.environ.get("PATCHEW_DEBUG", Fa= lse): # Development setup - return True, os.path.join(os.environ.get("VIRTUAL_ENV", - "/var/tmp/patchew-dev"), - "data") - elif os.environ.get("PATCHEW_TEST"): - # Test environment - return True, os.environ.get("PATCHEW_TEST_DATA_DIR") + data_dir =3D os.path.join(os.environ.get("VIRTUAL_ENV", + "/var/tmp/patchew-dev"), + "data") + return (True, data_dir, + { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': os.path.join(data_dir, "patchew-db.sqlite3"), + } + }) else: raise Exception("Unknown running environment") =20 -DEBUG, DATA_DIR =3D env_detect() +DEBUG, DATA_DIR, DATABASES =3D env_detect() =20 # In production environments, we run in a container, behind nginx, which s= hould # filter the allowed host names. So be a little flexible here @@ -135,13 +149,6 @@ MEDIA_URL =3D "/media/" if not os.path.isdir(MEDIA_ROOT): os.makedirs(MEDIA_ROOT) =20 -DATABASES =3D { - 'default': { - 'ENGINE': 'django.db.backends.sqlite3', - 'NAME': os.path.join(DATA_DIR, "patchew-db.sqlite3"), - } -} - # If the PATCHEW_ADMIN_EMAIL env var is set, let Django send error reporti= ng to # the address. admin_email =3D os.environ.get("PATCHEW_ADMIN_EMAIL") diff --git a/requirements.txt b/requirements.txt index aa89c4c..59c9480 100644 --- a/requirements.txt +++ b/requirements.txt @@ -8,3 +8,4 @@ jsonfield2 >=3D 3.0, < 4.0 drf-nested-routers coreapi-cli pyyaml +psycopg2 diff --git a/scripts/playbooks/deploy-servers.yml b/scripts/playbooks/deplo= y-servers.yml index 933d065..7c6281e 100644 --- a/scripts/playbooks/deploy-servers.yml +++ b/scripts/playbooks/deploy-servers.yml @@ -16,6 +16,7 @@ base_dir: "/data/{{ instance_name }}" src_dir: "{{ base_dir }}/src" data_dir: "{{ base_dir }}/data" + docker_run_args: "--link {{ instance_name }}-db" tasks: - name: Create data dir file: diff --git a/scripts/playbooks/templates/docker.service.j2 b/scripts/playbo= oks/templates/docker.service.j2 index afd5df1..85dd9d2 100644 --- a/scripts/playbooks/templates/docker.service.j2 +++ b/scripts/playbooks/templates/docker.service.j2 @@ -10,6 +10,7 @@ ExecStartPre=3D-/usr/bin/docker stop {{ instance_name }} = ; -/usr/bin/docker rm {{ ExecStart=3D/usr/bin/docker run --privileged --name {{ instance_name }} \ -v {{ data_dir }}:/data/patchew:rw \ -e PATCHEW_DATA_DIR=3D/data/patchew \ + {{ docker_run_args | default() }} \ patchew:{{ instance_name }} ExecStop=3D/usr/bin/docker stop -t 10 {{ instance_name }} RestartSec=3D60 --=20 2.17.2 _______________________________________________ Patchew-devel mailing list Patchew-devel@redhat.com https://www.redhat.com/mailman/listinfo/patchew-devel