-
Notifications
You must be signed in to change notification settings - Fork 6
Production environment
To build the project for production, the following command has to be executed for each service (currently ServiceNet, ServiceNetAuth and ServiceNetGateway):
./mvnw package -Pprod jib:dockerBuild -DskipTestsThe application requires some confidential data that needs to be set via environment variables:
-
GOOGLE_API_KEY- key for accessing the Google API -
EDEN_API_KEY- key for collecting the data for Eden, through the ICarol API -
UWBA_API_KEY- key for collecting the data for UWBA, through the ICarol API -
FEEDBACK_RECEIVER_ADDRESS- the email address used to receive feedback, defaults to feedback@benetech.org -
SENDGRID_API_KEY- Sendgrid API key -
JHIPSTER_OAUTH2_CLIENT_SECRET- A secret used internally by the microservices to communicate with each other. Since it can be used to obtain access tokens, it's worth setting a strong secret. -
SPRING_OAUTH2_CLIENT_SECRET- A secret used internally by the microservices to validate tokens. Since it can be used to obtain access tokens, it's worth setting a strong secret. -
TWILIO_ACCOUNT_SID- Account SID provided by Twilio -
TWILIO_AUTH_TOKEN- Auth Token provided by Twilio -
TWILIO_PHONE_NUMBER- Phone number used to send out messages -
RECAPTCHA_SITE_KEY- the key used to identify the reCAPTCHA site. Please make sure that the site includes your domain name and the type is set to 'v2 invisible' -
RECAPTCHA_SECRET_KEY- the key used on the backend to verify captchas with Google
There are some optional environment variables, allowing the services to connect to external PostgreSQL or MongoDB:
-
POSTGRES_HOST- Hostname of the PostgreSQL instance -
POSTGRES_PORT- Port of the PostgreSQL instance (default: 5432) -
POSTGRES_USERNAME- Postgres username -
POSTGRES_PASSWORD- Postgres password -
POSTGRES_DB- Postgres database name (default: ServiceNet). If using an external Postgres instance, please create 'uuid-ossp' extension aswell as 'auth' and 'gateway' schemas in this database -
MONGODB_HOST- MongoDB host -
MONGODB_PORT- MongoDB port -
MONGODB_DB- MongoDB database name
Docker tag overwrite:
-
SN_VERSION_TAG- It is being used to overwrite default Docker tag (dev) insideapp-docker-registry.yml. Thus, it is mostly being used with the Docker Swarm setup.
Spring profile:
-
SPRING_PROFILES_ACTIVE- Spring Profile env variable.
Sentry.io setup. These env variables are being used only in the docker registry-based setup (app-docker-registry.yml)
-
SENTRY_DSN- should contain sentry.io account token. if it is empty, the sentry.io component won't run. -
SENTRY_ENVIRONMENT- used to distinguish the environment in error reporting. used to tag error reports on sentry.io based on the environment. we can use e.g. 'prod', 'dev' depending on the server.
As the app is available to be run on the Docker, the following command will compose all required containers (PostgreSQL, MongoDB, Consul, Consul config loader, ServiceNet, ServiceNetAuth and ServiceNetGateway), has to be executed:
docker-compose -f ServiceNetGateway/src/main/docker/app.yml up -dIf you are using an external PostgreSQL or MongoDB instance, remove the corresponding container from app.yml to save resources.
If some service is running out of memory, it's possible to increase heap size by modifying java options in app.yml, for example: _JAVA_OPTIONS=-Xmx2048m -Xms1024m.
Essentially only two files from ServiceNetGateway repo are needed - template.env and app-docker-registry.yml
- Create your own
.envfrom template.env
cp template.env .env- Prepare your environment variables inside
.env- Edit
SN_VERSION_TAGenv variable if you want to base setup on different Docker image tag thandev. (latesttag for production setup) - Change
SPRING_PROFILES_ACTIVEin.envto 'prod,swagger' if you run prod environment.
- Edit
- Initiate Docker Swarm:
docker swarm init- Run the registry-based docker-compose setup with Swarm.
docker-composecommand is being used only as a pre-processor of a.env. Run inside ServiceNetGateway directory:
docker stack deploy -c <(docker-compose -f src/main/docker/app-docker-registry.yml config) sn