From patchwork Thu Dec 9 03:38:36 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: You-Sheng Yang X-Patchwork-Id: 1565575 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=QTp76RlH; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=2404:9400:2:0:216:3eff:fee1:b9f1; helo=lists.ozlabs.org; envelope-from=patchwork-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2404:9400:2:0:216:3eff:fee1:b9f1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4J8fsD23vwz9t2p for ; Thu, 9 Dec 2021 14:38:56 +1100 (AEDT) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4J8fsC6cpkz3069 for ; Thu, 9 Dec 2021 14:38:55 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=QTp76RlH; dkim-atps=neutral X-Original-To: patchwork@lists.ozlabs.org Delivered-To: patchwork@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::62e; helo=mail-pl1-x62e.google.com; envelope-from=vicamo@gmail.com; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=QTp76RlH; dkim-atps=neutral Received: from mail-pl1-x62e.google.com (mail-pl1-x62e.google.com [IPv6:2607:f8b0:4864:20::62e]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4J8fs805FCz2y7P for ; Thu, 9 Dec 2021 14:38:51 +1100 (AEDT) Received: by mail-pl1-x62e.google.com with SMTP id b13so2937488plg.2 for ; Wed, 08 Dec 2021 19:38:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=xP7+/HQNbAuv+xR5N0wqhgks77QNOyfR3wUKUZr25+g=; b=QTp76RlH7WTct/+r44vIMC7pzf3zRsOX7l/G5jtXI6V3VxvWvhVUwBG/kdojNJ5MyV myXQWtHOOP/K/ZdiV6dngCmZfNqK0QVA4qWY3x1p5f+CLc/5JVVzBGVR3GRsO9I+UnhK pnJRZEIIQIULvxpgBdWlQtFOGya/yQjH0oWOB+4kbbAnnqvwrSzV+Wqg1w5T1apB3LMT Ak6ssTWlttm92KNHxN0bNjUOkz4Mr6PBQY2FNsaNliefc/Ss6vZJ4MxPsZbKpyA9slBK kSrua9HEnMQpVtZHCPqyghpnM3GhegxtJ2hufLHMLI/R/JX3AJKVNdBxkHOPumy/mXgo bQ4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=xP7+/HQNbAuv+xR5N0wqhgks77QNOyfR3wUKUZr25+g=; b=TVWru34iio+WlpJa9OsuWlZL8qantOgIotHrR7rCrd0PMOy9ndOgjNkkMRrhrwfnJq RZAFk9Fjqi3EuSxnH4PImV8b8uYz/1YDhAwwVeNg9g3UgnKSikPxdNYUQru4vVy6enzG gKPHnFwIhyKqJPXUFbfHzniiIK7+HAvneH1QHxMKZS0N0Q+oNPmyqabiL1E/R5eEhvli 2FWe8aqsLQWsk1TmMfKDjN/+ChdFXBFr4Bt/tkfK2rWS3dMM9MB28czZBJUuIYIWnjQs Ll2LxdQ8SfXXc7v4jW1jM9oO7roH6NCsRyLDSP9BfIMIPZiE1gE2eCbBihDPRpH6i3Et pwWg== X-Gm-Message-State: AOAM532SZ37uFvxzBbDN1n0WVmZFc72kE0dwEcLRkJfsE5KI/arzWlfX fNOP6yLZyFd+KFYk5JiA46w9e8bFUn4= X-Google-Smtp-Source: ABdhPJwHtgevKloS6wiNePso3CR4yrb7u6EQI+vJZXTSojkmGeLyFtSp7biddAqwuADa/steJcXg3A== X-Received: by 2002:a17:90a:3e09:: with SMTP id j9mr12270317pjc.24.1639021128265; Wed, 08 Dec 2021 19:38:48 -0800 (PST) Received: from localhost (220-142-201-86.dynamic-ip.hinet.net. [220.142.201.86]) by smtp.gmail.com with ESMTPSA id np1sm7736729pjb.22.2021.12.08.19.38.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Dec 2021 19:38:47 -0800 (PST) From: You-Sheng Yang To: patchwork@lists.ozlabs.org Subject: [PATCH v4 1/8] settings: unify database connection variables Date: Thu, 9 Dec 2021 11:38:36 +0800 Message-Id: <20211209033843.205325-2-vicamo@gmail.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20211209033843.205325-1-vicamo@gmail.com> References: <20211209033843.205325-1-vicamo@gmail.com> MIME-Version: 1.0 X-BeenThere: patchwork@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Patchwork development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: patchwork-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Patchwork" This changeset replaces all PW_TEST_DB_* with corresponding DATABASE_* variables and fixes inconsistent DATABASE_PASS/DATABASE_PASSWORD usages. Signed-off-by: You-Sheng Yang --- .github/workflows/ci.yaml | 8 ++++---- docker-compose-pg.yml | 12 +++++------ docker-compose.yml | 10 +++++++--- docs/deployment/installation.rst | 4 ++-- docs/development/installation.rst | 13 ++++++------ lib/uwsgi/patchwork.ini | 2 +- patchwork/settings/dev.py | 16 +++++++-------- ...connection-variables-ac716f59ee7b8b48.yaml | 7 +++++++ tools/docker/entrypoint.sh | 20 +++++++++---------- tox.ini | 4 ++-- 10 files changed, 53 insertions(+), 43 deletions(-) create mode 100644 releasenotes/notes/settings-unify-database-connection-variables-ac716f59ee7b8b48.yaml diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index f4a33b3..59bc752 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -76,10 +76,10 @@ jobs: - name: Run unit tests (via tox) run: tox env: - PW_TEST_DB_TYPE: "${{ matrix.db }}" - PW_TEST_DB_USER: "patchwork" - PW_TEST_DB_PASS: "patchwork" - PW_TEST_DB_HOST: "127.0.0.1" + DATABASE_TYPE: "${{ matrix.db }}" + DATABASE_USER: "patchwork" + DATABASE_PASSWORD: "patchwork" + DATABASE_HOST: "127.0.0.1" docs: name: Build docs runs-on: ubuntu-latest diff --git a/docker-compose-pg.yml b/docker-compose-pg.yml index 44c49fb..8056d62 100644 --- a/docker-compose-pg.yml +++ b/docker-compose-pg.yml @@ -24,9 +24,9 @@ services: environment: - UID - GID - - PW_TEST_DB_HOST=db - - PW_TEST_DB_PORT=5432 - - PW_TEST_DB_TYPE=postgres - - PW_TEST_DB_USER=postgres - - PW_TEST_DB_PASS=password - - PGPASSWORD=password + - DATABASE_TYPE=postgres + - DATABASE_HOST=db + - DATABASE_PORT=5432 + - DATABASE_NAME=patchwork + - DATABASE_USER=patchwork + - DATABASE_PASSWORD=password diff --git a/docker-compose.yml b/docker-compose.yml index 1d49c51..103f19f 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -5,7 +5,7 @@ services: volumes: - ./tools/docker/db/data:/var/lib/mysql environment: - - MYSQL_ROOT_PASSWORD=password + - MYSQL_ROOT_PASSWORD=root - MYSQL_USER=patchwork - MYSQL_PASSWORD=password @@ -26,5 +26,9 @@ services: environment: - UID - GID - - PW_TEST_DB_HOST=db - - PW_TEST_DB_PORT=3306 + # skip DATABASE_TYPE explicitly as mysql should be the default type. + - DATABASE_HOST=db + - DATABASE_PORT=3306 + - DATABASE_USER=patchwork + - DATABASE_PASSWORD=password + - MYSQL_ROOT_PASSWORD=root diff --git a/docs/deployment/installation.rst b/docs/deployment/installation.rst index 1abf187..14ad746 100644 --- a/docs/deployment/installation.rst +++ b/docs/deployment/installation.rst @@ -64,7 +64,7 @@ used to ease deployment: Username that the Patchwork web application will access the database with. We will use ``www-data``, for reasons described later in this guide. -``DATABASE_PASS=`` +``DATABASE_PASSWORD=`` Password that the Patchwork web application will access the database with. As we're going to use *peer* authentication (more on this later), this will be unset. @@ -323,7 +323,7 @@ Once done, we should be able to check that all requirements are met using the $ sudo -u www-data \ --preserve-env=DATABASE_NAME \ --preserve-env=DATABASE_USER \ - --preserve-env=DATABASE_PASS \ + --preserve-env=DATABASE_PASSWORD \ --preserve-env=DATABASE_HOST \ --preserve-env=DATABASE_PORT \ --preserve-env=STATIC_ROOT \ diff --git a/docs/development/installation.rst b/docs/development/installation.rst index d16177c..3507f43 100644 --- a/docs/development/installation.rst +++ b/docs/development/installation.rst @@ -316,7 +316,7 @@ if necessary: The ``patchwork`` username and ``password`` password are the defaults expected by the provided ``dev`` settings files. If using something - different, export the ``PW_TEST_DB_USER`` and ``PW_TEST_DB_PASS`` variables + different, export the ``DATABASE_USER`` and ``DATABASE_PASSWORD`` variables described in the :ref:`Environment Variables ` section below. Alternatively, you can create your own settings file with these variables hardcoded and change the value of ``DJANGO_SETTINGS_MODULE`` as described @@ -470,17 +470,16 @@ __ https://django-dbbackup.readthedocs.io/en/stable/ Environment Variables --------------------- -The following environment variables are available to configure settings when -using the provided ``dev`` settings file. +The following environment variables are available to configure settings. -``PW_TEST_DB_NAME=patchwork`` +``DATABASE_NAME=patchwork`` Name of the database -``PW_TEST_DB_USER=patchwork`` +``DATABASE_USER=patchwork`` Username to access the database with -``PW_TEST_DB_PASS=password`` +``DATABASE_PASSWORD=password`` Password to access the database with< -``PW_TEST_DB_TYPE=mysql`` +``DATABASE_TYPE=mysql`` Type of database to use. Options: ``mysql``, ``postgres`` diff --git a/lib/uwsgi/patchwork.ini b/lib/uwsgi/patchwork.ini index 95a0613..dbff508 100644 --- a/lib/uwsgi/patchwork.ini +++ b/lib/uwsgi/patchwork.ini @@ -10,7 +10,7 @@ url = / # env = DJANGO_SECRET_KEY= # env = DATABASE_NAME= # env = DATABASE_USER= -# env = DATABASE_PASS= +# env = DATABASE_PASSWORD= # env = DATABASE_HOST= # env = DATABASE_PORT= # env = STATIC_ROOT= diff --git a/patchwork/settings/dev.py b/patchwork/settings/dev.py index 2b7fc95..4487494 100644 --- a/patchwork/settings/dev.py +++ b/patchwork/settings/dev.py @@ -39,21 +39,21 @@ DEBUG = True DATABASES = { 'default': { 'ENGINE': 'django.db.backends.mysql', - 'HOST': os.getenv('PW_TEST_DB_HOST', 'localhost'), - 'PORT': os.getenv('PW_TEST_DB_PORT', ''), - 'USER': os.getenv('PW_TEST_DB_USER', 'patchwork'), - 'PASSWORD': os.getenv('PW_TEST_DB_PASS', 'password'), - 'NAME': os.getenv('PW_TEST_DB_NAME', 'patchwork'), + 'HOST': os.getenv('DATABASE_HOST', 'localhost'), + 'PORT': os.getenv('DATABASE_PORT', ''), + 'USER': os.getenv('DATABASE_USER', 'patchwork'), + 'PASSWORD': os.getenv('DATABASE_PASSWORD', 'password'), + 'NAME': os.getenv('DATABASE_NAME', 'patchwork'), 'TEST': { 'CHARSET': 'utf8', }, }, } -if os.getenv('PW_TEST_DB_TYPE', None) == 'postgres': +if os.getenv('DATABASE_TYPE', None) == 'postgres': DATABASES['default']['ENGINE'] = 'django.db.backends.postgresql_psycopg2' - DATABASES['default']['HOST'] = os.getenv('PW_TEST_DB_HOST', '') -elif os.getenv('PW_TEST_DB_TYPE', None) == 'sqlite': + DATABASES['default']['HOST'] = os.getenv('DATABASE_HOST', '') +elif os.getenv('DATABASE_TYPE', None) == 'sqlite': DATABASES['default']['ENGINE'] = 'django.db.backends.sqlite3' DATABASES['default']['NAME'] = '/dev/shm/patchwork.test.db.sqlite3' del DATABASES['default']['HOST'] diff --git a/releasenotes/notes/settings-unify-database-connection-variables-ac716f59ee7b8b48.yaml b/releasenotes/notes/settings-unify-database-connection-variables-ac716f59ee7b8b48.yaml new file mode 100644 index 0000000..37dc2a3 --- /dev/null +++ b/releasenotes/notes/settings-unify-database-connection-variables-ac716f59ee7b8b48.yaml @@ -0,0 +1,7 @@ +--- +critical: + - | + Database configuration variables PW_TEST_DB_* are renamed to their + corresponding DATABASE_* names to sync development & production environments + setup. Some mistaken references to DATABASE_PASS are also corrected with + DATABASE_PASSWORD to follow the convention. diff --git a/tools/docker/entrypoint.sh b/tools/docker/entrypoint.sh index 5450a53..7ae9803 100755 --- a/tools/docker/entrypoint.sh +++ b/tools/docker/entrypoint.sh @@ -1,28 +1,28 @@ #!/bin/bash set -euo pipefail -PW_TEST_DB_TYPE=${PW_TEST_DB_TYPE:-mysql} +DATABASE_TYPE=${DATABASE_TYPE:-mysql} # functions test_db_connection() { - if [ ${PW_TEST_DB_TYPE} = "postgres" ]; then - echo ';' | psql -h $PW_TEST_DB_HOST -U postgres 2> /dev/null > /dev/null + if [ ${DATABASE_TYPE} = "postgres" ]; then + echo ';' | psql -h $DATABASE_HOST -U postgres 2> /dev/null > /dev/null else - mysqladmin -h $PW_TEST_DB_HOST -u patchwork --password=password ping > /dev/null 2> /dev/null + mysqladmin -h $DATABASE_HOST -u patchwork --password=password ping > /dev/null 2> /dev/null fi } test_database() { - if [ ${PW_TEST_DB_TYPE} = "postgres" ]; then - echo ';' | psql -h $PW_TEST_DB_HOST -U postgres patchwork 2> /dev/null + if [ ${DATABASE_TYPE} = "postgres" ]; then + echo ';' | psql -h $DATABASE_HOST -U postgres patchwork 2> /dev/null else - echo ';' | mysql -h $PW_TEST_DB_HOST -u patchwork -ppassword patchwork 2> /dev/null + echo ';' | mysql -h $DATABASE_HOST -u patchwork -ppassword patchwork 2> /dev/null fi } reset_data_mysql() { - mysql -uroot -ppassword -h $PW_TEST_DB_HOST << EOF + mysql -uroot -ppassword -h $DATABASE_HOST << EOF DROP DATABASE IF EXISTS patchwork; CREATE DATABASE patchwork CHARACTER SET utf8; GRANT ALL ON patchwork.* TO 'patchwork' IDENTIFIED BY 'password'; @@ -32,14 +32,14 @@ EOF } reset_data_postgres() { - psql -h $PW_TEST_DB_HOST -U postgres <