From 0697803f8f59857892241846032e0e80ab7f0654 Mon Sep 17 00:00:00 2001 From: Igor Perepilitsyn Date: Fri, 15 May 2020 09:01:59 +0300 Subject: [PATCH 1/4] add a simple method to bootstrap its_on --- docker-compose.yml | 28 ++++++++++++++++++++++++++++ entrypoint.sh | 8 ++++---- 2 files changed, 32 insertions(+), 4 deletions(-) create mode 100644 docker-compose.yml diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..7a6677c --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,28 @@ +version: '3' +services: + cache: + image: redis + container_name: its-on-redis + + db: + image: postgres + container_name: its-on-postgres + environment: + POSTGRES_PASSWORD: strongpassword + POSTGRES_USER: itson + POSTGRES_DB: itson + + web: + image: bestdoctor/its_on:local + build: . + container_name: its-on + environment: + DYNACONF_HOST: '0.0.0.0' + DYNACONF_DATABASE__dsn: postgresql://itson:strongpassword@db:5432/itson + DYNACONF_REDIS_URL: redis://cache:6379/0 + DYNACONF_CACHE_URL: redis://cache:6379/1 + ports: + - "127.0.0.1:8081:8081" + depends_on: + - cache + - db diff --git a/entrypoint.sh b/entrypoint.sh index f7d7dcc..96852b5 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -4,16 +4,13 @@ if [ -z "$1" ] then echo "No argument supplied" exit 1 -elif [ $1 = "migrate" ] - then - exec alembic upgrade head - exit $? elif [ $1 = "test" ] then exec make check exit $? elif [ $1 = "run" ] then + alembic upgrade head rm -rf /srv/www/its_on/static cp -r /its_on/its_on/static /srv/www/its_on exec gunicorn --bind 0.0.0.0:8081 \ @@ -25,4 +22,7 @@ elif [ $1 = "run" ] --worker-class aiohttp.GunicornUVLoopWebWorker \ its_on.main:init_gunicorn_app exit $? +else + echo "Invalid argument" + exit 1 fi From 410578a8e3f6c75ab5110278041ee686dd8ab345 Mon Sep 17 00:00:00 2001 From: Igor Perepilitsyn Date: Fri, 15 May 2020 09:04:53 +0300 Subject: [PATCH 2/4] add notes on running with docker in README --- README.md | 119 +++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 87 insertions(+), 32 deletions(-) diff --git a/README.md b/README.md index f09695d..015078b 100644 --- a/README.md +++ b/README.md @@ -4,20 +4,28 @@ [![Maintainability](https://api.codeclimate.com/v1/badges/35e678c4d05199a31eb9/maintainability)](https://codeclimate.com/github/best-doctor/its_on/maintainability) [![Test Coverage](https://api.codeclimate.com/v1/badges/35e678c4d05199a31eb9/test_coverage)](https://codeclimate.com/github/best-doctor/its_on/test_coverage) -flag/feature toggle service, written in aiohttp. +Flag/feature toggle service, written in aiohttp. ## API Reference ------- +### Basic + | Method | Endpoint | Description | | ------- | ---------------------------| ----------------------------------- | | `GET` | `/api/docs` | Api documentation | | `GET` | `/api/v1/switch` | List of active flags for the group. | +### Admin + +| Endpoint | Description | +| --------------------------------| -------------------------- | +| `/zbs/login` | Login form | +| `/zbs/switches` | List of flags | +| `/zbs/switches/{switch_id}` | Flag detail | + ## Sample /api/v1/switch output ```json - { "count": 2, "result": ["test_flag3", "test_flag4"] @@ -26,39 +34,86 @@ flag/feature toggle service, written in aiohttp. ## Installation -1. Clone repo - - `$ git clone git@gitlab.com:bestdoctor/public/its_on.git` -1. Install python packages - - `$ pip install -r requirements.txt` -1. Specify redis connection settings - - `$ export DYNACONF_REDIS_URL=redis://127.0.0.1:6379/1` - - default: `redis://127.0.0.1:6379/1` -1. Specify cache settings - - `$ export DYNACONF_CACHE_URL=redis://127.0.0.1:6379/1` - - default: `redis://127.0.0.1:6379/1` -1. Specify database connection settings - - `$ export DYNACONF_DATABASE__dsn=postgresql://user:password@127.0.0.1:5432/its_on` - - default: `postgresql://bestdoctor:bestdoctor@127.0.0.1:5432/its_on` -1. Apply DB migrations - - `$ alembic upgrade head` -1. Create user - - `$ python script/create_user.py --login=admmin --password=passwordd --is_superuser` -1. Run project - - `$ python -m its_on` -1. Open project - - `open http://localhost:8081/api/docs` +### Prerequisites -## Testing +`its_on` requires an SQL database and a cache storage engine. Currently, only PostgreSQL and Redis are supported as respective backends. -`$ make test` +### Manual -## Admin +Clone repo: -| Endpoint | Description | -| --------------------------------| -------------------------- | -| `/zbs/login` | Login form | -| `/zbs/switches` | List of flags | -| `/zbs/switches/{switch_id}` | Flag detail | +`$ git clone git@gitlab.com:bestdoctor/public/its_on.git` + +Install python packages: + +`$ pip install -r requirements.txt` + +Specify database and cache settings: + +```env +export DYNACONF_REDIS_URL=redis://127.0.0.1:6379/1 +export DYNACONF_CACHE_URL=redis://127.0.0.1:6379/1 +export DYNACONF_DATABASE__dsn=postgresql://user:password@127.0.0.1:5432/its_on +``` + +Apply database migrations: + +`$ alembic upgrade head` + +Create admin user: + +`$ python script/create_user.py --login=admmin --password=passwordd --is_superuser` + +Run server: + +`$ python -m its_on` + +Navigate to `http://127.0.0.1:8081/api/docs` in your browser and you are good to go! + +### Docker + +Example `docker-compose.yml` file: + +``` +version: '3' +services: + cache: + image: redis + container_name: its-on-redis + + db: + image: postgres + container_name: its-on-postgres + environment: + POSTGRES_PASSWORD: strongpassword + POSTGRES_USER: itson + POSTGRES_DB: itson + + web: + image: bestdoctor/its_on:latest-dev + container_name: its-on + environment: + DYNACONF_HOST: '0.0.0.0' + DYNACONF_DATABASE__dsn: postgresql://itson:strongpassword@db:5432/itson + DYNACONF_REDIS_URL: redis://cache:6379/0 + DYNACONF_CACHE_URL: redis://cache:6379/1 + ports: + - "127.0.0.1:8081:8081" + depends_on: + - cache + - db + +``` + +Don't forget to create a superuser: + +`docker exec -t its-on python scripts/create_user.py --login=admin --password=passwordd --is_superuser` + +Navigate to `http://127.0.0.1:8081/api/docs` in your browser and you are good to go! + +## Testing + +Run `make test` ## Contributing From 581b7021982429518b8a328b916dca7c8f6d5c10 Mon Sep 17 00:00:00 2001 From: Igor Perepilitsyn Date: Fri, 15 May 2020 09:13:30 +0300 Subject: [PATCH 3/4] fix CI errors --- README.md | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 015078b..a156910 100644 --- a/README.md +++ b/README.md @@ -36,7 +36,8 @@ Flag/feature toggle service, written in aiohttp. ### Prerequisites -`its_on` requires an SQL database and a cache storage engine. Currently, only PostgreSQL and Redis are supported as respective backends. +`its_on` requires an SQL database and a cache storage engine. +Currently, only PostgreSQL and Redis are supported as respective backends. ### Manual @@ -68,7 +69,8 @@ Run server: `$ python -m its_on` -Navigate to `http://127.0.0.1:8081/api/docs` in your browser and you are good to go! +Navigate to `http://127.0.0.1:8081/api/docs` in your browser +and you are good to go! ### Docker @@ -107,9 +109,12 @@ services: Don't forget to create a superuser: -`docker exec -t its-on python scripts/create_user.py --login=admin --password=passwordd --is_superuser` +```bash +docker exec -t its-on python scripts/create_user.py --login=admin --password=passwordd --is_superuser +``` -Navigate to `http://127.0.0.1:8081/api/docs` in your browser and you are good to go! +Navigate to `http://127.0.0.1:8081/api/docs` in your browser and +you are good to go! ## Testing From 0ccfca564a5965669eb671d6be5fc1d41ea4d5cb Mon Sep 17 00:00:00 2001 From: Igor Perepilitsyn Date: Fri, 15 May 2020 09:22:24 +0300 Subject: [PATCH 4/4] apply more CI fixes --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index a156910..e430474 100644 --- a/README.md +++ b/README.md @@ -110,7 +110,9 @@ services: Don't forget to create a superuser: ```bash -docker exec -t its-on python scripts/create_user.py --login=admin --password=passwordd --is_superuser +docker exec -t its-on python scripts/create_user.py --login=admin \ + --password=passwordd \ + --is_superuser ``` Navigate to `http://127.0.0.1:8081/api/docs` in your browser and