Skip to content
This repository was archived by the owner on Dec 9, 2022. It is now read-only.

Commit 67a6774

Browse files
author
Patrick Poetz
committed
alternatively use dockerhub instead of gpr
1 parent a23d891 commit 67a6774

File tree

4 files changed

+30
-6
lines changed

4 files changed

+30
-6
lines changed

.github/workflows/main.yml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
uses: actions/checkout@v1
1212
with:
1313
fetch-depth: 1
14-
- name: Build and Publish Docker image
14+
- name: Build and Publish Docker image in GPR
1515
uses: saubermacherag/gpr-docker-publish@master
1616
with:
1717
USERNAME: x-access-token
@@ -20,3 +20,12 @@ jobs:
2020
IMAGE_TAG: 'v0.0'
2121
DOCKERFILE_PATH: '.github/docker/Dockerfile'
2222
BUILD_CONTEXT: './'
23+
- name: Build and Publish Docker image in GPR
24+
uses: saubermacherag/gpr-docker-publish@master
25+
with:
26+
USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
27+
PASSWORD: ${{ secrets.DOCKERHUB_PAT }}
28+
IMAGE_TAG: 'v0.0'
29+
DOCKERFILE_PATH: '.github/docker/Dockerfile'
30+
BUILD_CONTEXT: './'
31+
DOCKERHUB_REPOSITORY: 'pinkrobin/docker-ansible-alpine'

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ jobs:
8282

8383
1. `cache`: if value is `true`, attempts to use the last pushed image as a cache. Default value is `false`.
8484
2. `IMAGE_TAG`: if value is set, use provided value. Default value is the first 12 characters of the GitHub SHA that triggered the action.
85+
3. `DOCKERHUB_REPOSITORY`: if value is set, you don't need to set `IMAGE_NAME`. It will push the image to the given dockerhub repository instead of using GPR.
86+
Why? Because Github Actions don't support downloading images without authentication at the moment. See: https://github.community/t5/GitHub-Actions/docker-pull-from-public-GitHub-Package-Registry-fail-with-quot/m-p/32782
8587

8688
## Outputs
8789

action.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ inputs:
2626
image_tag:
2727
description: Optional input to set a tag name instead of a hash.
2828
required: false
29+
dockerhub_repository:
30+
description: Optional input to push image to dockerhub repository instead of GPR.
31+
required: false
2932
outputs:
3033
IMAGE_SHA_NAME:
3134
description: name of the Docker Image including the tag

entrypoint.sh

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ if [[ -z "$INPUT_PASSWORD" ]]; then
1717
exit 1
1818
fi
1919

20-
if [[ -z "$INPUT_IMAGE_NAME" ]]; then
21-
echo "Set the IMAGE_NAME input."
20+
if [[ -z "$INPUT_IMAGE_NAME" && -z "$INPUT_DOCKERHUB_REPOSITORY" ]]; then
21+
echo "Set either the IMAGE_NAME or a valid DOCKERHUB_REPOSITORY."
2222
exit 1
2323
fi
2424

@@ -40,11 +40,17 @@ fi
4040

4141
# The following environment variables will be provided by the environment automatically: GITHUB_REPOSITORY, GITHUB_SHA
4242

43+
if [[ -z "$INPUT_DOCKERHUB_REPOSITORY" ]]; then
44+
DOCKER_REGISTRY=docker.pkg.github.com
45+
BASE_NAME="${DOCKER_REGISTRY}/${GITHUB_REPOSITORY}/${INPUT_IMAGE_NAME}"
46+
else
47+
BASE_NAME="${INPUT_DOCKERHUB_REPOSITORY}"
48+
fi
49+
4350
# send credentials through stdin (it is more secure)
44-
echo ${INPUT_PASSWORD} | docker login -u ${INPUT_USERNAME} --password-stdin docker.pkg.github.com
51+
echo ${INPUT_PASSWORD} | docker login -u ${INPUT_USERNAME} --password-stdin ${DOCKER_REGISTRY}
4552

4653
# Set Local Variables
47-
BASE_NAME="docker.pkg.github.com/${GITHUB_REPOSITORY}/${INPUT_IMAGE_NAME}"
4854
SHA_NAME="${BASE_NAME}:${IMAGE_TAG}"
4955

5056
# Build additional tags based on the GIT Tags pointing to the current commit
@@ -74,4 +80,8 @@ docker push ${BASE_NAME}
7480
docker push ${SHA_NAME}
7581

7682
echo "::set-output name=IMAGE_SHA_NAME::${SHA_NAME}"
77-
echo "::set-output name=IMAGE_URL::https://github.com/${GITHUB_REPOSITORY}/packages"
83+
if [[ -z "$INPUT_DOCKERHUB_REPOSITORY" ]]; then
84+
echo "::set-output name=IMAGE_URL::https://github.com/${GITHUB_REPOSITORY}/packages"
85+
else
86+
echo "::set-output name=IMAGE_URL::https://hub.docker.com/r/${INPUT_DOCKERHUB_REPOSITORY}"
87+
fi

0 commit comments

Comments
 (0)