diff --git a/README.md b/README.md index d50d3ca2..ec756aff 100644 --- a/README.md +++ b/README.md @@ -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) @@ -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="" + export VACHAN_SUPER_USERNAME="" export VACHAN_SUPER_PASSWORD="" export VACHAN_DOMAIN=127.0.0.1:8000 ``` @@ -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 diff --git a/docs/Vachan-deployment-steps.md b/docs/Vachan-deployment-steps.md index 8f77c257..1de7748f 100644 --- a/docs/Vachan-deployment-steps.md +++ b/docs/Vachan-deployment-steps.md @@ -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="" +VACHAN_SUPER_USERNAME="" VACHAN_SUPER_PASSWORD="" VACHAN_AUTH_DATABASE="postgresql://:@kratos-postgresd:/" VACHAN_SUPPORT_EMAIL_CREDS="smtps://:::/?skip_ssl_verify=true&legacy_ssl=true" @@ -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="" - VACHAN_KRATOS_DB_USER="" VACHAN_KRATOS_DB_PASSWORD="" VACHAN_KRATOS_DB_NAME="" VACHAN_GITLAB_TOKEN="" VACHAN_REDIS_PASS="" +VACHAN_AI_DELETION_PERIOD= +VACHAN_AI_CRON_DAY= +VACHAN_AI_CRON_HOUR= +VACHAN_AI_CRON_MINUTE= +VACHAN_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 +``` + + +` ``` @@ -94,4 +124,3 @@ Referenced article: https://mindsers.blog/post/https-using-nginx-certbot-docker/ - diff --git a/docs/docker-guide.md b/docs/docker-guide.md index 3325ce2f..78d63964 100644 --- a/docs/docker-guide.md +++ b/docs/docker-guide.md @@ -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="" + export VACHAN_SUPER_USERNAME="" export VACHAN_SUPER_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. @@ -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="" - VACHAN_KRATOS_DB_USER="" VACHAN_KRATOS_DB_PASSWORD="" VACHAN_KRATOS_DB_NAME="" VACHAN_GITLAB_TOKEN="" VACHAN_REDIS_PASS="" - +VACHAN_AI_DELETION_PERIOD= +VACHAN_AI_CRON_DAY= +VACHAN_AI_CRON_HOUR= +VACHAN_AI_CRON_MINUTE= +VACHAN_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. @@ -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. @@ -126,7 +168,17 @@ git pull origin 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`. @@ -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