Skip to content

Conversation

@igorcampos-dev
Copy link
Owner

@igorcampos-dev igorcampos-dev commented Jul 26, 2025

…ction in the GitHub workflows

Summary by CodeRabbit

  • Chores
    • Improved workflow reliability by dynamically detecting and health-checking all Docker Compose services, instead of relying on hardcoded service names, in relevant GitHub Actions workflows. This ensures all defined services are properly checked and handled during CI runs.

@coderabbitai
Copy link

coderabbitai bot commented Jul 26, 2025

Walkthrough

The GitHub Actions workflows for both the Spring Kafka and Spring Prometheus Grafana examples were updated to dynamically extract service names from their Docker Compose files. The health check steps now iterate over all detected services, checking each container's running state, replacing previous hardcoded service checks.

Changes

Files Change Summary
.github/workflows/spring-kafka-example.yml
.github/workflows/spring-prometheus-grafana-example.yml
Refactored workflow health-check jobs to dynamically extract and check all Docker Compose services instead of hardcoded service names.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Possibly related PRs

  • Update spring-kafka-example.yml #27: Previously added a static health-check job for hardcoded services in the spring-kafka-example workflow; this PR directly refactors and generalizes that logic.

Suggested labels

ci: github-actions

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.

✨ Finishing Touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch chore/issue-34

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

♻️ Duplicate comments (1)
.github/workflows/spring-kafka-example.yml (1)

48-77: Same improvements recommended as for the Prometheus/Grafana workflow

The extraction step should enable strict shell flags, and the health-check loop should rely on container IDs from docker compose ps to prevent false negatives. See prior comments on lines 48-54 and 70-77 of the Prometheus/Grafana workflow for concrete diffs.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5fe8824 and d875f7d.

📒 Files selected for processing (2)
  • .github/workflows/spring-kafka-example.yml (2 hunks)
  • .github/workflows/spring-prometheus-grafana-example.yml (2 hunks)
🧰 Additional context used
🧠 Learnings (3)
📓 Common learnings
Learnt from: igorcampos-dev
PR: igorcampos-dev/spring-integrations-examples#21
File: spring-kafka-example/README.md:12-17
Timestamp: 2025-07-22T01:35:41.406Z
Learning: User igorcampos-dev prefers minimal, high-level documentation in README files without detailed version specifications, choosing to keep tech stack information simple rather than adding precise version numbers.
Learnt from: igorcampos-dev
PR: igorcampos-dev/spring-integrations-examples#26
File: spring-kafka-example/compose.yaml:3-4
Timestamp: 2025-07-24T01:40:49.337Z
Learning: User igorcampos-dev requires hard-coded container names in Docker Compose files (like `container_name: app`) for CI pipeline validation purposes, which is a valid operational requirement that overrides the general best practice of avoiding hard-coded container names.
Learnt from: igorcampos-dev
PR: igorcampos-dev/spring-integrations-examples#21
File: spring-kafka-example/compose.yaml:30-32
Timestamp: 2025-07-22T01:30:57.054Z
Learning: User igorcampos-dev prefers to maintain environment parity between local development and production, avoiding development-specific configurations like ALLOW_PLAINTEXT_LISTENER even when they might provide clearer intent or safety nets.
.github/workflows/spring-kafka-example.yml (1)

Learnt from: igorcampos-dev
PR: #26
File: spring-kafka-example/compose.yaml:3-4
Timestamp: 2025-07-24T01:40:49.337Z
Learning: User igorcampos-dev requires hard-coded container names in Docker Compose files (like container_name: app) for CI pipeline validation purposes, which is a valid operational requirement that overrides the general best practice of avoiding hard-coded container names.

.github/workflows/spring-prometheus-grafana-example.yml (1)

Learnt from: igorcampos-dev
PR: #26
File: spring-kafka-example/compose.yaml:3-4
Timestamp: 2025-07-24T01:40:49.337Z
Learning: User igorcampos-dev requires hard-coded container names in Docker Compose files (like container_name: app) for CI pipeline validation purposes, which is a valid operational requirement that overrides the general best practice of avoiding hard-coded container names.

🪛 YAMLlint (1.37.1)
.github/workflows/spring-kafka-example.yml

[error] 78-78: no new line character at the end of file

(new-line-at-end-of-file)

.github/workflows/spring-prometheus-grafana-example.yml

[error] 78-78: no new line character at the end of file

(new-line-at-end-of-file)

echo "::error ::Service $service is not running."
exit 1
fi
done
Copy link

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.

-          done
\ No newline at end of file
+          done
+
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
done
done
🧰 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
In .github/workflows/spring-kafka-example.yml at line 78, the file is missing a
trailing newline at the end of the file. Add a single newline character after
the last line to comply with linting rules and ensure proper file formatting.

Comment on lines +48 to +54
- 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
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add strict shell-flags to surface failures early

If docker compose config --services fails (e.g., syntax error in compose.yaml or missing CLI plugin), the step will still succeed and later steps will receive an empty services output, masking the root cause. Enable set -euo pipefail so that the workflow aborts immediately on any error.

-      - 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

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
- 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
- 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
🤖 Prompt for AI Agents
In .github/workflows/spring-prometheus-grafana-example.yml around lines 48 to
54, the shell script running the docker compose command lacks strict error
handling, so failures do not abort the workflow immediately. Add `set -euo
pipefail` at the start of the run block to ensure the step fails fast on any
error, preventing silent failures and empty outputs downstream.

Comment on lines +70 to +77
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
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Verification agent

🧩 Analysis chain

Use container IDs from docker compose ps to avoid name-mismatch errors

docker inspect "$service" assumes every service sets container_name: and that the runtime name equals the service name. If those assumptions ever change, the health-check produces false negatives. Resolve by asking Compose for the container ID first:

-          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
           done

I need to inspect the workflow to see how services are defined and whether a COMPOSE_FILE variable is in use. Gathering context now:


🏁 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 || true

Length of output: 1294


Use container IDs from docker compose ps for reliable health checks

Relying on service names in docker inspect assumes the runtime container name matches the Compose service name (or a hard-coded container_name:). To avoid false negatives if that ever changes, first query the container ID with docker compose ps -q and then inspect that ID:

In .github/workflows/spring-prometheus-grafana-example.yml (around lines 70–77), update the loop as follows:

-          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
  • Ensures the health check always targets the correct container, regardless of explicit container_name: settings or Compose naming conventions.
  • Uses the same Compose file path you already reference for config --services.
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
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
SERVICES="${{ steps.services.outputs.services }}"
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
🤖 Prompt for AI Agents
In .github/workflows/spring-prometheus-grafana-example.yml around lines 70 to
77, the current health check uses service names with docker inspect, which can
fail if container names differ from service names. To fix this, first retrieve
container IDs using docker compose ps -q with the same Compose file path, then
loop over these container IDs to inspect their running state. This ensures the
health check targets the correct containers regardless of naming conventions or
container_name overrides.

echo "::error ::Service $service is not running."
exit 1
fi
done
Copy link

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

The YAML file is missing a final newline, flagged by yamllint.
Fixing it avoids noisy lint failures.

-          done
\ No newline at end of file
+          done
+
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
done
done
🧰 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
In .github/workflows/spring-prometheus-grafana-example.yml at line 78, the file
is missing a trailing newline at the end. Add a newline character after the last
line to comply with YAML formatting standards and prevent yamllint warnings.

@igorcampos-dev igorcampos-dev merged commit a17fcb4 into master Jul 26, 2025
3 checks passed
@igorcampos-dev igorcampos-dev deleted the chore/issue-34 branch July 26, 2025 21:13
@coderabbitai coderabbitai bot mentioned this pull request Aug 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unify service list between GitHub workflow and compose.yaml to avoid duplication

2 participants