From b2c6a5a7ae06a43d04b7cb8c8d862f961f3e9d4b Mon Sep 17 00:00:00 2001 From: Marc Cataford Date: Tue, 16 Jan 2024 20:10:40 -0500 Subject: [PATCH] build(containers): default to podman + update references --- README.md | 5 ++++- Taskfile.backend.yml | 23 +++++++++++++---------- backend/script/build.sh | 2 +- backend/script/start.sh | 12 ++++++------ backend/script/{test => test.sh} | 7 +++---- 5 files changed, 27 insertions(+), 22 deletions(-) rename backend/script/{test => test.sh} (73%) diff --git a/README.md b/README.md index 1b56e9e..2ff1900 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,9 @@ Note that this is the preferred way to running any tooling-related task within t environment. Individual scripts exist under `/{frontend,backend}/script` but generally assume that they will be called through `task` to inject some environment variables. +The project uses [Podman](https://podman.io/) as a default container manager, but is Docker-compatible +(`Taskfile.backend.yml` can be made to specify `CONTAINER_MANAGER="docker"` to use it). + #### Formatting Formatting in either frontend or backend environment can be done via `task {fe,be}:lint`. Applying fixes is available @@ -37,7 +40,7 @@ Test suites can be executed by environment via `task {fe,be}:test`. The application requires a Postgres database instance to be made available to the backend. Setting up a local database is handled by the backend start command. -Starting the backend (including a database) and frontend applications can be done via `task be:docker:start` and `task fe:start`. +Starting the backend (including a database) and frontend applications can be done via `task be:container:start` and `task fe:start`. See the README files of each of those environments ([backend](./backend/README.md), [frontend](./frontend/README.md)) for specific requirements around `*.env` files that aren't committed with the code. diff --git a/Taskfile.backend.yml b/Taskfile.backend.yml index 48ac331..1722f5f 100644 --- a/Taskfile.backend.yml +++ b/Taskfile.backend.yml @@ -6,6 +6,7 @@ env: APP_CONTAINER_NAME: "rotini_app" DB_CONTAINER_NAME: "rotini_db" SHELL: /bin/bash + CONTAINER_MANAGER: "podman" tasks: bootstrap: @@ -32,26 +33,28 @@ tasks: test: desc: "Run the test suites." deps: [bootstrap] - cmd: $SHELL script/test {{ .CLI_ARGS }} + cmd: $SHELL script/test.sh {{ .CLI_ARGS }} dotenv: - ../backend-test.env lock-deps: desc: "Locks production and development dependencies" deps: [bootstrap] cmd: $SHELL script/requirements-lock - docker:start: + container:start: desc: "Starts the backend application." - deps: [docker:build] + deps: [container:build] cmd: $SHELL script/start.sh dotenv: - ../backend.env - docker:stop: + container:stop: desc: "Stops the backend application." - cmd: docker rm -f {{ .APP_CONTAINER_NAME }} {{ .DB_CONTAINER_NAME }} - docker:logs: - desc: "Shortcut to Docker container logs" - cmd: docker logs {{ .APP_CONTAINER_NAME }} -f - docker:build: - desc: "Builds a docker image from /backend" + cmds: + - "{{ .CONTAINER_MANAGER }} rm -f {{ .APP_CONTAINER_NAME }}" + - "{{ .CONTAINER_MANAGER }} rm -f {{ .DB_CONTAINER_NAME }}" + container:logs: + desc: "Shortcut to container container logs" + cmd: "{{ .CONTAINER_MANAGER }} logs -f {{ .APP_CONTAINER_NAME }}" + container:build: + desc: "Builds a container image from /backend" cmd: $SHELL script/build.sh diff --git a/backend/script/build.sh b/backend/script/build.sh index 25bfed7..fad8dd3 100644 --- a/backend/script/build.sh +++ b/backend/script/build.sh @@ -1,3 +1,3 @@ #!/bin/bash -docker build -t rotini:dev . +$CONTAINER_MANAGER build -t rotini:dev . diff --git a/backend/script/start.sh b/backend/script/start.sh index c024c69..2e743fa 100644 --- a/backend/script/start.sh +++ b/backend/script/start.sh @@ -1,24 +1,24 @@ #!/bin/bash -docker network create rotini-local || echo "Network already exists" +$CONTAINER_MANAGER network create rotini-local || echo "Network already exists" -docker run \ +$CONTAINER_MANAGER run \ --name $DB_CONTAINER_NAME \ -e POSTGRES_PASSWORD=$DB_PASSWORD \ -e POSTGRES_USER=$DB_USER \ -e POSTGRES_DB=$DB_NAME \ - -v $DATABASE_STORAGE_PATH:/var/lib/postgresql/data \ + -v $DATABASE_STORAGE_PATH:/var/lib/postgresql/data:Z \ -p 5432:5432 \ --network rotini-local \ -d \ - postgres:15.4 + postgres:15 -until [ -n "$(docker exec $DB_CONTAINER_NAME pg_isready | grep accepting)" ]; do +until [ -n "$($CONTAINER_MANAGER exec $DB_CONTAINER_NAME pg_isready | grep accepting)" ]; do echo "Waiting for DB to come alive..." sleep 0.1; done; -docker run \ +$CONTAINER_MANAGER run \ --detach \ --publish 8000:8000 \ --name $APP_CONTAINER_NAME \ diff --git a/backend/script/test b/backend/script/test.sh similarity index 73% rename from backend/script/test rename to backend/script/test.sh index 953112f..ad10a1b 100644 --- a/backend/script/test +++ b/backend/script/test.sh @@ -23,26 +23,25 @@ function fail { # Cleanup before exit (success/failure) function cleanup { - docker rm $TEST_DB_CONTAINER -f > /dev/null || echo "Failed to clean up test database container." + $CONTAINER_MANAGER rm $TEST_DB_CONTAINER -f > /dev/null || echo "Failed to clean up test database container." } trap cleanup EXIT -docker run \ +$CONTAINER_MANAGER run \ --name $TEST_DB_CONTAINER \ -e POSTGRES_PASSWORD=test \ -p 5431:5432 \ -d \ postgres:15.4 -until [ -n "$(docker exec $TEST_DB_CONTAINER pg_isready | grep accepting)" ]; do +until [ -n "$($CONTAINER_MANAGER exec $TEST_DB_CONTAINER pg_isready | grep accepting)" ]; do echo "Waiting for DB to come alive..." sleep $HEALTHCHECK_SLEEP done; sleep $HEALTHCHECK_SLEEP -#ROTINI_TEST=1 PYTHONPATH=rotini $VENV_PYTHON rotini/migrations/migrate.py up || fail "Migrations failed." $VENV_PYTEST . -vv -s $@ || fail "Test run failed." cleanup