Skip to content

add: github action to publish docker image#784

Merged
nevil-mathew merged 1 commit into
masterfrom
githib-actions
Aug 6, 2025
Merged

add: github action to publish docker image#784
nevil-mathew merged 1 commit into
masterfrom
githib-actions

Conversation

@nevil-mathew

@nevil-mathew nevil-mathew commented Aug 6, 2025

Copy link
Copy Markdown
Collaborator

Summary by CodeRabbit

  • New Features
    • Introduced a manual workflow to build and push Docker images with a specified tag version.
    • Supports multi-architecture image builds (amd64 and arm64).
    • Ensures Docker image tags are unique before pushing.
    • Displays pushed image tags and digest upon completion.

@coderabbitai

coderabbitai Bot commented Aug 6, 2025

Copy link
Copy Markdown

Walkthrough

A new GitHub Actions workflow file is added to automate building and pushing Docker images. This workflow is manually triggered on the docker-image branch, requires a tag_version input, checks for tag uniqueness on Docker Hub, builds multi-architecture images, and pushes them with appropriate metadata and caching.

Changes

Cohort / File(s) Change Summary
GitHub Actions Workflow Addition
.github/workflows/docker-image.yml
Introduces a workflow for manual Docker image build and push, including tag validation, multi-arch build, and metadata handling.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant GitHub Actions
    participant Docker Hub

    User->>GitHub Actions: Manually triggers workflow with tag_version
    GitHub Actions->>GitHub Actions: Checkout code
    GitHub Actions->>GitHub Actions: Setup Buildx
    GitHub Actions->>Docker Hub: Login with secrets
    GitHub Actions->>Docker Hub: Check if tag exists
    alt Tag exists
        GitHub Actions-->>User: Abort workflow
    else Tag does not exist
        GitHub Actions->>GitHub Actions: Extract metadata
        GitHub Actions->>Docker Hub: Build & push multi-arch image
        GitHub Actions->>User: Output image digest and tags
    end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🐇
A Docker dance upon the cloud,
With tags unique, no duplicates allowed.
Multi-arch builds in a single sweep,
Metadata secrets the workflow will keep.
Push and print, the job is done—
Another carrot for a rabbit won!
🥕

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

🪧 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.
  • 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.

Support

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

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (3)
.github/workflows/docker-image.yml (3)

33-46: Shell test style is brittle

Using [ ! -z "$VAR" ] can break when $VAR contains spaces or is unset with set -u.
Prefer the more idiomatic -n test and always quote the variable:

-if [ ! -z "${{ github.event.inputs.tag_version }}" ]; then
+if [ -n "${{ github.event.inputs.tag_version }}" ]; then
...
-elif [ ! -z "${TAG_VERSION}" ]; then
+elif [ -n "${TAG_VERSION}" ]; then

This small change improves robustness without altering behaviour.


68-79: Consider enabling provenance/SBOM generation

docker/build-push-action@v5 supports provenance=true and sbom=true flags, producing SLSA provenance and CycloneDX SBOM without extra effort—valuable for supply-chain transparency.

         platforms: linux/amd64,linux/arm64
+        provenance: true
+        sbom: true
         cache-from: type=gha

87-87: Add a trailing newline

YAMLlint flags the missing newline at EOF.
Appending one keeps tooling quiet and adheres to POSIX text-file conventions.

-        echo "${{ steps.meta.outputs.tags }}" | tr ',' '\n'
+        echo "${{ steps.meta.outputs.tags }}" | tr ',' '\n'
+
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 7201adf and 32f2d53.

📒 Files selected for processing (1)
  • .github/workflows/docker-image.yml (1 hunks)
🧰 Additional context used
🪛 YAMLlint (1.37.1)
.github/workflows/docker-image.yml

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

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

Comment on lines +17 to +18
if: github.event_name == 'workflow_dispatch' && github.ref == 'refs/heads/docker-image'
runs-on: ubuntu-latest

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Job-level if: clause is redundant and over-restrictive

The workflow is already limited to workflow_dispatch via the on: section.
Adding an extra if: gate that hard-codes refs/heads/docker-image prevents maintainers from manually triggering the build from forks or feature branches—even though workflow_dispatch supports a branches: filter.

Consider removing the if: or moving the branch filter into the on.workflow_dispatch block:

-on:
-  workflow_dispatch:
-    inputs:
+on:
+  workflow_dispatch:
+    branches: [docker-image]
+    inputs:
...
-    if: github.event_name == 'workflow_dispatch' && github.ref == 'refs/heads/docker-image'
🤖 Prompt for AI Agents
In .github/workflows/docker-image.yml around lines 17 to 18, remove the
job-level if: condition that checks for github.event_name and github.ref because
it is redundant and restricts manual triggers from forks or feature branches.
Instead, move the branch filtering to the on.workflow_dispatch section by
specifying branches there, allowing more flexible manual triggering while
keeping the workflow limited to workflow_dispatch events.

Comment on lines +48 to +58
- name: Check if version exists on Docker Hub
id: check-version
run: |
VERSION=${{ steps.get-version.outputs.version }}
RESPONSE=$(curl -s -o /dev/null -w "%{http_code}" "https://hub.docker.com/v2/namespaces/${{ env.DOCKER_NAMESPACE }}/repositories/${{ env.DOCKER_IMAGE_NAME }}/tags/$VERSION")
if [ "$RESPONSE" -eq 200 ]; then
echo "Error: Tag $VERSION already exists on Docker Hub"
exit 1
else
echo "Tag $VERSION does not exist, proceeding with build"
fi

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Unauthenticated tag-existence check is fragile

The curl probe is unauthenticated, so:

• Private repositories will return 401, not 404.
• Public repositories are subject to Docker Hub’s low anonymous-rate limits.

Inject the Docker Hub token to avoid both issues and broaden the status-code check:

-RESPONSE=$(curl -s -o /dev/null -w "%{http_code}" "https://hub.docker.com/v2/namespaces/${{ env.DOCKER_NAMESPACE }}/repositories/${{ env.DOCKER_IMAGE_NAME }}/tags/$VERSION")
+RESPONSE=$(curl -s -o /dev/null -w "%{http_code}" \
+  -H "Authorization: Bearer ${{ secrets.DOCKERHUB_TOKEN }}" \
+  "https://hub.docker.com/v2/namespaces/${{ env.DOCKER_NAMESPACE }}/repositories/${{ env.DOCKER_IMAGE_NAME }}/tags/$VERSION")
+# Treat 200 (exists) vs 404 (missing); fail on 401/429 to surface auth or rate-limit problems.

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
In .github/workflows/docker-image.yml around lines 48 to 58, the curl command
checking if a Docker tag exists is unauthenticated, causing 401 errors for
private repos and rate limiting for public ones. Modify the curl command to
include authentication by injecting the Docker Hub token via an Authorization
header. Also, update the status code check to handle a broader range of success
codes appropriately, ensuring reliable detection of existing tags.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant