- Request access to the
Google Cloud Developer Console
andMongoDB Atlas console
- Install the latest stable version of Maven. This will be your main version across your machine.
This project contains two profiles:
- dev
- prod
To run the desired profile use mvn spring-boot:run -P dev|prod
Follow the official Firebase guide to set up the emulator locally.
Routes can be found in src/main/***/http/controller
Documents can be found in src/main/***/model
Repositories can be found in src/main/***/repository
This app uses Logback for logging. You can find the config in /src/main/resources
folder
When running in prod
Logs are sent to Cloud Logging via Logback Cloud logging plugin.
The Logback plugin only reports logs from the LF4J logging API, so we only use the org.slf4j.Logger
interface for logging.
When running in dev
profile, logs are configured to write to the console.
Use this setup to configure Docker to work with Cloud Logging when moving to a new VM
Use Google Cloud Secrets Manager to manage secrets (API keys, passwords, database URLs, etc.)
Deployments are currently automated with GitHub actions.
The workflow file is located at /.github/workflows/deploy.yml
The app runs on a Google Compute Engine VM with full GCP API permissions and required scopes.
- Install Docker and Gcloud CLI
- Run
gcloud auth application-default login
to authenticate with Google Cloud Platform - Run
CP $HOME/.config/gcloud/application_default_credentials.json cred.json
from the project root folder. - Temporarily allow the production MongoDB Atlas to accept traffic from your local machine's IP address.
- Run
docker-compose up <service-name>
from the project root folder. Usejvm
ornative
as the service name.
You will need to have write access to our Google Artifact Registry on Google Cloud Platform and install docker on your machine.
- Run
gcloud auth configure-docker us-central1-docker.pkg.dev
to enable Google Cloud CLI to authenticate requests to Artifact Registry. - Run the
docker tag web <GCP_IMAGE_NAME> && docker push <GCP_IMAGE_NAME>
command to publish the new version to Google Artifact Registry.
$ gcloud compute instances update-container [instance-name] --zone=[zone-name] --container-image=[container-image-name]
Replace the instance-name
, zone-name
and container-image-name
with the appropriate values.
While you will not need to log into the VM to get Telementry information, you can SSH into the VM and run the following command to inspect the app
- Run
docker ps
to view the docker instances running - Run
docker attach [container-id]
to attach to the container and start seeing logs. Note that you will only see logs from when you attach, not the past logs.
Use Cloud logging to inspect the logs and health of the machine.
The goal is to achieve close to production behaviour as possible. Database and Repositories are powered by
an Embedded DB that only runs in test
profile.
Mockito
is used for Mocking external servicesMockMvc
is used for the Integration test
While mvn clean test
is good for running the tests during development, we advise you use the following command to build the test.Dockerfile
to verify that the test can run in an isolated environment without any preconfiguration on your local machine.
docker build -t test -f test.Dockerfile .
A successful build from the above command indicates that all tests are passing on your local machine.
Here are some tips on how to optimize java application.