Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Add GitHub Workflow for Container Image CI/CD #18

@jbrinkman

Description

@jbrinkman

Description

Implement a GitHub workflow that automatically builds and publishes container images to ghcr.io, manages versioning using Semantic Release, and creates GitHub releases based on conventional commits.

Tasks

  • Set up GitHub Actions workflow file structure (High Priority)
  • Configure Semantic Release (High Priority)
  • Implement Docker image build step (High Priority)
  • Configure GitHub Container Registry authentication (High Priority)
  • Implement image tagging with semantic versions (Medium Priority)
  • Add image push to GitHub Container Registry (High Priority)
  • Configure Git tag creation (Medium Priority)
  • Set up GitHub Release creation (Medium Priority)
  • Implement PR trigger for workflow (Medium Priority)
  • Add conventional commit validation (Low Priority)
  • Create workflow documentation (Medium Priority)
  • Set up required GitHub secrets (High Priority)
  • Implement caching for Docker builds (Low Priority)
  • Add workflow status badges (Low Priority)

Implementation Details

Workflow Overview

The workflow will:

  1. Trigger on pull request events
  2. Build the Docker image
  3. Use Semantic Release to determine the next version based on conventional commits
  4. Tag the image with the semantic version
  5. Push the image to GitHub Container Registry (ghcr.io)
  6. Create a Git tag for the version
  7. Generate a changelog
  8. Create a GitHub Release

Semantic Release Configuration

{
  "plugins": [
    "@semantic-release/commit-analyzer",
    "@semantic-release/release-notes-generator",
    "@semantic-release/changelog",
    "@semantic-release/github",
    [
      "@semantic-release/git",
      {
        "assets": ["CHANGELOG.md", "package.json"],
        "message": "chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}"
      }
    ]
  ]
}

Docker Image Build and Push

# Example workflow step
- name: Build and push Docker image
  uses: docker/build-push-action@v5
  with:
    context: .
    push: true
    tags: |
      ghcr.io/${{ github.repository }}:${{ steps.semantic.outputs.new_version }}
      ghcr.io/${{ github.repository }}:latest

Required Secrets

  • GITHUB_TOKEN (with appropriate permissions)
  • Any additional secrets needed for the Docker build process

Acceptance Criteria

  • Workflow successfully builds Docker images on PR events
  • Images are correctly tagged with semantic versions
  • Images are pushed to ghcr.io
  • Git tags are created for each release
  • GitHub Releases are created with changelogs
  • Documentation is updated with workflow details
  • Build caching is implemented for performance
  • Status badges are added to the README

References

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions