Skip to content

Commit

Permalink
Merge pull request #854 from shimilgithub/api-refactor
Browse files Browse the repository at this point in the history
Documentation updates after docker compose changes
  • Loading branch information
shimilgithub authored Jul 23, 2024
2 parents 5142a28 + 30c8a45 commit ed84568
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 25 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ Implemented Using

```cd vachan-api/docker```

```docker compose --profile local-run up```
``` docker compose -f docker-compose-staging.yml --profile local-run up```
or
```sudo -E docker compose --profile local-run up```
```sudo -E docker compose -f docker-compose-staging.yml --profile local-run up```

Set environment variables VACHAN_SUPER_USERNAME, VACHAN_SUPER_PASSWORD. Use `--build` and `--force-recreate` flags if there has been code change. Refer [the detailed usage guide](./docs/docker-guide.md#to-start-app-locally) and [section on environments variables](#set-up-environmental-variables), for more information.

If all goes well you should be able to get proper outputs at `http://localhost`, `http://localhost/docs`,
`http://localhost/v2/cms/rest/docs`,`http://localhost/v2/text/translate/token-based/docs`,`http://localhost/v2/auth/docs`,`http://localhost//v2/ai/docs`,`http://127.0.0.1:4434/identities`and connect to postgresDB at `localhost`, `5433`
`http://localhost/v2/cms/rest/docs`,`http://localhost/v2/text/translate/token-based/docs`,`http://localhost/v2/auth/docs`,`http://localhost//v2/ai/docs`,`http://localhost/v2/graphql`,`http://localhost/v2/demos`,`http://127.0.0.1:4434/identities` and connect to postgresDB at `localhost`, `5433`


## Set up locally for development and testing(without docker)
Expand Down Expand Up @@ -83,7 +83,7 @@ Edit the following contents appropriatetly and paste to the `.bashrc` file
export VACHAN_LOGGING_LEVEL="WARNING"
export VACHAN_KRATOS_ADMIN_URL="http://127.0.0.1:4434/"
export VACHAN_KRATOS_PUBLIC_URL="http://127.0.0.1:4433/"
export VACHAN_SUPER_USERNAME="<super-admin-emial-id>"
export VACHAN_SUPER_USERNAME="<super-admin-email-id>"
export VACHAN_SUPER_PASSWORD="<a-strong-password>"
export VACHAN_DOMAIN=127.0.0.1:8000
```
Expand Down Expand Up @@ -117,7 +117,7 @@ If you need to run the app on another port `--port` can be used. To run in debug

### Access Documentations

Once the app is running, from your browser access http://127.0.0.1:8000/docs for swagger documentation.
Once the app is running, from your browser access http://127.0.0.1:8000/docs for swagger documentation links of microservices.

Redoc documentaion is also available at http://127.0.0.1:8000/redoc

Expand Down
37 changes: 33 additions & 4 deletions docs/Vachan-deployment-steps.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,22 @@ to remove sudo need

```
cd vachan-api/docker
docker compose --env-file prod.env --profile deployment up --build --force-recreate -d
```

For Staging:
```
docker compose -f docker-compose-staging.yml --env-file prod.env --profile deployment up --build --force-recreate -d
```

For Production:
```
docker compose -f docker-compose-production.yml --env-file prod.env --profile deployment up --build --force-recreate -d
```


The environment values to be set in `prod.env` or `.env` file and their expected format are:
```
VACHAN_SUPER_USERNAME="<super-admin-emial-id>"
VACHAN_SUPER_USERNAME="<super-admin-email-id>"
VACHAN_SUPER_PASSWORD="<a-strong-password>"
VACHAN_AUTH_DATABASE="postgresql://<DB-user>:<DB-passwords>@kratos-postgresd:<DB-port>/<DB-name>"
VACHAN_SUPPORT_EMAIL_CREDS="smtps://<email-id>:<password>:<email-service>:<smtp-port>/?skip_ssl_verify=true&legacy_ssl=true"
Expand All @@ -59,12 +68,33 @@ VACHAN_DOMAIN=api.vachanengine.org
VACHAN_KRATOS_PUBLIC_URL="http://api.vachanengine.org:4433/"
VACHAN_KRATOS_ADMIN_URL="http://api.vachanengine.org:4434/"
VACHAN_POSTGRES_PASSWORD="<a-strong-password>"
VACHAN_KRATOS_DB_USER="<vachan_auth_user>"
VACHAN_KRATOS_DB_PASSWORD="<a-strong-password>"
VACHAN_KRATOS_DB_NAME="<vachan_auth_db>"
VACHAN_GITLAB_TOKEN="<api-token-from-gitlab>"
VACHAN_REDIS_PASS="<a-strong-password>"
VACHAN_AI_DELETION_PERIOD=<no_of_days>
VACHAN_AI_CRON_DAY=<no_of_days>
VACHAN_AI_CRON_HOUR=<hour>
VACHAN_AI_CRON_MINUTE=<minute>
VACHAN_AI_DATA_PATH=<ai_data_path>
```
## To Down the App

For Staging:

```
docker compose -f docker-compose-staging.yml --profile deployment --env-file prod.env down
```

For Production:

```
docker compose -f docker-compose-production.yml --profile deployment --env-file prod.env down
```


`

```
Expand Down Expand Up @@ -94,4 +124,3 @@ Referenced article: https://mindsers.blog/post/https-using-nginx-certbot-docker/

84 changes: 68 additions & 16 deletions docs/docker-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,40 +36,41 @@ If you have already set up the repo and remotes for development, pull latest cod

VACHAN_SUPER_USERNAME, VACHAN_SUPER_PASSWORD are the minimum required environment variables. This can either be set in the `~/.bashrc` file or save in a local `.env` file and passed via command line.
```
export VACHAN_SUPER_USERNAME="<super-admin-emial-id>"
export VACHAN_SUPER_USERNAME="<super-admin-email-id>"
export VACHAN_SUPER_PASSWORD="<a-strong-password>"
```
The username should be your email id and password must be a strong password.

If you just want to setup and start app locally, from the vachan-api/docker folder, do

```docker compose --profile local-run up```
```docker compose -f docker-compose-staging.yml --profile local-run up```

or

```docker compose --env-file=path/to/file.env --profile local-run up```
```docker compose -f docker-compose-staging.yml --env-file=path/to/file.env --profile local-run up```

If all goes well you should be able to get proper outputs at `http://localhost`, `http://localhost/docs`, `http://localhost/v2/demos`,
`http://127.0.0.1:4434/identities` and connect to postgresDB at `localhost`, `5433`
If all goes well you should be able to get proper outputs at `http://localhost`, `http://localhost/docs`,
`http://localhost/v2/cms/rest/docs`,`http://localhost/v2/text/translate/token-based/docs`,`http://localhost/v2/auth/docs`,`http://localhost//v2/ai/docs`,`http://localhost/v2/graphql`,`http://localhost/v2/demos`,`http://127.0.0.1:4434/identities` and connect to postgresDB at `localhost`, `5433`

(Error reports from Kratos container related to failed email sending can be ignored as long as above URLs are accessible).

To turn the app down, use

```docker compose --profile local-run down```
```docker compose -f docker-compose-staging.yml --profile local-run down```


## To run tests

This method is recommended to just run all the tests once to make sure everything works, like in production, CI/CD or locally when verifying a PR. While doing local development and when we may have to run tests selectively and multiple times, after code changes, use the method specificed in [readme](../README.md#set-up-locally-for-development-and-testingwithout-docker).

```
docker compose up # to start the dependancies
docker compose run vachan-api-test --build
docker compose -f docker-compose-staging.yml up # to start the dependancies
docker compose -f docker-compose-staging.yml run vachan-api-test --build
```

To turn down the running containers after test has been exited,

```docker compose down```
```docker compose -f docker-compose-staging.yml down```

## To deploy on server
Install docker, docker-compose & git and set up the right repo and branch.
Expand All @@ -87,23 +88,41 @@ VACHAN_DOMAIN=api.vachanengine.org
VACHAN_KRATOS_PUBLIC_URL="http://api.vachanengine.org:4433/"
VACHAN_KRATOS_ADMIN_URL="http://api.vachanengine.org:4434/"
VACHAN_POSTGRES_PASSWORD="<a-strong-password>"
VACHAN_KRATOS_DB_USER="<vachan_auth_user>"
VACHAN_KRATOS_DB_PASSWORD="<a-strong-password>"
VACHAN_KRATOS_DB_NAME="<vachan_auth_db>"
VACHAN_GITLAB_TOKEN="<api-token-from-gitlab>"
VACHAN_REDIS_PASS="<a-strong-password>"
VACHAN_AI_DELETION_PERIOD=<no_of_days>
VACHAN_AI_CRON_DAY=<no_of_days>
VACHAN_AI_CRON_HOUR=<hour>
VACHAN_AI_CRON_MINUTE=<minute>
VACHAN_AI_DATA_PATH=<ai_data_path>
```
Once the ENV file is ready, pass it to CLI and start the services as below:

For Staging:
```
docker compose --env-file=prod.env --profile deployment up --build --force-recreate -d
docker compose -f docker-compose-staging.yml --env-file=prod.env --profile deployment up --build --force-recreate -d
```

For Production:
```
docker compose -f docker-compose-production.yml --env-file=prod.env --profile deployment up --build --force-recreate -d
```

To re-create SSL certificates, follow instructions [here](https://mindsers.blog/post/https-using-nginx-certbot-docker/)

For Staging:

```
docker compose --profile deployment run --rm certbot renew
docker compose -f docker-compose-staging.yml --profile deployment run --rm certbot renew
```

For Production:

```
docker compose -f docker-compose-production.yml --profile deployment run --rm certbot renew
```

After this make sure the certificate folder in the app root has access permission. or change it with `sudo chmod -R 777 certbot/`. Then the App needs to be restarted as shown below to use the updated ceritifcate.
Expand All @@ -112,9 +131,32 @@ After this make sure the certificate folder in the app root has access permissio

```
cd ~/vachan-api/docker
docker compose --env-file=prod.env --profile deployment up --build --force-recreate -d
```
For Staging:
```
docker compose -f docker-compose-staging.yml --env-file=prod.env --profile deployment up --build --force-recreate -d
```

For Production:
```
docker compose -f docker-compose-production.yml --env-file=prod.env --profile deployment up --build --force-recreate -d
```

## To Down the App

For Staging:

```
docker compose -f docker-compose-staging.yml --profile deployment --env-file prod.env down
```

For Production:

```
docker compose -f docker-compose-production.yml --profile deployment --env-file prod.env down
```


### To re-deploy on server

After git pull, running the same command above, will re-build and re-start the containers.
Expand All @@ -126,7 +168,17 @@ git pull origin <branch or tag>
cd docker
```

```docker compose --env-file=prod.env --profile deployment up --build --force-recreate -d```
For Staging:

```
docker compose -f docker-compose-staging.yml --env-file=prod.env --profile deployment up --build --force-recreate -d
```

For Production:

```
docker compose -f docker-compose-production.yml --env-file=prod.env --profile deployment up --build --force-recreate -d
```


To start with a fresh DB, stop and remove containers and remove volume `vachan-db-vol`.
Expand All @@ -135,7 +187,7 @@ To clear all user data, remove the volume `kratos-postgres-vol`, on local or on

Some useful commands for the above tasks
```
docker compose down
docker compose -f docker-compose-staging.yml down
docker ps # list all running containers
docker ps -a # list all running and stopped containers
Expand Down

0 comments on commit ed84568

Please sign in to comment.