Skip to content

Commit

Permalink
Add image parameters to compose.yaml
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]). Because we also have a `build` element on the
`divviup-api` services, the behavior is to pull the specified image and
fall back to the `build` element if it can't be found ([3]). So if you
want to build `divviup-api` from source and use that, do:

```sh
DIVVIUP_API_IMAGE=divviup_api:1 docker compose up
```

`divviup_api:1` will be built from the local context, unless it's
already in the local Docker repository, and then launched.

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 9777fa9 commit 6c84f1f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,22 @@ This will get you up and running quickly for development purposes.
`docker compose` will automatically reload containers when you make changes. 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`. If the tag set for `DIVVIUP_API_IMAGE`
or `DIVVIUP_API_MIGRATOR_IMAGE` cannot be found, it will be built from local context. 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
```

If `divviup_api:localversion` is present in the local Docker repository, it will be used, but it
will be built otherwise, and then run.
`us-west2-docker.pkg.dev/divviup-artifacts-public/janus/janus_aggregator:0.7.18` will be pulled and
run.

Two Janus aggregators will be created for you, but are not automatically paired to divviup-api.
Their information is:
1. Address: `http://janus_1_aggregator:8080/aggregator-api`, Token: `0000`
Expand All @@ -58,6 +74,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
6 changes: 4 additions & 2 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!

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,6 +43,7 @@ services:
target: /docker-entrypoint-initdb.d/postgres_init.sql

divviup_api_migrate:
image: ${DIVVIUP_API_MIGRATOR_IMAGE:-us-west2-docker.pkg.dev/janus-artifacts/divviup-api/divviup_api:0.3.9}
build:
context: .
args:
Expand All @@ -66,6 +67,7 @@ services:
- README.md

divviup_api:
image: ${DIVVIUP_API_IMAGE:-us-west2-docker.pkg.dev/janus-artifacts/divviup-api/divviup_api:0.3.9}
build:
context: .
args:
Expand Down

0 comments on commit 6c84f1f

Please sign in to comment.