Skip to content

feat: Github Action | Build and push image to DockerHub - #23

Merged
lvarin merged 5 commits into
devfrom
github_actions
Jan 20, 2025
Merged

lvarin merged 5 commits into
devfrom
github_actions

Conversation

@akash2237778

@akash2237778 akash2237778 commented Jan 13, 2025 •

Copy link
Copy Markdown
Collaborator

Description

Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. List any dependencies that are required for this change.

Fixes # (issue)

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • I have not reduced the existing code coverage
  • I have added docstrings following the Python style guidelines of this project to all new modules, classes, methods and functions are documented with docstrings following; I have updated any previously existing docstrings, if applicable
  • I have updated any sections of the app's documentation that are affected by the proposed changes, if applicable

Summary by Sourcery

CI:

  • Add GitHub Action workflow to build and push Docker image to DockerHub on push events.

@sourcery-ai

sourcery-ai Bot commented Jan 13, 2025 •

Copy link
Copy Markdown

Reviewer's Guide by Sourcery

This pull request introduces a new GitHub Action workflow to automate the process of building and pushing Docker images to DockerHub. The workflow is defined in a new file 'main.yaml' and is triggered by pushes to the 'github_actions' branch. It includes steps for checking out the repository, generating a tag, building and publishing the Docker image using 'philips-software/docker-ci-scripts', and verifying the push. Environment variables for DockerHub credentials are configured using GitHub secrets.

Sequence diagram for GitHub Actions Docker build and push workflow

sequenceDiagram
    participant Dev as Developer
    participant GH as GitHub
    participant Action as GitHub Action
    participant DH as DockerHub

    Dev->>GH: Push to github_actions branch
    GH->>Action: Trigger workflow
    Action->>Action: Check out repository
    Action->>Action: Generate date-based tag
    Action->>Action: Build Docker image
    Action->>DH: Authenticate with credentials
    Action->>DH: Push image with tags
    Action->>Action: Verify push status
    Action-->>GH: Report workflow result
Loading

File-Level Changes

Change Details Files
Added a GitHub Action workflow to build and publish Docker images.
  • Created a new GitHub Action workflow file named 'main.yaml'.
  • Configured the workflow to trigger on pushes to the 'github_actions' branch.
  • Defined a job named 'build-and-publish' that runs on 'ubuntu-latest'.
  • Included steps to check out the repository, generate a tag, build and publish the Docker image, and verify the image push.
  • Utilized 'philips-software/[email protected]' for building and publishing the Docker image.
  • Set up environment variables for DockerHub credentials and organization details.
.github/workflows/main.yaml

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time. You can also use
    this command to specify where the summary should be inserted.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai 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.

Hey @akash2237778 - I've reviewed your changes - here's some feedback:

Overall Comments:

  • Please properly fill out the PR description template with details about the changes and their impact. This helps reviewers understand the context better.
  • The workflow is triggered on a hardcoded branch name 'github_actions' with a comment indicating it will be changed later. Consider using a more permanent solution or making it configurable.
  • The Dockerfile path is specified as '.' - it would be more explicit and maintainable to specify 'Dockerfile' directly in the workflow configuration.
Here's what I looked at during the review
  • 🟡 General issues: 1 issue found
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

uses: actions/checkout@v4
- name: Generate tag
run: |
echo "TAG=$(date '+%Y%m%d')" >> $GITHUB_ENV

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

issue: Consider adding uniqueness to the tag to prevent overwrites from multiple builds on the same day

You could append the GitHub run number (${{ github.run_number }}) or commit SHA to ensure uniqueness, e.g., $(date '+%Y%m%d')-${{ github.run_number }}

@lvarin lvarin left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM

@lvarin
lvarin merged commit 29d9fa1 into dev Jan 20, 2025
@lvarin
lvarin deleted the github_actions branch January 20, 2025 12:44
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.

2 participants