Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions .docker/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
## What is this directory?
This directory is a space for mounting directories to docker containers, allowing the mounts to be specified in committed code, but the contents of the mounts to remain ignored by git.

### postgres
The `postgres` directory is mounted to `/docker-entrypoint-initdb.d`. Any `.sh` or `.sql` files will be executed when the container is first started with a new data volume. You may read more regarding this functionality on the [Docker Hub page](https://hub.docker.com/_/postgres), under _Initialization scripts_.

When running docker services through the Makefile commands, it specifies a docker-compose project name that depends on the name of the current git branch. This causes the volumes to change when the branch changes, which is helpful when switching between many branches that might have incompatible database schema changes. The downside is that whenever you start a new branch, you'll have to re-initialize the database again, like with `yarn run devsetup`. Creating a SQL dump from an existing, initialized database and placing it in this directory will allow you to skip this step.

To create a SQL dump of your preferred database data useful for local testing, run `make .docker/postgres/init.sql` while the docker postgres container is running.

> Note: you will likely need to run `make migrate` to ensure your database schema is up-to-date when using this technique.

#### pgpass
Stores the postgres authentication for the docker service for scripting access without manually providing a password, created by `make .docker/pgpass`

### minio
The `minio` directory is mounted to `/data`, since it isn't necessarily useful to have this data isolated based off the current git branch.
7 changes: 5 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,11 @@ contentcuration/csvs/
# Ignore the TAGS file generated by some editors
TAGS

# Ignore Vagrant-created files
/.vagrant/
# Services
.vagrant/
.docker/minio/*
.docker/postgres/*
.docker/pgpass

# Ignore test files
/contentcuration/contentcuration/proxy_settings.py
Expand Down
31 changes: 24 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,9 @@ hascaptions:

export COMPOSE_PROJECT_NAME=studio_$(shell git rev-parse --abbrev-ref HEAD)

purge-postgres:
-PGPASSWORD=kolibri dropdb -U learningequality "kolibri-studio" --port 5432 -h localhost
PGPASSWORD=kolibri createdb -U learningequality "kolibri-studio" --port 5432 -h localhost
purge-postgres: .docker/pgpass
-PGPASSFILE=.docker/pgpass dropdb -U learningequality "kolibri-studio" --port 5432 -h localhost
PGPASSFILE=.docker/pgpass createdb -U learningequality "kolibri-studio" --port 5432 -h localhost

destroy-and-recreate-database: purge-postgres setup

Expand All @@ -138,15 +138,29 @@ devceleryworkers:
run-services:
$(MAKE) -j 2 dcservicesup devceleryworkers

.docker/minio:
mkdir -p $@

.docker/postgres:
mkdir -p $@

.docker/pgpass:
echo "localhost:5432:kolibri-studio:learningequality:kolibri" > $@
chmod 600 $@

.docker/postgres/init.sql: .docker/pgpass
# assumes postgres is running in a docker container
PGPASSFILE=.docker/pgpass pg_dump --host localhost --port 5432 --username learningequality --dbname "kolibri-studio" --file $@

dcbuild:
# build all studio docker image and all dependent services using docker-compose
docker-compose build

dcup:
dcup: .docker/minio .docker/postgres
# run all services except for cloudprober
docker-compose up studio-app celery-worker

dcup-cloudprober:
dcup-cloudprober: .docker/minio .docker/postgres
# run all services including cloudprober
docker-compose up

Expand All @@ -163,11 +177,14 @@ dcshell:
# bash shell inside the (running!) studio-app container
docker-compose exec studio-app /usr/bin/fish

dctest:
dcpsql: .docker/pgpass
PGPASSFILE=.docker/pgpass psql --host localhost --port 5432 --username learningequality --dbname "kolibri-studio"

dctest: .docker/minio .docker/postgres
# run backend tests inside docker, in new instances
docker-compose run studio-app make test

dcservicesup:
dcservicesup: .docker/minio .docker/postgres
# launch all studio's dependent services using docker-compose
docker-compose -f docker-compose.yml -f docker-compose.alt.yml up minio postgres redis

Expand Down
3 changes: 2 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ services:
MINIO_SECRET_KEY: development
MINIO_API_CORS_ALLOW_ORIGIN: 'http://localhost:8080,http://127.0.0.1:8080'
volumes:
- minio_data:/data
- .docker/minio:/data

postgres:
image: postgres:12
Expand All @@ -61,6 +61,7 @@ services:
POSTGRES_DB: kolibri-studio
volumes:
- pgdata:/var/lib/postgresql/data/pgdata
- .docker/postgres:/docker-entrypoint-initdb.d

redis:
image: redis:6.0.9
Expand Down