diff --git a/Makefile b/Makefile index f09f2c467..c77ce83b1 100644 --- a/Makefile +++ b/Makefile @@ -1,26 +1,62 @@ +MY_USER := $(shell id -u) +MY_GROUP := $(shell id -g) +ME := $(MY_USER):$(MY_GROUP) + +BACKEND_CONTAINER ?= spiffworkflow-backend +BACKEND_DEV_OVERLAY ?= spiffworkflow-backend/dev.docker-compose.yml + FRONTEND_CONTAINER ?= spiffworkflow-frontend FRONTEND_DEV_OVERLAY ?= spiffworkflow-frontend/dev.docker-compose.yml -dev-env: - docker compose -f docker-compose.yml \ - -f $(FRONTEND_DEV_OVERLAY) \ - build +DOCKER_COMPOSE ?= RUN_AS=$(ME) docker compose $(YML_FILES) +IN_BACKEND ?= $(DOCKER_COMPOSE) run $(BACKEND_CONTAINER) +IN_FRONTEND ?= $(DOCKER_COMPOSE) run $(FRONTEND_CONTAINER) -start-dev: - docker compose -f docker-compose.yml \ - -f $(FRONTEND_DEV_OVERLAY) \ - up -d +YML_FILES := -f docker-compose.yml \ + -f $(BACKEND_DEV_OVERLAY) \ + -f $(FRONTEND_DEV_OVERLAY) + +all: dev-env start-dev be-tests-par + @/bin/true + +build-images: + $(DOCKER_COMPOSE) build + +dev-env: build-images fe-npm-i be-recreate-db + @/bin/true + +start-dev: stop-dev + $(DOCKER_COMPOSE) up -d stop-dev: - docker compose -f docker-compose.yml \ - -f $(FRONTEND_DEV_OVERLAY) \ - down + $(DOCKER_COMPOSE) down + +be-recreate-db: + $(IN_BACKEND) ./bin/recreate_db clean + +be-sh: + $(IN_BACKEND) /bin/bash + +be-tests: + $(IN_BACKEND) poetry run pytest + +be-tests-par: + $(IN_BACKEND) poetry run pytest -n auto -x --random-order fe-lint-fix: - docker exec -it $(FRONTEND_CONTAINER) npm run lint:fix + $(IN_FRONTEND) npm run lint:fix + +fe-npm-i: + $(IN_FRONTEND) npm i fe-sh: - docker exec -it $(FRONTEND_CONTAINER) /bin/bash + $(IN_FRONTEND) /bin/bash -.PHONY: dev-env start-dev stop-dev \ - fe-lint-fix fe-sh +take-ownership: + sudo chown -R $(ME) . + +.PHONY: build-images dev-env \ + start-dev stop-dev \ + be-recreate-db be-sh be-tests be-tests-par \ + fe-lint-fix fe-npm-i fe-sh \ + take-ownership diff --git a/spiffworkflow-backend/dev.Dockerfile b/spiffworkflow-backend/dev.Dockerfile new file mode 100644 index 000000000..72e20f11d --- /dev/null +++ b/spiffworkflow-backend/dev.Dockerfile @@ -0,0 +1,19 @@ +FROM python:3.12.1-slim-bookworm + +WORKDIR /app + +RUN apt-get update \ + && apt-get install -y -q \ + gcc libssl-dev libpq-dev default-libmysqlclient-dev \ + pkg-config libffi-dev git-core curl + +RUN pip install --upgrade pip +RUN pip install poetry==1.6.1 pytest-xdist + +COPY pyproject.toml poetry.lock . +RUN poetry install --no-root + +COPY ./ ./ +RUN poetry install --only-root + +CMD ["./bin/run_server_locally"] diff --git a/spiffworkflow-backend/dev.docker-compose.yml b/spiffworkflow-backend/dev.docker-compose.yml new file mode 100644 index 000000000..547d6b89e --- /dev/null +++ b/spiffworkflow-backend/dev.docker-compose.yml @@ -0,0 +1,17 @@ + +services: + spiffworkflow-backend: + build: + context: spiffworkflow-backend + dockerfile: dev.Dockerfile + # + # TODO: would like to figure out the permissions issue that is preventing this + # + #user: "${RUN_AS}" + environment: + FLASK_DEBUG: "1" + SPIFFWORKFLOW_BACKEND_DATABASE_URI: "" + SPIFFWORKFLOW_BACKEND_ENV: "local_development" + SPIFFWORKFLOW_BACKEND_LOAD_FIXTURE_DATA: "" + volumes: + - ./spiffworkflow-backend:/app diff --git a/spiffworkflow-backend/src/spiffworkflow_backend/config/unit_testing.py b/spiffworkflow-backend/src/spiffworkflow_backend/config/unit_testing.py index 26824dbac..e15a539ea 100644 --- a/spiffworkflow-backend/src/spiffworkflow_backend/config/unit_testing.py +++ b/spiffworkflow-backend/src/spiffworkflow_backend/config/unit_testing.py @@ -5,10 +5,9 @@ from os import environ TESTING = True SPIFFWORKFLOW_BACKEND_LOG_TO_FILE = environ.get("SPIFFWORKFLOW_BACKEND_LOG_TO_FILE", default="true") == "true" -SPIFFWORKFLOW_BACKEND_PERMISSIONS_FILE_NAME = environ.get( - "SPIFFWORKFLOW_BACKEND_PERMISSIONS_FILE_NAME", default="unit_testing.yml" -) +SPIFFWORKFLOW_BACKEND_PERMISSIONS_FILE_NAME = "unit_testing.yml" +SPIFFWORKFLOW_BACKEND_URL = "http://localhost:7000" SPIFFWORKFLOW_BACKEND_OPEN_ID_SERVER_URL = "http://localhost:7000/openid" SPIFFWORKFLOW_BACKEND_OPEN_ID_CLIENT_ID = "spiffworkflow-backend" SPIFFWORKFLOW_BACKEND_OPEN_ID_CLIENT_SECRET_KEY = "JXeQExm0JhQPLumgHtIIqf52bDalHz0q" # noqa: S105 diff --git a/spiffworkflow-frontend/dev.docker-compose.yml b/spiffworkflow-frontend/dev.docker-compose.yml index 37669061c..3e5e5d87f 100644 --- a/spiffworkflow-frontend/dev.docker-compose.yml +++ b/spiffworkflow-frontend/dev.docker-compose.yml @@ -3,6 +3,7 @@ services: build: context: spiffworkflow-frontend dockerfile: dev.Dockerfile + user: "${RUN_AS}" environment: HOST: "0.0.0.0" PORT: "${SPIFFWORKFLOW_FRONTEND_PORT:-8001}"