Skip to content

Commit 0020afa

Browse files
authored
Upgrade java and memory handlings (#237)
* Upgrade java and memory handlings
1 parent 617a00a commit 0020afa

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+234
-172
lines changed

.github/workflows/pr-build.yml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ jobs:
181181
uses: actions/setup-java@v4
182182
with:
183183
distribution: 'adopt'
184-
java-version: '11'
184+
java-version: '17'
185185

186186
- name: Setup Go
187187
uses: actions/setup-go@v5
@@ -203,6 +203,16 @@ jobs:
203203
mkdir test-results
204204
go run gotest.tools/gotestsum@latest --format testname --junitfile test-results/unit-tests.xml
205205
206+
- name: golangci-lint
207+
uses: golangci/golangci-lint-action@v3
208+
with:
209+
# Require: The version of golangci-lint to use.
210+
# When `install-mode` is `binary` (default) the value can be v1.2 or v1.2.3 or `latest` to use the latest version.
211+
# When `install-mode` is `goinstall` the value can be v1.2.3, `latest`, or the hash of a commit.
212+
version: v1.54
213+
working-directory: services/community
214+
215+
206216
- name: Run workshop tests
207217
run: |
208218
cd services/workshop

services/community/Dockerfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,6 @@ RUN ls -al /app
4141

4242
ARG SERVER_PORT
4343
EXPOSE ${SERVER_PORT}
44+
# Expose profiling port
45+
EXPOSE 6060
4446
CMD /app/main

services/community/api/auth/token.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,12 @@ func ExtractTokenID(r *http.Request, db *gorm.DB) (uint32, error) {
6666
return 0, err
6767
}
6868

69-
resp, err := http.Post(tokenVerifyURL, "application/json",
70-
bytes.NewBuffer(tokenJSON))
69+
resp, err := http.Post(tokenVerifyURL, "application/json", bytes.NewBuffer(tokenJSON))
7170
if err != nil {
7271
log.Println(err)
7372
return 0, err
7473
}
74+
defer resp.Body.Close()
7575

7676
tokenValid := resp.StatusCode == 200
7777
token, _, err := new(jwt.Parser).ParseUnverified(tokenString, jwt.MapClaims{})

services/community/api/controllers/coupon_controller.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import (
3030
//Server have database connection
3131
func (s *Server) AddNewCoupon(w http.ResponseWriter, r *http.Request) {
3232
body, err := io.ReadAll(r.Body)
33+
defer r.Body.Close()
3334
if err != nil {
3435
responses.ERROR(w, http.StatusBadRequest, err)
3536
return
@@ -61,6 +62,7 @@ func (s *Server) ValidateCoupon(w http.ResponseWriter, r *http.Request) {
6162
var bsonMap bson.M
6263

6364
body, err := io.ReadAll(r.Body)
65+
defer r.Body.Close()
6466
if err != nil {
6567
responses.ERROR(w, http.StatusBadRequest, err)
6668
log.Println("No payload for ValidateCoupon", body, err)

services/community/api/controllers/post_controller.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import (
3232
func (s *Server) AddNewPost(w http.ResponseWriter, r *http.Request) {
3333

3434
body, err := io.ReadAll(r.Body)
35+
defer r.Body.Close()
3536
if err != nil {
3637
responses.ERROR(w, http.StatusBadRequest, err)
3738
return
@@ -112,6 +113,7 @@ func (s *Server) Comment(w http.ResponseWriter, r *http.Request) {
112113

113114
vars := mux.Vars(r)
114115
body, err := io.ReadAll(r.Body)
116+
defer r.Body.Close()
115117
if err != nil {
116118
responses.ERROR(w, http.StatusBadRequest, err)
117119
return

services/community/api/router/routes.go

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ package router
1717
import (
1818
"log"
1919
"net/http"
20+
_ "net/http/pprof"
2021
"os"
2122
"time"
2223

@@ -29,16 +30,19 @@ import (
2930

3031
type Server config.Server
3132

33+
var controller = controllers.Server{}
3234

3335
// initializeRoutes initialize routes of url with Authentication or without Authentication
3436
func (server *Server) InitializeRoutes() *mux.Router {
35-
var controller = controllers.Server{}
3637

3738
controller.DB = server.DB
3839

3940
controller.Client = server.Client
4041

4142
server.Router.Use(middlewares.AccessControlMiddleware)
43+
if os.Getenv("DEBUG") == "1" {
44+
server.Router.PathPrefix("/debug/pprof/").Handler(http.DefaultServeMux)
45+
}
4246
// Post Route
4347
server.Router.HandleFunc("/community/api/v2/community/posts/recent", middlewares.SetMiddlewareJSON(middlewares.SetMiddlewareAuthentication(controller.GetPost, server.DB))).Methods("GET", "OPTIONS")
4448

@@ -77,14 +81,8 @@ func (server *Server) Run(addr string) {
7781
if !is_key || key == "" {
7882
key = "certs/server.key"
7983
}
80-
err := srv.ListenAndServeTLS(certificate, key)
81-
if err != nil {
82-
log.Println(err)
83-
}
84+
log.Println(srv.ListenAndServeTLS(certificate, key))
8485
} else {
85-
err := srv.ListenAndServe()
86-
if err != nil {
87-
log.Println(err)
88-
}
86+
log.Println(srv.ListenAndServe())
8987
}
9088
}

services/identity/.java-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
17

services/identity/Dockerfile

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@
1212

1313

1414
# Java Maven Build
15-
FROM gradle:7.3.3-jdk11 AS gradlebuild
15+
FROM gradle:8.1-jdk17-focal AS gradlebuild
1616
WORKDIR /app
1717
COPY *.gradle.kts ./
18+
COPY gradle.properties ./
1819
# Only download dependencies
1920
# Eat the expected build failure since no source code has been copied yet
2021
RUN gradle clean build --no-daemon > /dev/null 2>&1 || true
@@ -23,15 +24,19 @@ RUN gradle build
2324
RUN gradle bootJar
2425

2526
# Main Image
26-
FROM openjdk:11.0.15-jre-slim-buster
27-
28-
#Java
27+
FROM openjdk:17.0-jdk-slim
28+
# #Java
2929
RUN apt-get -y update && apt-get -y install curl && apt-get -y clean
30+
# RUN apt-get -y update && apt-get -y install wget curl unzip && apt-get -y clean
31+
# RUN wget https://www.yourkit.com/download/docker/YourKit-JavaProfiler-2023.9-docker.zip -P /tmp/ && \
32+
# unzip /tmp/YourKit-JavaProfiler-2023.9-docker.zip -d /usr/local && \
33+
# rm /tmp/YourKit-JavaProfiler-2023.9-docker.zip
3034
RUN mkdir /app
3135
COPY --from=gradlebuild /app/build/libs/identity-service-1.0-SNAPSHOT.jar /app/identity-service-1.0-SNAPSHOT.jar
3236

33-
ARG SERVER_PORT
37+
ARG SERVER_PORT
3438
EXPOSE ${SERVER_PORT}
39+
EXPOSE 10001
3540

3641
ENV JAVA_TOOL_OPTIONS "-Xmx128m"
3742

services/identity/build.gradle.kts

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
plugins {
2-
id("java")
32
application
4-
id("org.springframework.boot") version "2.6.1"
3+
id("java")
4+
id("org.springframework.boot") version "3.2.2"
55
id("io.spring.dependency-management") version "1.0.11.RELEASE"
66
id("com.diffplug.spotless") version "5.9.0"
77
}
@@ -14,11 +14,13 @@ repositories {
1414
}
1515

1616
application {
17-
mainClassName = "com.crapi.CRAPIBootApplication"
17+
mainClass.set("com.crapi.CRAPIBootApplication")
1818
}
1919

20-
java.sourceCompatibility = JavaVersion.VERSION_11
21-
20+
java {
21+
sourceCompatibility = JavaVersion.VERSION_17
22+
targetCompatibility = JavaVersion.VERSION_17
23+
}
2224
pluginManager.withPlugin("java") {
2325
apply(plugin = "com.diffplug.spotless")
2426
configure<com.diffplug.gradle.spotless.SpotlessExtension> {
@@ -32,39 +34,44 @@ pluginManager.withPlugin("java") {
3234
}
3335
}
3436
dependencies {
35-
val lombokVersion = "1.18.12"
36-
val mockito = "3.7.7"
37-
val springBootVersion = "2.6.1"
37+
val lombokVersion = "1.18.30"
38+
val mockito = "5.2.0"
39+
val springBootVersion = "3.2.2"
40+
val springSecurityVersion = "6.0.3"
3841
val log4jVersion = "2.14.0"
3942
compileOnly("org.projectlombok:lombok:${lombokVersion}")
4043
testCompileOnly("org.projectlombok:lombok:${lombokVersion}")
4144
annotationProcessor("org.projectlombok:lombok:${lombokVersion}")
42-
annotationProcessor("javax.annotation:javax.annotation-api:1.3.2")
45+
annotationProcessor("jakarta.annotation:jakarta.annotation-api:2.1.1")
4346
annotationProcessor("org.springframework.boot:spring-boot-configuration-processor")
44-
testImplementation("org.projectlombok:lombok:${lombokVersion}")
47+
annotationProcessor("jakarta.xml.bind:jakarta.xml.bind-api:4.0.1")
4548
testAnnotationProcessor("org.projectlombok:lombok-mapstruct-binding:0.2.0")
46-
implementation("org.springframework.boot:spring-boot-starter:${springBootVersion}")
47-
implementation("org.springframework.boot:spring-boot-starter-web:${springBootVersion}")
48-
implementation("org.springframework.boot:spring-boot-starter-security:${springBootVersion}")
49-
implementation("org.springframework.boot:spring-boot-starter-data-jpa:${springBootVersion}")
49+
implementation("jakarta.xml.bind:jakarta.xml.bind-api:4.0.1")
50+
implementation("org.springframework.boot:spring-boot-starter:${springBootVersion}")
51+
implementation("org.springframework.boot:spring-boot-starter-web:${springBootVersion}")
52+
implementation("org.springframework.boot:spring-boot-starter-security:${springBootVersion}")
53+
implementation("org.springframework.boot:spring-boot-starter-data-jpa:${springBootVersion}")
5054
implementation("org.springframework.boot:spring-boot-starter-mail:${springBootVersion}")
51-
implementation("org.springframework.boot:spring-boot-starter-validation:${springBootVersion}")
52-
testImplementation("org.springframework.boot:spring-boot-starter-test:${springBootVersion}")
53-
implementation("io.jsonwebtoken:jjwt:0.9.1")
54-
implementation("com.nimbusds:nimbus-jose-jwt:9.25.6")
55-
implementation("javax.validation:validation-api:2.0.1.Final")
55+
implementation("org.springframework.boot:spring-boot-starter-validation:${springBootVersion}")
56+
implementation("org.springframework.security:spring-security-config:${springSecurityVersion}")
57+
implementation("io.jsonwebtoken:jjwt:0.12.5")
58+
implementation("com.nimbusds:nimbus-jose-jwt:9.37.3")
59+
implementation("jakarta.validation:jakarta.validation-api:3.0.2")
5660
implementation("org.postgresql:postgresql:runtime")
5761
implementation("org.postgresql:postgresql:42.4.0")
5862
implementation("com.google.cloud:google-cloud-storage:2.10.0")
5963
implementation("org.apache.logging.log4j:log4j-api:${log4jVersion}")
6064
implementation("org.apache.logging.log4j:log4j-core:${log4jVersion}")
6165
implementation("org.apache.logging.log4j:log4j-web:${log4jVersion}")
62-
implementation("com.google.cloud:libraries-bom:25.4.0")
66+
implementation("com.google.cloud:libraries-bom:26.32.0")
6367
implementation("org.apache.httpcomponents:httpclient:4.5.13")
6468
implementation("com.google.cloud:google-cloud-storage:2.10.0")
69+
implementation("org.apache.httpcomponents.client5:httpclient5:5.3")
70+
testImplementation("org.springframework.boot:spring-boot-starter-test:${springBootVersion}")
71+
testImplementation("org.projectlombok:lombok:${lombokVersion}")
6572
testImplementation("org.mockito:mockito-junit-jupiter:${mockito}")
6673
testImplementation("org.mockito:mockito-core:${mockito}")
6774
testImplementation("org.mockito:mockito-inline:${mockito}")
68-
testImplementation("junit:junit:4.13.1")
75+
testImplementation("junit:junit:4.13.2")
6976
//implementation("org.apache.logging.log4j:log4j-slf4j-impl:${log4jVersion}")
7077
}

services/identity/entrypoint.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ else
77
echo "Loading default JWKS file."
88
JWKS=$(openssl base64 -in /default_jwks.json -A)
99
fi
10-
1110
java -jar /app/identity-service-1.0-SNAPSHOT.jar --app.jwksJson=$JWKS
1211

1312
exec "$@"

0 commit comments

Comments
 (0)