From 00604b6f50f201ec1d03b38ac51760b0ad5207b7 Mon Sep 17 00:00:00 2001 From: Abdullah Adeel Date: Fri, 21 Jan 2022 16:43:26 +0500 Subject: [PATCH 01/17] =?UTF-8?q?=F0=9F=94=83=20upate=20`ci.yml`=20to=20in?= =?UTF-8?q?clude=20mysql=20docket=20tests?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/ci.yml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index fb88f3334..c184193d2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -43,10 +43,14 @@ jobs: fail-fast: false matrix: script: - - name: Basic + - name: Basic - Postgres args: "database_engine=postgresql database_version=postgresql@14.1" - - name: Extended + - name: Extended - Postgres args: "use_celery=y use_drf=y js_task_runner=Gulp database_engine=postgresql database_version=postgresql@14.1" + - name: Basic - MySQL + args: "database_engine=mysql database_version=mysql@8.0.28" + - name: Extended - MySQL + args: "use_celery=y use_drf=y js_task_runner=Gulp database_engine=mysql database_version=mysql@8.0.28" name: "${{ matrix.script.name }} Docker" runs-on: ubuntu-latest From 1e741e9bbfe73aaaa953f9305c4b3fa179267d04 Mon Sep 17 00:00:00 2001 From: Abdullah Adeel Date: Fri, 21 Jan 2022 17:02:13 +0500 Subject: [PATCH 02/17] =?UTF-8?q?=F0=9F=94=A7=20updated=20`post=5Fgen=5Fho?= =?UTF-8?q?ok`=20and=20.envs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hooks/post_gen_project.py | 27 ++++++++++++++++++- .../.envs/.local/.postgres | 4 +-- .../.envs/.production/.postgres | 4 +-- 3 files changed, 30 insertions(+), 5 deletions(-) diff --git a/hooks/post_gen_project.py b/hooks/post_gen_project.py index adb0f894d..70ff207a7 100644 --- a/hooks/post_gen_project.py +++ b/hooks/post_gen_project.py @@ -257,7 +257,7 @@ def set_database_user(file_path: str, value: str, database_engine: str): def set_database_password(file_path: str, database_engine: str, value: str = None): database_password = set_flag( file_path, - f"!!!SET {database_engine.upper()}_USER!!!", + f"!!!SET {database_engine.upper()}_PASSWORD!!!", value=value, length=64, using_digits=True, @@ -266,6 +266,18 @@ def set_database_password(file_path: str, database_engine: str, value: str = Non return database_password +def set_mysql_root_password(file_path: str, database_engine: str, value: str = None): + database_root_password = set_flag( + file_path, + f"!!!SET {database_engine.upper()}_ROOT_PASSWORD!!!", + value=value, + length=74, + using_digits=True, + using_ascii_letters=True, + ) + return database_root_password + + def get_database_env_path(env: str, database_engine: str): local_postgres_envs_path = os.path.join(".envs", ".local", ".postgres") production_postgres_envs_path = os.path.join(".envs", ".production", ".postgres") @@ -345,6 +357,19 @@ def set_flags_in_envs(database_user, celery_flower_user, debug=False): value=DEBUG_VALUE if debug else None, ) + if selected_database == "mysql": + set_mysql_root_password( + get_database_env_path(env="local", database_engine=selected_database), + database_engine=selected_database, + value=DEBUG_VALUE if debug else None, + ) + + set_mysql_root_password( + get_database_env_path(env="prod", database_engine=selected_database), + database_engine=selected_database, + value=DEBUG_VALUE if debug else None, + ) + set_celery_flower_user(local_django_envs_path, value=celery_flower_user) set_celery_flower_password( local_django_envs_path, value=DEBUG_VALUE if debug else None diff --git a/{{cookiecutter.project_slug}}/.envs/.local/.postgres b/{{cookiecutter.project_slug}}/.envs/.local/.postgres index f190db8e6..7a11cb3ad 100644 --- a/{{cookiecutter.project_slug}}/.envs/.local/.postgres +++ b/{{cookiecutter.project_slug}}/.envs/.local/.postgres @@ -3,5 +3,5 @@ POSTGRES_HOST=postgres POSTGRES_PORT=5432 POSTGRES_DB={{ cookiecutter.project_slug }} -POSTGRES_USER=!!!SET POSTGRES_USER!!! -POSTGRES_PASSWORD=!!!SET POSTGRES_PASSWORD!!! +POSTGRES_USER=!!!SET POSTGRESQL_USER!!! +POSTGRES_PASSWORD=!!!SET POSTGRESQL_PASSWORD!!! diff --git a/{{cookiecutter.project_slug}}/.envs/.production/.postgres b/{{cookiecutter.project_slug}}/.envs/.production/.postgres index f190db8e6..7a11cb3ad 100644 --- a/{{cookiecutter.project_slug}}/.envs/.production/.postgres +++ b/{{cookiecutter.project_slug}}/.envs/.production/.postgres @@ -3,5 +3,5 @@ POSTGRES_HOST=postgres POSTGRES_PORT=5432 POSTGRES_DB={{ cookiecutter.project_slug }} -POSTGRES_USER=!!!SET POSTGRES_USER!!! -POSTGRES_PASSWORD=!!!SET POSTGRES_PASSWORD!!! +POSTGRES_USER=!!!SET POSTGRESQL_USER!!! +POSTGRES_PASSWORD=!!!SET POSTGRESQL_PASSWORD!!! From f8cbebb7519049a981a01c4013b21435a938f2d8 Mon Sep 17 00:00:00 2001 From: Abdullah Adeel Date: Fri, 21 Jan 2022 17:49:04 +0500 Subject: [PATCH 03/17] =?UTF-8?q?=F0=9F=94=A7=20update=20end=20of=20line?= =?UTF-8?q?=20`.env/local/.mysql`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- {{cookiecutter.project_slug}}/.envs/.local/.mysql | 1 - 1 file changed, 1 deletion(-) diff --git a/{{cookiecutter.project_slug}}/.envs/.local/.mysql b/{{cookiecutter.project_slug}}/.envs/.local/.mysql index 765b69183..221c8e264 100644 --- a/{{cookiecutter.project_slug}}/.envs/.local/.mysql +++ b/{{cookiecutter.project_slug}}/.envs/.local/.mysql @@ -6,4 +6,3 @@ MYSQL_DATABASE={{ cookiecutter.project_slug }} MYSQL_USER=!!!SET MYSQL_USER!!! MYSQL_PASSWORD=!!!SET MYSQL_PASSWORD!!! MYSQL_ROOT_PASSWORD=!!!SET MYSQL_ROOT_PASSWORD!!! - From 28538f1713d4f130c41aa3e7e8b770540fe0aff6 Mon Sep 17 00:00:00 2001 From: Abdullah Adeel Date: Fri, 21 Jan 2022 18:07:05 +0500 Subject: [PATCH 04/17] =?UTF-8?q?=F0=9F=94=A7=20updated=20`ci.yml`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/ci.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c184193d2..a9821f13a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -44,13 +44,13 @@ jobs: matrix: script: - name: Basic - Postgres - args: "database_engine=postgresql database_version=postgresql@14.1" + args: "database_engine=postgresql database_version='postgresql@14.1'" - name: Extended - Postgres - args: "use_celery=y use_drf=y js_task_runner=Gulp database_engine=postgresql database_version=postgresql@14.1" + args: "use_celery=y use_drf=y js_task_runner=Gulp database_engine=postgresql database_version='postgresql@14.1'" - name: Basic - MySQL - args: "database_engine=mysql database_version=mysql@8.0.28" + args: "database_engine=mysql database_version='mysql@8.0.28'" - name: Extended - MySQL - args: "use_celery=y use_drf=y js_task_runner=Gulp database_engine=mysql database_version=mysql@8.0.28" + args: "use_celery=y use_drf=y js_task_runner=Gulp database_engine=mysql database_version='mysql@8.0.28'" name: "${{ matrix.script.name }} Docker" runs-on: ubuntu-latest From 97508460b94d923684109fc37a166f4f8daf8811 Mon Sep 17 00:00:00 2001 From: Abdullah Adeel Date: Sat, 22 Jan 2022 06:39:25 +0500 Subject: [PATCH 05/17] =?UTF-8?q?=F0=9F=A7=AA=20testing=20workflow?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- {{cookiecutter.project_slug}}/compose/local/django/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/{{cookiecutter.project_slug}}/compose/local/django/Dockerfile b/{{cookiecutter.project_slug}}/compose/local/django/Dockerfile index 190a9f518..7651c5e77 100644 --- a/{{cookiecutter.project_slug}}/compose/local/django/Dockerfile +++ b/{{cookiecutter.project_slug}}/compose/local/django/Dockerfile @@ -15,9 +15,9 @@ RUN apt-get update && apt-get install --no-install-recommends -y \ {%- if cookiecutter.database_engine == "postgresql" %} # psycopg2 dependencies libpq-dev + default-libmysqlclient-dev {%- elif cookiecutter.database_engine == "mysql" %} # mysql dependency - default-libmysqlclient-dev {%- endif %} # Requirements are installed here to ensure they will be cached. From a1b591883f86d4cdacf26a44fa57537b8bc75dc7 Mon Sep 17 00:00:00 2001 From: Abdullah Adeel Date: Sat, 22 Jan 2022 06:42:17 +0500 Subject: [PATCH 06/17] =?UTF-8?q?=F0=9F=A7=AA=20testing=20workflow=20-=20u?= =?UTF-8?q?pdate=20docketfile?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- {{cookiecutter.project_slug}}/compose/local/django/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/{{cookiecutter.project_slug}}/compose/local/django/Dockerfile b/{{cookiecutter.project_slug}}/compose/local/django/Dockerfile index 7651c5e77..53839b1d5 100644 --- a/{{cookiecutter.project_slug}}/compose/local/django/Dockerfile +++ b/{{cookiecutter.project_slug}}/compose/local/django/Dockerfile @@ -14,7 +14,7 @@ RUN apt-get update && apt-get install --no-install-recommends -y \ build-essential \ {%- if cookiecutter.database_engine == "postgresql" %} # psycopg2 dependencies - libpq-dev + libpq-dev \ default-libmysqlclient-dev {%- elif cookiecutter.database_engine == "mysql" %} # mysql dependency From 0bf041492d5a29e691e5eb4e1cc5eff1595a1bde Mon Sep 17 00:00:00 2001 From: Abdullah Adeel Date: Sat, 22 Jan 2022 06:43:18 +0500 Subject: [PATCH 07/17] =?UTF-8?q?=F0=9F=A7=AA=20testing=20workflow=20-=20u?= =?UTF-8?q?pdate=20docketfile?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- {{cookiecutter.project_slug}}/compose/local/django/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/{{cookiecutter.project_slug}}/compose/local/django/Dockerfile b/{{cookiecutter.project_slug}}/compose/local/django/Dockerfile index 53839b1d5..c84cbf765 100644 --- a/{{cookiecutter.project_slug}}/compose/local/django/Dockerfile +++ b/{{cookiecutter.project_slug}}/compose/local/django/Dockerfile @@ -45,9 +45,9 @@ RUN apt-get update && apt-get install --no-install-recommends -y \ {%- if cookiecutter.database_engine == "postgresql" %} # psycopg2 dependencies libpq-dev \ + default-libmysqlclient-dev \ {%- elif cookiecutter.database_engine == "mysql" %} # mysql dependency - default-libmysqlclient-dev \ {%- endif %} # Translations dependencies gettext \ From 7942cdc7711360a1ae5323bccdd5b895069bf34b Mon Sep 17 00:00:00 2001 From: Abdullah Adeel Date: Sat, 22 Jan 2022 06:49:55 +0500 Subject: [PATCH 08/17] =?UTF-8?q?=F0=9F=A7=AA=20testing=20workflow=20-=20u?= =?UTF-8?q?pdate=20django=20dockerfile?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../compose/local/django/Dockerfile | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/{{cookiecutter.project_slug}}/compose/local/django/Dockerfile b/{{cookiecutter.project_slug}}/compose/local/django/Dockerfile index c84cbf765..a3286f2ac 100644 --- a/{{cookiecutter.project_slug}}/compose/local/django/Dockerfile +++ b/{{cookiecutter.project_slug}}/compose/local/django/Dockerfile @@ -14,10 +14,11 @@ RUN apt-get update && apt-get install --no-install-recommends -y \ build-essential \ {%- if cookiecutter.database_engine == "postgresql" %} # psycopg2 dependencies - libpq-dev \ - default-libmysqlclient-dev - {%- elif cookiecutter.database_engine == "mysql" %} + libpq-dev + {%- endif %} + {%- if cookiecutter.database_engine == "mysql" %} # mysql dependency + default-libmysqlclient-dev {%- endif %} # Requirements are installed here to ensure they will be cached. @@ -45,9 +46,10 @@ RUN apt-get update && apt-get install --no-install-recommends -y \ {%- if cookiecutter.database_engine == "postgresql" %} # psycopg2 dependencies libpq-dev \ - default-libmysqlclient-dev \ - {%- elif cookiecutter.database_engine == "mysql" %} + {%- endif %} + {%- if cookiecutter.database_engine == "mysql" %} # mysql dependency + default-libmysqlclient-dev \ {%- endif %} # Translations dependencies gettext \ From 338ca58dfff0468576b59e9552f996d48a59d08e Mon Sep 17 00:00:00 2001 From: Abdullah Adeel Date: Sat, 22 Jan 2022 07:01:48 +0500 Subject: [PATCH 09/17] =?UTF-8?q?=E2=9D=8C=20added=20test=20workflow?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/cimysql.yml | 44 +++++++++++++++++++ .../compose/local/django/Dockerfile | 6 +-- 2 files changed, 46 insertions(+), 4 deletions(-) create mode 100644 .github/workflows/cimysql.yml diff --git a/.github/workflows/cimysql.yml b/.github/workflows/cimysql.yml new file mode 100644 index 000000000..b0abab2ee --- /dev/null +++ b/.github/workflows/cimysql.yml @@ -0,0 +1,44 @@ +name: CIMYSQL + +on: + push: + pull_request: + +jobs: + lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-python@v2 + with: + python-version: "3.9" + cache: pip + - name: Run pre-commit + uses: pre-commit/action@v2.0.3 + + docker: + strategy: + fail-fast: false + matrix: + script: + - name: Basic - MySQL + args: "database_engine=mysql database_version='mysql@8.0.28'" + - name: Extended - MySQL + args: "use_celery=y use_drf=y js_task_runner=Gulp database_engine=mysql database_version='mysql@8.0.28'" + + name: "${{ matrix.script.name }} Docker" + runs-on: ubuntu-latest + env: + DOCKER_BUILDKIT: 1 + COMPOSE_DOCKER_CLI_BUILD: 1 + + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-python@v2 + with: + python-version: "3.9" + cache: pip + - name: Install dependencies + run: pip install -r requirements.txt + - name: Docker ${{ matrix.script.name }} + run: sh tests/test_docker.sh ${{ matrix.script.args }} diff --git a/{{cookiecutter.project_slug}}/compose/local/django/Dockerfile b/{{cookiecutter.project_slug}}/compose/local/django/Dockerfile index a3286f2ac..190a9f518 100644 --- a/{{cookiecutter.project_slug}}/compose/local/django/Dockerfile +++ b/{{cookiecutter.project_slug}}/compose/local/django/Dockerfile @@ -15,8 +15,7 @@ RUN apt-get update && apt-get install --no-install-recommends -y \ {%- if cookiecutter.database_engine == "postgresql" %} # psycopg2 dependencies libpq-dev - {%- endif %} - {%- if cookiecutter.database_engine == "mysql" %} + {%- elif cookiecutter.database_engine == "mysql" %} # mysql dependency default-libmysqlclient-dev {%- endif %} @@ -46,8 +45,7 @@ RUN apt-get update && apt-get install --no-install-recommends -y \ {%- if cookiecutter.database_engine == "postgresql" %} # psycopg2 dependencies libpq-dev \ - {%- endif %} - {%- if cookiecutter.database_engine == "mysql" %} + {%- elif cookiecutter.database_engine == "mysql" %} # mysql dependency default-libmysqlclient-dev \ {%- endif %} From a0565e077f1c3d14774118989e27241270c055eb Mon Sep 17 00:00:00 2001 From: Abdullah Adeel Date: Sat, 22 Jan 2022 07:32:12 +0500 Subject: [PATCH 10/17] =?UTF-8?q?=E2=9D=8C=20removed=20`cimysql.yml`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/cimysql.yml | 44 ----------------------------------- 1 file changed, 44 deletions(-) delete mode 100644 .github/workflows/cimysql.yml diff --git a/.github/workflows/cimysql.yml b/.github/workflows/cimysql.yml deleted file mode 100644 index b0abab2ee..000000000 --- a/.github/workflows/cimysql.yml +++ /dev/null @@ -1,44 +0,0 @@ -name: CIMYSQL - -on: - push: - pull_request: - -jobs: - lint: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - uses: actions/setup-python@v2 - with: - python-version: "3.9" - cache: pip - - name: Run pre-commit - uses: pre-commit/action@v2.0.3 - - docker: - strategy: - fail-fast: false - matrix: - script: - - name: Basic - MySQL - args: "database_engine=mysql database_version='mysql@8.0.28'" - - name: Extended - MySQL - args: "use_celery=y use_drf=y js_task_runner=Gulp database_engine=mysql database_version='mysql@8.0.28'" - - name: "${{ matrix.script.name }} Docker" - runs-on: ubuntu-latest - env: - DOCKER_BUILDKIT: 1 - COMPOSE_DOCKER_CLI_BUILD: 1 - - steps: - - uses: actions/checkout@v2 - - uses: actions/setup-python@v2 - with: - python-version: "3.9" - cache: pip - - name: Install dependencies - run: pip install -r requirements.txt - - name: Docker ${{ matrix.script.name }} - run: sh tests/test_docker.sh ${{ matrix.script.args }} From db0f24eb164077dccfd3d20b9104c780cf00a3c8 Mon Sep 17 00:00:00 2001 From: Abdullah Adeel Date: Sat, 22 Jan 2022 07:38:06 +0500 Subject: [PATCH 11/17] =?UTF-8?q?=F0=9F=90=9B=E2=9D=8C=20debug=20actions?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/test_docker.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/test_docker.sh b/tests/test_docker.sh index b3663bd2c..8b52da5ac 100755 --- a/tests/test_docker.sh +++ b/tests/test_docker.sh @@ -22,6 +22,7 @@ git add . pre-commit run --show-diff-on-failure -a # make sure all images build +cat ./compose/local/django/Dockerfile docker-compose -f local.yml build # run the project's type checks From c1be2304377894e7fa30f44bfe3127864dec090e Mon Sep 17 00:00:00 2001 From: Abdullah Adeel Date: Sat, 22 Jan 2022 07:41:46 +0500 Subject: [PATCH 12/17] =?UTF-8?q?=F0=9F=90=9B=E2=9D=8C=20debug=20actions?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/test_docker.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/test_docker.sh b/tests/test_docker.sh index 8b52da5ac..b3663bd2c 100755 --- a/tests/test_docker.sh +++ b/tests/test_docker.sh @@ -22,7 +22,6 @@ git add . pre-commit run --show-diff-on-failure -a # make sure all images build -cat ./compose/local/django/Dockerfile docker-compose -f local.yml build # run the project's type checks From 18817deb183f0cba92ff2f903750bd1f8fc8b282 Mon Sep 17 00:00:00 2001 From: Abdullah Adeel Date: Sat, 22 Jan 2022 07:50:28 +0500 Subject: [PATCH 13/17] =?UTF-8?q?=E2=9C=8B=20disable=20cache=20in=20`gh`?= =?UTF-8?q?=20workflow?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a9821f13a..5c7646349 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -67,6 +67,7 @@ jobs: - name: Install dependencies run: pip install -r requirements.txt - name: Docker ${{ matrix.script.name }} + key: ${{ runner.os }}-mycache-v2-${{ hashFiles(...) }} run: sh tests/test_docker.sh ${{ matrix.script.args }} bare: From c3165c78440f33d91daa359325906116703a4892 Mon Sep 17 00:00:00 2001 From: Abdullah Adeel Date: Sat, 22 Jan 2022 08:09:02 +0500 Subject: [PATCH 14/17] =?UTF-8?q?=F0=9F=90=9B=20fixed=20bug=20in=20`local/?= =?UTF-8?q?docs`=20dockerfile?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/ci.yml | 1 - .../compose/local/docs/Dockerfile | 12 +++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5c7646349..a9821f13a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -67,7 +67,6 @@ jobs: - name: Install dependencies run: pip install -r requirements.txt - name: Docker ${{ matrix.script.name }} - key: ${{ runner.os }}-mycache-v2-${{ hashFiles(...) }} run: sh tests/test_docker.sh ${{ matrix.script.args }} bare: diff --git a/{{cookiecutter.project_slug}}/compose/local/docs/Dockerfile b/{{cookiecutter.project_slug}}/compose/local/docs/Dockerfile index 6f1bb8b5e..4363f6aab 100644 --- a/{{cookiecutter.project_slug}}/compose/local/docs/Dockerfile +++ b/{{cookiecutter.project_slug}}/compose/local/docs/Dockerfile @@ -11,9 +11,14 @@ ENV PYTHONDONTWRITEBYTECODE 1 RUN apt-get update && apt-get install --no-install-recommends -y \ # dependencies for building Python packages - build-essential \ + {%- if cookiecutter.database_engine == "postgresql" %} # psycopg2 dependencies libpq-dev \ + {%- elif cookiecutter.database_engine == "mysql" %} + # mysql dependency + default-libmysqlclient-dev \ + {%- endif %} + libpq-dev \ # cleaning up unused files && apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false \ && rm -rf /var/lib/apt/lists/* @@ -37,8 +42,13 @@ ENV PYTHONDONTWRITEBYTECODE 1 RUN apt-get update && apt-get install --no-install-recommends -y \ # To run the Makefile make \ + {%- if cookiecutter.database_engine == "postgresql" %} # psycopg2 dependencies libpq-dev \ + {%- elif cookiecutter.database_engine == "mysql" %} + # mysql dependency + default-libmysqlclient-dev \ + {%- endif %} # Translations dependencies gettext \ # Uncomment below lines to enable Sphinx output to latex and pdf From 4a0028768d93b499e3c7b47599380c27a06b0489 Mon Sep 17 00:00:00 2001 From: Abdullah Adeel Date: Sat, 22 Jan 2022 08:36:35 +0500 Subject: [PATCH 15/17] =?UTF-8?q?=F0=9F=90=9B=20finxed=20bug=20in=20`docs`?= =?UTF-8?q?=20dockerfile?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- {{cookiecutter.project_slug}}/compose/local/docs/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/{{cookiecutter.project_slug}}/compose/local/docs/Dockerfile b/{{cookiecutter.project_slug}}/compose/local/docs/Dockerfile index 4363f6aab..c9c4bfc4d 100644 --- a/{{cookiecutter.project_slug}}/compose/local/docs/Dockerfile +++ b/{{cookiecutter.project_slug}}/compose/local/docs/Dockerfile @@ -11,6 +11,7 @@ ENV PYTHONDONTWRITEBYTECODE 1 RUN apt-get update && apt-get install --no-install-recommends -y \ # dependencies for building Python packages + build-essential \ {%- if cookiecutter.database_engine == "postgresql" %} # psycopg2 dependencies libpq-dev \ @@ -18,7 +19,6 @@ RUN apt-get update && apt-get install --no-install-recommends -y \ # mysql dependency default-libmysqlclient-dev \ {%- endif %} - libpq-dev \ # cleaning up unused files && apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false \ && rm -rf /var/lib/apt/lists/* From 455f06f90d8e16abf85bf6f6e0d791ab0e2775c4 Mon Sep 17 00:00:00 2001 From: Abdullah Adeel Date: Thu, 27 Jan 2022 00:45:23 +0500 Subject: [PATCH 16/17] =?UTF-8?q?=F0=9F=93=9D=20fixed=20db=20user=20check?= =?UTF-8?q?=20in=20=20`entrypoint`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../compose/production/django/entrypoint | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/{{cookiecutter.project_slug}}/compose/production/django/entrypoint b/{{cookiecutter.project_slug}}/compose/production/django/entrypoint index 109fcfdcc..52f535609 100644 --- a/{{cookiecutter.project_slug}}/compose/production/django/entrypoint +++ b/{{cookiecutter.project_slug}}/compose/production/django/entrypoint @@ -19,7 +19,7 @@ export DATABASE_URL="postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${POSTGRES {%- endif %} {%- if cookiecutter.database_engine == 'mysql' %} if [ -z "${MYSQL_USER}" ]; then - base_mysql_image_default_user='mysql' + base_mysql_image_default_user='root' export MYSQL_USER="${base_mysql_image_default_user}" fi export DATABASE_URL="mysql://${MYSQL_USER}:${MYSQL_PASSWORD}@${MYSQL_HOST}:${MYSQL_PORT}/${MYSQL_DATABASE}" From 8ddf8dbb9090f758430b412e3ea7fbf0b29a9906 Mon Sep 17 00:00:00 2001 From: Abdullah Adeel Date: Fri, 28 Jan 2022 14:52:07 +0500 Subject: [PATCH 17/17] =?UTF-8?q?=F0=9F=94=A7add=20`init`=20script=20for?= =?UTF-8?q?=20mysql=20container=20to=20run=20tests=20without=20db=20permis?= =?UTF-8?q?sion=20errors?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../compose/production/mysql/Dockerfile | 4 ++ .../compose/production/mysql/init.sh | 40 +++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 {{cookiecutter.project_slug}}/compose/production/mysql/init.sh diff --git a/{{cookiecutter.project_slug}}/compose/production/mysql/Dockerfile b/{{cookiecutter.project_slug}}/compose/production/mysql/Dockerfile index 71eabc804..65aa79ab9 100644 --- a/{{cookiecutter.project_slug}}/compose/production/mysql/Dockerfile +++ b/{{cookiecutter.project_slug}}/compose/production/mysql/Dockerfile @@ -4,3 +4,7 @@ COPY ./compose/production/mysql/maintenance /usr/local/bin/maintenance RUN chmod +x /usr/local/bin/maintenance/* RUN mv /usr/local/bin/maintenance/* /usr/local/bin \ && rmdir /usr/local/bin/maintenance + +COPY ./compose/production/mysql/init.sh /docker-entrypoint-initdb.d +RUN sed -i 's/\r$//g' /docker-entrypoint-initdb.d/init.sh +RUN chown -R mysql:mysql /docker-entrypoint-initdb.d/init.sh diff --git a/{{cookiecutter.project_slug}}/compose/production/mysql/init.sh b/{{cookiecutter.project_slug}}/compose/production/mysql/init.sh new file mode 100644 index 000000000..e6802e377 --- /dev/null +++ b/{{cookiecutter.project_slug}}/compose/production/mysql/init.sh @@ -0,0 +1,40 @@ +#!/bin/bash + + +initialize() { + { + mysql_note "Giving user ${MYSQL_USER} access to schema test_${MYSQL_DATABASE}" + docker_process_sql --database=mysql <<<"GRANT ALL ON \`test_${MYSQL_DATABASE//_/\\_}\`.* TO '$MYSQL_USER'@'%' ;" + + # exporting dummy MYSQL_ONETIME_PASSWORD to avoid -> MYSQL_ONETIME_PASSWORD: unbound variable + export DUMMY_ONETIME_PASSWORD="$MYSQL_ROOT_PASSWORD" + } || { + exit 1 + } +} + +docker_process_sql() { + if [ -n "$MYSQL_DATABASE" ]; then + set -- --database="$MYSQL_DATABASE" "$@" + fi + + mysql --protocol=socket -uroot --password="${MYSQL_ROOT_PASSWORD}" -hlocalhost --socket="${SOCKET}" --comments "$@" +} + +# logging functions +mysql_log() { + local type="$1"; shift + # accept argument string or stdin + local text="$*"; if [ "$#" -eq 0 ]; then text="$(cat)"; fi + local dt; dt="$(date --rfc-3339=seconds)" + printf '%s [%s] [Entrypoint]: %s\n' "$dt" "$type" "$text" +} + +mysql_note() { + mysql_log Note "$@" +} + +until (initialize); do + >&2 echo 'Waiting for MYSQL to execute init' + sleep 1 +done