Skip to content

Commit

Permalink
Add image parameters to compose.yaml (#1092)
Browse files Browse the repository at this point in the history
Compose files can be parameterized using Bash-style (*sigh*) syntax
([1]). We add variables `JANUS_AGGREGATOR_IMAGE`,
`JANUS_MIGRATOR_IMAGE`, `DIVVIUP_API_IMAGE` and
`DIVVIUP_API_MIGRATOR_IMAGE` to allow setting Docker image tags like so:

```sh
DIVVIUP_API_IMAGE=myrepository.dev/divviup_api:0.0.1 \
  JANUS_AGGREGATOR_IMAGE=myrepository.dev/janus_aggregator:0.7.8 \
  docker compose up
```

These variables are interpolated into the `image` field of the `service`
elements ([2]). 

We also add `compose.dev.yaml`, which includes the base
`compose.yaml` and adds overrides which remove the `image`
element from the `divviup-api` services and add a `build` instead. This
causes `docker compose` to build those images from local sources, on
demand.

We provide defaults for all these images that pull from Divvi Up owned
public artifact repositories. It's somewhat unfortunate that we use a
`divviup-api` version that is behind `main`, but on the other hand the
objective is to enable a demo experience, so it makes sense to pin
Janus and divviup-api versions where the demo is known to work
end-to-end.

[1]: https://docs.docker.com/compose/compose-file/12-interpolation/
[2]: https://docs.docker.com/compose/compose-file/05-services/#image
[3]: https://docs.docker.com/compose/compose-file/build/#using-build-and-image
  • Loading branch information
tgeoghegan committed Jun 12, 2024
1 parent 6bf75f0 commit b189dbd
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 28 deletions.
29 changes: 26 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,33 @@ This will get you up and running quickly for development purposes.

1. Clone the repository and navigate to its root.
1. Execute `echo "http://localhost:8080" >app/public/api_url`
1. Execute `docker compose watch`.
1. Execute `docker compose up`.
1. Navigate in your browser to `http://localhost:8081/`.

`docker compose` will automatically reload containers when you make changes. Data is persisted
until you `docker compose rm --volumes`.
Data is persisted until you `docker compose rm --volumes`.

If you want to use image versions besides the defaults, you can use environment variables
`JANUS_AGGREGATOR_IMAGE`, `JANUS_MIGRATOR_IMAGE`, `DIVVIUP_API_IMAGE` and
`DIVVIUP_API_MIGRATOR_IMAGE` when invoking `docker compose`. For example:

```bash
DIVVIUP_API_IMAGE=divviup_api:localversion \
JANUS_IMAGE=us-west2-docker.pkg.dev/divviup-artifacts-public/janus/janus_aggregator:0.7.18 \
docker compose up
```

`divviup_api:localversion` will be pulled from the local Docker repository and
`us-west2-docker.pkg.dev/divviup-artifacts-public/janus/janus_aggregator:0.7.18` will be pulled from
`us-west2-docker.pkg.dev`.

We also provide `compose.dev.yaml`, which will build `divviup-api` from local sources. Try:

```bash
docker compose -f compose.dev.yaml watch
```

`docker compose` will automatically reload containers when you make changes. The `JANUS_IMAGE` and
`JANUS_MIGRATOR_IMAGE` variables are honored by `compose.dev.yaml`.

Two Janus aggregators will be created for you, but are not automatically paired to divviup-api.
Their information is:
Expand All @@ -58,6 +80,7 @@ testing client, they are mapped to `localhost:9001` and `localhost:9002`, respec

If using the divviup CLI, consider compiling with the `--features admin` option. Also, set these
environment variables.

```bash
# This token is intentionally blank, but you'll still need to set the variable.
export DIVVIUP_TOKEN=
Expand Down
31 changes: 31 additions & 0 deletions compose.dev.override.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Overrides for the local development docker compose setup. Meant only to be used by
# compose.dev.yaml

services:
divviup_api:
image: !reset null
build:
context: .
args:
RUST_PROFILE: dev
RUST_FEATURES: integration-testing
develop:
watch:
- path: src/
action: rebuild

divviup_api_migrate:
image: !reset null
build:
context: .
args:
RUST_PROFILE: dev
# This isn't strictly required for migrations, but it allows reusing one container image
# for both this and the divviup_api service.
RUST_FEATURES: integration-testing
develop:
watch:
- path: migration
action: rebuild
ignore:
- README.md
8 changes: 8 additions & 0 deletions compose.dev.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Local development-only compose file which builds divviup-api from source. This is not suitable for
# production!

include:
- path:
# These files are ordered deliberately so that they will be merged correctly
- compose.yaml
- compose.dev.override.yaml
30 changes: 5 additions & 25 deletions compose.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Local development-only compose file. This is not suitable for production!
# Compose file for bringing up a simple local Divvi Up environment. This is not suitable for production!

x-janus-common: &janus_common
image: us-west2-docker.pkg.dev/divviup-artifacts-public/janus/janus_aggregator:0.7.7
image: ${JANUS_AGGREGATOR_IMAGE:-us-west2-docker.pkg.dev/divviup-artifacts-public/janus/janus_aggregator:0.7.7}
restart: always
healthcheck:
test: ["CMD", "/bin/sh", "-c", "wget http://0.0.0.0:8000/healthz -O - >/dev/null"]
Expand All @@ -12,7 +12,7 @@ x-janus-common: &janus_common
condition: service_completed_successfully

x-janus-migrate: &janus_migrate
image: us-west2-docker.pkg.dev/divviup-artifacts-public/janus/janus_db_migrator:0.7.7
image: ${JANUS_MIGRATOR_IMAGE:-us-west2-docker.pkg.dev/divviup-artifacts-public/janus/janus_db_migrator:0.7.7}
command:
- migrate
- run
Expand Down Expand Up @@ -43,13 +43,7 @@ services:
target: /docker-entrypoint-initdb.d/postgres_init.sql

divviup_api_migrate:
build:
context: .
args:
RUST_PROFILE: dev
# This isn't strictly required for migrations, but it allows reusing one container image
# for both this and the divviup_api service.
RUST_FEATURES: integration-testing
image: ${DIVVIUP_API_MIGRATOR_IMAGE:-us-west2-docker.pkg.dev/divviup-artifacts-public/divviup-api/divviup_api:0.3.12}
entrypoint:
- /migration
- up
Expand All @@ -58,19 +52,9 @@ services:
depends_on:
postgres:
condition: service_started
develop:
watch:
- path: migration
action: rebuild
ignore:
- README.md

divviup_api:
build:
context: .
args:
RUST_PROFILE: dev
RUST_FEATURES: integration-testing
image: ${DIVVIUP_API_IMAGE:-us-west2-docker.pkg.dev/divviup-artifacts-public/divviup-api/divviup_api:0.3.12}
ports:
- "8080:8080"
environment:
Expand All @@ -89,10 +73,6 @@ services:
depends_on:
divviup_api_migrate:
condition: service_completed_successfully
develop:
watch:
- path: src/
action: rebuild

divviup_api_vite:
build:
Expand Down

0 comments on commit b189dbd

Please sign in to comment.