Skip to content

Commit

Permalink
Merge pull request #7 from Kazauwa/improve_readme
Browse files Browse the repository at this point in the history
Improve readme
  • Loading branch information
Melevir authored May 15, 2020
2 parents 89b73f2 + 0ccfca5 commit f5d8ebd
Show file tree
Hide file tree
Showing 3 changed files with 126 additions and 36 deletions.
126 changes: 94 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand All @@ -26,39 +34,93 @@ flag/feature toggle service, written in aiohttp.

## Installation

1. Clone repo
- `$ git clone [email protected]: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:[email protected]:5432/its_on`
- default: `postgresql://bestdoctor:[email protected]: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 [email protected]: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:[email protected]: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:

```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!

## Testing

Run `make test`

## Contributing

Expand Down
28 changes: 28 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -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
8 changes: 4 additions & 4 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand All @@ -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

0 comments on commit f5d8ebd

Please sign in to comment.