diff --git a/.gitignore b/.gitignore index c639e95f4aa8..7f6f061c6f70 100644 --- a/.gitignore +++ b/.gitignore @@ -14,6 +14,7 @@ checkstyle.txt .envrc .tool-versions .elasticbeanstalk/ +.local/ # These get baked into the docker container on build src/CI_COMMIT_SHA diff --git a/api/run b/api/run new file mode 100755 index 000000000000..a5fce1c3f930 --- /dev/null +++ b/api/run @@ -0,0 +1,37 @@ +#!/bin/sh +set -e + +# Runs any command from within an `api` container. +# If no command is given, it runs the application's default command. + +# NOTE: This script is intended as a one-command option to run Flagsmith code +# with no previous setup except from installing Docker. + +# Requirements: +# - Docker + +# Examples: +# - `./run` — runs pending migrations and starts the API HTTP server in dev mode. +# - `./run bash` — starts a bash shell in the API container. +# - `./run python manage.py makemigrations` — runs the command in the API container. +# - `./run flagsmith createsuperuser` — the Flagsmith CLI should be there too! +# - `./run pytest --sw --pdb tests/unit/test_my_feature.py` — you get it. +SCRIPT=$(readlink -f "$0") +SCRIPT_DIR=$(dirname "$SCRIPT") +ROOT_DIR=$(cd "$SCRIPT_DIR/.."; pwd -P) + +opts="--rm" + +if [ $# -eq 0 ]; then + # Run default command, i.e. API server + opts="$opts --service-ports --use-aliases --workdir /opt/app/api" +else + PWD=$(pwd -P) + WORKING_DIR=$(echo "$PWD" | sed "s|$ROOT_DIR||") + if [ -n "${WORKING_DIR}" ]; then + opts="$opts --workdir /opt/app${WORKING_DIR}" + fi +fi + +set -x +docker compose -f "${ROOT_DIR}/docker/new/docker-compose.yml" run $opts api "$@" diff --git a/docker/new/docker-compose.yml b/docker/new/docker-compose.yml new file mode 100644 index 000000000000..4e23121a5351 --- /dev/null +++ b/docker/new/docker-compose.yml @@ -0,0 +1,57 @@ +# Reusable app definition +x-app: &app + image: ${DOCKER_IMAGE:-local/flagsmith/flagsmith}:${DOCKER_TAG:-latest} + build: + context: ../../ + target: oss-unified + args: + POETRY_VERSION: 2.1.1 + INSTALL_DEV_DEPENDENCIES: true + depends_on: + default-database: + condition: service_healthy + task-processor-database: + condition: service_healthy + environment: + # LOG_LEVEL: DEBUG + DATABASE_URL: postgres://postgres@default-database:5432/postgres + DEBUG: true + DJANGO_SETTINGS_MODULE: app.settings.local + TASK_PROCESSOR_DATABASE_URL: postgres://postgres@task-processor-database:5432/postgres + TASK_PROCESSOR_DATABASES: task_processor + volumes: + # - ?:/app:rw,cached # Application directory + +services: + api: + <<: *app + command: migrate-and-serve + ports: + - 8000:8000 + + # TODO + task-processor: + <<: *app + command: run-task-processor + + default-database: + image: postgres:15.5-alpine + volumes: + - ../../.local/default-database:/var/lib/postgresql/data:rw,cached + environment: + POSTGRES_HOST_AUTH_METHOD: trust + healthcheck: + test: pg_isready -Upostgres + interval: 1s + timeout: 30s + + task-processor-database: + image: postgres:15.5-alpine + volumes: + - ../../.local/task-processor-database:/var/lib/postgresql/data:rw,cached + environment: + POSTGRES_HOST_AUTH_METHOD: trust + healthcheck: + test: pg_isready -Upostgres + interval: 1s + timeout: 30s