Openverse is a search engine for openly-licensed media. This monorepo includes all application code.
Use profiles in Docker Compose (#914)
Dhruv Bhanushali15e14a385ec1
diff --git a/.editorconfig b/.editorconfigindex 14bf61a59..ced878448 100644--- a/.editorconfig+++ b/.editorconfig@@ -1,4 +1,5 @@root = true+[*]charset = utf-8indent_style = space@@ -9,3 +10,6 @@ trim_trailing_whitespace = true[*.py]indent_size = 4++[justfile]+indent_size = 4diff --git a/.github/workflows/ci_cd.yml b/.github/workflows/ci_cd.ymlindex cd7ca71fe..97fcbee23 100644--- a/.github/workflows/ci_cd.yml+++ b/.github/workflows/ci_cd.yml@@ -313,7 +313,7 @@ jobs:uses: ./.github/actions/load-img- name: Start API, ingest and index test data- run: just init+ run: just api/init- name: Run API testsrun: just api/test@@ -486,7 +486,6 @@ jobs:- name: collectstaticrun: |- just _all-upjust api/collectstaticenv:DC_USER: rootdiff --git a/api/justfile b/api/justfileindex c7f132703..0b89f2fbf 100644--- a/api/justfile+++ b/api/justfile@@ -10,15 +10,27 @@ NO_COLOR := "\\033[0m"just --list --unsorted-# Aliases _all-up from the parent directory-# https://github.com/casey/just/issues/1550-_all-up:- just ../_all-up-# Install dependenciesinstall *args="--dev":pipenv install {{ args }}+######+# Up #+######++# Bring up services specific to the API profile+up *flags:+ env COMPOSE_PROFILES="api" just ../up {{ flags }}++# Wait for all profile services to be up+wait-up: up+ just ../ingestion_server/wait # API profile includes ingestion server+ just wait # API waits for ES in entrypoint++# Load sample data into API via ingestion server+init: wait-up+ cd .. && ./load_sample_data.sh+########### Health ###########@@ -60,7 +72,7 @@ dj-local +args="":pipenv run python manage.py {{ args }}# Run Django administrative commands inside the Docker container-dj +args="": _all-up+dj +args="": wait-upjust ../exec web python manage.py {{ args }}# Get IPython shell inside the Docker container@@ -83,7 +95,7 @@ collectstatic:########## Run API tests inside the Docker container-test *args: _all-up+test *args: wait-upjust ../exec web ./test/run_test.sh {{ args }}# Run API tests locally@@ -91,5 +103,5 @@ test-local *args:pipenv run ./test/run_test.sh {{ args }}# Run smoke test for the API docs-doc-test: _all-up+doc-test: wait-upcurl --fail 'http://localhost:50280/v1/?format=openapi'diff --git a/docker-compose.yml b/docker-compose.ymlindex 1a2a20a1c..4d53a8c5c 100644--- a/docker-compose.yml+++ b/docker-compose.yml@@ -1,6 +1,9 @@version: "2.4"services:db:+ profiles:+ - ingestion_server+ - apiimage: postgres:13.2-alpineports:- "50254:5432"@@ -12,6 +15,9 @@ services:test: "pg_isready -U deploy -d openledger"upstream_db:+ profiles:+ - ingestion_server+ - apibuild: ./docker/upstream_db/image: openverse-upstream_dbexpose:@@ -25,6 +31,8 @@ services:test: "pg_isready -U deploy -d openledger"plausible_db:+ profiles:+ - frontendimage: postgres:13.2-alpineexpose:- "5432"@@ -36,6 +44,8 @@ services:test: "pg_isready -U deploy -d plausible"plausible_ch:+ profiles:+ - frontendimage: clickhouse/clickhouse-server:22.6-alpinevolumes:- plausible-clickhouse:/var/lib/clickhouse@@ -47,6 +57,8 @@ services:hard: 262144plausible:+ profiles:+ - frontendimage: plausible/analytics:latestports:- "50288:8000"@@ -58,11 +70,16 @@ services:- docker/plausible/env.dockercache:+ profiles:+ - apiimage: redis:4.0.10ports:- "50263:6379"es:+ profiles:+ - ingestion_server+ - apiimage: docker.elastic.co/elasticsearch/elasticsearch:7.12.0ports:- "50292:9200"@@ -89,6 +106,8 @@ services:- es-data:/usr/share/elasticsearch/dataweb:+ profiles:+ - apibuild:context: ./api/args:@@ -113,6 +132,9 @@ services:tty: trueingestion_server:+ profiles:+ - ingestion_server+ - apibuild: ./ingestion_server/image: openverse-ingestion_servercommand: gunicorn -c ./gunicorn.conf.py@@ -131,6 +153,9 @@ services:tty: trueindexer_worker:+ profiles:+ - ingestion_server+ - apibuild: ./ingestion_server/image: openverse-ingestion_servercommand: gunicorn -c ./gunicorn_worker.conf.py@@ -148,6 +173,8 @@ services:tty: trueproxy:+ profiles:+ - apiimage: nginx:alpineports:- "50200:9080"diff --git a/frontend/justfile b/frontend/justfileindex 0b197c9fd..644531958 100644--- a/frontend/justfile+++ b/frontend/justfile@@ -10,6 +10,22 @@ NO_COLOR := "\\033[0m"just --list --unsorted+######+# Up #+######++# Bring up services specific to the frontend profile+up *flags:+ env COMPOSE_PROFILES="frontend" just ../up {{ flags }}++# Wait for all profile services to be up+wait-up: up+ echo "🚧 TODO"++# Set up user and test site in Plausible+init: wait-up+ cd .. && ./setup_plausible.sh+# Run a package.json script via pnpmrun *args:pnpm run {{ args }}diff --git a/ingestion_server/justfile b/ingestion_server/justfileindex 9980c541e..62bbb439e 100644--- a/ingestion_server/justfile+++ b/ingestion_server/justfile@@ -14,6 +14,18 @@ NO_COLOR := "\\033[0m"install *args="--dev":pipenv install {{ args }}+######+# Up #+######++# Bring up services specific to the ingestion server profile+up *flags:+ env COMPOSE_PROFILES="ingestion_server" just ../up {{ flags }}++# Wait for all profile services to be up+wait-up: up+ just wait+########### Health ###########diff --git a/ingestion_server/test/integration_test.py b/ingestion_server/test/integration_test.pyindex a202f5d4b..98891195a 100644--- a/ingestion_server/test/integration_test.py+++ b/ingestion_server/test/integration_test.py@@ -219,7 +219,14 @@ class TestIngestion(unittest.TestCase):def _compose_cmd(cls, cmd: list[str], **kwargs):"""Run a Docker Compose command"""- cmd = ["docker-compose", "-f", cls.compose_path, *cmd]+ cmd = [+ "docker-compose",+ "--profile",+ "ingestion_server",+ "-f",+ cls.compose_path,+ *cmd,+ ]subprocess.run(cmd,cwd=cls.compose_path.parent,diff --git a/justfile b/justfileindex d9e42f1f9..16da6411e 100644--- a/justfile+++ b/justfile@@ -91,17 +91,6 @@ env:cp api/env.template api/.envcp ingestion_server/env.template ingestion_server/.env-# Ensure all services are up and running-@_all-up:- just up- just ingestion_server/wait- just api/wait # API waits for ES in entrypoint--# Load sample data into the Docker Compose services-init: _all-up- ./load_sample_data.sh- ./setup_plausible.sh-########### Docker ###########@@ -114,18 +103,32 @@ DOCKER_FILE := "-f " + (# Run `docker-compose` configured with the correct files and environmentdc *args:@{{ if IS_CI != "" { "just env" } else { "true" } }}- docker-compose {{ DOCKER_FILE }} {{ args }}+ env COMPOSE_PROFILES="{{ env_var_or_default("COMPOSE_PROFILES", "api,ingestion_server,frontend") }}" docker-compose {{ DOCKER_FILE }} {{ args }}# Build all (or specified) servicesbuild *args:just dc build {{ args }}-# Bring all Docker services up-up *flags="":+# Also see `up` recipe in sub-justfiles+# Bring all Docker services up, in all profiles+up *flags:just dc up -d {{ flags }}-# Take all Docker services down-down flags="":+# Also see `wait-up` recipe in sub-justfiles+# Wait for all services to be up+wait-up: up+ just ingestion_server/wait-up+ just api/wait-up+ just frontend/wait-up++# Also see `init` recipe in sub-justfiles+# Load sample data into the Docker Compose services+init:+ just api/init+ just frontend/init++# Take all Docker services down, in all profiles+down *flags:just dc down {{ flags }}# Recreate all volumes and containers from scratch