From 84e6e4595460f5661862781ce168573063e1503f Mon Sep 17 00:00:00 2001 From: Rui Conti Date: Mon, 22 Mar 2021 19:27:39 -0300 Subject: [PATCH 01/14] feat: Sets-up first version of docker and docker compose ymls --- Dockerfile | 21 +++++++++++++++++++++ docker-compose.yml | 44 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+) create mode 100644 Dockerfile create mode 100644 docker-compose.yml diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..b139a8e --- /dev/null +++ b/Dockerfile @@ -0,0 +1,21 @@ +FROM python:3.8.8-slim-buster + +# python is already updated +# os is already updated + +WORKDIR /app +COPY requirements.txt . +RUN pip install --no-cache-dir -r requirements.txt + +COPY . . +EXPOSE 5000 + +ENV HOST_UID $(id -u) +ENV HOST_USER + +RUN [ $USER == "root" ] || \ + (adduser -h /home/$(whoami) -D -u $(whoami) +# CMD uvicorn src.server.app:app --port 5000 --host 0.0.0.0 --loop uvloop --log-level info --workers 8 +CMD ["sh", "docker/entrypoint.sh"] + + diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..99fc187 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,44 @@ +version: "3.9" + +x-common-variables: &common-variables + POSTGRES_USER: ${POSTGRES_USER:-postgres} + POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-postgres} + POSTGRES_DB: ${POSTGRES_DB:-template} + +services: + dbpg: + container_name: postgres + image: postgres + environment: + <<: *common-variables + PGDATA: /data/postgres + ports: + - "5432:5432" + networks: + - backend + restart: unless-stopped + + web: + environment: + <<: *common-variables + POSTGRES_HOST: dbpg + MAX_CONCURRENCY: 8 + HOST: "0.0.0.0" + PORT: "5000" + image: kms:test + build: + context: . + ports: + - "5000:5000" + depends_on: + - dbpg + volumes: + - ./:/app + networks: + - backend + restart: unless-stopped + + +networks: + backend: + driver: bridge From 61c10ec34dc5532a4e22cad7242e10470e002570 Mon Sep 17 00:00:00 2001 From: Rui Conti Date: Mon, 22 Mar 2021 19:28:32 -0300 Subject: [PATCH 02/14] refactor: Centers ORM business under ORM module --- src/config.py | 15 ++++++++++++++- src/core/ports/unit_of_work.py | 15 ++------------- src/orm.py | 14 +++++++++++++- 3 files changed, 29 insertions(+), 15 deletions(-) diff --git a/src/config.py b/src/config.py index 4fd42bb..6076742 100644 --- a/src/config.py +++ b/src/config.py @@ -2,7 +2,20 @@ from typing import Any POSTGRES_URI_TEMPLATE = "postgresql://{}:{}@{}:{}/{}" -POSTGRES_DEFAULT = ("postgres", "", "localhost", 5432, "template") + +PG_USER = os.environ.get("POSTGRES_USER", "postgres") +PG_PASSWORD = os.environ.get("POSTGRES_PASSWORD", "postgres") +PG_HOST = os.environ.get("POSTGRES_HOST", "localhost") +PG_PORT = os.environ.get("POSTGRES_PORT", 5432) +PG_DB = os.environ.get("POSTGRES_DB", "template") + +POSTGRES_DEFAULT = ( + PG_USER, + PG_PASSWORD, + PG_HOST, + PG_PORT, + PG_DB +) def default_user() -> tuple: diff --git a/src/core/ports/unit_of_work.py b/src/core/ports/unit_of_work.py index a23d2e4..95381cd 100644 --- a/src/core/ports/unit_of_work.py +++ b/src/core/ports/unit_of_work.py @@ -1,20 +1,9 @@ import abc from typing import Callable, Generator -from sqlalchemy import create_engine, orm - -from src import config +from src import orm from src.core.ports import repository -DEFAULT_SESSION_FACTORY = orm.sessionmaker( - bind=create_engine( - # ISOLATION LEVEL ENSURES aggregate's version IS RESPECTED - # That is, if version differs it will raise an exception - config.get_postgres_uri(), - isolation_level="REPEATABLE_READ", - ), - autoflush=False, -) class AbstractUnitOfWork(abc.ABC): @@ -50,7 +39,7 @@ def rollback(self) -> None: class SqlAlchemyUnitOfWork(AbstractUnitOfWork): session: orm.Session - def __init__(self, session_factory: Callable = DEFAULT_SESSION_FACTORY): + def __init__(self, session_factory: Callable = orm.DEFAULT_SESSION_FACTORY): self.session_factory: Callable = session_factory def __exit__(self, *args): # type: ignore diff --git a/src/orm.py b/src/orm.py index f98818e..fbc9886 100644 --- a/src/orm.py +++ b/src/orm.py @@ -1,6 +1,18 @@ -from sqlalchemy import MetaData +from sqlalchemy.orm import Session +from sqlalchemy import create_engine, orm, MetaData + +from src import config import src.auth.adapters.orm +DEFAULT_SESSION_FACTORY: Session = orm.sessionmaker( + bind=create_engine( + # ISOLATION LEVEL ENSURES aggregate's version IS RESPECTED + # That is, if version differs it will raise an exception + config.get_postgres_uri(), + isolation_level="REPEATABLE_READ", + ), + autoflush=False, +) def start_mappers() -> MetaData: """ From 34c9131c181d652a4f4b22a790c85f39302b728d Mon Sep 17 00:00:00 2001 From: Rui Conti Date: Mon, 22 Mar 2021 19:29:01 -0300 Subject: [PATCH 03/14] refactor: Changes Makefile to use docker commands --- Makefile | 23 +++++++++++++++++++++-- docker/entrypoint.sh | 3 +++ docker/init-user-db.sh | 9 +++++++++ docker/migration.sh | 2 ++ docker/test.sh | 5 +++++ docker/uvicorn.sh | 1 + 6 files changed, 41 insertions(+), 2 deletions(-) create mode 100644 docker/entrypoint.sh create mode 100644 docker/init-user-db.sh create mode 100644 docker/migration.sh create mode 100644 docker/test.sh create mode 100644 docker/uvicorn.sh diff --git a/Makefile b/Makefile index 09c0558..cfe0417 100644 --- a/Makefile +++ b/Makefile @@ -1,8 +1,11 @@ .phony: test +PROJECT_NAME=$(notdir $(PWD)) +HOST_NAME=$(USER) +CONTAINER_UID=$(HOSTNAME)_$(PROJECT_NAME) -tests: +test-local: @echo "*** `tests` directory should exist at project root. Stop." db-migration: @@ -18,5 +21,21 @@ test-integration: test-e2e: pytest --color=yes --showlocals --tb=short -v tests/auth/e2e -test: tests db-migration test-unit test-integration test-e2e +test-local: tests db-migration test-unit test-integration test-e2e + +build: + docker-compose build + +test: + docker-compose -p $(CONTAINER_UID) run --rm --use-aliases --service-ports web docker/test.sh + +clean: + docker-compose -p $(CONTAINER_UID) down --remove-orphans --rmi all 2>/dev/null + +web: + docker-compose -p $(CONTAINER_UID) up + +prune: + docker system prune -af + diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh new file mode 100644 index 0000000..fe8847c --- /dev/null +++ b/docker/entrypoint.sh @@ -0,0 +1,3 @@ +#/bin/bash +# sh ./docker/migration.sh && sh ./docker/uvicorn.sh +sh ./docker/migration.sh && sh ./docker/test.sh diff --git a/docker/init-user-db.sh b/docker/init-user-db.sh new file mode 100644 index 0000000..559b476 --- /dev/null +++ b/docker/init-user-db.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +set -e + +psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-EOSQL + CREATE USER tester; + CREATE DATABASE court; + GRANT ALL PRIVILEGES ON DATABASE court TO tester; +EOSQL diff --git a/docker/migration.sh b/docker/migration.sh new file mode 100644 index 0000000..a2e2a5c --- /dev/null +++ b/docker/migration.sh @@ -0,0 +1,2 @@ +alembic -x data=true downgrade base +alembic -x data=true upgrade head diff --git a/docker/test.sh b/docker/test.sh new file mode 100644 index 0000000..7362247 --- /dev/null +++ b/docker/test.sh @@ -0,0 +1,5 @@ +#!/bash/sh +sh docker/migration.sh +pytest --color=yes --showlocals --tb=short -v tests/auth/unit +pytest --color=yes --showlocals --tb=short -v tests/auth/integration +pytest --color=yes --showlocals --tb=short -v tests/auth/e2e diff --git a/docker/uvicorn.sh b/docker/uvicorn.sh new file mode 100644 index 0000000..a6e1053 --- /dev/null +++ b/docker/uvicorn.sh @@ -0,0 +1 @@ +uvicorn src.server.app:app --port $PORT --host $HOST --loop uvloop --log-level info --workers $MAX_CONCURRENCY From 60999d945f5eec4002b1fb8d6e8f6bd719068cf2 Mon Sep 17 00:00:00 2001 From: Rui Conti Date: Mon, 22 Mar 2021 19:29:23 -0300 Subject: [PATCH 04/14] refactor: Minor changes in migrations --- migrations/env.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/migrations/env.py b/migrations/env.py index bbbd0dd..daeada8 100644 --- a/migrations/env.py +++ b/migrations/env.py @@ -12,7 +12,7 @@ from alembic import context from src import config as config_app -from src.federation import init +from src.federation import init # this is the Alembic Config object, which provides # access to the values within the .ini file in use. From 291a4abd13bf1c91161fdc29d20652afc2373a43 Mon Sep 17 00:00:00 2001 From: Rui Conti Date: Tue, 23 Mar 2021 16:37:24 -0300 Subject: [PATCH 05/14] feat: Improve user security on container process --- Dockerfile | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/Dockerfile b/Dockerfile index b139a8e..26f973f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,21 +1,29 @@ FROM python:3.8.8-slim-buster -# python is already updated -# os is already updated -WORKDIR /app +ARG PROJECT_NAME=${PROJECT_NAME:-kps} +ARG HOST_UID=${HOST_UID:-9000} +ARG HOST_USER=${HOST_USER:-app} + +ENV HOST_HOME=/home/$HOST_USER +ENV APP_DIR=$HOST_HOME/$PROJECT_NAME + +# Create a new system user with proper permissions to its home directory +# so that all dependencies are installed properly +RUN adduser --home /home/$HOST_USER --uid $HOST_UID $HOST_USER --quiet --system \ + && chown -R $HOST_UID:$HOST_UID $HOST_HOME \ + && mkdir $APP_DIR + +USER $HOST_USER +WORKDIR $APP_DIR +ENV PATH $HOST_HOME/.local/bin:$PATH + COPY requirements.txt . RUN pip install --no-cache-dir -r requirements.txt -COPY . . -EXPOSE 5000 +# Updates contents and permission +COPY . . -ENV HOST_UID $(id -u) -ENV HOST_USER +EXPOSE 5000 -RUN [ $USER == "root" ] || \ - (adduser -h /home/$(whoami) -D -u $(whoami) -# CMD uvicorn src.server.app:app --port 5000 --host 0.0.0.0 --loop uvloop --log-level info --workers 8 CMD ["sh", "docker/entrypoint.sh"] - - From 7c29a7c80cd38242248751d3334c7c5e8983152d Mon Sep 17 00:00:00 2001 From: Rui Conti Date: Tue, 23 Mar 2021 16:37:42 -0300 Subject: [PATCH 06/14] feat: Extends commands available to Makefile --- Makefile | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index cfe0417..00e2d7e 100644 --- a/Makefile +++ b/Makefile @@ -2,8 +2,11 @@ test PROJECT_NAME=$(notdir $(PWD)) -HOST_NAME=$(USER) -CONTAINER_UID=$(HOSTNAME)_$(PROJECT_NAME) +HOST_NAME=$USER +CONTAINER_UID=$(HOSTNAME)_$PROJECT_NAME + +# Sanity check & removal of idle postgres images +IDLE_CONTAINERS = $(shell docker ps -aq -f name=postgres -f name=web) test-local: @echo "*** `tests` directory should exist at project root. Stop." @@ -24,16 +27,17 @@ test-e2e: test-local: tests db-migration test-unit test-integration test-e2e build: - docker-compose build + docker-compose build test: - docker-compose -p $(CONTAINER_UID) run --rm --use-aliases --service-ports web docker/test.sh + docker-compose -p $(CONTAINER_UID) run --rm --use-aliases --service-ports web sh docker/test.sh clean: - docker-compose -p $(CONTAINER_UID) down --remove-orphans --rmi all 2>/dev/null + @[ ! -z $(IDLE_CONTAINERS) ] && (docker kill $(IDLE_CONTAINERS) && docker rm $(IDLE_CONTAINERS)) + @docker-compose -p $(CONTAINER_UID) down --remove-orphans 2>/dev/null web: - docker-compose -p $(CONTAINER_UID) up + docker-compose -p $(CONTAINER_UID) up prune: docker system prune -af From 2ef4d6d5a97a42eb6de9eba4ce29bcd26ce7564b Mon Sep 17 00:00:00 2001 From: Rui Conti Date: Tue, 23 Mar 2021 16:38:08 -0300 Subject: [PATCH 07/14] feat: Passes Dockerfile args --- docker-compose.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docker-compose.yml b/docker-compose.yml index 99fc187..ae075f3 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -28,6 +28,9 @@ services: image: kms:test build: context: . + args: + - HOST_UID=${HOST_UID:-9000} + - HOST_USER=${HOST_USER:-app} ports: - "5000:5000" depends_on: From 61828679a7645fda5fa92b3515c3460c91a106be Mon Sep 17 00:00:00 2001 From: Rui Conti Date: Tue, 23 Mar 2021 16:38:33 -0300 Subject: [PATCH 08/14] chore: Makes'em executables --- docker/entrypoint.sh | 5 ++--- docker/init-user-db.sh | 0 docker/migration.sh | 0 docker/test.sh | 0 docker/uvicorn.sh | 0 5 files changed, 2 insertions(+), 3 deletions(-) mode change 100644 => 100755 docker/entrypoint.sh mode change 100644 => 100755 docker/init-user-db.sh mode change 100644 => 100755 docker/migration.sh mode change 100644 => 100755 docker/test.sh mode change 100644 => 100755 docker/uvicorn.sh diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh old mode 100644 new mode 100755 index fe8847c..6a4b42b --- a/docker/entrypoint.sh +++ b/docker/entrypoint.sh @@ -1,3 +1,2 @@ -#/bin/bash -# sh ./docker/migration.sh && sh ./docker/uvicorn.sh -sh ./docker/migration.sh && sh ./docker/test.sh +#!/bin/bash +sh docker/uvicorn.sh diff --git a/docker/init-user-db.sh b/docker/init-user-db.sh old mode 100644 new mode 100755 diff --git a/docker/migration.sh b/docker/migration.sh old mode 100644 new mode 100755 diff --git a/docker/test.sh b/docker/test.sh old mode 100644 new mode 100755 diff --git a/docker/uvicorn.sh b/docker/uvicorn.sh old mode 100644 new mode 100755 From e748feb6445d9e2f9b644aa6ca5a7bbc9f7ec5c2 Mon Sep 17 00:00:00 2001 From: Rui Conti Date: Tue, 23 Mar 2021 16:52:19 -0300 Subject: [PATCH 09/14] refactor: clean now properly kills and rms containers --- Makefile | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 00e2d7e..0adac3f 100644 --- a/Makefile +++ b/Makefile @@ -2,11 +2,12 @@ test PROJECT_NAME=$(notdir $(PWD)) -HOST_NAME=$USER -CONTAINER_UID=$(HOSTNAME)_$PROJECT_NAME +HOST_NAME=${USER} +CONTAINER_UID=$(HOST_NAME)_${PROJECT_NAME} # Sanity check & removal of idle postgres images IDLE_CONTAINERS = $(shell docker ps -aq -f name=postgres -f name=web) +UP_CONTAINERS = $(shell docker ps -q -f name=postgres -f name=web) test-local: @echo "*** `tests` directory should exist at project root. Stop." @@ -27,14 +28,15 @@ test-e2e: test-local: tests db-migration test-unit test-integration test-e2e build: - docker-compose build + @docker-compose build test: docker-compose -p $(CONTAINER_UID) run --rm --use-aliases --service-ports web sh docker/test.sh clean: - @[ ! -z $(IDLE_CONTAINERS) ] && (docker kill $(IDLE_CONTAINERS) && docker rm $(IDLE_CONTAINERS)) @docker-compose -p $(CONTAINER_UID) down --remove-orphans 2>/dev/null + @[ ! -z "$(UP_CONTAINERS)" ] && docker kill $(UP_CONTAINERS) || echo "Neat." + @[ ! -z "$(IDLE_CONTAINERS)" ] && docker rm $(IDLE_CONTAINERS) || echo "Clean." web: docker-compose -p $(CONTAINER_UID) up From f61a37e78ed15596f3ce0b1d79de1e78be4bf493 Mon Sep 17 00:00:00 2001 From: Rui Conti Date: Wed, 24 Mar 2021 18:19:40 -0300 Subject: [PATCH 10/14] refactor: Changes containers names and persist db volume --- .gitignore | 1 + docker-compose.yml | 10 ++++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 7c28183..0b53c76 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,7 @@ __pycache__/ management/ management.py tests/resources/ +db-pgdata/ # Elastic Beanstalk Files .elasticbeanstalk/ diff --git a/docker-compose.yml b/docker-compose.yml index ae075f3..f5d0933 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -7,13 +7,15 @@ x-common-variables: &common-variables services: dbpg: - container_name: postgres + container_name: ${PROJECT_NAME}_postgres image: postgres environment: <<: *common-variables PGDATA: /data/postgres ports: - "5432:5432" + volumes: + - ./db-pgdata:/var/lib/postgresql/data/pgdata networks: - backend restart: unless-stopped @@ -22,9 +24,10 @@ services: environment: <<: *common-variables POSTGRES_HOST: dbpg - MAX_CONCURRENCY: 8 + MAX_CONCURRENCY: 1 HOST: "0.0.0.0" PORT: "5000" + container_name: ${PROJECT_NAME}_web image: kms:test build: context: . @@ -45,3 +48,6 @@ services: networks: backend: driver: bridge + +volumes: + db-pgdata: From f68d5160e6b32d0342466ed3929c228dfd41acb7 Mon Sep 17 00:00:00 2001 From: Rui Conti Date: Wed, 24 Mar 2021 18:19:59 -0300 Subject: [PATCH 11/14] refactor: Exposes PROJECT_NAME variable to child processes --- Makefile | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 0adac3f..5222dd1 100644 --- a/Makefile +++ b/Makefile @@ -4,6 +4,7 @@ PROJECT_NAME=$(notdir $(PWD)) HOST_NAME=${USER} CONTAINER_UID=$(HOST_NAME)_${PROJECT_NAME} +export PROJECT_NAME $(PROJECT_NAME) # Sanity check & removal of idle postgres images IDLE_CONTAINERS = $(shell docker ps -aq -f name=postgres -f name=web) @@ -31,7 +32,7 @@ build: @docker-compose build test: - docker-compose -p $(CONTAINER_UID) run --rm --use-aliases --service-ports web sh docker/test.sh + @docker-compose -p $(CONTAINER_UID) run --rm --use-aliases --service-ports web sh docker/test.sh clean: @docker-compose -p $(CONTAINER_UID) down --remove-orphans 2>/dev/null @@ -39,7 +40,7 @@ clean: @[ ! -z "$(IDLE_CONTAINERS)" ] && docker rm $(IDLE_CONTAINERS) || echo "Clean." web: - docker-compose -p $(CONTAINER_UID) up + @docker-compose -p $(CONTAINER_UID) up prune: docker system prune -af From 204a7e3a8bc26b2ea6dcc58fd52137051e2bf8de Mon Sep 17 00:00:00 2001 From: Rui Conti Date: Wed, 24 Mar 2021 18:20:30 -0300 Subject: [PATCH 12/14] fix: Fixes permission setting on container --- Dockerfile | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/Dockerfile b/Dockerfile index 26f973f..df917d1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,21 +7,27 @@ ARG HOST_USER=${HOST_USER:-app} ENV HOST_HOME=/home/$HOST_USER ENV APP_DIR=$HOST_HOME/$PROJECT_NAME +ENV PATH $HOST_HOME/.local/bin:$PATH + +# Create a user specifically for app running +# Sets them with enough permissions in its home dir +RUN adduser --home $HOST_HOME --uid $HOST_UID $HOST_USER --quiet --system --group \ + && chown -R $HOST_UID:$HOST_UID $HOST_HOME/ \ + && chmod -R 770 $HOST_HOME \ + && chmod g+s $HOST_HOME -# Create a new system user with proper permissions to its home directory -# so that all dependencies are installed properly -RUN adduser --home /home/$HOST_USER --uid $HOST_UID $HOST_USER --quiet --system \ - && chown -R $HOST_UID:$HOST_UID $HOST_HOME \ - && mkdir $APP_DIR +# Switches to created user +USER $HOST_UID -USER $HOST_USER +# Creates an app dir +RUN mkdir $APP_DIR WORKDIR $APP_DIR -ENV PATH $HOST_HOME/.local/bin:$PATH +# Copies and installs requirements COPY requirements.txt . RUN pip install --no-cache-dir -r requirements.txt -# Updates contents and permission +# Finishes copying code COPY . . EXPOSE 5000 From 034e146c5ca7e8eb924e06906041b845620b543c Mon Sep 17 00:00:00 2001 From: Rui Conti Date: Wed, 24 Mar 2021 18:25:17 -0300 Subject: [PATCH 13/14] chore: Properly kills and removes pg container after tests --- Makefile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Makefile b/Makefile index 5222dd1..740c0eb 100644 --- a/Makefile +++ b/Makefile @@ -33,6 +33,8 @@ build: test: @docker-compose -p $(CONTAINER_UID) run --rm --use-aliases --service-ports web sh docker/test.sh + @docker kill $(PROJECT_NAME)_postgres + @docker rm $(PROJECT_NAME)_postgres clean: @docker-compose -p $(CONTAINER_UID) down --remove-orphans 2>/dev/null From 1cac9c4c8aaaf0ae1f517ffa59245d29d95a5fbc Mon Sep 17 00:00:00 2001 From: Rui Conti Date: Wed, 24 Mar 2021 19:45:41 -0300 Subject: [PATCH 14/14] doc: Includes docker instructions --- Makefile | 2 +- README.md | 47 +++++++++++++++++++++++++++++++++++++++-------- 2 files changed, 40 insertions(+), 9 deletions(-) diff --git a/Makefile b/Makefile index 740c0eb..abbff5c 100644 --- a/Makefile +++ b/Makefile @@ -41,7 +41,7 @@ clean: @[ ! -z "$(UP_CONTAINERS)" ] && docker kill $(UP_CONTAINERS) || echo "Neat." @[ ! -z "$(IDLE_CONTAINERS)" ] && docker rm $(IDLE_CONTAINERS) || echo "Clean." -web: +service: @docker-compose -p $(CONTAINER_UID) up prune: diff --git a/README.md b/README.md index f892c84..693d69d 100644 --- a/README.md +++ b/README.md @@ -33,21 +33,52 @@ This is project's in its early stages, and should receive a big WIP tag. We shou ## Instructions -As it is disclaimed the project current status, running *for now* means making sure tests pass. -We are shortly improving the entire installation experience and usage. Hold tight. +There are two ways to run this: i. Locally, through a virtual pyenv; ii. Using `docker-compose`. -### Step 1: Dependencies & environment +We like `Makefile` interface and while we also don't deliver an appropriate and fancy CLI, commands will be handled there. +To find out which commands are available, `cat Makefile`. + +This projects uses `poetry` to manage dependencies. Even though `poetry` is way too slow to run `poetry install`, we find +that for managing dependencies' version compatibility is a valuable tool. + +While we don't have a fully automated build pipeline, we agree to `poetry export -f requirements.txt > requirements.txt`. + +### Local docker + +Make sure docker daemon is running. + +### Step 1: Build image + +```bash +make build +``` + +### Step 2: Serve it or test it + +```bash +make service +make test +``` + +### Step 3 (Optional): Clean containers + +```bash +make clean +``` + +### Local python + +#### Step 1: Dependencies & environment -This projects uses `poetry` to manage dependencies. Having said that, how you instantiate your virtual environment is up to you. You can do that now. Inside your blank python virtual environment: ```shell -pip install poetry && poetry install +pip install -r requirements.txt ``` -### Step 2: Prepare your database +#### Step 2: Prepare your database As there aren't any containerization being done for now, you'd need `postgres` up and running in your local machine. @@ -55,12 +86,12 @@ As there aren't any containerization being done for now, you'd need `postgres` u psql -c "create database template" ``` -### Step 3: Test it +#### Step 3: Test it Right now you should be able to run the entire test-suite properly. ```shell -make test +make test-local ```