Skip to content

Github Action to Build and Push Docker Image

License

Notifications You must be signed in to change notification settings

connoraird/build-push

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 

Repository files navigation

build-push

Builds Docker images with customized image tags, labels, and annotations, and pushes them to a specified container registry. It is designed to run in a rootless, unprivileged container for enhanced security, including environments like self-hosted GitHub Action Runner Controller (ARC) on Kubernetes.

This is a composite GitHub Action that incorporates the following actions:

Inputs

Name Description Required Default
image_name Name of the Docker image to be built and pushed. Yes -
registry_address URL of the container registry where the image will be pushed. Yes -
registry_username Username for authentication with the container registry. Yes -
registry_password Password for authentication with the container registry. Yes -
context The directory path used as the build context. No ./
dockerfile_path Location of the Dockerfile. No Dockerfile
flavor Specifies the tagging strategy. For options, see Docker Metadata Action documentation. No -
tags Defines how the image is tagged. For detailed configuration, refer to Docker Metadata Action documentation. No
type=sha
type=ref,event=branch
type=ref,event=pr
type=schedule,pattern={{date 'YYYYMMDD-hhmmss'}}
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}},enable=${{ !startsWith(github.ref, 'refs/tags/v0.') }}
labels Custom labels to apply to the built image, separated by newlines. No -
annotations Additional annotations for the image, separated by newlines. No -
archs CPU architectures to target during the build, separated by commas (eg: amd64,arm64). Note: Not functional in Kubernetes (ARC). Cannot be used with platforms. No -
platforms Target platforms for the image build, separated by commas (eg: linux/amd64,linux/arm64). Note: Not functional in Kubernetes (ARC). Cannot be used with archs. No -
build_args Build-time variables in the form arg_name=arg_value. Separate multiple arguments with newlines. These are passed to Docker build with --build-arg. No -
buildah_extra_args Additional arguments for the buildah bud command, separated by newlines. No -
oci Sets the image format. true for OCI format, false for Docker format. Default is false. No false
push_extra_args Extra arguments for the podman push command, separated by newlines. No -

Outputs

Name Description
push_result JSON string with the digest and registry paths for pushed images.

Example Usage

name: Build image and Push to  Github Container Registry

on:
  push:

jobs:
  build-push-ghcr:
    name: Build and push image
    runs-on: ubuntu-22.04

    permissions:
      contents: read
      packages: write

    steps:
    - name: Checkout
      uses: actions/checkout@v4

    - name: Build and Push Docker image to GHCR
      uses: aleskxyz/build-push@v1
      with:
        image_name: ${{ github.event.repository.name }}
        registry_address: ghcr.io/${{ github.repository_owner }}
        registry_username: ${{ github.actor }}
        registry_password: ${{ github.token }}

About

Github Action to Build and Push Docker Image

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Shell 100.0%