diff --git a/README.md b/README.md index 22b221d..f1e89f2 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,54 @@ # HotPocket by BTHLabs This repository contains the _HotPocket_ project. + +## Development setup + +### Requirements: + +* Python 3.12, +* Poetry 1.8.3, +* `git-crypt`, +* Docker with Docker Compose and Buildx. + +### Setup + +1. `$ git-crypt unlock KEYFILE` +1. `$ poetry install` +1. `$ docker buildx bake` +1. `$ poetry run inv setup` + +### Running local development stack + +1. `$ docker compose up` + +**Exported services:** + +* The app: https://app.hotpocket.work.bthlabs.net:8000/ +* The admin: https://app.hotpocket.work.bthlabs.net:8000/ +* Keycloak: https://auth.hotpocket.work.bthlabs.net:8443/ +* Postgres: postgres://postgres.hotpocket.work.bthlabs.net:5432/ +* RabbitMQ: amqp://rabbitmq.hotpocket.work.bthlabs.net:5672/ +* RabbitMQ Management: amqp://rabbitmq.hotpocket.work.bthlabs.net:15672/ + +**Default credentials:** + +The default credentials across most of the services are: +`hotpocket:hotpocketm4st3r`. This applies to the initial app and admin account, +Keycloak master realm, Postgres and RabbitMQ. + +The Keycloak `hotpocket-development` realm user's credentials are: +`hotpocket@bthlabs.net:hotpocketm4st3r`. You can use these to log in to the app +and admin using OIDC. + +## Deployment + +TODO + +## Author + +_HotPocket_ is developed by [BTHLabs](https://www.bthlabs.pl/). + +## License + +_HotPocket_ is licensed under the Apache 2.0 License. diff --git a/poetry.lock b/poetry.lock index a0ed9f2..8295a93 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1,5 +1,18 @@ # This file is automatically @generated by Poetry 1.8.3 and should not be changed by hand. +[[package]] +name = "hotpocket-workspace-tools" +version = "1.0.0.dev0" +description = "HotPocket Workspace Tools" +optional = false +python-versions = "^3.12" +files = [] +develop = true + +[package.source] +type = "directory" +url = "services/packages/workspace_tools" + [[package]] name = "invoke" version = "2.2.0" @@ -14,4 +27,4 @@ files = [ [metadata] lock-version = "2.0" python-versions = "^3.12" -content-hash = "f82ba2e109e4c2d37ddfb64b80fa2ac34947f6c98133ce09f8c61cdd00cd930a" +content-hash = "ec33c3b3ec0f988e333872bdd134c1adce0782e98512dd2484cb85009b3da6cb" diff --git a/pyproject.toml b/pyproject.toml index 606b4eb..e08d89a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -8,6 +8,7 @@ package-mode = false [tool.poetry.dependencies] python = "^3.12" +hotpocket-workspace-tools = {path = "services/packages/workspace_tools", develop = true} invoke = "2.2.0" [build-system] diff --git a/services/backend/ops/docker/settings/webapp.py b/services/backend/ops/docker/settings/webapp.py index f72ab7a..9b141fe 100644 --- a/services/backend/ops/docker/settings/webapp.py +++ b/services/backend/ops/docker/settings/webapp.py @@ -23,6 +23,6 @@ CELERY_BEAT_SCHEDULE_FILENAME = 'run/celerybeat-schedule-docker' UPLOADS_PATH = Path( os.environ.get( 'HOTPOCKET_BACKEND_UPLOADS_PATH', - '/srv/run/uploads', + '/srv/app/run/uploads', ), ) diff --git a/services/backend/poetry.lock b/services/backend/poetry.lock index 8c6d38d..14a74c2 100644 --- a/services/backend/poetry.lock +++ b/services/backend/poetry.lock @@ -855,6 +855,19 @@ python-dateutil = "2.9.0.post0" type = "directory" url = "../packages/testing" +[[package]] +name = "hotpocket-workspace-tools" +version = "1.0.0.dev0" +description = "HotPocket Workspace Tools" +optional = false +python-versions = "^3.12" +files = [] +develop = true + +[package.source] +type = "directory" +url = "../packages/workspace_tools" + [[package]] name = "hvac" version = "2.3.0" @@ -2274,4 +2287,4 @@ brotli = ["brotli"] [metadata] lock-version = "2.0" python-versions = "^3.12" -content-hash = "777763feee98b9615a284910e9fddc9477ab4bbe42f6766cb570319319b8c488" +content-hash = "3d8cf7ddb06917472eed4724058178f36c17f40db891a19d13f5d0d758e61102" diff --git a/services/backend/pyproject.toml b/services/backend/pyproject.toml index 00240ac..9197e27 100644 --- a/services/backend/pyproject.toml +++ b/services/backend/pyproject.toml @@ -33,6 +33,7 @@ flake8-commas = "4.0.0" freezegun = "1.5.2" hotpocket-backend-testing = {path = "testing", develop = true} hotpocket-testing = {path = "../packages/testing", develop = true} +hotpocket-workspace-tools = {path = "../packages/workspace_tools", develop = true} invoke = "2.2.0" ipdb = "0.13.13" ipython = "9.3.0" diff --git a/services/backend/tasks.py b/services/backend/tasks.py index 4b1c1d0..b634d35 100644 --- a/services/backend/tasks.py +++ b/services/backend/tasks.py @@ -9,6 +9,9 @@ import os from invoke import task from invoke.exceptions import UnexpectedExit +from hotpocket_workspace_tools import get_workspace_mode + +WORKSPACE_MODE = get_workspace_mode() ENV = os.getenv('HOTPOCKET_BACKEND_ENV', 'docker') @@ -105,11 +108,10 @@ def ci(ctx): @task def setup(ctx): ctx.run('python manage.py migrate') - ctx.run('python manage.py migrate', env=dict( - DJANGO_SETTINGS_MODULE=f'hotpocket_backend.settings.{ENV}.admin', - HOTPOCKET_BACKEND_APP='admin', - )) - ctx.run('mkdir -p run/uploads') + ctx.run('python manage.py create_initial_account hotpocket hotpocketm4st3r') + + if WORKSPACE_MODE == WORKSPACE_MODE.METAL: + ctx.run('mkdir -p run/uploads') @task diff --git a/services/packages/poetry.lock b/services/packages/poetry.lock index 7da99fc..33e5a55 100644 --- a/services/packages/poetry.lock +++ b/services/packages/poetry.lock @@ -221,6 +221,19 @@ python-dateutil = "2.9.0.post0" type = "directory" url = "testing" +[[package]] +name = "hotpocket-workspace-tools" +version = "1.0.0.dev0" +description = "HotPocket Workspace Tools" +optional = false +python-versions = "^3.12" +files = [] +develop = true + +[package.source] +type = "directory" +url = "workspace_tools" + [[package]] name = "iniconfig" version = "2.1.0" @@ -889,4 +902,4 @@ files = [ [metadata] lock-version = "2.0" python-versions = "^3.12" -content-hash = "cb0ccd3db8ca24c4b439c880dbb6012bc7d9104fb59b45b9dd4738b8e975f1a8" +content-hash = "02c9f754b0dbe7e7b2f24d576f294be52027f4267b9a8ea3ac316f2eba1b881b" diff --git a/services/packages/pyproject.toml b/services/packages/pyproject.toml index 6375842..9b6e0ec 100644 --- a/services/packages/pyproject.toml +++ b/services/packages/pyproject.toml @@ -12,6 +12,7 @@ python = "^3.12" hotpocket-common = {path = "common", develop = true} hotpocket-soa = {path = "soa", develop = true} hotpocket-testing = {path = "testing", develop = true} +hotpocket-workspace-tools = {path = "workspace_tools", develop = true} [tool.poetry.group.dev.dependencies] factory-boy = "3.3.3" diff --git a/services/packages/tasks.py b/services/packages/tasks.py index 71e7de9..3d463e4 100644 --- a/services/packages/tasks.py +++ b/services/packages/tasks.py @@ -3,12 +3,12 @@ from __future__ import annotations -import os - from invoke import task from invoke.exceptions import UnexpectedExit -ENV = os.getenv('HOTPOCKET_COMMON_ENV', 'docker') +from hotpocket_workspace_tools import get_workspace_mode + +WORKSPACE_MODE = get_workspace_mode() @task @@ -89,7 +89,7 @@ def ci(ctx): @task def setup(ctx): - raise NotImplementedError() + print('NOOP') @task diff --git a/services/packages/workspace_tools/README.md b/services/packages/workspace_tools/README.md new file mode 100644 index 0000000..38b7a30 --- /dev/null +++ b/services/packages/workspace_tools/README.md @@ -0,0 +1,3 @@ +# HotPocket by BTHLabs + +This repository contains the _HotPocket Workspace Tools_ project. diff --git a/services/packages/workspace_tools/hotpocket_workspace_tools/__init__.py b/services/packages/workspace_tools/hotpocket_workspace_tools/__init__.py new file mode 100644 index 0000000..f3c99a5 --- /dev/null +++ b/services/packages/workspace_tools/hotpocket_workspace_tools/__init__.py @@ -0,0 +1,2 @@ +from .constants import WorkspaceMode # noqa: F401 +from .workspace_mode import get_workspace_mode # noqa: F401 diff --git a/services/packages/workspace_tools/hotpocket_workspace_tools/constants.py b/services/packages/workspace_tools/hotpocket_workspace_tools/constants.py new file mode 100644 index 0000000..f16825f --- /dev/null +++ b/services/packages/workspace_tools/hotpocket_workspace_tools/constants.py @@ -0,0 +1,11 @@ +# -*- coding: utf-8 -*- +from __future__ import annotations + +import enum + +DEFAULT_WORKSPACE_MODE = 'docker' + + +class WorkspaceMode(enum.Enum): + DOCKER = 'docker' + METAL = 'metal' diff --git a/services/packages/workspace_tools/hotpocket_workspace_tools/workspace_mode.py b/services/packages/workspace_tools/hotpocket_workspace_tools/workspace_mode.py new file mode 100644 index 0000000..bbacf34 --- /dev/null +++ b/services/packages/workspace_tools/hotpocket_workspace_tools/workspace_mode.py @@ -0,0 +1,17 @@ +# -*- coding: utf-8 -*- +from __future__ import annotations + +import os + +from .constants import DEFAULT_WORKSPACE_MODE, WorkspaceMode + + +def get_workspace_mode(default: str | None = None) -> WorkspaceMode: + return WorkspaceMode(os.getenv( + 'HOTPOCKET_WORKSPACE_MODE', + ( + default + if default is not None + else DEFAULT_WORKSPACE_MODE + ), + )) diff --git a/services/packages/workspace_tools/pyproject.toml b/services/packages/workspace_tools/pyproject.toml new file mode 100644 index 0000000..331e401 --- /dev/null +++ b/services/packages/workspace_tools/pyproject.toml @@ -0,0 +1,14 @@ +[tool.poetry] +name = "hotpocket-workspace-tools" +version = "1.0.0.dev0" +description = "HotPocket Workspace Tools" +authors = ["Tomek Wójcik "] +license = "BTHLabs Source Available License Agreement" +readme = "README.md" + +[tool.poetry.dependencies] +python = "^3.12" + +[build-system] +requires = ["poetry-core"] +build-backend = "poetry.core.masonry.api" diff --git a/tasks.py b/tasks.py index 35cda3e..9d66900 100644 --- a/tasks.py +++ b/tasks.py @@ -2,15 +2,10 @@ from __future__ import annotations import datetime -import enum -import os from invoke import task - -class WorkspaceMode(enum.Enum): - DOCKER = 'docker' - METAL = 'metal' +from hotpocket_workspace_tools import get_workspace_mode, WorkspaceMode class DockerBuildContext: @@ -63,16 +58,16 @@ class DockerBuildContext: ) -WORKSPACE_MODE = WorkspaceMode(os.getenv('HOTPOCKET_WORKSPACE_MODE', 'docker')) +WORKSPACE_MODE = get_workspace_mode() -ALL_SERVICES = ['backend'] +ALL_SERVICES = ['backend', 'packages'] def _run_in_service(ctx, service, command, **kwargs): match WORKSPACE_MODE: case WorkspaceMode.DOCKER: return ctx.run( - f'docker compose run --rm -it {service}-ops {command}', + f'docker compose run --rm -it {service}-management {command}', ) case WorkspaceMode.METAL: