Skip to content

Latest commit

Β 

History

History
101 lines (81 loc) Β· 3.68 KB

File metadata and controls

101 lines (81 loc) Β· 3.68 KB

🐳 Docker Build Workflow

πŸ” Overview

This reusable GitHub Actions workflow automates the process of building and pushing Docker images to Docker Hub. It simplifies the Docker build process in your CI/CD pipeline by handling authentication, building, and tagging in a standardized way. Perfect for teams looking to streamline their containerization workflow with minimal configuration.

✨ Features

  • πŸ” Securely authenticates with Docker Hub using best practices
  • πŸ—οΈ Builds optimized Docker images from a specified Dockerfile
  • 🏷️ Intelligently tags and pushes images to Docker Hub
  • πŸ›‘οΈ Handles authentication securely using GitHub Secrets
  • πŸš€ Optimizes build performance with layer caching
  • πŸ“¦ Supports multi-platform builds (AMD64, ARM64)

βš™οΈ Inputs

Name Description Required Default
dockerfile Path to the Dockerfile to build (e.g., './Dockerfile', './docker/Dockerfile') Yes -
tag Tag to apply to the built image (e.g., 'myimage:latest', 'myorg/myimage:v1.2.3') Yes -

πŸ” Secrets

Name Description Required
dockerhub_username Username for Docker Hub authentication Yes
dockerhub_pat Personal Access Token for Docker Hub authentication (with appropriate permissions) Yes

πŸ’» Example Usage

name: Build and Push Docker Image

on:
  push:
    branches: [ main ]
  # Also trigger on tag creation for release versioning
  tags:
    - 'v*.*.*'

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
        with:
          fetch-depth: 0  # Fetch all history for proper versioning

      - name: Build and Push Docker Image
        uses: iExecBlockchainComputing/github-actions-workflows/.github/workflows/docker-build.yml@docker-build-v2.2.0
        with:
          dockerfile: 'Dockerfile'
          tag: 'my-image:latest'
        secrets: 
          dockerhub_username: ${{ secrets.DOCKERHUB_USERNAME }}
          dockerhub_pat: ${{ secrets.DOCKERHUB_PAT }}

πŸ” Advanced Usage

Multi-Platform Build Example

name: Build Multi-Platform Docker Image

on:
  release:
    types: [published]

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3

      - name: Set up QEMU
        uses: docker/setup-qemu-action@v2

      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v2

      - name: Build and Push Docker Image
        uses: iExecBlockchainComputing/github-actions-workflows/.github/workflows/docker-build.yml@docker-build-v2.2.0
        with:
          dockerfile: 'Dockerfile'
          tag: 'myorg/myapp:${{ github.event.release.tag_name }}'
        secrets: 
          dockerhub_username: ${{ secrets.DOCKERHUB_USERNAME }}
          dockerhub_pat: ${{ secrets.DOCKERHUB_PAT }}

πŸ“ Notes

  • πŸ”’ Ensure your Docker Hub credentials are stored securely as GitHub Secrets
  • πŸ”„ The workflow will automatically handle the Docker build and push process
  • 🏷️ You can specify any valid Docker tag format in the tag input
  • πŸ“… Consider using dynamic tags based on git tags, commit SHAs, or dates
  • πŸ§ͺ For testing purposes, you can use the --dry-run flag in your own implementation

πŸ› οΈ Troubleshooting

  • If you encounter authentication issues, verify your Docker Hub credentials are correct and have appropriate permissions
  • For build failures, check your Dockerfile syntax and ensure all referenced files exist
  • Large images may take longer to push - consider optimizing your Dockerfile with multi-stage builds
  • If you need to debug the build process, you can add the ACTIONS_STEP_DEBUG secret set to true in your repository