Skip to content

Docker build push

This Action builds then pushes a Docker container from the repository.

Docker build push

- uses: Yellow-Dog-Man/composite-actions-templates/.github/actions/docker-build-push@main
  with:
    docker-token: (1)
    docker-image-name: (2)
  1. Docker auth token for the registry.

  2. The name of the Docker image.

Builds a Docker container and pushes it to the specified registry.

Inputs: ยค

Name Description Default
docker-registry

Registry which Docker will push to.

ghcr.io
docker-token

Docker auth token for the registry.

dockerfile-path

Path to the Dockerfile file.

${{ github.workspace }}/Dockerfile
docker-context-path

Context to pass to the Docker daemon for the build.

.
docker-platforms

List of platforms to build the image for.

linux/amd64
docker-image-name

The name of the Docker image.

Source of Yellow-Dog-Man/composite-actions-templates/.github/actions/docker-build-push@main
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
name: 'Docker build push'
description: 'Builds a Docker container and pushes it to the specified registry.'

inputs:
  docker-registry:
    description: 'Registry which Docker will push to.'
    default: 'ghcr.io'
    required: false
  docker-token:
    description: 'Docker auth token for the registry.'
    required: true
  dockerfile-path:
    description: 'Path to the Dockerfile file.'
    default: '${{ github.workspace }}/Dockerfile'
    required: false
  docker-context-path:
    description: 'Context to pass to the Docker daemon for the build.'
    default: '.'
    required: false
  docker-platforms:
    description: 'List of platforms to build the image for.'
    default: 'linux/amd64'
    required: false
  docker-image-name:
    description: 'The name of the Docker image.'
    required: true

runs:
  using: composite

  steps:
    - name: 'Setup QEMU'
      uses: docker/setup-qemu-action@ce360397dd3f832beb865e1373c09c0e9f86d70a # v4.0.0

    - name: 'Setup Buildx'
      uses: docker/setup-buildx-action@4d04d5d9486b7bd6fa91e7baf45bbb4f8b9deedd # v4.0.0

    - name: Login to GHCR
      uses: docker/login-action@4907a6ddec9925e35a0a9e82d7399ccc52663121 # v4.1.0
      with:
        username: ${{ github.actor }}
        password: ${{ inputs.docker-token }}
        registry: ${{ inputs.docker-registry }}

    - name: 'Extract metadata'
      id: meta
      uses: docker/metadata-action@030e881283bb7a6894de51c315a6bfe6a94e05cf # v6.0.0
      with:
        images: ghcr.io/${{ inputs.docker-image-name }}
        tags: |
          type=ref,event=branch
          type=ref,event=pr
          type=semver,pattern={{version}}
          type=semver,pattern={{major}}.{{minor}}

    - name: Build and push Wiki Image
      uses: docker/build-push-action@bcafcacb16a39f128d818304e6c9c0c18556b85f # v7.1.0
      with:
        push: true
        tags: ${{ steps.meta.outputs.tags }}
        labels: ${{ steps.meta.outputs.labels }}
        file: ${{ inputs.dockerfile-path }}
        context: ${{ inputs.docker-context-path }}
        platforms: ${{ inputs.docker-platforms }}