Skip to content

bnc-projects/spring-boot-java-base

Repository files navigation

Build Status Quality Gate Coverage Known Vulnerabilities

Spring Boot Java Base

Build & Test

This project uses gradle and uses the default tasks to compile and run unit tests.

./gradlew clean assemble check

Build and run locally on Docker

  1. Build the docker container
./gradlew clean assemble check docker
  1. Run the docker container
docker run -e SPRING_PROFILES_ACTIVE=localhost -p 8080:8080 -i -t spring-boot-java-base

Build production equivalent container

./gradlew clean assemble check docker dockerTag -PTAG=$(git rev-parse --verify HEAD --short) -PREPOSITORY_URI=${DOCKER_REPO}${IMAGE_NAME}

Profiling

To debug the container locally, the JAVA_OPTS environment variable can be provided when running the container.

docker run -p 8080:8080 -i -t -e JAVA_OPTS="-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005" spring-boot-java-base

Enabling New Relic

New relic can be enabled by providing the following JAVA_OPTS environment variable. Ensure to provide the correct newrelic.environment system property. To configure New Relic add/update the Application Environments section in newrelic.yml, more information can be found here.

docker run -p 8080:8080 -i -t -e JAVA_OPTS="-javaagent:newrelic/newrelic.jar -Dnewrelic.environment=development -Dnewrelic.config.file=newrelic/newrelic.yml" spring-boot-java-base

Deployment

This project uses Terraform and the AWS CLI to deploy the service to the BNC ECS Cluster. To have the CI/CD pipeline deploy a service which has be deployed using a fork of this project you can follow the instructions below.

Terraform ECS Workspaces

By default Terraform will not create the required workspaces. Before setting up the deployment in the CI environment, ensure you have created all of the appropriate workspaces.

The default workspaces for BNC are:

  • development
  • production

To create the workspaces run the following commands:

cd deployment/terraform/ecs-service
terraform workspace new production
terraform workspace new development

Setting up Travis-CI deployment

  1. Fill in the following environment variables.
AWS_DEFAULT_REGION=
STATE_S3_BUCKET=
STATE_DYNAMODB_TABLE=
KEY=<The project key for the ECR repository>, e.g bnc/<team>/ecr/<service-name>
SERVICE_KEY=<The project key for ECS service>, e.g ecs/<service-name>
SPLUNK_URL=
  1. Encrypt the following global environment variables using the Travis-CI CLI.
DEPLOYMENT_ACCESS_KEY_ID=
DEPLOYMENT_SECRET_ACCESS_KEY=
KMS_KEY_ID=
ROLE_ARN=
OPERATIONS_ROLE_ARN=
  1. Encrypt the following environment variables for the development deployment:
TF_WORKSPACE=
SPLUNK_TOKEN=

Deployment to development ECS cluster

Terraform ECR Project

  1. cd deployment/terraform/ecr

  2. Copy backend.tfvars.example to backend.tfvars.

  3. Fill out the backend.tfvars

  4. Run terraform init "-backend-config=backend.tfvars".

  5. Copy master.tfvars.example to master.tfvars.

  6. Fill in the master.tfvars with the correct values.

  7. Now the project is fully setup and you will have the ability to run terraform commands.

terraform plan "-var-file=master.tfvars"

Terraform ECS Project

  1. cd deployment/terraform/ecs-service

  2. Copy backend.tfvars.example to backend.tfvars.

  3. Fill out the backend.tfvars

  4. Run terraform init "-backend-config=backend.tfvars".

  5. Copy master.tfvars.example to master.tfvars.

  6. Fill in the master.tfvars with the correct values.

  7. Select the development work space terraform workspace select development

  8. Now the project is fully setup and you will have the ability to run terraform commands.

terraform plan "-var-file=master.tfvars"