Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev #19

Merged
merged 29 commits into from
May 26, 2024
Merged

Dev #19

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
16c1f4b
Merge pull request #5 from ADPRO-C11/dev
asteriskzie May 1, 2024
628df10
[FIX] Fix CD workflow
asteriskzie May 1, 2024
55bb53d
[FIX] Fix cd workflow
asteriskzie May 1, 2024
5518184
Add async function
asteriskzie May 8, 2024
9c61cfd
[REFACTOR] simplify controller API endpoint path
asteriskzie May 8, 2024
124e622
[REFACTOR] Rename APO endpoint path, rename user to author, change re…
asteriskzie May 15, 2024
a416bbc
[FIX] Change application properties
asteriskzie May 15, 2024
d8e6f42
Merge pull request #8 from ADPRO-C11/basic-crud
asteriskzie May 15, 2024
032d5df
[FIX] Fix ci-cd application properties
asteriskzie May 15, 2024
f45549c
Add prometheus & grafana config
asteriskzie May 15, 2024
eefe104
Add Prometheus and Grafana configuration
asteriskzie May 18, 2024
cc9c970
Merge pull request #9 from ADPRO-C11/deployment-monitoring
asteriskzie May 18, 2024
130fa41
[FIX] fix Dockerfile
asteriskzie May 18, 2024
6cb3966
Merge branch 'dev' into async
asteriskzie May 18, 2024
26bc305
Add SonarCloud analysis workflow and configuration files
asteriskzie May 18, 2024
697428a
Merge pull request #12 from ADPRO-C11/async
asteriskzie May 18, 2024
1ab0694
Merge pull request #13 from ADPRO-C11/sonar
asteriskzie May 18, 2024
55c1249
chore: Update SonarCloud workflow to include dev branch
asteriskzie May 18, 2024
1316bfb
Merge pull request #14 from ADPRO-C11/sonar
asteriskzie May 18, 2024
f3c9895
[REFACTOR] Rename variables and improve code readability
asteriskzie May 18, 2024
5b315ac
[FIX] Fix sonarcloud workflow
asteriskzie May 18, 2024
58fcb8c
[FIX] Add test coverage
asteriskzie May 18, 2024
ad36882
[FIX] Update workflow
asteriskzie May 18, 2024
0bcb63d
[FIX] Remove sonarcloud workflow
asteriskzie May 18, 2024
4bc3c8f
Revert "Merge pull request #12 from ADPRO-C11/async"
asteriskzie May 19, 2024
c4e50d3
Configure prometheus to monitor deployed app
asteriskzie May 20, 2024
a0f92f4
Merge pull request #16 from ADPRO-C11/sonar
asteriskzie May 25, 2024
c8aac1a
[FIX] Fix Sonar settings
asteriskzie May 26, 2024
78a3a29
Merge pull request #18 from ADPRO-C11/sonar
asteriskzie May 26, 2024
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 .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,24 @@ jobs:
./gradlew check --info --stacktrace
./gradlew test
./gradlew jacocoTestReport
env:
PRODUCTION: test
# (Optional) Add steps for generating coverage report and other post-test tasks

publish:
name: Publish Docker Image
runs-on: ubuntu-latest
needs: test
services:
postgres:
image: postgres:latest
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: snackscription_review
ports:
- 5432:5432
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
steps:
- name: Checkout Repository
uses: actions/checkout@v4
Expand Down
13 changes: 6 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,7 @@ name: Java CI Pipeline
on:
push:
branches:
- main
- dev
pull_request:
branches:
- main
- dev
- "**"
workflow_dispatch:

jobs:
Expand Down Expand Up @@ -70,8 +65,10 @@ jobs:
distribution: "temurin"
java-version: "21"
cache: "gradle"

- name: Make gradlew executable
run: chmod +x ./gradlew

- name: Cache Gradle dependencies
uses: actions/cache@v4
with:
Expand All @@ -85,4 +82,6 @@ jobs:
./gradlew check --info --stacktrace
./gradlew test
./gradlew jacocoTestReport
# (Optional) Add steps for generating coverage report and other post-test tasks
env:
PRODUCTION: test
# (Optional) Add steps for generating coverage report and other post-test tasks
19 changes: 19 additions & 0 deletions .monitoring/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
version: '3.7'

services:
prometheus:
image: prom/prometheus:v2.44.0
container_name: prometheus
ports:
- "9090:9090"
volumes:
- ./prometheus/prometheus.yml:/etc/prometheus/prometheus.yml

grafana:
image: grafana/grafana:9.5.2
container_name: grafana
ports:
- "3000:3000"
restart: unless-stopped
volumes:
- ./grafana/provisioning/datasources:/etc/grafana/provisioning/datasources
7 changes: 7 additions & 0 deletions .monitoring/grafana/provisioning/datasources/datasources.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
apiVersion: 1
datasources:
- name: Prometheus
type: prometheus
access: proxy
url: http://prometheus:9090
isDefault: true
11 changes: 11 additions & 0 deletions .monitoring/prometheus/prometheus.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
scrape_configs:
- job_name: 'Snackscription Metrics'
metrics_path: '/actuator/prometheus'
scrape_interval: 3s
static_configs:
- targets: ['host.docker.internal:8080']
labels:
application: 'Snackscription Review'
- targets: ['34.124.152.90']
labels:
application: 'Snackscription Review (deployed)'
5 changes: 5 additions & 0 deletions application.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
management:
endpoints:
web:
exposure:
include: [ "prometheus" ]
16 changes: 15 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ plugins {
id("org.springframework.boot") version "3.2.5"
id("io.spring.dependency-management") version "1.1.4"
jacoco
id("org.sonarqube") version "4.4.1.3373"
}

group = "snackscription"
Expand All @@ -12,6 +13,7 @@ java {
sourceCompatibility = JavaVersion.VERSION_21
}


configurations {
compileOnly {
extendsFrom(configurations.annotationProcessor.get())
Expand All @@ -26,6 +28,9 @@ dependencies {
implementation("org.springframework.boot:spring-boot-starter-data-jpa")
implementation("org.springframework.boot:spring-boot-starter-thymeleaf")
implementation("org.springframework.boot:spring-boot-starter-web")
implementation("org.springframework.boot:spring-boot-starter-actuator")
implementation("io.micrometer:micrometer-registry-prometheus")
implementation("io.micrometer:micrometer-core")
compileOnly("org.projectlombok:lombok")
developmentOnly("org.springframework.boot:spring-boot-devtools")
runtimeOnly("org.postgresql:postgresql")
Expand All @@ -48,8 +53,17 @@ tasks.jacocoTestReport {
}))
dependsOn(tasks.test)
reports {
xml.required.set(false)
xml.required.set(true)
html.required.set(true)
csv.required.set(false)
html.outputLocation.set(layout.buildDirectory.dir("jacocoHtml"))
}
}

sonar {
properties {
property("sonar.projectKey","ADPRO-C11_snackscription-review")
property("sonar.organization", "adpro-c11")
property("sonar.host.url", "https://sonarcloud.io")
}
}
22 changes: 22 additions & 0 deletions deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: snackscription-review-deployment
spec:
replicas: 3
selector:
matchLabels:
app: snackscription-review
template:
metadata:
labels:
app: snackscription-review
spec:
containers:
- name: snackscription-review
image: asteriskzie/snackscription-review:latest
ports:
- containerPort: 8080
env:
- name: PRODUCTION
value: prod
5 changes: 5 additions & 0 deletions gradle/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
systemProp.sonar.host.url=https://sonarcloud.io

# Token generated from an account with 'Execute analysis' permission.
# It can also be set with the environment variable SONAR_TOKEN.
systemProp.sonar.token=${SONAR_TOKEN}
2 changes: 1 addition & 1 deletion gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
# Collect all arguments for the java command:
# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
# and any embedded shellness will be escaped.
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
# * For example: A author cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
# treated as '${Hostname}' itself on the command line.

set -- \
Expand Down
11 changes: 11 additions & 0 deletions service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apiVersion: v1
kind: Service
metadata:
name: snackscription-review-service
spec:
type: LoadBalancer
ports:
- port: 80
targetPort: 8080
selector:
app: snackscription-review
14 changes: 14 additions & 0 deletions src/main/java/snackscription/review/ReviewAppConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package snackscription.review;

import io.micrometer.core.instrument.MeterRegistry;
import io.micrometer.core.instrument.composite.CompositeMeterRegistry;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class ReviewAppConfig {
@Bean
public MeterRegistry getMeterRegistry() {
return new CompositeMeterRegistry();
}
}
Loading