diff --git a/.env.template b/.env.template index debcfe3..ecea0b0 100644 --- a/.env.template +++ b/.env.template @@ -1,22 +1,17 @@ -USER_ID= -GROUP_ID= - -# Authentication variables +##ORCID Authentication Variables for user to set OAUTH_CLIENT_ID= -OAUTH_CLIENT_SECRET= -JWT_SECRET= -JWT_DOMAIN= +OAUTH_CLIENT_SECRET= -# Database variables -DB_PASSWORD= -DB_SERVER= -DB_NAME= -DB_USER= -ADMIN_ORCID= +##Variables already set +#Authentication variables +JWT_SECRET=insecure2520f59b2bccc64ce155482bc413f6b9ede5c6d418ab529d1b2051baa6f0849e +JWT_DOMAIN=deltabreed.localhost -# Build variables needed to pull down JAR files from Github Packages -GITHUB_ACTOR= -GITHUB_TOKEN= +# Database variables +DB_PASSWORD=postgres +DB_SERVER=dbserver:5432 +DB_NAME=bidb +DB_USER=postgres # Micronaut variables API_INTERNAL_PORT=8081 @@ -37,40 +32,50 @@ BRAPI_SERVER_PORT=8080 BRAPI_DEFAULT_URL=http://brapiserver:8080 BRAPI_REFERENCE_SOURCE=breedinginsight.org -BRAPI_DB_SERVER= -BRAPI_DB= -BRAPI_DB_USER= -BRAPI_DB_PASSWORD= +#BrAPI database variables +BRAPI_DB_SERVER=dbserver:5432 +BRAPI_DB=postgres +BRAPI_DB_USER=postgres +BRAPI_DB_PASSWORD=postgres -WEB_BASE_URL=http://localhost -API_BASE_URL=http://localhost -ANALYTICS_GTAG_ID= +WEB_BASE_URL=http://deltabreed.localhost +API_BASE_URL=http://deltabreed.localhost # Public domain name -REGISTERED_DOMAIN=localhost +REGISTERED_DOMAIN=deltabreed.localhost # Email relay information -EMAIL_RELAY_HOST= -EMAIL_RELAY_PORT=<1025 for development, 2587 for production> -EMAIL_FROM=noreply@breedinginsight.org -#EMAIL_RELAY_LOGIN= -#EMAIL_RELAY_PASSWORD= - -REDIS_URL= -REDIS_TIMEOUT= -REDIS_SSL= - -GIGWA_HOST= -GIGWA_USER= -GIGWA_PASSWORD= -GIGWA_MONGO_USER= -GIGWA_MONGO_PASSWORD= - -AWS_REGION= -AWS_ACCESS_KEY_ID= -AWS_SECRET_KEY= -AWS_GENO_BUCKET= -AWS_S3_ENDPOINT= +#REDIS_SSL= +#USER_ID= +#GROUP_ID= + +#Optional Variables +#ANALYTICS_GTAG_ID= +#EMAIL_RELAY_LOGIN= +#EMAIL_RELAY_PASSWORD= \ No newline at end of file diff --git a/README.md b/README.md index 48a9037..7199f78 100644 --- a/README.md +++ b/README.md @@ -6,43 +6,86 @@ This repo contains the docker-compose configurations used to run DeltaBreed. -# Prereqs +# Table of Contents +

+ Getting Started | + Architecture | + Setting Up Other Environments +

+ +# Getting Started +## Outline +
    +
  • Download prereqs
  • +
  • Set up OAuth with ORCID
  • +
  • Set up environment variables
  • +
  • Run docker-compose
  • +
  • Get ORCID credentials into database
  • +
  • Access DeltaBreed on web
  • +
+ +## Download Prereqs Docker and Docker-compose are both required. -# Architecture +## Set up OAuth with ORCID +Running DeltaBreed requires setting up OAuth with [ORCID](https://info.orcid.org/what-is-orcid/) (Open Researcher and Contributor ID). + +
    +
  1. Create an ORCID account
  2. +
  3. Sign into ORCID
  4. +
  5. Go to "Developer Tools"
  6. +
  7. Agree to Terms of Service and register for ORCID public API credentials
  8. +
  9. Enter application name and description (no particular requirements)
  10. +
  11. Enter application URL http://deltabreed.localhost:8080
  12. +
  13. Add Redirect URI http://deltabreed.localhost/sso/success/orcid
  14. +
  15. Select "Save application" at the bottom of the page
  16. +
  17. Copy the generated Client ID and Client Secret to add to the .env file (see Set up environment variables)
  18. +
+ +## Set up environment variables +To set necessary private environment variables for DeltaBreed to run, at the root level of the repo locally create a file called `.env`. +A template exists named `.env.template` that has most environment variables already filled. + +In this new `.env` based off the template, set `OAUTH_CLIENT_ID` and `OAUTH_CLIENT_SECRET` to the generated Client ID and Client Secret copied in the previous step + +## Run docker-compose +Run the following in the bi-docker-stack repository + +``` +docker-compose -f docker-compose.yml -f docker-compose-redis.yml -f docker-compose-gigwa.yml -f docker-compose-localstack.yml -f docker-compose-mailhog.yml -f docker-compose-qa.yml up -d --build +``` + +## Get ORCID credentials into database +To get ORCID credentials into the database, an interactive script must be run that prompts the user to input their ORCID and email. + +For Mac/Linux, run `addUser.sh` + +For Windows, run `addUser.ps1` + +## Access DeltaBreed on web +DeltaBreed can then be accessed via `http://deltabreed.localhost:8080`. + +# Architecture The primary components of DeltaBreed are the Web UI (Breeding-Insight/bi-web) and the API (Breeding-Insight/bi-api). The [BrAPI Java Server](https://github.com/plantbreeding/brapi-Java-TestServer) is used for phenotypic data storage, [Gigwa](https://github.com/SouthGreenPlatform/Gigwa2) is used for genotypic data storage, and interoperability with external applications such as [Field Book](https://github.com/PhenoApps/Field-Book/) is enabled by [BrAPI](https://brapi.org/). DeltaBreed uses [ORCID](https://orcid.org/) for authentication. ![DeltaBreed v1.0 architecture diagram.](./images/architecture.1.0.png) -# Configuration -The containers are not run by the root user but by a new user and group called -'host'. The user and group ids for host are both set to 1001 by default. If -you wish to change these to your own user and group ids, add the following -contents to .env: -``` -USER_ID=1001 -GROUP_ID=1001 -``` -Change 1001 to your own id values. You can find at the console your user and group ids using the id command: -for user id -``` -id -u -``` -and for group id +# Setting up Other Environments +## Development Environment + +To run a development environment, you will need to initialize the git submodules that exist within this repository: + ``` -id -g +git submodule update --init --recursive ``` -## Configure Services - -Private values used in each environment are stored in Lastpass and are never -placed in docker-compose.yml and never committed to the repo. At the root level -of the repo locally create a file called `.env` (a template exists named `.env.template`) -and save the Lastpass contents for "bi-api secrets" in this file. +Then run: -# Run +``` +docker-compose -f docker-compose.yml -f docker-compose-redis.yml -f docker-compose-gigwa.yml -f docker-compose-dev.yml up -d +``` ## Production Environment @@ -104,17 +147,21 @@ traffic to the appropriate upstream server. Any new features added to bi-api that use an endpoint not in the /v1/ or /sso/ name spaces must have a rule added to the proxy config in order to send these requests upstream. - -# Development Environment - -To run a development environment, you will need to initialize the git submodules that exist within this repository: - +## User Configuration +The containers are not run by the root user but by a new user and group called +'host'. The user and group ids for host are both set to 1001 by default. If +you wish to change these to your own user and group ids, add the following +contents to .env: ``` -git submodule update --init --recursive +USER_ID=1001 +GROUP_ID=1001 ``` - -Then run: - +Change 1001 to your own id values. You can find at the console your user and group ids using the id command: +for user id ``` -docker-compose -f docker-compose.yml -f docker-compose-redis.yml -f docker-compose-gigwa.yml -f docker-compose-dev.yml up -d +id -u ``` +and for group id +``` +id -g +``` \ No newline at end of file diff --git a/addUser.ps1 b/addUser.ps1 new file mode 100644 index 0000000..e4e04a6 --- /dev/null +++ b/addUser.ps1 @@ -0,0 +1,8 @@ +$oauth_id = Read-Host "Enter ORCID (e.g. 0000-1111-2222-3333)" +$email = Read-Host "Enter email (must be the email used with ORCID)" + +$insertUser = "INSERT INTO bi_user (orcid, name, email, created_by, updated_by, active) VALUES ('${oauth_id}', 'admin', '${email}', '00000000-0000-0000-0000-000000000000', '00000000-0000-0000-0000-000000000000', true);" +$insertRole = "INSERT INTO system_user_role (bi_user_id, system_role_id, created_by, updated_by) VALUES ((SELECT id FROM bi_user WHERE email='${email}'), (SELECT id FROM system_role WHERE domain = 'System Administrator'), '00000000-0000-0000-0000-000000000000', '00000000-0000-0000-0000-000000000000');" + +docker exec -it bidb psql -U postgres -d bidb -c $insertUser +docker exec -it bidb psql -U postgres -d bidb -c $insertRole \ No newline at end of file diff --git a/addUser.sh b/addUser.sh new file mode 100644 index 0000000..1d68bac --- /dev/null +++ b/addUser.sh @@ -0,0 +1,8 @@ +read -p "Enter ORCID (e.g. 0000-1111-2222-3333):" oauth_id +read -p "Enter email (must be the email used with ORCID):" email + +insertUser="INSERT INTO bi_user (orcid, name, email, created_by, updated_by, active) VALUES ('${oauth_id}', 'admin', '${email}', '00000000-0000-0000-0000-000000000000', '00000000-0000-0000-0000-000000000000', true);" +docker exec -it bidb psql -U postgres -d bidb -c "${insertUser}" + +insertRole="INSERT INTO system_user_role (bi_user_id, system_role_id, created_by, updated_by) VALUES ((SELECT id FROM bi_user WHERE email='${email}'), (SELECT id FROM system_role WHERE domain = 'System Administrator'), '00000000-0000-0000-0000-000000000000', '00000000-0000-0000-0000-000000000000');" +docker exec -it bidb psql -U postgres -d bidb -c "${insertRole}" \ No newline at end of file diff --git a/docker-compose-localstack.yml b/docker-compose-localstack.yml index c552570..7e152e7 100644 --- a/docker-compose-localstack.yml +++ b/docker-compose-localstack.yml @@ -6,6 +6,7 @@ services: image: localstack/localstack:3.0.2 ports: - "4566:4566" + restart: always networks: backend: aliases: diff --git a/docker-compose-mailhog.yml b/docker-compose-mailhog.yml new file mode 100644 index 0000000..ad81bf3 --- /dev/null +++ b/docker-compose-mailhog.yml @@ -0,0 +1,12 @@ +version: "3.7" + +services: + mailhog: + image: mailhog/mailhog:latest + container_name: mailhog + restart: always + ports: + - ${MAILHOG_WEB_PORT:-8025}:8025 + - ${MAILHOG_PORT:-1025}:1025 + networks: + backend: