From 6b8b790fffb867c7c1d7a559164e9e71db34cce9 Mon Sep 17 00:00:00 2001 From: TaskMasterErnest Date: Wed, 25 Oct 2023 13:36:42 +0000 Subject: [PATCH 01/27] added new host --- smart_learning/settings.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/smart_learning/settings.py b/smart_learning/settings.py index 10f63d2..dc92740 100644 --- a/smart_learning/settings.py +++ b/smart_learning/settings.py @@ -27,7 +27,7 @@ # SECURITY WARNING: keep the secret key used in production secret! SECRET_KEY = os.getenv('SECRET_KEY'), -ALLOWED_HOSTS = ['smart-learn.onrender.com', '127.0.0.1', 'localhost'] +ALLOWED_HOSTS = ['smart-learn.onrender.com', '127.0.0.1', 'localhost', '0.0.0.0'] CORS_ORIGIN_ALLOW_ALL = True # SECURITY WARNING: don't run with debug turned on in production! @@ -123,11 +123,20 @@ DATABASES = { # Development + # 'default': { + # "ENGINE": "django.db.backends.sqlite3", + # "NAME": BASE_DIR / "db.sqlite3", + # } + + # STAGING 'default': { - "ENGINE": "django.db.backends.sqlite3", - "NAME": BASE_DIR / "db.sqlite3", + 'ENGINE': 'django.db.backends.postgresql_psycopg2', + 'NAME': os.environ.get("POSTGRESQL_DATABASE"), + 'USER': os.environ.get("POSTGRESQL_USERNAME"), + 'PASSWORD': os.environ.get("POSTGRESQL_PASSWORD"), + 'HOST': os.environ.get("POSTGRESQL_HOST", 'localhost'), + 'PORT': os.environ.get("POSTGRESQL_PORT", 5432), } - #PRODUCTION # 'default': dj_database_url.config( From 1ff74718c10c3a1d571323df3ca101e3bd2a745e Mon Sep 17 00:00:00 2001 From: TaskMasterErnest Date: Wed, 25 Oct 2023 13:37:08 +0000 Subject: [PATCH 02/27] updated requirements list --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index cc6ac69..2735cbb 100644 --- a/requirements.txt +++ b/requirements.txt @@ -13,7 +13,7 @@ drf-yasg==1.21.5 gunicorn==20.1.0 phonenumbers==8.13.7 Pillow==9.4.0 -psycopg2==2.9.5 +# psycopg2==2.9.5 psycopg2-binary==2.9.7 python-dotenv==1.0.0 random-password-generator==2.2.0 From 1b6373f219eab8b974b63ff2fc9c1caa088b8f90 Mon Sep 17 00:00:00 2001 From: TaskMasterErnest Date: Wed, 25 Oct 2023 13:37:58 +0000 Subject: [PATCH 03/27] modified code to work with Dockerfile --- build.sh | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) mode change 100644 => 100755 build.sh diff --git a/build.sh b/build.sh old mode 100644 new mode 100755 index 55a62f3..839ed8d --- a/build.sh +++ b/build.sh @@ -2,12 +2,18 @@ set -o errexit # exit when there is an error error -pip install -r requirements.txt +# provide the superuser email, or a default +SUPERUSER_EMAIL=${DJANGO_SUPERUSER_EMAIL:-"hello@ernest.com"} + +cd /api/ + +# /opt/venv/bin/pip install -r requirements.txt # python manage.py collectstatic --no-input -python manage.py migrate +/opt/venv/bin/python manage.py migrate --noinput -if [[ $CREATE_SUPERUSER ]]; then - python manage.py createsuperuser --no-input -fi +/opt/venv/bin/python manage.py createsuperuser --email $SUPERUSER_EMAIL --noinput || true +# if [[ $CREATE_SUPERUSER ]]; then +# /opt/venv/bin/python manage.py createsuperuser --no-input +# fi \ No newline at end of file From 6cc28e8a80010d6866cb5903c4d5dc9f53b28875 Mon Sep 17 00:00:00 2001 From: TaskMasterErnest Date: Wed, 25 Oct 2023 13:38:19 +0000 Subject: [PATCH 04/27] added a dockerignore file --- .dockerignore | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 .dockerignore diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..db92b1e --- /dev/null +++ b/.dockerignore @@ -0,0 +1,9 @@ +*.log +*.pot +*.pyc +.env* +# __pycache__ +db.sqlite3 +venv +virtualenv +.idea \ No newline at end of file From 179f0f3266a3c820cd4a1d1f64b58c36c0a5a9db Mon Sep 17 00:00:00 2001 From: TaskMasterErnest Date: Wed, 25 Oct 2023 13:38:46 +0000 Subject: [PATCH 05/27] created a Dockerfile for dev environment --- Dockerfile.dev | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 Dockerfile.dev diff --git a/Dockerfile.dev b/Dockerfile.dev new file mode 100644 index 0000000..70a3a2b --- /dev/null +++ b/Dockerfile.dev @@ -0,0 +1,18 @@ +FROM python:3.11-slim + +WORKDIR /api + +COPY . . + +# create a virtual env for the python application +# this goes into the /opt dir +RUN python3 -m venv /opt/venv + +# install requirements and run the entrypoint script +RUN /opt/venv/bin/pip install -r requirements.txt && \ + chmod +x entrypoint.sh + +EXPOSE 8080 + +# Start the application +CMD ["/api/entrypoint.sh"] \ No newline at end of file From 2cba19a3d30b9a8c0de797e3cd4e6d013c077d83 Mon Sep 17 00:00:00 2001 From: TaskMasterErnest Date: Wed, 25 Oct 2023 13:39:10 +0000 Subject: [PATCH 06/27] created a Docker compose file --- docker-compose.yaml | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 docker-compose.yaml diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 0000000..5fa4c90 --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,28 @@ +version: "3.9" +services: + postgres_db: + image: docker.io/bitnami/postgresql:latest + env_file: + - .env + expose: + - 5432 + ports: + - "5432:5432" + volumes: + - postgres_data:/var/lib/postgresql/data/ + api: + build: + context: . + dockerfile: Dockerfile.dev + depends_on: + - postgres_db + image: smart_learn:v1 + env_file: + - .env + ports: + - "8080:8080" + command: sh -c "chmod +x /api/build.sh && sh /api/build.sh && /api/entrypoint.sh" + restart: always + +volumes: + postgres_data: \ No newline at end of file From b0dcd24e0d30c1a4665849cc1b93b5209edb375b Mon Sep 17 00:00:00 2001 From: TaskMasterErnest Date: Wed, 25 Oct 2023 13:39:45 +0000 Subject: [PATCH 07/27] created entrypoint script to handle running app --- entrypoint.sh | 5 +++++ 1 file changed, 5 insertions(+) create mode 100755 entrypoint.sh diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100755 index 0000000..35770b1 --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# creating a default application port to run on +APP_PORT=${PORT:-8080} +cd /api/ +/opt/venv/bin/gunicorn --worker-tmp-dir /dev/shm smart_learning.wsgi:application --bind "0.0.0.0:$APP_PORT" \ No newline at end of file From 8679b883af5708506c970c6bffa495c9cc5067de Mon Sep 17 00:00:00 2001 From: TaskMasterErnest Date: Wed, 25 Oct 2023 13:45:31 +0000 Subject: [PATCH 08/27] created workflows for GitHub Actions --- .github/workflows/test.yaml | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 .github/workflows/test.yaml diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml new file mode 100644 index 0000000..69a76c1 --- /dev/null +++ b/.github/workflows/test.yaml @@ -0,0 +1,30 @@ +name: Django CI - Test Phase + +on: + push: + branches: [ "feature/deployment" ] + pull_request: + branches: [ "main" ] + +jobs: + build: + + runs-on: ubuntu-latest + strategy: + max-parallel: 4 + matrix: + python-version: [3.9] + + steps: + - uses: actions/checkout@v3 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v3 + with: + python-version: ${{ matrix.python-version }} + - name: Install Dependencies + run: | + python -m pip install --upgrade pip + pip install -r requirements.txt + - name: Run Tests + run: | + python manage.py test \ No newline at end of file From 79badfd1d480ecd690467ed85dc617b39792db77 Mon Sep 17 00:00:00 2001 From: TaskMasterErnest Date: Wed, 25 Oct 2023 13:55:35 +0000 Subject: [PATCH 09/27] added database for integration with code --- .github/workflows/test.yaml | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 69a76c1..f0ec793 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -8,13 +8,32 @@ on: jobs: build: - runs-on: ubuntu-latest + + env: + DJANGO_SUPERUSER_EMAIL: hello@taskmaster.com + SECRET_KEY: "someSampleKeydyNBYa83J+2RpTstv36ZSqX48D2EKBfz+OplD22GPNXoo/POvAwZI6BwUPKB54FSwiszzOfquIIFiJPfmniCA" + POSTGRESQL_DATABASE: dockerdc + POSTGRESQL_PASSWORD: mysecret1@Passwd + POSTGRESQL_USERNAME: myuser + POSTGRESQL_HOST: postgres_db + POSTGRESQL_PORT: 5432 + strategy: max-parallel: 4 matrix: python-version: [3.9] + services: + postgres_db: + image: docker.io/bitnami/postgresql:latest + env: + POSTGRESQL_DATABASE: ${{ env.POSTGRESQL_DATABASE }} + POSTGRESQL_PASSWORD: ${{ env.POSTGRESQL_PASSWORD }} + POSTGRESQL_USERNAME: ${{ env.POSTGRESQL_USERNAME }} + ports: + - 5432:5432 + steps: - uses: actions/checkout@v3 - name: Set up Python ${{ matrix.python-version }} From d501ce78ff2eeccd7a559edac68f8db105359102 Mon Sep 17 00:00:00 2001 From: TaskMasterErnest Date: Wed, 25 Oct 2023 13:59:44 +0000 Subject: [PATCH 10/27] updated service in test actions file --- .github/workflows/test.yaml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index f0ec793..831194d 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -31,8 +31,15 @@ jobs: POSTGRESQL_DATABASE: ${{ env.POSTGRESQL_DATABASE }} POSTGRESQL_PASSWORD: ${{ env.POSTGRESQL_PASSWORD }} POSTGRESQL_USERNAME: ${{ env.POSTGRESQL_USERNAME }} + POSTGRESQL_HOST: ${{ env.POSTGRESQL_HOST }} + POSTGRESQL_PORT: 5432 ports: - 5432:5432 + options: >- + --health-cmd pg_isready + --health-interval 10s + --health-timeout 5s + --health-retries 5 steps: - uses: actions/checkout@v3 From b46f304401c4d10a723fa2efbf9dd53d98ed323d Mon Sep 17 00:00:00 2001 From: TaskMasterErnest Date: Wed, 25 Oct 2023 14:02:36 +0000 Subject: [PATCH 11/27] updated image for database conn --- .github/workflows/test.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 831194d..3b9ffc7 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -26,7 +26,7 @@ jobs: services: postgres_db: - image: docker.io/bitnami/postgresql:latest + image: bitnami/postgresql:latest env: POSTGRESQL_DATABASE: ${{ env.POSTGRESQL_DATABASE }} POSTGRESQL_PASSWORD: ${{ env.POSTGRESQL_PASSWORD }} From 50cd58af8fe8553761731a06503cab2a56074700 Mon Sep 17 00:00:00 2001 From: TaskMasterErnest Date: Wed, 25 Oct 2023 14:11:33 +0000 Subject: [PATCH 12/27] updated image for database conn - 2 --- .github/workflows/test.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 3b9ffc7..3567281 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -16,7 +16,7 @@ jobs: POSTGRESQL_DATABASE: dockerdc POSTGRESQL_PASSWORD: mysecret1@Passwd POSTGRESQL_USERNAME: myuser - POSTGRESQL_HOST: postgres_db + POSTGRESQL_HOST: 127.0.0.1 POSTGRESQL_PORT: 5432 strategy: From 27e14f463abb319f0410d7d2f81a482554e01a2e Mon Sep 17 00:00:00 2001 From: TaskMasterErnest Date: Wed, 25 Oct 2023 14:17:54 +0000 Subject: [PATCH 13/27] updated env files for database conn --- .github/workflows/test.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 3567281..933349b 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -15,8 +15,8 @@ jobs: SECRET_KEY: "someSampleKeydyNBYa83J+2RpTstv36ZSqX48D2EKBfz+OplD22GPNXoo/POvAwZI6BwUPKB54FSwiszzOfquIIFiJPfmniCA" POSTGRESQL_DATABASE: dockerdc POSTGRESQL_PASSWORD: mysecret1@Passwd - POSTGRESQL_USERNAME: myuser - POSTGRESQL_HOST: 127.0.0.1 + POSTGRESQL_USERNAME: postgres + POSTGRESQL_HOST: localhost POSTGRESQL_PORT: 5432 strategy: From 2c876d08dc545cbafb7cbb078480f99f133bce7a Mon Sep 17 00:00:00 2001 From: TaskMasterErnest Date: Wed, 25 Oct 2023 14:20:25 +0000 Subject: [PATCH 14/27] updated database image for test --- .github/workflows/test.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 933349b..5a52256 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -26,7 +26,7 @@ jobs: services: postgres_db: - image: bitnami/postgresql:latest + image: postgres:13 env: POSTGRESQL_DATABASE: ${{ env.POSTGRESQL_DATABASE }} POSTGRESQL_PASSWORD: ${{ env.POSTGRESQL_PASSWORD }} From 0331f77aa7f72c3d508da8fb620671b0939fffbe Mon Sep 17 00:00:00 2001 From: TaskMasterErnest Date: Wed, 25 Oct 2023 14:22:47 +0000 Subject: [PATCH 15/27] updated database env-vars --- .github/workflows/test.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 5a52256..0b33006 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -33,6 +33,7 @@ jobs: POSTGRESQL_USERNAME: ${{ env.POSTGRESQL_USERNAME }} POSTGRESQL_HOST: ${{ env.POSTGRESQL_HOST }} POSTGRESQL_PORT: 5432 + POSTGRES_HOST_AUTH_METHOD: trust ports: - 5432:5432 options: >- From 7400ea1343f0e91629e9a5e4d5089c6d453ad3e1 Mon Sep 17 00:00:00 2001 From: TaskMasterErnest Date: Wed, 25 Oct 2023 15:32:08 +0000 Subject: [PATCH 16/27] modified template for specifying env-vars --- .env.templates | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.env.templates b/.env.templates index e28b084..0b4b46d 100644 --- a/.env.templates +++ b/.env.templates @@ -2,11 +2,11 @@ SECRET_KEY = # Development environment -DB_USER = -DB_PASSWORD = -DB_HOST = -DB_PORT = -DB_NAME = +POSTGRES_USER = +POSTGRES_PASSWORD = +POSTGRES_HOST = +POSTGRES_PORT = +POSTGRES_DB = SIGNING_KEY = From e46bcc5e4eab7ad82d0168966f642f4010e4d6f9 Mon Sep 17 00:00:00 2001 From: TaskMasterErnest Date: Wed, 25 Oct 2023 15:33:36 +0000 Subject: [PATCH 17/27] modified global test env-vars --- .github/workflows/test.yaml | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 0b33006..c681201 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -11,13 +11,13 @@ jobs: runs-on: ubuntu-latest env: - DJANGO_SUPERUSER_EMAIL: hello@taskmaster.com + DJANGO_SUPERUSER_EMAIL: hello@smartlearn.com SECRET_KEY: "someSampleKeydyNBYa83J+2RpTstv36ZSqX48D2EKBfz+OplD22GPNXoo/POvAwZI6BwUPKB54FSwiszzOfquIIFiJPfmniCA" - POSTGRESQL_DATABASE: dockerdc - POSTGRESQL_PASSWORD: mysecret1@Passwd - POSTGRESQL_USERNAME: postgres - POSTGRESQL_HOST: localhost - POSTGRESQL_PORT: 5432 + POSTGRES_DB: dockerdc + POSTGRES_PASSWORD: mysecret1@Passwd + POSTGRES_USER: postgres + POSTGRES_HOST: localhost + POSTGRES_PORT: 5432 strategy: max-parallel: 4 @@ -28,12 +28,12 @@ jobs: postgres_db: image: postgres:13 env: - POSTGRESQL_DATABASE: ${{ env.POSTGRESQL_DATABASE }} - POSTGRESQL_PASSWORD: ${{ env.POSTGRESQL_PASSWORD }} - POSTGRESQL_USERNAME: ${{ env.POSTGRESQL_USERNAME }} - POSTGRESQL_HOST: ${{ env.POSTGRESQL_HOST }} - POSTGRESQL_PORT: 5432 - POSTGRES_HOST_AUTH_METHOD: trust + POSTGRES_DB: ${{ env.POSTGRES_DB }} + POSTGRES_PASSWORD: ${{ env.POSTGRES_PASSWORD }} + POSTGRES_USER: ${{ env.POSTGRES_USER }} + POSTGRES_HOST: ${{ env.POSTGRES_HOST }} + POSTGRES_PORT: 5432 + # POSTGRES_HOST_AUTH_METHOD: trust ports: - 5432:5432 options: >- From 320f4db9e4d939cf95140365633913d12fac8854 Mon Sep 17 00:00:00 2001 From: TaskMasterErnest Date: Wed, 25 Oct 2023 15:36:49 +0000 Subject: [PATCH 18/27] restored to original state --- build.sh | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/build.sh b/build.sh index 839ed8d..d5d3739 100755 --- a/build.sh +++ b/build.sh @@ -2,18 +2,11 @@ set -o errexit # exit when there is an error error -# provide the superuser email, or a default -SUPERUSER_EMAIL=${DJANGO_SUPERUSER_EMAIL:-"hello@ernest.com"} - -cd /api/ - -# /opt/venv/bin/pip install -r requirements.txt +pip install -r requirements.txt # python manage.py collectstatic --no-input -/opt/venv/bin/python manage.py migrate --noinput - -/opt/venv/bin/python manage.py createsuperuser --email $SUPERUSER_EMAIL --noinput || true +python manage.py migrate -# if [[ $CREATE_SUPERUSER ]]; then -# /opt/venv/bin/python manage.py createsuperuser --no-input -# fi \ No newline at end of file +if [[ $CREATE_SUPERUSER ]]; then + python manage.py createsuperuser --no-input +fi From 4443a9808fa5fc3c2329016e84d434f32eb22e76 Mon Sep 17 00:00:00 2001 From: TaskMasterErnest Date: Wed, 25 Oct 2023 15:38:33 +0000 Subject: [PATCH 19/27] added script to run migration --- migrate.sh | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 migrate.sh diff --git a/migrate.sh b/migrate.sh new file mode 100644 index 0000000..9f5fa55 --- /dev/null +++ b/migrate.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env bash + +set -o errexit # exit when there is an error error + +# provide the superuser email, or a default +SUPERUSER_EMAIL=${DJANGO_SUPERUSER_EMAIL:-"hello@smartlearn.com"} + +# enter working directory +cd /api/ + +# use the virtual env to run the python commands +/opt/venv/bin/python manage.py migrate --noinput + +/opt/venv/bin/python manage.py createsuperuser --email $SUPERUSER_EMAIL --noinput || true From 6a8e7a8be75b7fe748c6f8a5fd545c52cdf44104 Mon Sep 17 00:00:00 2001 From: TaskMasterErnest Date: Wed, 25 Oct 2023 15:39:18 +0000 Subject: [PATCH 20/27] modified docker compose file --- docker-compose.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docker-compose.yaml b/docker-compose.yaml index 5fa4c90..ad1161f 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -1,7 +1,7 @@ version: "3.9" services: postgres_db: - image: docker.io/bitnami/postgresql:latest + image: postgres:16 env_file: - .env expose: @@ -21,7 +21,7 @@ services: - .env ports: - "8080:8080" - command: sh -c "chmod +x /api/build.sh && sh /api/build.sh && /api/entrypoint.sh" + command: sh -c "chmod +x /api/migrate.sh && sh /api/migrate.sh && /api/entrypoint.sh" restart: always volumes: From 6984ee1baef0d409e461ea96f1b1963e9635cb53 Mon Sep 17 00:00:00 2001 From: TaskMasterErnest Date: Wed, 25 Oct 2023 15:40:04 +0000 Subject: [PATCH 21/27] modified settings to work with new configuration --- smart_learning/settings.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/smart_learning/settings.py b/smart_learning/settings.py index dc92740..4198c5e 100644 --- a/smart_learning/settings.py +++ b/smart_learning/settings.py @@ -128,14 +128,14 @@ # "NAME": BASE_DIR / "db.sqlite3", # } - # STAGING + # DEVELOPMENT 'default': { 'ENGINE': 'django.db.backends.postgresql_psycopg2', - 'NAME': os.environ.get("POSTGRESQL_DATABASE"), - 'USER': os.environ.get("POSTGRESQL_USERNAME"), - 'PASSWORD': os.environ.get("POSTGRESQL_PASSWORD"), - 'HOST': os.environ.get("POSTGRESQL_HOST", 'localhost'), - 'PORT': os.environ.get("POSTGRESQL_PORT", 5432), + 'NAME': os.environ.get("POSTGRES_DB"), + 'USER': os.environ.get("POSTGRES_USER"), + 'PASSWORD': os.environ.get("POSTGRES_PASSWORD"), + 'HOST': os.environ.get("POSTGRES_HOST", 'localhost'), + 'PORT': os.environ.get("POSTGRES_PORT", 5432), } #PRODUCTION From c09c3d7da0d94732744a4cf7fe407e8fe8edcc91 Mon Sep 17 00:00:00 2001 From: TaskMasterErnest Date: Wed, 25 Oct 2023 15:52:25 +0000 Subject: [PATCH 22/27] added redis to compose file --- docker-compose.yaml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/docker-compose.yaml b/docker-compose.yaml index ad1161f..56a5066 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -23,6 +23,14 @@ services: - "8080:8080" command: sh -c "chmod +x /api/migrate.sh && sh /api/migrate.sh && /api/entrypoint.sh" restart: always + redis: + image: redis:alpine + env_file: + - .env + expose: + - 6379 + ports: + - "6379:6379" volumes: postgres_data: \ No newline at end of file From 35caded13814771067929baccdf0b403410d06bd Mon Sep 17 00:00:00 2001 From: TaskMasterErnest Date: Wed, 25 Oct 2023 16:03:34 +0000 Subject: [PATCH 23/27] added sample env-var configuration --- .env.templates | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/.env.templates b/.env.templates index 0b4b46d..4e9b336 100644 --- a/.env.templates +++ b/.env.templates @@ -8,7 +8,25 @@ POSTGRES_HOST = POSTGRES_PORT = POSTGRES_DB = +REDIS_HOST = +REDIS_PORT = + SIGNING_KEY = -STRIPE_SECRET = \ No newline at end of file +STRIPE_SECRET = + +########### SAMPLE ENV-VAR SETTING ########### +# DJANGO_SUPERUSER_USERNAME=admin +# DJANGO_SUPERUSER_PASSWORD=superpasswd +# DJANGO_SUPERUSER_EMAIL=hello@smartlearn.com +# SECRET_KEY="dyNBYa83J+2RpTstv36ZSqX--SOME_SAMPLE_KEY--FSwiszzOfquIIFiJPfmniCA==" + +# POSTGRES_DB=postgresDB +# POSTGRES_PASSWORD=mysecret1@Passwd +# POSTGRES_USER=myuser +# POSTGRES_HOST=postgres_db +# POSTGRES_PORT=5432 + +# REDIS_HOST=localhost +# REDIS_PORT=6379 \ No newline at end of file From 7c4838abd2224a0d0d3958cd0ffd866213485e55 Mon Sep 17 00:00:00 2001 From: TaskMasterErnest Date: Wed, 25 Oct 2023 16:04:07 +0000 Subject: [PATCH 24/27] updated README, docker with compose instructions --- README.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 319342d..91e0595 100644 --- a/README.md +++ b/README.md @@ -27,11 +27,17 @@ To run the API locally, follow these steps: 3. Activate the virtual environment: `source venv/bin/activate` 4. Install dependencies: `pip install -r requirements.txt` 5. Go to .settings.DATABASES section, deactivate #PRODUCTION mode and activate #Development mode, add PostgreSQL configuration to connect to your database to be the default database. -6. Change `.env.templates` to .env and setup you environment variables. +6. Change `.env.templates` to .env and setup your environment variables. 7. Set up the database: `python manage.py migrate` 8. Create a superuser account: `python manage.py createsuperuser` 9. Start the development server: `python manage.py runserver` +To run the API locally, with Docker and Docker Compose, follow these steps: + +1. Go to .settings.DATABASES section, deactivate #PRODUCTION mode and activate #Development mode, add PostgreSQL configuration to connect to your database to be the default database. +2. Change `.env.templates` to .env and setup your environment variables. +3. Start application and database integration: `sudo docker compose -f docker-compose.yaml up --build` +4. Stop and clear integration: `sudo docker compose -f docker-compose.yaml down` Running Tests --------------- From a2427de6abdebaddc8a96854b262993d556b6199 Mon Sep 17 00:00:00 2001 From: TaskMasterErnest Date: Wed, 25 Oct 2023 16:05:38 +0000 Subject: [PATCH 25/27] updated Action test file to run on push to main --- .github/workflows/test.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index c681201..f281898 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -2,7 +2,7 @@ name: Django CI - Test Phase on: push: - branches: [ "feature/deployment" ] + branches: [ "main" ] pull_request: branches: [ "main" ] From d7448b9353d9647155068f6b572397ed462553fc Mon Sep 17 00:00:00 2001 From: TaskMasterErnest Date: Wed, 25 Oct 2023 17:36:21 +0000 Subject: [PATCH 26/27] modified config to remove secret keys --- .env.templates | 2 +- .github/workflows/test.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.env.templates b/.env.templates index 4e9b336..6953dce 100644 --- a/.env.templates +++ b/.env.templates @@ -20,7 +20,7 @@ STRIPE_SECRET = # DJANGO_SUPERUSER_USERNAME=admin # DJANGO_SUPERUSER_PASSWORD=superpasswd # DJANGO_SUPERUSER_EMAIL=hello@smartlearn.com -# SECRET_KEY="dyNBYa83J+2RpTstv36ZSqX--SOME_SAMPLE_KEY--FSwiszzOfquIIFiJPfmniCA==" +# SECRET_KEY="SOME_SAMPLE_KEY" # POSTGRES_DB=postgresDB # POSTGRES_PASSWORD=mysecret1@Passwd diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index f281898..8065034 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -12,7 +12,7 @@ jobs: env: DJANGO_SUPERUSER_EMAIL: hello@smartlearn.com - SECRET_KEY: "someSampleKeydyNBYa83J+2RpTstv36ZSqX48D2EKBfz+OplD22GPNXoo/POvAwZI6BwUPKB54FSwiszzOfquIIFiJPfmniCA" + SECRET_KEY: "SOME_SAMPLE_KEY" POSTGRES_DB: dockerdc POSTGRES_PASSWORD: mysecret1@Passwd POSTGRES_USER: postgres From 89a6f958f4b16db5fd7f2c8f6b96e0cf8205ca13 Mon Sep 17 00:00:00 2001 From: TaskMasterErnest Date: Wed, 25 Oct 2023 17:48:17 +0000 Subject: [PATCH 27/27] removed explicit secret keys --- .env.templates | 2 +- .github/workflows/test.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.env.templates b/.env.templates index 6953dce..41f5569 100644 --- a/.env.templates +++ b/.env.templates @@ -20,7 +20,7 @@ STRIPE_SECRET = # DJANGO_SUPERUSER_USERNAME=admin # DJANGO_SUPERUSER_PASSWORD=superpasswd # DJANGO_SUPERUSER_EMAIL=hello@smartlearn.com -# SECRET_KEY="SOME_SAMPLE_KEY" +# SECRET_KEY="" # POSTGRES_DB=postgresDB # POSTGRES_PASSWORD=mysecret1@Passwd diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 8065034..819de46 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -12,7 +12,7 @@ jobs: env: DJANGO_SUPERUSER_EMAIL: hello@smartlearn.com - SECRET_KEY: "SOME_SAMPLE_KEY" + SECRET_KEY: "" POSTGRES_DB: dockerdc POSTGRES_PASSWORD: mysecret1@Passwd POSTGRES_USER: postgres