From 26dc3624ca8ef955ecaaa6f30a4bc697fed6f4a0 Mon Sep 17 00:00:00 2001 From: Sadiq Khoja Date: Fri, 20 Dec 2024 11:48:44 -0500 Subject: [PATCH] Add dev docker-compose file to manage supporting services (#525) * Added a docker compose file for development * Added Makefile for quick start and stop * Added instruction in README.md --- Makefile | 9 ++++++ README.md | 6 ++++ docker-compose.dev.yml | 62 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 77 insertions(+) create mode 100644 Makefile create mode 100644 docker-compose.dev.yml diff --git a/Makefile b/Makefile new file mode 100644 index 00000000..dd192f47 --- /dev/null +++ b/Makefile @@ -0,0 +1,9 @@ +docker-compose-dev := docker compose --profile central -f docker-compose.yml -f docker-compose.dev.yml + +.PHONY: dev +dev: + $(docker-compose-dev) up -d + +.PHONY: stop +stop: + $(docker-compose-dev) stop diff --git a/README.md b/README.md index 2cfe34dd..b45f2d90 100644 --- a/README.md +++ b/README.md @@ -28,6 +28,12 @@ In addition to the Backend and the Frontend, Central deploys services: * Central relies on [pyxform-http](https://github.com/getodk/pyxform-http) for converting Forms from XLSForm. It generally shouldn't be needed in development but can be run locally. * Central relies on [Enketo](https://github.com/enketo/enketo-express) for Web Form functionality. Enketo can be run locally and configured to work with Frontend and Backend in development by following [these instructions](https://github.com/getodk/central-frontend/blob/master/docs/enketo.md). +If you want to work on Central codebase and don't want to setup dependent services like Postgresql, Enketo, etc manually then you can run `make dev`, which will start those services as Docker containers. With this setup you would need a local domain name, `central-dev` is a good choice. Following are the places where you need to add this: + +* Set `DOMAIN=central-dev` in .env file. +* Add an entry in your `/etc/hosts` file for `127.0.0.1 central-dev`. +* Create `local.json` in central-backend directory and set value of default.env.domain to `http://central-dev:8989` + Operations ---------- diff --git a/docker-compose.dev.yml b/docker-compose.dev.yml new file mode 100644 index 00000000..94c6f42e --- /dev/null +++ b/docker-compose.dev.yml @@ -0,0 +1,62 @@ +# Assumption: This file will be merged by `docker compose` +# +# What it does: +# Sets profiles for each service depending on whether that +# service is required for Central development or not. +# +# depends_on of some services are reset using !reset custom yml tag +# nb: can't replace depends_on so we have removed all the values, ok for dev +services: + postgres14: + profiles: + - central + ports: + - 5432:5432 + postgres: + profiles: + - central + image: debian:bullseye + command: /bin/sh -c 'mkdir -p /var/lib/postgresql/14/data && touch /var/lib/postgresql/14/.postgres14-upgrade-successful' + mail: + profiles: + - none + service: + profiles: + - none + nginx: + profiles: + - none + pyxform: + profiles: + - central + ports: + - 5001:80 + secrets: + profiles: + - central + volumes: + - dev_secrets:/etc/secrets + working_dir: /etc/secrets + command: /bin/sh -c 'echo "s0m3v3rys3cr3tk3y" > enketo-secret && echo "this $3cr3t key is crackable" > enketo-less-secret && echo "enketorules" > enketo-api-key' + enketo: + profiles: + - central + volumes: + - dev_secrets:/etc/secrets + depends_on: !override + - secrets + - enketo_redis_main + environment: + - ENV=DEV + extra_hosts: + - "${DOMAIN}:host-gateway" + ports: + - 8005:8005 + enketo_redis_main: + profiles: + - central + enketo_redis_cache: + profiles: + - central +volumes: + dev_secrets: