Skip to content

Commit 686488d

Browse files
committed
Use docker Github actions to tag containers
Signed-off-by: Dane Wagner <[email protected]>
1 parent 37fc2fa commit 686488d

File tree

4 files changed

+88
-46
lines changed

4 files changed

+88
-46
lines changed

actions/publish_images/action.yml

Lines changed: 36 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -20,34 +20,48 @@ inputs:
2020
description: Path to Dockerbuild context
2121
type: string
2222
default: ""
23+
platforms:
24+
description: Docker platforms to build
25+
type: string
26+
default: "linux/amd64,linux/arm/v7,linux/arm64,linux/ppc64le,linux/s390x"
2327
container_image_name:
2428
description: Name of the container image
2529
type: string
26-
default: ""
30+
default: ${{ github.event.repository.name }}
31+
github_token:
32+
type: string
33+
description: Github Token
2734
docker_image_tag:
2835
description: A custom image tag to be added
2936
type: string
3037
runs:
3138
using: composite
3239
steps:
33-
- if: inputs.dockerfile_path != ''
34-
run: echo "export DOCKERFILE_PATH=${{ inputs.dockerfile_path }}" >> /tmp/tmp-profile
35-
shell: bash
36-
- if: inputs.container_image_name != ''
37-
run: echo "export DOCKER_IMAGE_NAME=${{ inputs.container_image_name }}" >> /tmp/tmp-profile
38-
shell: bash
39-
- if: inputs.dockerbuild_context != ''
40-
run: echo "export DOCKERBUILD_CONTEXT=${{ inputs.dockerbuild_context }}" >> /tmp/tmp-profile
41-
shell: bash
42-
- if: inputs.docker_image_tag != ''
43-
run: echo "export DOCKER_IMAGE_TAG=${{ inputs.docker_image_tag }}" >> /tmp/tmp-profile
44-
shell: bash
45-
- run: |
46-
touch /tmp/tmp-profile
47-
. /tmp/tmp-profile
48-
make docker DOCKER_REPO=${{ inputs.registry }}/${{ inputs.organization }}
49-
docker images
50-
echo ${{ inputs.password }} | docker login -u ${{ inputs.login }} --password-stdin ${{ inputs.registry }}
51-
make docker-publish DOCKER_REPO=${{ inputs.registry }}/${{ inputs.organization }}
52-
make docker-manifest DOCKER_REPO=${{ inputs.registry }}/${{ inputs.organization }}
53-
shell: bash
40+
- name: Docker meta
41+
id: meta
42+
uses: docker/metadata-action@v5
43+
with:
44+
github-token: ${{ inputs.github_token }}
45+
images: |
46+
${{ inputs.registry }}/${{ inputs.organization }}/${{ inputs.container_image_name }}
47+
flavor: |
48+
latest=false
49+
tags: |
50+
type=ref,event=branch
51+
type=ref,event=pr
52+
- name: Login to DockerHub
53+
if: github.event_name != 'pull_request'
54+
uses: docker/login-action@v3
55+
with:
56+
registry: ${{ inputs.registry }}
57+
username: ${{ inputs.login }}
58+
password: ${{ inputs.password }}
59+
- name: Build and push
60+
uses: docker/build-push-action@v6
61+
with:
62+
context: ${{ inputs.dockerbuild_context || '.' }}
63+
file: ${{ inputs.dockerfile_path }}
64+
platforms: ${{ inputs.platforms }}
65+
push: ${{ github.event_name != 'pull_request' }}
66+
tags: ${{ steps.meta.outputs.tags }}
67+
labels: ${{ steps.meta.outputs.labels }}

actions/publish_main/action.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ inputs:
2020
quay_io_password:
2121
type: string
2222
description: Quay.io password
23+
github_token:
24+
type: string
25+
description: Github Token
2326
runs:
2427
using: composite
2528
steps:
@@ -34,10 +37,12 @@ runs:
3437
organization: ${{ inputs.docker_hub_organization }}
3538
login: ${{ inputs.docker_hub_login }}
3639
password: ${{ inputs.docker_hub_password }}
40+
github_token: ${{ inputs.github_token }}
3741
- uses: ./.github/promci/actions/publish_images
3842
if: inputs.quay_io_organization != '' && inputs.quay_io_login != ''
3943
with:
4044
registry: quay.io
4145
organization: ${{ inputs.quay_io_organization }}
4246
login: ${{ inputs.quay_io_login }}
4347
password: ${{ inputs.quay_io_password }}
48+
github_token: ${{ inputs.github_token }}

actions/publish_release/action.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,12 @@ runs:
4949
organization: ${{ inputs.docker_hub_organization }}
5050
login: ${{ inputs.docker_hub_login }}
5151
password: ${{ inputs.docker_hub_password }}
52+
github_token: ${{ inputs.github_token }}
5253
- uses: ./.github/promci/actions/publish_release_images
5354
if: inputs.quay_io_organization != '' && inputs.quay_io_login != ''
5455
with:
5556
registry: quay.io
5657
organization: ${{ inputs.quay_io_organization }}
5758
login: ${{ inputs.quay_io_login }}
5859
password: ${{ inputs.quay_io_password }}
60+
github_token: ${{ inputs.github_token }}

actions/publish_release_images/action.yml

Lines changed: 45 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -20,34 +20,55 @@ inputs:
2020
description: Path to Dockerbuild context
2121
type: string
2222
default: ""
23+
platforms:
24+
description: Docker platforms to build
25+
type: string
26+
default: "linux/amd64,linux/arm/v7,linux/arm64,linux/ppc64le,linux/s390x"
2327
container_image_name:
2428
description: Name of the container image
2529
type: string
26-
default: ""
30+
default: ${{ github.event.repository.name }}
31+
github_token:
32+
type: string
33+
description: Github Token
2734
runs:
2835
using: composite
2936
steps:
30-
- if: inputs.dockerfile_path != ''
31-
run: echo "export DOCKERFILE_PATH=${{ inputs.dockerfile_path }}" >> /tmp/tmp-profile
32-
shell: bash
33-
- if: inputs.container_image_name != ''
34-
run: echo "export DOCKER_IMAGE_NAME=${{ inputs.container_image_name }}" >> /tmp/tmp-profile
35-
shell: bash
36-
- if: inputs.dockerbuild_context != ''
37-
run: echo "export DOCKERBUILD_CONTEXT=${{ inputs.dockerbuild_context }}" >> /tmp/tmp-profile
38-
shell: bash
39-
- run: |
40-
current_tag=${GITHUB_REF#refs/*/}
41-
touch /tmp/tmp-profile
42-
. /tmp/tmp-profile
43-
make docker DOCKER_IMAGE_TAG="$current_tag" DOCKER_REPO=${{ inputs.registry }}/${{ inputs.organization }}
44-
docker images
45-
echo ${{ inputs.password }} | docker login -u ${{ inputs.login }} --password-stdin ${{ inputs.registry }}
46-
make docker-publish DOCKER_IMAGE_TAG="$current_tag" DOCKER_REPO=${{ inputs.registry }}/${{ inputs.organization }}
47-
make docker-manifest DOCKER_IMAGE_TAG="$current_tag" DOCKER_REPO=${{ inputs.registry }}/${{ inputs.organization }}
48-
if [[ "$current_tag" =~ ^v[0-9]+(\.[0-9]+){2}$ ]]; then
49-
make docker-tag-latest DOCKER_IMAGE_TAG="$current_tag" DOCKER_REPO=${{ inputs.registry }}/${{ inputs.organization }}
50-
make docker-publish DOCKER_IMAGE_TAG="latest" DOCKER_REPO=${{ inputs.registry }}/${{ inputs.organization }}
51-
make docker-manifest DOCKER_IMAGE_TAG="latest" DOCKER_REPO=${{ inputs.registry }}/${{ inputs.organization }}
37+
- name: Determine latest
38+
id: update_latest
39+
run: |
40+
if [ ${{ startsWith(github.ref, 'refs/tags/v3.') }} ]
41+
then
42+
echo "::set-output name=latest::auto"
43+
else
44+
echo "::set-output name=latest::false"
5245
fi
53-
shell: bash
46+
- name: Docker meta
47+
id: meta
48+
uses: docker/metadata-action@v5
49+
with:
50+
github-token: ${{ inputs.github_token }}
51+
images: |
52+
${{ inputs.registry }}/${{ inputs.organization }}/${{ inputs.container_image_name }}
53+
flavor: |
54+
latest=${{ steps.update_latest.outputs.latest }}
55+
tags: |
56+
type=semver,pattern={{version}}
57+
type=semver,pattern={{major}}.{{minor}}
58+
type=semver,pattern={{major}}
59+
- name: Login to DockerHub
60+
if: github.event_name != 'pull_request'
61+
uses: docker/login-action@v3
62+
with:
63+
registry: ${{ inputs.registry }}
64+
username: ${{ inputs.login }}
65+
password: ${{ inputs.password }}
66+
- name: Build and push
67+
uses: docker/build-push-action@v6
68+
with:
69+
context: ${{ inputs.dockerbuild_context || '.' }}
70+
file: ${{ inputs.dockerfile_path }}
71+
platforms: ${{ inputs.platforms }}
72+
push: ${{ github.event_name != 'pull_request' }}
73+
tags: ${{ steps.meta.outputs.tags }}
74+
labels: ${{ steps.meta.outputs.labels }}

0 commit comments

Comments
 (0)