From nobody Mon Sep 16 19:05:01 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