Skip to content

Commit f279707

Browse files
author
Bhavik Kumar
authored
Merge pull request #61 from bnc-projects/jdk13-updates
Update to use JDK 13 and latest TF modules for deployment
2 parents 0a4ffb9 + b57ad3e commit f279707

File tree

11 files changed

+140
-339
lines changed

11 files changed

+140
-339
lines changed

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
language: java
22
jdk:
3-
- openjdk11
4-
dist: xenial
3+
- openjdk13
4+
dist: bionic
55
env:
66
global:
77
- TF_IN_AUTOMATION=1

build.gradle

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ plugins {
22
id 'eclipse'
33
id 'idea'
44
id "org.sonarqube" version "2.8" apply false
5-
id "com.github.spotbugs" version "2.0.0" apply false
6-
id "com.bnc.gradle.travis-ci-versioner" version "1.0.6"
5+
id "com.github.spotbugs" version "2.0.1" apply false
6+
id "com.bnc.gradle.travis-ci-versioner" version "1.1.0"
77
}
88

99
ext {
@@ -25,8 +25,8 @@ allprojects {
2525
apply plugin: 'org.sonarqube'
2626

2727
group = 'com.bnc'
28-
sourceCompatibility = JavaVersion.VERSION_11
29-
targetCompatibility = JavaVersion.VERSION_11
28+
sourceCompatibility = JavaVersion.VERSION_13
29+
targetCompatibility = JavaVersion.VERSION_13
3030
compileJava.options.encoding = "UTF-8"
3131
compileTestJava.options.encoding = "UTF-8"
3232

@@ -50,7 +50,7 @@ allprojects {
5050
}
5151

5252
spotbugs {
53-
toolVersion = '3.1.12'
53+
toolVersion = '4.0.0-beta4'
5454
tasks.withType(com.github.spotbugs.SpotBugsTask) {
5555
reports {
5656
xml.enabled = false
@@ -60,7 +60,7 @@ allprojects {
6060
}
6161

6262
jacoco {
63-
toolVersion = "0.8.4"
63+
toolVersion = "0.8.5"
6464
}
6565

6666
checkstyle {
@@ -81,10 +81,10 @@ allprojects {
8181
}
8282

8383
dependencies {
84-
implementation group: 'com.bnc', name: 'market-data-api', version: '0.0.8'
84+
implementation group: 'com.bnc', name: 'market-data-api', version: '0.1.9'
8585

8686
testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter', version: '5.5.2'
87-
testImplementation group: 'org.assertj', name: 'assertj-core', version: '3.13.2'
87+
testImplementation group: 'org.assertj', name: 'assertj-core', version: '3.14.0'
8888
testImplementation group: 'org.mockito', name: 'mockito-core', version: '3.1.0'
8989
testImplementation group: 'org.mockito', name: 'mockito-junit-jupiter', version: '3.1.0'
9090
}

deployment/terraform/ecr/ecr.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module "ecr" {
2-
source = "git::https://github.com/bnc-projects/terraform-aws-ecr.git?ref=1.1.0"
2+
source = "git::https://github.com/bnc-projects/terraform-aws-ecr.git?ref=1.1.1"
33
allowed_read_principals = [
44
data.terraform_remote_state.bnc_ops.outputs.bnc_account_ids["market_data_development"],
55
data.terraform_remote_state.bnc_ops.outputs.bnc_account_ids["market_data_production"],

deployment/terraform/ecr/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ locals {
1515

1616
provider "aws" {
1717
region = var.aws_default_region
18-
version = "~> 2.11.0"
18+
version = "~> 2.36.0"
1919
profile = var.profile
2020

2121
allowed_account_ids = [

deployment/terraform/ecs-service/ecs.tf

Lines changed: 97 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,107 @@
1-
module "ecs_service" {
2-
source = "git::https://github.com/bnc-projects/terraform-ecs-service.git?ref=1.1.0"
3-
alarm_actions = [
4-
data.terraform_remote_state.market_data.outputs.alert_topic_arn
1+
data "aws_iam_policy_document" "task_service_assume_role" {
2+
statement {
3+
sid = "AllowECSTaskToAssumeRole"
4+
effect = "Allow"
5+
6+
actions = [
7+
"sts:AssumeRole"
8+
]
9+
10+
principals {
11+
type = "Service"
12+
identifiers = [
13+
"ecs-tasks.amazonaws.com"
14+
]
15+
}
16+
}
17+
}
18+
19+
data "aws_iam_policy" "execution_policy" {
20+
arn = "arn:aws:iam::aws:policy/service-role/AmazonECSTaskExecutionRolePolicy"
21+
}
22+
23+
module "container_definition" {
24+
source = "git::https://github.com/bnc-projects/terraform-ecs-container-definition.git?ref=1.0.0"
25+
environment = [
26+
{
27+
name = "SPRING_PROFILES_ACTIVE",
28+
value = terraform.workspace
29+
}
30+
]
31+
healthCheck = {
32+
"command" = [
33+
"CMD-SHELL",
34+
"curl --silent --fail --max-time 30 http://localhost:8080/actuator/health || exit 1"
35+
],
36+
"interval" = 30,
37+
"retries" = 3,
38+
"startPeriod" = 300,
39+
"timeout": 5
40+
}
41+
logConfiguration = {
42+
"logDriver": "splunk",
43+
"options": {
44+
"splunk-format": "raw",
45+
"splunk-insecureskipverify": "true",
46+
"splunk-token": var.splunk_token,
47+
"splunk-url": var.splunk_url
48+
}
49+
}
50+
image = format("%s:%s", data.terraform_remote_state.ecr.outputs.repository_url, var.service_version)
51+
name = var.service_name
52+
cpu = var.cpu
53+
memory = var.memory
54+
memoryReservation = var.memory_reservation
55+
portMappings = [
56+
{
57+
containerPort = 8080
58+
hostPort = 8080,
59+
protocol = "tcp"
60+
}
561
]
6-
application_path = "/sbjb"
7-
cluster_name = data.terraform_remote_state.market_data.outputs.ecs_cluster_name
8-
docker_image = format("%s:%s", data.terraform_remote_state.ecr.outputs.repository_url, var.service_version)
62+
}
63+
64+
resource "aws_iam_role" "execution_task_role" {
65+
name = format("%s-execution", var.service_name)
66+
assume_role_policy = data.aws_iam_policy_document.task_service_assume_role.json
67+
tags = var.tags
68+
}
69+
70+
resource "aws_iam_role_policy_attachment" "ecs_task_default_policy" {
71+
role = aws_iam_role.execution_task_role.name
72+
policy_arn = data.aws_iam_policy.execution_policy.arn
73+
}
74+
75+
resource "aws_iam_role" "task_role" {
76+
name = format("%s-task", var.service_name)
77+
assume_role_policy = data.aws_iam_policy_document.task_service_assume_role.json
78+
tags = var.tags
79+
}
80+
81+
resource "aws_ecs_task_definition" "task_definition" {
82+
container_definitions = "[${module.container_definition.container_definition}]"
83+
family = var.service_name
84+
cpu = var.cpu
85+
memory = var.memory
86+
execution_role_arn = aws_iam_role.execution_task_role.arn
87+
task_role_arn = aws_iam_role.task_role.arn
88+
tags = merge(local.common_tags, var.tags)
89+
}
90+
91+
module "ecs_service" {
92+
source = "git::https://github.com/bnc-projects/terraform-ecs-service.git?ref=1.3.2"
93+
application_path = "/v1/sbjb"
94+
attach_load_balancer = true
95+
cluster = data.terraform_remote_state.market_data.outputs.ecs_cluster_name
996
external_lb_listener_arn = data.terraform_remote_state.market_data.outputs.external_lb_https_listener_arn
1097
external_lb_name = data.terraform_remote_state.market_data.outputs.external_lb_name
98+
healthcheck_path = "/actuator/health"
1199
internal_lb_listener_arn = data.terraform_remote_state.market_data.outputs.internal_lb_https_listener_arn
12100
internal_lb_name = data.terraform_remote_state.market_data.outputs.internal_lb_name
13-
java_options = format("-javaagent:newrelic/newrelic.jar -Dnewrelic.environment=%s -Dnewrelic.config.file=newrelic/newrelic.yml", terraform.workspace)
14101
is_exposed_externally = false
15-
priority = 50
102+
priority = 53
16103
service_name = var.service_name
17-
splunk_token = var.splunk_token
18-
splunk_url = var.splunk_url
19-
spring_profile = terraform.workspace
104+
task_definition_arn = aws_ecs_task_definition.task_definition.arn
20105
vpc_id = data.terraform_remote_state.market_data.outputs.vpc_id
21106
tags = merge(local.common_tags, var.tags)
22107
}
23-

deployment/terraform/ecs-service/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ locals {
1616

1717
provider "aws" {
1818
region = var.aws_default_region
19-
version = "~> 2.11.0"
19+
version = "~> 2.36.0"
2020
profile = var.profile
2121

2222
allowed_account_ids = [

deployment/terraform/ecs-service/variables.tf

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,24 @@ variable "aws_default_region" {
33
default = "us-west-2"
44
}
55

6+
variable "cpu" {
7+
type = number
8+
default = 128
9+
description = "The CPU limit for the task and container."
10+
}
11+
12+
variable "memory" {
13+
type = number
14+
default = 512
15+
description = "The hard memory limit for the task and container"
16+
}
17+
18+
variable "memory_reservation" {
19+
type = number
20+
default = 512
21+
description = "The soft memory limit for the task and container"
22+
}
23+
624
variable "profile" {
725
type = string
826
default = "default"
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.2-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-6.0-bin.zip
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists

service/Dockerfile

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
1-
FROM openjdk:11.0.4-jre-slim
1+
FROM adoptopenjdk:13-jre-hotspot
22

3-
ARG JAR_FILE
4-
5-
RUN apt-get update && apt-get install -y wget
6-
RUN mkdir newrelic && wget https://download.newrelic.com/newrelic/java-agent/newrelic-agent/5.3.0/newrelic-agent-5.3.0.jar -O newrelic/newrelic.jar
7-
8-
COPY newrelic.yml newrelic/newrelic.yml
9-
COPY ${JAR_FILE} app.jar
3+
RUN groupadd -g 999 appuser && useradd -r -u 999 -g appuser appuser
4+
USER appuser
105

116
EXPOSE 8080
127

138
ENTRYPOINT exec java -XX:MaxRAMPercentage=80 -XX:+AlwaysPreTouch -XX:+UseStringDeduplication -Djava.security.egd=file:/dev/./urandom $JAVA_OPTS -jar app.jar
149

1510
HEALTHCHECK --start-period=300s \
16-
CMD wget --quiet --tries=1 --spider --timeout=30 http://localhost:8080/actuator/health || exit 1
11+
CMD curl --silent --fail --max-time 30 http://localhost:8080/actuator/health || exit 1
12+
13+
COPY *.jar app.jar

service/build.gradle

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
plugins {
2-
id "org.springframework.boot" version "2.1.9.RELEASE"
2+
id "org.springframework.boot" version "2.2.1.RELEASE"
33
id "io.spring.dependency-management" version "1.0.8.RELEASE"
44
id "com.palantir.docker" version "0.22.1"
5-
id "com.gorylenko.gradle-git-properties" version "2.0.0"
5+
id "com.gorylenko.gradle-git-properties" version "2.2.0"
66
}
77

88
jar {
@@ -32,15 +32,14 @@ if (!project.hasProperty("TAG")) {
3232
docker {
3333
name "${REPOSITORY_URI}:latest"
3434
tag "version", "${REPOSITORY_URI}:${TAG}"
35-
files bootJar.archiveFile.getOrNull(), "${project.projectDir.absolutePath}/config/newrelic/newrelic.yml"
36-
buildArgs(['JAR_FILE': "${bootJar.archiveFileName.getOrNull()}"])
35+
files bootJar.archiveFile.getOrNull()
3736
}
3837

3938
dependencies {
4039
implementation project(':client')
4140
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-web'
4241
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-actuator'
43-
implementation group: 'org.springframework.cloud', name: 'spring-cloud-starter-sleuth', version: '2.1.4.RELEASE'
44-
implementation group: 'io.micrometer', name: 'micrometer-registry-new-relic', version: '1.3.0'
42+
implementation group: 'org.springframework.cloud', name: 'spring-cloud-starter-sleuth', version: '2.1.5.RELEASE'
43+
implementation group: 'io.micrometer', name: 'micrometer-registry-new-relic', version: '1.3.1'
4544
testImplementation group: 'org.springframework.boot', name: 'spring-boot-starter-test'
4645
}

0 commit comments

Comments
 (0)