Skip to content

Commit

Permalink
Merge pull request #170 from stephengtuggy/switch-to-sqlite
Browse files Browse the repository at this point in the history
Switch to SQLite
  • Loading branch information
stephengtuggy authored Jul 1, 2024
2 parents 7d780a1 + 2a7d793 commit 3ae9aa0
Show file tree
Hide file tree
Showing 10 changed files with 16 additions and 84 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,4 @@ venv.bak/
.DS_Store
.vscode/
**/public/
data/
9 changes: 1 addition & 8 deletions .env.example
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -136,3 +136,4 @@ dmypy.json
*.sql
/local-env.sh
/app/static/
/data/
1 change: 1 addition & 0 deletions .idea/job-history.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions app/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +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

Expand All @@ -19,7 +17,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
Expand Down
13 changes: 0 additions & 13 deletions app/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
10 changes: 1 addition & 9 deletions app/jobHistorySite/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down Expand Up @@ -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'),
}
}

Expand Down
8 changes: 5 additions & 3 deletions app/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,16 +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
psycopg2-binary==2.9.9
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
30 changes: 3 additions & 27 deletions docker-compose.circleci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
24 changes: 3 additions & 21 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:

0 comments on commit 3ae9aa0

Please sign in to comment.