From 17dc64d123139fb16c968604c123042cab8c13f2 Mon Sep 17 00:00:00 2001 From: Stephen G Tuggy Date: Sun, 30 Jun 2024 19:40:26 -0700 Subject: [PATCH 1/4] settings.py: Switch to SQLite3 for the database engine --- app/jobHistorySite/settings.py | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/app/jobHistorySite/settings.py b/app/jobHistorySite/settings.py index ede600c..5895e46 100644 --- a/app/jobHistorySite/settings.py +++ b/app/jobHistorySite/settings.py @@ -20,10 +20,6 @@ JOB_HISTORY_DEBUG=bool, JOB_HISTORY_ALLOWED_HOSTS=list, JOB_HISTORY_DB_NAME=str, - JOB_HISTORY_DB_USERNAME=str, - JOB_HISTORY_DB_PASSWORD=str, - JOB_HISTORY_DB_HOST=str, - JOB_HISTORY_DB_PORT=int, JOB_HISTORY_STATIC_URL=str, JOB_HISTORY_STATIC_ROOT=str ) @@ -97,12 +93,8 @@ DATABASES = { 'default': { - 'ENGINE': 'django.contrib.gis.db.backends.postgis', + 'ENGINE': 'django.db.backends.sqlite3', 'NAME': env('JOB_HISTORY_DB_NAME'), - 'USER': env('JOB_HISTORY_DB_USERNAME'), - 'PASSWORD': env('JOB_HISTORY_DB_PASSWORD'), - 'HOST': env('JOB_HISTORY_DB_HOST'), - 'PORT': env('JOB_HISTORY_DB_PORT'), } } From d25c0955bd0f24e37f75922994e5656ed6cdf129 Mon Sep 17 00:00:00 2001 From: Stephen G Tuggy Date: Mon, 1 Jul 2024 04:21:56 -0700 Subject: [PATCH 2/4] Change 9 more files to account for switching to SQLite3 --- .dockerignore | 1 + .env.example | 9 +-------- .gitignore | 1 + .idea/job-history.iml | 1 + app/Dockerfile | 5 ----- app/docker-entrypoint.sh | 13 ------------- app/requirements.txt | 1 - docker-compose.circleci.yml | 30 +++--------------------------- docker-compose.yml | 24 +++--------------------- 9 files changed, 10 insertions(+), 75 deletions(-) diff --git a/.dockerignore b/.dockerignore index 6ba2399..643c7c9 100644 --- a/.dockerignore +++ b/.dockerignore @@ -55,3 +55,4 @@ venv.bak/ .DS_Store .vscode/ **/public/ +data/ diff --git a/.env.example b/.env.example index 39d6032..d562c9a 100644 --- a/.env.example +++ b/.env.example @@ -1,13 +1,6 @@ JOB_HISTORY_ALLOWED_HOSTS=0.0.0.0 -JOB_HISTORY_DB_HOST=job_history_db -JOB_HISTORY_DB_NAME=job_history -JOB_HISTORY_DB_PASSWORD= -JOB_HISTORY_DB_PORT=5432 -JOB_HISTORY_DB_USERNAME=postgres +JOB_HISTORY_DB_NAME=/data/job_history.sqlite3 JOB_HISTORY_DEBUG=FALSE JOB_HISTORY_SECRET_KEY= JOB_HISTORY_STATIC_ROOT=/usr/src/app/static/ JOB_HISTORY_STATIC_URL=/app/static/ -POSTGRES_DB=job_history -POSTGRES_PASSWORD= -POSTGRES_USER=postgres diff --git a/.gitignore b/.gitignore index f44b510..bb57859 100644 --- a/.gitignore +++ b/.gitignore @@ -136,3 +136,4 @@ dmypy.json *.sql /local-env.sh /app/static/ +/data/ diff --git a/.idea/job-history.iml b/.idea/job-history.iml index 2eb104f..d53b6e5 100644 --- a/.idea/job-history.iml +++ b/.idea/job-history.iml @@ -17,6 +17,7 @@ + diff --git a/app/Dockerfile b/app/Dockerfile index e398b87..5a76a2a 100644 --- a/app/Dockerfile +++ b/app/Dockerfile @@ -7,10 +7,6 @@ WORKDIR /usr/src/app RUN apt-get -y update RUN apt-get -y upgrade -# Netcat is used by tcp-port-wait.sh -RUN apt-get -y install netcat-traditional postgresql-client libgdal-dev - -RUN python -m pip install --upgrade --upgrade-strategy eager pip RUN mkdir -p /usr/src/app COPY ./requirements.txt /usr/src/app @@ -19,7 +15,6 @@ RUN python -m pip install --upgrade -r ./requirements.txt COPY . /usr/src/app RUN chmod u+x docker-entrypoint.sh -RUN chmod u+x tcp-port-wait.sh RUN chmod u+x manage.py HEALTHCHECK CMD curl --fail http://localhost:8000 || exit 1 diff --git a/app/docker-entrypoint.sh b/app/docker-entrypoint.sh index 9fa9969..e606e25 100644 --- a/app/docker-entrypoint.sh +++ b/app/docker-entrypoint.sh @@ -3,19 +3,6 @@ # Abort the entire script if an error occurs set -e -# Wait for the db (postgres) container to be ready -./tcp-port-wait.sh "$JOB_HISTORY_DB_HOST" "$JOB_HISTORY_DB_PORT" - -# Give it a little extra time, in case it has to create the database -sleep 2; - -# If there's a database backup to restore, restore it -if [ -f "./backup_to_restore.sql" ] -then - echo "backup_to_restore.sql exists; restoring it" - PGPASSWORD=$JOB_HISTORY_DB_PASSWORD psql -U "$JOB_HISTORY_DB_USERNAME" -d "$JOB_HISTORY_DB_NAME" -h "$JOB_HISTORY_DB_HOST" -p "$JOB_HISTORY_DB_PORT" < ./backup_to_restore.sql -fi - # Next, run any pending database migrations ./manage.py migrate --no-input diff --git a/app/requirements.txt b/app/requirements.txt index c8de6b7..6f1eced 100644 --- a/app/requirements.txt +++ b/app/requirements.txt @@ -5,7 +5,6 @@ django-environ==0.11.2 isort==5.13.2 lazy-object-proxy==1.10.0 mccabe==0.7.0 -psycopg2-binary==2.9.9 pylint==3.2.3 pytz==2024.1 six==1.16.0 diff --git a/docker-compose.circleci.yml b/docker-compose.circleci.yml index 36b4484..a9f65dc 100644 --- a/docker-compose.circleci.yml +++ b/docker-compose.circleci.yml @@ -9,47 +9,23 @@ services: - JOB_HISTORY_DEBUG - JOB_HISTORY_ALLOWED_HOSTS - JOB_HISTORY_DB_NAME - - JOB_HISTORY_DB_USERNAME - - JOB_HISTORY_DB_PASSWORD - - JOB_HISTORY_DB_HOST - - JOB_HISTORY_DB_PORT - JOB_HISTORY_STATIC_ROOT - JOB_HISTORY_STATIC_URL command: /usr/src/app/manage.py test - depends_on: - - db ports: - "8000:8000" + volumes: + - "db_data:/data" networks: - job_history_net_1 - - job_history_internal_net healthcheck: test: curl --fail http://localhost:8000 || exit 1 restart: "no" - db: - image: - postgis/postgis:15-3.4 - container_name: - job_history_db - environment: - - POSTGRES_USER - - POSTGRES_PASSWORD - - POSTGRES_DB - volumes: - - "pg_data:/var/lib/postgresql/data" - ports: - - "5432:5432" - networks: - - job_history_internal_net - restart: - "no" networks: job_history_net_1: - job_history_internal_net: - internal: true volumes: - pg_data: + db_data: diff --git a/docker-compose.yml b/docker-compose.yml index e1690dd..63b8029 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -8,37 +8,19 @@ services: ./.env command: /usr/src/app/manage.py runserver 0.0.0.0:8000 - depends_on: - - db ports: - "8000:8000" + volumes: + - "db_data:/data" networks: - job_history_net_1 - - job_history_internal_net healthcheck: test: curl --fail http://localhost:8000 || exit 1 restart: "no" - db: - image: - postgis/postgis:15-3.4 - container_name: - job_history_db - env_file: - ./.env - volumes: - - "pg_data:/var/lib/postgresql/data" - ports: - - "5432:5432" - networks: - - job_history_internal_net - restart: - "no" networks: job_history_net_1: - job_history_internal_net: - internal: true volumes: - pg_data: + db_data: From 81c3c18da460ebf3c99dd1f5675ae2d962a70218 Mon Sep 17 00:00:00 2001 From: Stephen G Tuggy Date: Mon, 1 Jul 2024 04:44:46 -0700 Subject: [PATCH 3/4] Dockerfile: Upgrade pip every time after all? --- app/Dockerfile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/Dockerfile b/app/Dockerfile index 5a76a2a..936a173 100644 --- a/app/Dockerfile +++ b/app/Dockerfile @@ -8,6 +8,8 @@ WORKDIR /usr/src/app RUN apt-get -y update RUN apt-get -y upgrade +RUN python -m pip install --upgrade --upgrade-strategy eager pip + RUN mkdir -p /usr/src/app COPY ./requirements.txt /usr/src/app RUN python -m pip install --upgrade -r ./requirements.txt From 2a7d7932a54e7cc22f8b68477d6fa64ba0077aee Mon Sep 17 00:00:00 2001 From: Stephen G Tuggy Date: Mon, 1 Jul 2024 04:57:40 -0700 Subject: [PATCH 4/4] requirements.txt: Omit typed-ast; update pylint; make several implicit dependencies explicit --- app/requirements.txt | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/app/requirements.txt b/app/requirements.txt index 6f1eced..32b4d5b 100644 --- a/app/requirements.txt +++ b/app/requirements.txt @@ -1,15 +1,18 @@ +asgiref==3.8.1 astroid==3.2.2 colorama==0.4.6 +dill==0.3.8 Django==3.2.25 django-environ==0.11.2 isort==5.13.2 lazy-object-proxy==1.10.0 mccabe==0.7.0 -pylint==3.2.3 +platformdirs==4.2.2 +pylint==3.2.5 pytz==2024.1 six==1.16.0 sqlparse==0.5.0 -typed-ast==1.5.5 +tomlkit==0.12.5 wheel==0.43.0 whitenoise==6.7.0 wrapt==1.16.0