-
Notifications
You must be signed in to change notification settings - Fork 0
feat(spring-prometheus-grafana-example): add base #31
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| name: spring-prometheus-grafana-example CI Build | ||
|
|
||
| on: | ||
| pull_request: | ||
| branches: [master] | ||
| paths: | ||
| - "spring-prometheus-grafana-example/**" | ||
| types: | ||
| - opened | ||
| - synchronize | ||
| - reopened | ||
|
|
||
| jobs: | ||
|
|
||
| integration-tests: | ||
| name: Run Unit & Integration Tests | ||
| runs-on: ubuntu-latest | ||
| defaults: | ||
| run: | ||
| working-directory: spring-prometheus-grafana-example | ||
| strategy: | ||
| matrix: | ||
| distribution: [ 'temurin' ] | ||
| java: [ '21' ] | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| with: | ||
| fetch-depth: 0 | ||
|
|
||
| - name: Set up JDK ${{ matrix.java }} | ||
| uses: actions/[email protected] | ||
| with: | ||
| java-version: ${{ matrix.java }} | ||
| distribution: ${{ matrix.distribution }} | ||
| cache: 'maven' | ||
| - name: Build and analyze | ||
| run: ./mvnw clean verify | ||
|
|
||
| health-check: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Checkout repository and submodules | ||
| uses: actions/checkout@v4 | ||
| with: | ||
| submodules: true | ||
|
|
||
| - name: Start containers with Compose Action | ||
| uses: hoverkraft-tech/[email protected] | ||
| with: | ||
| compose-file: './spring-prometheus-grafana-example/compose.yaml' | ||
| services: | | ||
| app | ||
| up-flags: '--build' | ||
| down-flags: '--volumes' | ||
|
|
||
| - name: Wait for containers to initialize | ||
| run: sleep 10 | ||
|
|
||
| - name: Check container health | ||
| run: | | ||
| echo "Verificando saúde dos containers..." | ||
|
|
||
| APP_STATUS=$(docker inspect -f '{{.State.Running}}' app || echo "false") | ||
|
|
||
| echo "Status do app: $APP_STATUS" | ||
|
|
||
| if [ "$APP_STATUS" != "true" ]; then | ||
| echo "::error ::An error occurred while executing the containers." | ||
| exit 1 | ||
| fi | ||
igorcampos-dev marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| # Se chegou aqui, ambos estão ativos | ||
| - name: Success message | ||
| run: echo "Container testing completed successfully!" | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| # Include any files or directories that you don't want to be copied to your | ||
| # container here (e.g., local build artifacts, temporary files, etc.). | ||
| # | ||
| # For more help, visit the .dockerignore file reference guide at | ||
| # https://docs.docker.com/go/build-context-dockerignore/ | ||
|
|
||
| **/.DS_Store | ||
| **/.classpath | ||
| **/.dockerignore | ||
| **/.env | ||
| **/.factorypath | ||
| **/.git | ||
| **/.gitignore | ||
| **/.idea | ||
| **/.project | ||
| **/.sts4-cache | ||
| **/.settings | ||
| **/.toolstarget | ||
| **/.vs | ||
| **/.vscode | ||
| **/.next | ||
| **/.cache | ||
| **/*.dbmdl | ||
| **/*.jfm | ||
| **/charts | ||
| **/docker-compose* | ||
| **/compose.y*ml | ||
| **/Dockerfile* | ||
| **/secrets.dev.yaml | ||
| **/values.dev.yaml | ||
| **/vendor | ||
| LICENSE | ||
| README.md | ||
| **/*.class | ||
igorcampos-dev marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| **/*.iml | ||
| **/*.ipr | ||
| **/*.iws | ||
| **/*.log | ||
| **/.apt_generated | ||
| **/.gradle | ||
| **/.gradletasknamecache | ||
| **/.nb-gradle | ||
| **/.springBeans | ||
| **/build | ||
| **/dist | ||
| **/gradle-app.setting | ||
| **/nbbuild | ||
| **/nbdist | ||
| **/nbproject/private | ||
| **/target | ||
| *.ctxt | ||
| .mtj.tmp | ||
| .mvn/timing.properties | ||
| buildNumber.properties | ||
| dependency-reduced-pom.xml | ||
| hs_err_pid* | ||
| pom.xml.next | ||
| pom.xml.releaseBackup | ||
| pom.xml.tag | ||
| pom.xml.versionsBackup | ||
| release.properties | ||
| replay_pid* | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| /mvnw text eol=lf | ||
| *.cmd text eol=crlf |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| name: CI Build | ||
|
|
||
| on: | ||
| push: | ||
| branches: | ||
| - "**" | ||
|
|
||
| jobs: | ||
| build: | ||
| name: Build | ||
| runs-on: ubuntu-latest | ||
| strategy: | ||
| matrix: | ||
| distribution: [ 'temurin' ] | ||
| java: [ '21' ] | ||
| steps: | ||
igorcampos-dev marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| - uses: actions/checkout@v4 | ||
|
|
||
| - name: Setup Java 21 | ||
| uses: actions/setup-java@v4 | ||
| with: | ||
| java-version: ${{ matrix.java }} | ||
| distribution: ${{ matrix.distribution }} | ||
| cache: 'maven' | ||
|
|
||
| - name: Grant execute permission for mvnw | ||
| run: chmod +x mvnw | ||
|
|
||
| - name: Build with Maven | ||
| run: ./mvnw clean verify | ||
igorcampos-dev marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| target/ | ||
| .mvn/wrapper/maven-wrapper.jar | ||
| !**/src/main/**/target/ | ||
| !**/src/test/**/target/ | ||
|
|
||
| ### STS ### | ||
| .apt_generated | ||
| .classpath | ||
| .factorypath | ||
| .project | ||
| .settings | ||
| .springBeans | ||
| .sts4-cache | ||
|
|
||
| ### IntelliJ IDEA ### | ||
| .idea | ||
| *.iws | ||
| *.iml | ||
| *.ipr | ||
|
|
||
| ### NetBeans ### | ||
| /nbproject/private/ | ||
| /nbbuild/ | ||
| /dist/ | ||
| /nbdist/ | ||
| /.nb-gradle/ | ||
| build/ | ||
| !**/src/main/**/build/ | ||
| !**/src/test/**/build/ | ||
|
|
||
| ### VS Code ### | ||
| .vscode/ |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| # Licensed to the Apache Software Foundation (ASF) under one | ||
| # or more contributor license agreements. See the NOTICE file | ||
| # distributed with this work for additional information | ||
| # regarding copyright ownership. The ASF licenses this file | ||
| # to you under the Apache License, Version 2.0 (the | ||
| # "License"); you may not use this file except in compliance | ||
| # with the License. You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, | ||
| # software distributed under the License is distributed on an | ||
| # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| # KIND, either express or implied. See the License for the | ||
| # specific language governing permissions and limitations | ||
| # under the License. | ||
| wrapperVersion=3.3.2 | ||
| distributionType=only-script | ||
| distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.11/apache-maven-3.9.11-bin.zip |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,47 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| FROM eclipse-temurin:21-jdk-jammy as deps | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| WORKDIR /build | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| COPY --chmod=0755 mvnw mvnw | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| COPY .mvn/ .mvn/ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| RUN --mount=type=bind,source=pom.xml,target=pom.xml \ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| --mount=type=cache,target=/root/.m2 ./mvnw dependency:go-offline -DskipTests | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| FROM deps as package | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| WORKDIR /build | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| COPY ./src src/ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| RUN --mount=type=bind,source=pom.xml,target=pom.xml \ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| --mount=type=cache,target=/root/.m2 \ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ./mvnw package -DskipTests && \ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| mv target/$(./mvnw help:evaluate -Dexpression=project.artifactId -q -DforceStdout)-$(./mvnw help:evaluate -Dexpression=project.version -q -DforceStdout).jar target/app.jar | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+16
to
+19
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick (assertive) Quote command substitution to avoid word-splitting (Hadolint SC2046) - mv target/$(./mvnw help:evaluate -Dexpression=project.artifactId -q -DforceStdout)-$(./mvnw help:evaluate -Dexpression=project.version -q -DforceStdout).jar target/app.jar
+ mv target/"$(./mvnw help:evaluate -Dexpression=project.artifactId -q -DforceStdout)"-"$(./mvnw help:evaluate -Dexpression=project.version -q -DforceStdout)".jar target/app.jarPrevents edge-cases when artifactId contains spaces. 📝 Committable suggestion
Suggested change
🧰 Tools🪛 Hadolint (2.12.0)[warning] 16-16: Quote this to prevent word splitting. (SC2046) 🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| FROM package as extract | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| WORKDIR /build | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| RUN java -Djarmode=layertools -jar target/app.jar extract --destination target/extracted | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| FROM eclipse-temurin:21-jre-jammy AS final | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ARG UID=10001 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| RUN adduser \ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| --disabled-password \ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| --gecos "" \ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| --home "/nonexistent" \ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| --shell "/sbin/nologin" \ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| --no-create-home \ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| --uid "${UID}" \ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| appuser | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| USER appuser | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| COPY --from=extract build/target/extracted/dependencies/ ./ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| COPY --from=extract build/target/extracted/spring-boot-loader/ ./ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| COPY --from=extract build/target/extracted/snapshot-dependencies/ ./ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| COPY --from=extract build/target/extracted/application/ ./ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+27
to
+43
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Set Without a -FROM eclipse-temurin:21-jre-jammy AS final
+FROM eclipse-temurin:21-jre-jammy AS final
+
+WORKDIR /app
...
-COPY --from=extract build/target/extracted/dependencies/ ./
+COPY --from=extract /build/target/extracted/dependencies/ ./(Repeat for the other three COPY lines.) This keeps the layer structure tidy and predictable. 📝 Committable suggestion
Suggested change
🧰 Tools🪛 Hadolint (2.12.0)[warning] 40-40: (DL3045) [warning] 41-41: (DL3045) [warning] 42-42: (DL3045) [warning] 43-43: (DL3045) 🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| EXPOSE 80 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ENTRYPOINT [ "java", "org.springframework.boot.loader.launch.JarLauncher" ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+45
to
+47
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick (assertive) Provide a container Checkov flags missing health-checks. A lightweight HTTP probe against Spring Boot’s actuator keeps orchestrators informed: EXPOSE 80
+HEALTHCHECK --interval=30s --timeout=3s --retries=3 \
+ CMD curl -f http://localhost:80/actuator/health || exit 1
+
ENTRYPOINT [ "java", "org.springframework.boot.loader.launch.JarLauncher" ]📝 Committable suggestion
Suggested change
🧰 Tools🪛 Checkov (3.2.334)[LOW] 1-47: Ensure that HEALTHCHECK instructions have been added to container images (CKV_DOCKER_2) 🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,9 @@ | ||||||||||||
|
|
||||||||||||
| services: | ||||||||||||
|
Comment on lines
+1
to
+2
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick (assertive) Remove leading blank line—YAMLlint failure The first empty line violates -
services:📝 Committable suggestion
Suggested change
🧰 Tools🪛 YAMLlint (1.37.1)[error] 1-1: too many blank lines (1 > 0) (empty-lines) 🤖 Prompt for AI Agents |
||||||||||||
|
|
||||||||||||
| app: | ||||||||||||
| container_name: app | ||||||||||||
| build: | ||||||||||||
| context: . | ||||||||||||
| ports: | ||||||||||||
| - "80:80" | ||||||||||||
|
Comment on lines
+4
to
+9
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Verification agent 🧩 Analysis chainConsider including Prometheus & Grafana services Since this example showcases Prometheus/Grafana integration, composing those containers here would let users spin up the full stack with one command. If omission is intentional (e.g., external stack or k8s), feel free to disregard. 🏁 Script executed: #!/bin/bash
# Locate any Docker Compose files and show their contents
find . -maxdepth 3 -type f \( -name "*compose*.yml" -o -name "*compose*.yaml" \) | while read -r f; do
echo "File: $f"
head -n 200 "$f"
echo "----"
doneLength of output: 1408 Add Prometheus & Grafana services to the Compose file To enable users to bring up the full Prometheus/Grafana stack with the example, extend • File: spring-prometheus-grafana-example/compose.yaml Suggested diff: services:
app:
container_name: app
build:
context: .
ports:
- "80:80"
+ prometheus:
+ container_name: prometheus
+ image: prom/prometheus:latest
+ ports:
+ - "9090:9090"
+ volumes:
+ - ./prometheus/prometheus.yml:/etc/prometheus/prometheus.yml
+
+ grafana:
+ container_name: grafana
+ image: grafana/grafana:latest
+ ports:
+ - "3000:3000"
+ environment:
+ GF_SECURITY_ADMIN_PASSWORD: "admin"If you intentionally manage Prometheus/Grafana outside of this Compose file (e.g., via Kubernetes or an external stack), you can ignore this suggestion. 🧰 Tools🪛 YAMLlint (1.37.1)[error] 9-9: no new line character at the end of file (new-line-at-end-of-file) 🤖 Prompt for AI Agents
Comment on lines
+8
to
+9
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick (assertive) Add terminating newline A missing final newline also raises YAMLlint warnings and can trip diff tools. - - "80:80"
+ - "80:80"
+📝 Committable suggestion
Suggested change
🧰 Tools🪛 YAMLlint (1.37.1)[error] 9-9: no new line character at the end of file (new-line-at-end-of-file) 🤖 Prompt for AI Agents |
||||||||||||
Uh oh!
There was an error while loading. Please reload this page.