Skip to content

Commit

Permalink
Getting started:
Browse files Browse the repository at this point in the history
- add docker compose for easiere dev with dockerized version
- update the readme
- add DB init script
  • Loading branch information
marionb committed Feb 15, 2024
1 parent 67d5ef0 commit 58b5778
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 5 deletions.
10 changes: 5 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ ENV PYTHONUNBUFFERED 1
COPY . /app/geoshop_back/

ARG ENV_FILE
RUN mv ${ENV_FILE} .env && mkdir /mnt/geoshop_data
RUN mkdir /mnt/geoshop_data

RUN export $(egrep -v '^#' .env | xargs) && \
python manage.py migrate && \
python manage.py collectstatic --noinput && \
python manage.py compilemessages --locale=fr
RUN export $(egrep -v '^#' .env | xargs)
# python manage.py migrate && \ # TODO: it is probably dangerous to run this every time on start up - it is better to make a volumne for the DB
# python manage.py collectstatic --noinput && \
# python manage.py compilemessages --locale=fr
29 changes: 29 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,35 @@ cp .env.sample .env
`.env` will vary depending on the environements you're targetting.
`settings.py` will get the specific config of your project.

## Using a docker compose dev env with a container DB:

**NOTE:**
This should only be used for development purposes!

### Set up the containers:

1. follow the steps under **Getting started**
2. launch the docker composition with `$ docker compose up -d`

This should result in two running containers:

1. PostGIS DB
2. The geoshop backend container

### Django settings:

1. Inside the geoshop container run the DB migration script, collection of static files and language translations:
```
python manage.py migrate
python manage.py collectstatic --noinput
python manage.py compilemessages --locale=fr
```
2. Create a super user (from within the geoshop container):
```
python manage.py createsuperuser
```
now you can access the api under [localhost:8080](localhost:8080) or what port you have configured
### Database
Create a `geoshop` user if not existing yet, set your password according to your `env.local`:
Expand Down
15 changes: 15 additions & 0 deletions db/docker_db/init-scripts/01_init_db.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
-- CREATE ROLE geoshop WITH LOGIN PASSWORD geoshop;
--
-- CREATE DATABASE geoshop OWNER geoshop;
-- REVOKE ALL ON DATABASE geoshop FROM PUBLIC;

CREATE EXTENSION postgis;
CREATE EXTENSION unaccent;
CREATE EXTENSION "uuid-ossp";

CREATE SCHEMA geoshop AUTHORIZATION geoshop;

CREATE TEXT SEARCH CONFIGURATION fr (COPY = simple);

ALTER TEXT SEARCH CONFIGURATION fr ALTER MAPPING FOR hword, hword_part, word
WITH unaccent, simple;
50 changes: 50 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
version: '3'

services:
db:
image: postgis/postgis:15-3.4-alpine
volumes:
# - "/db/docker_db/data:/var/lib/postgresql/data"
- "/db/docker_db/init-scripts:/docker-entrypoint-initdb.d"
environment:
POSTGRES_USER: ${PGUSER}
POSTGRES_PASSWORD: ${PGPASSWORD}
POSTGRES_DB: ${PGDATABASE}
# TODO set this from env vars
# this is needed to avoid issues like ---database "postgres" has no actual collation version, but a version was recorded---
# perhaps setting POSTGRES_COLLATE: would also be enoughe
LANG: 'en_US.utf8'
LC_COLLATE: 'en_US.utf8'
LC_CTYPE: 'en_US.utf8'
ports:
- ${PGPORT}:5432
networks:
- default

api:
image: geoshop-api
build:
context: .
args:
ENV_FILE: .env
depends_on:
- db
env_file: .env
command: "gunicorn wsgi -b :8000 --timeout 90"
restart: unless-stopped
ports:
- "8080:8000"
volumes:
- "${GEOSHOP_DATA}:/mnt/geoshop_data"
networks:
- default

# front:
# image: ${DOCKER_BASE}-front
# build:
# context: ./front/
# args:
# FRONT_HREF: ${FRONT_HREF}
# restart: unless-stopped
# ports:
# - "${DOCKER_FRONT_PORT}:80"

0 comments on commit 58b5778

Please sign in to comment.