Skip to content

Commit

Permalink
SQLite -> PostgreSQL
Browse files Browse the repository at this point in the history
  • Loading branch information
ghickman committed Oct 20, 2021
1 parent b73a9ce commit 096c8b6
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 22 deletions.
16 changes: 16 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,21 @@ jobs:
needs: [assets, format, lint, sort, upgrade]
runs-on: ubuntu-latest

services:
postgres:
image: postgres:13
env:
POSTGRES_USER: user
POSTGRES_PASSWORD: password
POSTGRES_DB: jobserver
ports:
- 5432:5432
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- uses: actions/checkout@v2
- uses: "actions/setup-python@v2"
Expand All @@ -119,6 +134,7 @@ jobs:

- name: Run tests
env:
DATABASE_URL: postgres://user:password@localhost/jobserver
SECRET_KEY: 12345
SOCIAL_AUTH_GITHUB_KEY: test
SOCIAL_AUTH_GITHUB_SECRET: test
Expand Down
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ __pycache__/
/assets/dist
/assets/stats.html
/coverage
db.sqlite3
db.sqlite3-shm
db.sqlite3-wal
htmlcov
node_modules/
releases
Expand Down
5 changes: 0 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,6 @@ ENV PIP_NO_CACHE_DIR=1 \

WORKDIR /app

RUN apt-get update && \
apt-get install --no-install-recommends -y sqlite3=3.27.2-3+deb10u1 && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*

# Only requirements to cache them in docker layer so we can skip package
# installation if they haven't changed
COPY requirements.prod.txt .
Expand Down
12 changes: 1 addition & 11 deletions INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,13 @@ dokku$ dokku domains:add job-server jobs.opensafely.org
dokku$ dokku git:set job-server deploy-branch main
```

## Create storage & load sqlite db into it

```bash
dokku$ mkdir /var/lib/dokku/data/storage/job-server
dokku$ chown dokku:dokku /var/lib/dokku/data/storage/job-server
dokku$ cp ./job-server-db.sqlite3 /var/lib/dokku/data/storage/job-server/db.sqlite3
dokku$ chown dokku:dokku /var/lib/dokku/data/storage/job-server/*
dokku$ dokku storage:mount job-server /var/lib/dokku/data/storage/job-server/:/storage
```

## Configure app

```bash
dokku config:set job-server ADMIN_USERS='xxx'
dokku config:set job-server BACKENDS='tpp,emis'
dokku config:set job-server BASE_URL='https://jobs.opensafely.org'
dokku config:set job-server DATABASE_URL='sqlite:////storage/db.sqlite3'
dokku config:set job-server DATABASE_URL='postgres://localhost/jobserver'
dokku config:set job-server EMAIL_BACKEND='anymail.backends.mailgun.EmailBackend'
dokku config:set job-server GITHUB_TOKEN='xxx'
dokku config:set job-server MAILGUN_API_KEY='xxx'
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ It provides an API to [job-runner](https://github.com/opensafely-core/job-runner
## Stack

This is a [Django](https://www.djangoproject.com) project.
It uses [Django Rest Framework](https://www.django-rest-framework.org) for the API and [SQLite](https://www.sqlite.org/index.html) for the database.
It uses [Django Rest Framework](https://www.django-rest-framework.org) for the API and [PostgreSQL](https://www.postgresql.org/) for the database.
It is deployed via [dokku](https://dokku.com), serves static files using the [whitenoise](http://whitenoise.evans.io) package, and is itself served by [gunicorn](https://gunicorn.org).
We authenticate Users with the [Python Social Auth](https://python-social-auth.readthedocs.io) Django-specific package, using [GitHub](https://github.com/) as the OAuth Provider backend.

Expand Down
16 changes: 15 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,24 @@
version: "3.6"

services:
db:
image: "postgres:13"
environment:
POSTGRES_USER: user
POSTGRES_PASSWORD: pass
POSTGRES_DB: jobserver
ports:
- "5432:5432"
volumes:
- postgres_data:/var/lib/postgresql/data/

job-server:
build: .
command: /app/manage.py runserver 0.0.0.0:8000
environment:
- ADMIN_USERS
- AUTHORIZATION_ORGS
- DATABASE_URL
- DATABASE_URL=postgres://user:pass@db:5432/jobserver
- DEBUG
- GITHUB_TOKEN
- SECRET_KEY=${SECRET_KEY:-12345}
Expand All @@ -18,3 +29,6 @@ services:
- "8000:8000"
volumes:
- .:/app

volumes:
postgres_data:
4 changes: 3 additions & 1 deletion jobserver/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,9 @@

# Database
# https://docs.djangoproject.com/en/3.0/ref/settings/#databases
DATABASES = {"default": env.dj_db_url("DATABASE_URL", default="sqlite:///db.sqlite3")}
DATABASES = {
"default": env.dj_db_url("DATABASE_URL", default="postgres://localhost/jobserver")
}

# Default primary key field type
# https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field
Expand Down
5 changes: 5 additions & 0 deletions sqlite.load
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
load database
from sqlite://db.sqlite3
into postgresql://localhost/jobserver

with include drop, reset sequences;

0 comments on commit 096c8b6

Please sign in to comment.