Skip to content

Commit

Permalink
Merge pull request #19 from ADPRO-C11/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
asteriskzie authored May 26, 2024
2 parents fb3c52e + 78a3a29 commit 4f48d23
Show file tree
Hide file tree
Showing 23 changed files with 375 additions and 476 deletions.
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

0 comments on commit 4f48d23

Please sign in to comment.