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

Commit d9cbb6d

Browse files
author
Patrick Poetz
committed
Images can be pushed to GPR or Dockerhub
supply github token for test dockerhub specific settings try to make tests "fork agnostic" try to make tests "fork agnostic". still don't know if this works action names cannot be fork agnostic fixed typo
1 parent 6b726e8 commit d9cbb6d

File tree

6 files changed

+50
-44
lines changed

6 files changed

+50
-44
lines changed

.github/workflows/dockerhub.yml

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: Test Dockerhub Push
2+
on: [push]
3+
4+
jobs:
5+
build:
6+
runs-on: ubuntu-latest
7+
steps:
8+
9+
- name: Copy Repo Files
10+
uses: actions/checkout@v1
11+
with:
12+
fetch-depth: 1
13+
- name: Build and Publish Docker image to Dockerhub
14+
uses: saubermacherag/gpr-docker-publish@master
15+
with:
16+
TAG: 'my-optional-tag-name'
17+
DOCKERFILE_PATH: '.github/docker/Dockerfile'
18+
BUILD_CONTEXT: '.'
19+
DOCKERHUB_REPOSITORY: 'pinkrobin/gpr-docker-publish-example'
20+
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
21+
env:
22+
REGISTRY_TOKEN: ${{ secrets.DOCKERHUB_PAT }}
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Tests
1+
name: Test GPR Push
22
on: push
33

44
jobs:
@@ -7,14 +7,15 @@ jobs:
77
steps:
88

99
- name: Copy Repo Files
10-
uses: actions/checkout@master
11-
10+
uses: actions/checkout@v1
11+
with:
12+
fetch-depth: 1
1213
- name: Publish Docker Image to GPR
13-
uses: machine-learning-apps/gpr-docker-publish@master
14+
uses: saubermacherag/gpr-docker-publish@master
1415
with:
1516
IMAGE_NAME: 'test-docker-action-v2'
1617
TAG: 'my-optional-tag-name'
1718
DOCKERFILE_PATH: 'Dockerfile'
1819
BUILD_CONTEXT: '.'
1920
env:
20-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
21+
REGISTRY_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/main.yml

-29
This file was deleted.

README.md

+5-3
Original file line numberDiff line numberDiff line change
@@ -60,18 +60,19 @@ jobs:
6060
DOCKERFILE_PATH: 'argo/gpu.Dockerfile'
6161
BUILD_CONTEXT: 'argo/'
6262
env:
63-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
63+
REGISTRY_TOKEN: ${{ secrets.GITHUB_TOKEN }}
6464

6565
#To access another docker registry like dockerhub you'll have to add `DOCKERHUB_UERNAME` and `DOCKERHUB_PAT` in github secrets.
6666
- name: Build and Publish Docker image to Dockerhub instead of GPR
6767
uses: saubermacherag/gpr-docker-publish@master
6868
with:
69-
USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
70-
PASSWORD: ${{ secrets.DOCKERHUB_PAT }}
7169
IMAGE_TAG: 'v0.0'
7270
DOCKERFILE_PATH: '.github/docker/Dockerfile'
7371
BUILD_CONTEXT: './'
7472
DOCKERHUB_REPOSITORY: 'pinkrobin/gpr-docker-publish-example'
73+
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
74+
env:
75+
REGISTRY_TOKEN: ${{ secrets.DOCKERHUB_PAT }}
7576

7677
# This second step is illustrative and shows how to reference the
7778
# output variables. This is completely optional.
@@ -96,6 +97,7 @@ jobs:
9697
2. `tag`: a custom tag you wish to assign to the image.
9798
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.
9899
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
100+
4. `DOCKERHUB_USERNAME`: required when `DOCKERHUB_REPOSITORY` set to true.
99101

100102
## Outputs
101103

action.yml

+3
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ inputs:
2323
dockerhub_repository:
2424
description: Optional input to push image to dockerhub repository instead of GPR.
2525
required: false
26+
dockerhub_username:
27+
description: Required if dockerhub_repository set to true.
28+
required: false
2629
outputs:
2730
IMAGE_SHA_NAME:
2831
description: name of the Docker Image including the tag

entrypoint.sh

+14-7
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
set -e
88

99
#check inputs
10-
if [[ -z "$GITHUB_TOKEN" ]]; then
11-
echo "You must supply the environment variable GITHUB_TOKEN."
10+
if [[ -z "$REGISTRY_TOKEN" ]]; then
11+
echo "You must supply the environment variable REGISTRY_TOKEN."
1212
exit 1
1313
fi
1414

@@ -33,15 +33,22 @@ fi
3333
if [[ -z "$INPUT_DOCKERHUB_REPOSITORY" ]]; then
3434
DOCKER_REGISTRY=docker.pkg.github.com
3535
BASE_NAME="${DOCKER_REGISTRY}/${GITHUB_REPOSITORY}/${INPUT_IMAGE_NAME}"
36+
# send credentials through stdin (it is more secure)
37+
user=$(curl -s -H "Authorization: token ${REGISTRY_TOKEN}" https://api.github.com/user | jq -r .login)
38+
# lowercase the username
39+
username="$(echo ${user} | tr "[:upper:]" "[:lower:]")"
3640
else
41+
if [ -z "$INPUT_DOCKERHUB_USERNAME" ]
42+
then
43+
echo "If you use Docker Hub as repository please provide your username as DOCKERHUB_USERNAME."
44+
exit 1
45+
fi
46+
username="${INPUT_DOCKERHUB_USERNAME}"
3747
BASE_NAME="${INPUT_DOCKERHUB_REPOSITORY}"
3848
fi
3949

40-
# send credentials through stdin (it is more secure)
41-
user=$(curl -s -H "Authorization: token ${GITHUB_TOKEN}" https://api.github.com/user | jq -r .login)
42-
# lowercase the username
43-
username="$(echo ${user} | tr "[:upper:]" "[:lower:]")"
44-
echo ${GITHUB_TOKEN} | docker login -u "${username}" --password-stdin ${DOCKER_REGISTRY}
50+
51+
echo ${REGISTRY_TOKEN} | docker login -u "${username}" --password-stdin ${DOCKER_REGISTRY}
4552

4653
# Set Local Variables
4754
shortSHA=$(echo "${GITHUB_SHA}" | cut -c1-12)

0 commit comments

Comments
 (0)