Skip to content

Commit

Permalink
Remove use of profiles with docker compose (#598)
Browse files Browse the repository at this point in the history
Always expose the CLI_PIXL_DB_PORT on the postgres container
Update docs to reflect changes
Remove EXTERNAL_PIXL_DB env var as we're no longer using profiles
  • Loading branch information
p-j-smith authored Feb 18, 2025
1 parent 3f3419c commit aa702e3
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 108 deletions.
5 changes: 2 additions & 3 deletions .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,18 @@ PIXL_QUERY_TIMEOUT=10
CLI_RETRY_SECONDS=300

# PIXL PostgreSQL instance
PIXL_DB_HOST=postgres-exposed
PIXL_DB_HOST=postgres
PIXL_DB_PORT=5432
PIXL_DB_NAME=pixl
PIXL_DB_USER=pixl
PIXL_DB_PASSWORD=
SKIP_ALEMBIC=false
EXTERNAL_PIXL_DB=false

# PIXL DB Postgres host
CLI_PIXL_DB_HOST=localhost

# Orthanc Raw PostgreSQL instance
ORTHANC_RAW_DB_HOST=postgres-exposed # change to correct host if PIXL DB is external postgres instance
ORTHANC_RAW_DB_HOST=postgres
ORTHANC_RAW_DB_PORT=5432
ORTHANC_RAW_DB_NAME=pixl
ORTHANC_RAW_DB_USER=pixl
Expand Down
23 changes: 3 additions & 20 deletions cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,34 +29,17 @@ See general pixl commands and subcommands with:
pixl --help
```

### Starting PIXL

For convenience, we provide the `pixl dc` command, which acts as a wrapper for `docker compose`,
but takes care of some of the configuration for you.

**1) Default Start-up**
For example,

```bash
pixl dc up
```

**2) Start-up with External PIXL DB**

PIXL can be set up so that the PIXL DB uses a separate postgres instance to Orthanc Raw, e.g. for production environment configurations.
Edit the .env file to enable this:

```bash
EXTERNAL_PIXL_DB=true

CLI_PIXL_DB_PORT=7001

ORTHANC_RAW_DB_HOST=postgres
```

Start-up PIXL:
```bash
pixl dc up
```
will run `docker compose --project pixl_{pixl_env} up --wait --build --remove-orphans`, where `pixl_env`
is determined by the `ENV` environment variable.

### Configuration

Expand Down
16 changes: 1 addition & 15 deletions cli/src/pixl_cli/_docker_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,27 +34,13 @@ def dc(args: tuple[str]) -> None:
docker_args = list(args)

if "up" in args:
docker_args = _parse_up_args(args)
docker_args = [*args, "--wait", "--build", "--remove-orphans"]
if "down" in args:
docker_args = _check_down_args(args)

run_docker_compose(docker_args, working_dir=PIXL_ROOT)


def _parse_up_args(args: tuple[str, ...]) -> list:
"""Check up args and set docker compose profile"""
args_list = list(args)

up_index = args.index("up")
external_pixl_db_env = config("EXTERNAL_PIXL_DB", cast=bool)
args_list[up_index:up_index] = (
["--profile", "postgres"] if external_pixl_db_env else ["--profile", "postgres-exposed"]
)

args_list.extend(["--wait", "--build", "--remove-orphans"])
return args_list


def _check_down_args(args: tuple[str, ...]) -> list:
"""Stop all the PIXL services"""
if config("ENV") == "prod" and "--volumes" in args:
Expand Down
41 changes: 2 additions & 39 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,8 @@ services:
extra_hosts:
- "host.docker.internal:host-gateway"
depends_on:
postgres-exposed:
postgres:
condition: service_healthy
required: false
healthcheck:
test:
[
Expand Down Expand Up @@ -224,10 +223,6 @@ services:
depends_on:
postgres:
condition: service_healthy
required: false
postgres-exposed:
condition: service_healthy
required: false
orthanc-anon:
condition: service_started
healthcheck:
Expand Down Expand Up @@ -295,10 +290,6 @@ services:
condition: service_healthy
postgres:
condition: service_healthy
required: false
postgres-exposed:
condition: service_healthy
required: false
hasher-api:
condition: service_healthy
ports:
Expand Down Expand Up @@ -368,8 +359,7 @@ services:

################################################################################
# Data Stores
postgres-exposed:
profiles: [postgres-exposed]
postgres:
build:
context: .
dockerfile: ./docker/postgres/Dockerfile
Expand Down Expand Up @@ -397,30 +387,3 @@ services:
restart: always
networks:
- pixl-net
postgres:
profiles: [postgres]
build:
context: .
dockerfile: ./docker/postgres/Dockerfile
args:
<<: *build-args-common
environment:
POSTGRES_USER: ${ORTHANC_RAW_DB_USER}
POSTGRES_PASSWORD: ${ORTHANC_RAW_DB_PASSWORD}
POSTGRES_DB: ${ORTHANC_RAW_DB_NAME}
PGTZ: ${TZ:-Europe/London}
env_file:
- ./docker/common.env
command: postgres -c 'config_file=/etc/postgresql/postgresql.conf'
volumes:
- type: volume
source: postgres-data
target: /var/lib/postgresql/data
healthcheck:
test: ["CMD", "pg_isready", "-U", "${ORTHANC_RAW_DB_USER}", "--dbname", "${ORTHANC_RAW_DB_NAME}"]
interval: 10s
timeout: 30s
retries: 5
restart: always
networks:
- pixl-net
7 changes: 3 additions & 4 deletions test/.env
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@ PIXL_MAX_MESSAGES_IN_FLIGHT=5
TZ=Europe/London

# PIXL PostgreSQL instance
PIXL_DB_HOST=postgres-pixl-db
PIXL_DB_HOST=postgres
PIXL_DB_PORT=5432
PIXL_DB_NAME=pixl
PIXL_DB_USER=pixl_db_username
PIXL_DB_PASSWORD=pixl_db_password
SKIP_ALEMBIC=false
EXTERNAL_PIXL_DB=true

# PIXL DB Postgres host
CLI_PIXL_DB_HOST=localhost
Expand All @@ -23,8 +22,8 @@ CLI_PIXL_DB_HOST=localhost
ORTHANC_RAW_DB_HOST=postgres
ORTHANC_RAW_DB_PORT=5432
ORTHANC_RAW_DB_NAME=pixl
ORTHANC_RAW_DB_USER=orthanc_raw_db_username
ORTHANC_RAW_DB_PASSWORD=orthanc_raw_db_password
ORTHANC_RAW_DB_USER=pixl_db_username
ORTHANC_RAW_DB_PASSWORD=pixl_db_password

# Exposed ports
HASHER_API_PORT=7010
Expand Down
25 changes: 0 additions & 25 deletions test/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
# limitations under the License.
volumes:
vna-qr-data:
postgres-pixl-db-data:

networks:
pixl-net:
Expand Down Expand Up @@ -74,27 +73,3 @@ services:
retries: 2
interval: 3s
timeout: 2s
postgres-pixl-db:
build:
context: ../
dockerfile: ./docker/postgres/Dockerfile
environment:
POSTGRES_USER: ${PIXL_DB_USER}
POSTGRES_PASSWORD: ${PIXL_DB_PASSWORD}
POSTGRES_DB: ${PIXL_DB_NAME}
PGTZ: ${TZ:-Europe/London}
command: postgres -c 'config_file=/etc/postgresql/postgresql.conf'
volumes:
- type: volume
source: postgres-pixl-db-data
target: /var/lib/postgresql/data
ports:
- "${CLI_PIXL_DB_PORT}:5432"
healthcheck:
test: ["CMD", "pg_isready", "-U", "${PIXL_DB_USER}", "--dbname", "${PIXL_DB_NAME}"]
interval: 10s
timeout: 30s
retries: 5
restart: always
networks:
- pixl-net
4 changes: 2 additions & 2 deletions test/run-system-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ setup() {
# Warning: Requires to be run from the project root
(
cd "${PACKAGE_DIR}"
docker compose --env-file test/.env --env-file test/.secrets.env --profile postgres -p system-test up --wait -d --build
docker compose --env-file test/.env --env-file test/.secrets.env -p system-test up --wait -d --build
)
}

teardown() {
(
cd "${PACKAGE_DIR}"
docker compose -f docker-compose.yml -f test/docker-compose.yml --profile postgres -p system-test down --volumes
docker compose -f docker-compose.yml -f test/docker-compose.yml -p system-test down --volumes
)
}

Expand Down

0 comments on commit aa702e3

Please sign in to comment.