Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
b899617
Update to use session token
guobaorou1989 May 12, 2019
641169d
Add terraform files to create ecr repository
guobaorou1989 May 14, 2019
828b861
Add Terraform ECR build config to TravisCI
guobaorou1989 May 14, 2019
8e3226b
Remove condition from init ecr stage
guobaorou1989 May 14, 2019
2d17cdb
Provide stage ordering to Travis-CI
guobaorou1989 May 14, 2019
f335fb3
Add terraform binary to bin folder
guobaorou1989 May 14, 2019
cd8bcf1
Use terraform instead of ./terraform
guobaorou1989 May 14, 2019
0bea518
Add backend key
guobaorou1989 May 14, 2019
b22c7ae
Tag and push docker image
guobaorou1989 May 14, 2019
c9bc195
Only run against openjdk11
guobaorou1989 May 14, 2019
c9ab640
Use xenial instead of trusty
guobaorou1989 May 14, 2019
190d7c4
Switch to travis build dir instead of home directory
guobaorou1989 May 14, 2019
b89aa04
Use snap to install awscli
guobaorou1989 May 14, 2019
d3e5eb6
Fix snap install issue
guobaorou1989 May 14, 2019
933f0a4
Use dockerTagsPush to push both latest and with travis number
guobaorou1989 May 14, 2019
774ce3b
Add dockerPush to push the latest docker image
guobaorou1989 May 14, 2019
21413d8
Add dockerPush to push the latest docker image
guobaorou1989 May 15, 2019
cda704a
Simplify deploys to use single deployment user
bhavikkumar May 16, 2019
ac42660
Remove pip and ecs deploy as they will not be used for future deploys
bhavikkumar May 16, 2019
0235177
Move switch role into correct location
bhavikkumar May 16, 2019
128f322
Update the principal allowed to write to the ECR repository
bhavikkumar May 16, 2019
0db9c96
Fix role session name having invalid characters
bhavikkumar May 16, 2019
9c365a8
Print out assumed user info
bhavikkumar May 16, 2019
b7de3be
Removed [secure] from env variables
bhavikkumar May 16, 2019
dbb95db
Fix up role session name
bhavikkumar May 16, 2019
aae51c6
Remove AWS_INFO env variable
bhavikkumar May 16, 2019
17057da
Fix client artifact group to include root project name
bhavikkumar May 16, 2019
5222577
Add dev and prod role arns
bhavikkumar May 16, 2019
fc457ea
Remvoe unrequired Travis AWS credentials
bhavikkumar May 16, 2019
a10062c
Update assume role command
bhavikkumar May 17, 2019
50f2229
Revert "Update assume role command"
bhavikkumar May 17, 2019
3554cad
Retry shorter assume role command
bhavikkumar May 17, 2019
816c5a4
Deploy service with terraform script
guobaorou1989 May 17, 2019
21dad36
Select workspace after initialization
guobaorou1989 May 17, 2019
baefe3c
Add and encrypt SERVICE_KEY
guobaorou1989 May 17, 2019
4e64c03
Fix travis error that deploy script not supporting list
guobaorou1989 May 17, 2019
3cae0ed
Fix -var error when executing terraform apply
guobaorou1989 May 17, 2019
9a4edfb
Fix -var error when executing terraform apply
guobaorou1989 May 17, 2019
46042ea
Fix -var error when executing terraform apply
guobaorou1989 May 17, 2019
465178c
Split deployment step
bhavikkumar May 17, 2019
a6d90e6
Get the cluster name from terraform outputs to reduce variables
bhavikkumar May 17, 2019
9490e66
Add change directory at each step
bhavikkumar May 17, 2019
d001b22
Move workspace_account_ids to global
guobaorou1989 May 17, 2019
cba2fbd
Attempt to fix WORKSPACE_ACCOUNT_IDS variable with single quote
bhavikkumar May 17, 2019
a60fd1c
Temporary echo of workspace variable
bhavikkumar May 17, 2019
70bc98b
Revert "Temporary echo of workspace variable"
bhavikkumar May 17, 2019
8d1bdfa
Change setting for workspace_account_ids
guobaorou1989 May 17, 2019
7f448b0
Change setting for workspace_account_ids
guobaorou1989 May 17, 2019
0ef554e
Add includes group for the brave new coin repo
May 17, 2019
f599bc8
Change setting for workspace_account_ids
guobaorou1989 May 17, 2019
926e2c3
Change setting for workspace_account_ids
guobaorou1989 May 17, 2019
7b52dc8
Echo WORKSPACE variable
bhavikkumar May 17, 2019
6043077
Use the roles defined instead of building the role arn dynamically
bhavikkumar May 17, 2019
58fec60
Fix env variable
bhavikkumar May 17, 2019
0d93ed6
Remove cloudformation related templates and scripts
guobaorou1989 May 19, 2019
bf72356
Add deploy to production stage
guobaorou1989 May 19, 2019
7c9f56e
Use a deployment script for more control in the deploy stage
bhavikkumar May 19, 2019
fb46b82
Give execute permissions
bhavikkumar May 19, 2019
c125d9e
Remove conditions from stages
bhavikkumar May 19, 2019
f477f57
Move duplicate commands to travis deploy script
bhavikkumar May 20, 2019
29e9bfc
Attempt to fix script failing to run
bhavikkumar May 20, 2019
9821084
Add sh in front of deploy script
bhavikkumar May 20, 2019
15a5763
Use bash instead sh
bhavikkumar May 20, 2019
ce1c3ab
Remove stage condition
bhavikkumar May 20, 2019
c5bd31d
Add variables for alerting
bhavikkumar May 20, 2019
a614d35
Update redirect to /dev/null
bhavikkumar May 20, 2019
9a7cc40
Use versioned ECS module
bhavikkumar May 20, 2019
508559c
Update documentation
bhavikkumar May 20, 2019
c0ab725
Update application path and module version
bhavikkumar May 20, 2019
0ab67e6
Update documentation
bhavikkumar May 20, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
# Local .terraform directories
**/.terraform/*

# .tfstate files
*.tfstate
*.tfstate.*

# .tfvars files
*.tfvars

# Crash logs
crash.log

# Created by https://www.gitignore.io/api/java,gradle,eclipse,netbeans,intellij

Expand Down
153 changes: 86 additions & 67 deletions .travis.yml

Large diffs are not rendered by default.

116 changes: 104 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,30 @@
[![Known Vulnerabilities](https://sonarcloud.io/api/project_badges/measure?project=spring-boot-java-base&metric=vulnerabilities)](https://sonarcloud.io/api/project_badges/measure?project=spring-boot-java-base&metric=vulnerabilities)
# Spring Boot Java Base

## How tos
## Build & Test

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

### Build & Test
```bash
./gradlew clean assemble check
```

### How to: Build and run locally on Docker
1. `./gradlew clean assemble check docker`
2. `docker run -e SPRING_PROFILES_ACTIVE=localhost -p 8080:8080 -i -t spring-boot-java-base`
### Build and run locally on Docker
1. Build the docker container
```bash
./gradlew clean assemble check docker
```
2. Run the docker container
```bash
docker run -e SPRING_PROFILES_ACTIVE=localhost -p 8080:8080 -i -t spring-boot-java-base
```

### Build production equivalent container
```bash
./gradlew clean assemble check docker dockerTag -PTAG=$(git rev-parse --verify HEAD --short) -PREPOSITORY_URI=${DOCKER_REPO}${IMAGE_NAME}
```

#### Debug / Profiling
### Profiling
To debug the container locally, the `JAVA_OPTS` environment variable can be provided when running the container.
```bash
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
Expand All @@ -27,12 +39,92 @@ New relic can be enabled by providing the following `JAVA_OPTS` environment vari
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
```

### How to: Build production equivalent container
```bash
./gradlew clean assemble check docker dockerTag -PTAG=$(git rev-parse --verify HEAD --short) -PREPOSITORY_URI=${DOCKER_REPO}${IMAGE_NAME}
## 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
```

## For more tasks run
```bash
./gradlew tasks
### Setting up Travis-CI deployment

1. Encrypt the following global environment variables using the Travis-CI CLI.
```
AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_DEFAULT_REGION=
KMS_KEY_ID=
ROLE_ARN=
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 bnc/<team>/<workspace>/ecs/<service-name>
OPERATIONS_ROLE_ARN=
DEVELOPMENT_ROLE_ARN=
PRODUCTION_ROLE_ARN=
SPLUNK_URL=
```

2. Encrypt the following environment variables for the development deployment:
```
TF_WORKSPACE=
SPLUNK_TOKEN=
```

### Deployment to development ECS cluster

#### Setup AWS Credentials

1. Setup the AWS profile using `aws configure --profile bnc-terraform`. The credentials can be retrieved using `terraform output` command in the terraform-techemy-master project if you have this setup.

#### 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](https://www.terraform.io/docs/commands/index.html).
```
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](https://www.terraform.io/docs/commands/index.html).
```
terraform plan "-var-file=master.tfvars"
```
11 changes: 10 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
plugins {
id 'eclipse'
id 'idea'
id "org.sonarqube" version "2.7" apply false
id "org.sonarqube" version "2.7.1" apply false
id "com.github.spotbugs" version "1.6.9" apply false
id "com.bnc.gradle.travis-ci-versioner" version "1.0.6"
}

ext {
awsAccessKeyId = properties.containsKey('AWS_ACCESS_KEY_ID') ? AWS_ACCESS_KEY_ID : System.getenv('AWS_ACCESS_KEY_ID')
awsSecretAccessKey = properties.containsKey('AWS_SECRET_ACCESS_KEY') ? AWS_SECRET_ACCESS_KEY : System.getenv('AWS_SECRET_ACCESS_KEY')
awsSessionToken = System.getenv('AWS_SESSION_TOKEN')
}

travisVersioner {
Expand All @@ -27,15 +28,23 @@ allprojects {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
compileJava.options.encoding = "UTF-8"
compileTestJava.options.encoding = "UTF-8"

repositories {
mavenCentral()
jcenter()
maven {
// This repository is only used for Brave New Coin artifacts. It is not required to build this project.
url "s3://artifact.bravenewcoin.com/maven/release"
content {
includeGroup "com.bnc"
}
credentials(AwsCredentials) {
accessKey "${awsAccessKeyId}"
secretKey "${awsSecretAccessKey}"
if (awsSessionToken) {
sessionToken "${awsSessionToken}"
}
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions client/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ jar {
publishing {
publications {
mavenJava(MavenPublication) {
groupId = "com.bnc.${rootProject.name}"
from components.java
}
}
Expand All @@ -19,6 +20,9 @@ publishing {
credentials(AwsCredentials) {
accessKey "${awsAccessKeyId}"
secretKey "${awsSecretAccessKey}"
if (awsSessionToken) {
sessionToken "${awsSessionToken}"
}
}
}
}
Expand Down
Loading