-
Notifications
You must be signed in to change notification settings - Fork 0
chore(spring-prometheus-grafana-example): adjustments to bring abstra… #38
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 |
|---|---|---|
|
|
@@ -37,20 +37,26 @@ jobs: | |
| run: ./mvnw clean verify | ||
|
|
||
| health-check: | ||
| name: Health Check on Services | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Checkout repository and submodules | ||
| uses: actions/checkout@v4 | ||
| with: | ||
| submodules: true | ||
|
|
||
| - name: Extract service names from docker compose | ||
| id: services | ||
| run: | | ||
| echo "services<<EOF" >> $GITHUB_OUTPUT | ||
| docker compose -f ./spring-kafka-example/compose.yaml config --services >> $GITHUB_OUTPUT | ||
| echo "EOF" >> $GITHUB_OUTPUT | ||
|
|
||
| - name: Start containers with Compose Action | ||
| uses: hoverkraft-tech/[email protected] | ||
| with: | ||
| compose-file: './spring-kafka-example/compose.yaml' | ||
| services: | | ||
| app | ||
| kafka | ||
| services: ${{ steps.services.outputs.services }} | ||
| up-flags: '--build' | ||
| down-flags: '--volumes' | ||
|
|
||
|
|
@@ -59,19 +65,14 @@ jobs: | |
|
|
||
| - name: Check container health | ||
| run: | | ||
| echo "Verificando saúde dos containers..." | ||
|
|
||
| APP_STATUS=$(docker inspect -f '{{.State.Running}}' app || echo "false") | ||
| KAFKA_STATUS=$(docker inspect -f '{{.State.Running}}' kafka || echo "false") | ||
|
|
||
| echo "Status do app: $APP_STATUS" | ||
| echo "Status do kafka: $KAFKA_STATUS" | ||
|
|
||
| if [ "$APP_STATUS" != "true" ] || [ "$KAFKA_STATUS" != "true" ]; then | ||
| echo "::error ::Um ou ambos os containers estão inativos. PR não deve ser autorizado!" | ||
| exit 1 | ||
| fi | ||
| echo "Checking the health of the containers..." | ||
|
|
||
| # Se chegou aqui, ambos estão ativos | ||
| - name: Success message | ||
| run: echo "✅ Todos os containers estão rodando com sucesso!" | ||
| SERVICES="${{ steps.services.outputs.services }}" | ||
| for service in $SERVICES; do | ||
| status=$(docker inspect -f '{{.State.Running}}' "$service" || echo "false") | ||
| echo "$service status: $status" | ||
| if [ "$status" != "true" ]; then | ||
| echo "::error ::Service $service is not running." | ||
| exit 1 | ||
| fi | ||
| done | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -37,21 +37,26 @@ jobs: | |||||||||||||||||||||||||||||||||||||||||
| run: ./mvnw clean verify | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| health-check: | ||||||||||||||||||||||||||||||||||||||||||
| name: Health Check on Services | ||||||||||||||||||||||||||||||||||||||||||
| runs-on: ubuntu-latest | ||||||||||||||||||||||||||||||||||||||||||
| steps: | ||||||||||||||||||||||||||||||||||||||||||
| - name: Checkout repository and submodules | ||||||||||||||||||||||||||||||||||||||||||
| uses: actions/checkout@v4 | ||||||||||||||||||||||||||||||||||||||||||
| with: | ||||||||||||||||||||||||||||||||||||||||||
| submodules: true | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| - name: Extract service names from docker compose | ||||||||||||||||||||||||||||||||||||||||||
| id: services | ||||||||||||||||||||||||||||||||||||||||||
| run: | | ||||||||||||||||||||||||||||||||||||||||||
| echo "services<<EOF" >> $GITHUB_OUTPUT | ||||||||||||||||||||||||||||||||||||||||||
| docker compose -f ./spring-prometheus-grafana-example/compose.yaml config --services >> $GITHUB_OUTPUT | ||||||||||||||||||||||||||||||||||||||||||
| echo "EOF" >> $GITHUB_OUTPUT | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+48
to
+54
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 Add strict shell-flags to surface failures early If - - name: Extract service names from docker compose
+ - name: Extract service names from docker compose
id: services
run: |
+ set -euo pipefail
echo "services<<EOF" >> $GITHUB_OUTPUT
docker compose -f ./spring-prometheus-grafana-example/compose.yaml config --services >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||
| - name: Start containers with Compose Action | ||||||||||||||||||||||||||||||||||||||||||
| uses: hoverkraft-tech/[email protected] | ||||||||||||||||||||||||||||||||||||||||||
| with: | ||||||||||||||||||||||||||||||||||||||||||
| compose-file: './spring-prometheus-grafana-example/compose.yaml' | ||||||||||||||||||||||||||||||||||||||||||
| services: | | ||||||||||||||||||||||||||||||||||||||||||
| app | ||||||||||||||||||||||||||||||||||||||||||
| prometheus | ||||||||||||||||||||||||||||||||||||||||||
| grafana | ||||||||||||||||||||||||||||||||||||||||||
| services: ${{ steps.services.outputs.services }} | ||||||||||||||||||||||||||||||||||||||||||
| up-flags: '--build' | ||||||||||||||||||||||||||||||||||||||||||
| down-flags: '--volumes' | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -62,19 +67,12 @@ jobs: | |||||||||||||||||||||||||||||||||||||||||
| run: | | ||||||||||||||||||||||||||||||||||||||||||
| echo "Checking the health of the containers..." | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| APP_STATUS=$(docker inspect -f '{{.State.Running}}' app || echo "false") | ||||||||||||||||||||||||||||||||||||||||||
| PROMETHEUS_STATUS=$(docker inspect -f '{{.State.Running}}' prometheus || echo "false") | ||||||||||||||||||||||||||||||||||||||||||
| GRAFANA_STATUS=$(docker inspect -f '{{.State.Running}}' grafana || echo "false") | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| echo "App status: $APP_STATUS" | ||||||||||||||||||||||||||||||||||||||||||
| echo "Prometheus status: $PROMETHEUS_STATUS" | ||||||||||||||||||||||||||||||||||||||||||
| echo "Grafana status: $GRAFANA_STATUS" | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| if [ "$APP_STATUS" != "true" ] || [ "$PROMETHEUS_STATUS" != "true" ] || [ "$GRAFANA_STATUS" != "true" ]; then | ||||||||||||||||||||||||||||||||||||||||||
| echo "::error ::An error occurred while executing the containers." | ||||||||||||||||||||||||||||||||||||||||||
| exit 1 | ||||||||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| # Se chegou aqui, ambos estão ativos | ||||||||||||||||||||||||||||||||||||||||||
| - name: Success message | ||||||||||||||||||||||||||||||||||||||||||
| run: echo "Container testing completed successfully!" | ||||||||||||||||||||||||||||||||||||||||||
| SERVICES="${{ steps.services.outputs.services }}" | ||||||||||||||||||||||||||||||||||||||||||
| for service in $SERVICES; do | ||||||||||||||||||||||||||||||||||||||||||
| status=$(docker inspect -f '{{.State.Running}}' "$service" || echo "false") | ||||||||||||||||||||||||||||||||||||||||||
| echo "$service status: $status" | ||||||||||||||||||||||||||||||||||||||||||
| if [ "$status" != "true" ]; then | ||||||||||||||||||||||||||||||||||||||||||
| echo "::error ::Service $service is not running." | ||||||||||||||||||||||||||||||||||||||||||
| exit 1 | ||||||||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+70
to
+77
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 chainUse container IDs from
- for service in $SERVICES; do
- status=$(docker inspect -f '{{.State.Running}}' "$service" || echo "false")
+ for service in $SERVICES; do
+ cid=$(docker compose -f ./spring-prometheus-grafana-example/compose.yaml ps -q "$service")
+ status=$(docker inspect -f '{{.State.Running}}' "$cid" 2>/dev/null || echo "false")
echo "$service status: $status"
if [ "$status" != "true" ]; then
echo "::error ::Service $service is not running."
exit 1
fi
doneI need to inspect the workflow to see how services are defined and whether a 🏁 Script executed: #!/bin/bash
# Locate and preview the workflow around the health-check step
file=$(fd spring-prometheus-grafana-example.yml)
echo "Workflow file: $file"
sed -n '1,200p' "$file"Length of output: 155 Gathering workflow files and inspecting Docker commands: 🏁 Script executed: #!/bin/bash
# List all workflow files
echo "Workflow files:"
find .github/workflows -type f \( -name '*.yml' -o -name '*.yaml' \)
echo ""
# Search for docker inspect in workflows
echo "docker inspect occurrences:"
rg -n 'docker inspect' .github/workflows || true
echo ""
# Search for docker compose usage in workflows
echo "docker compose occurrences:"
rg -n 'docker compose' .github/workflows || trueLength of output: 1294 Use container IDs from Relying on service names in In - for service in $SERVICES; do
- status=$(docker inspect -f '{{.State.Running}}' "$service" || echo "false")
+ for service in $SERVICES; do
+ # Get the container ID for this service
+ cid=$(docker compose -f ./spring-prometheus-grafana-example/compose.yaml ps -q "$service")
+ # Inspect by ID to avoid name mismatches
+ status=$(docker inspect -f '{{.State.Running}}' "$cid" 2>/dev/null || echo "false")
echo "$service status: $status"
if [ "$status" != "true" ]; then
echo "::error ::Service $service is not running."
exit 1
fi
done
📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||
| done | ||||||||||||||||||||||||||||||||||||||||||
|
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 a trailing newline The YAML file is missing a final newline, flagged by yamllint. - done
\ No newline at end of file
+ done
+📝 Committable suggestion
Suggested change
🧰 Tools🪛 YAMLlint (1.37.1)[error] 78-78: no new line character at the end of file (new-line-at-end-of-file) 🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧹 Nitpick (assertive)
Add a trailing newline
Identical lint warning as the other workflow—insert a newline at EOF.
📝 Committable suggestion
🧰 Tools
🪛 YAMLlint (1.37.1)
[error] 78-78: no new line character at the end of file
(new-line-at-end-of-file)
🤖 Prompt for AI Agents