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

Commit 6b726e8

Browse files
author
Patrick Poetz
committed
# Conflicts: # README.md # action.yml # entrypoint.sh
2 parents d2af0b2 + 173aef5 commit 6b726e8

File tree

6 files changed

+58
-44
lines changed

6 files changed

+58
-44
lines changed

.github/workflows/main.yml

+7-9
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,16 @@ jobs:
1414
- name: Build and Publish Docker image in GPR
1515
uses: saubermacherag/gpr-docker-publish@master
1616
with:
17-
USERNAME: x-access-token
18-
PASSWORD: ${{ secrets.GITHUB_TOKEN }}
1917
IMAGE_NAME: 'gpr-docker-publish-test'
20-
IMAGE_TAG: 'v0.0'
18+
TAG: 'v0.0'
2119
DOCKERFILE_PATH: '.github/docker/Dockerfile'
22-
BUILD_CONTEXT: './'
20+
BUILD_CONTEXT: '.'
2321
- name: Build and Publish Docker image to Dockerhub instead of GPR
2422
uses: saubermacherag/gpr-docker-publish@master
2523
with:
26-
USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
27-
PASSWORD: ${{ secrets.DOCKERHUB_PAT }}
28-
IMAGE_TAG: 'v0.0'
24+
TAG: 'v0.0'
2925
DOCKERFILE_PATH: '.github/docker/Dockerfile'
30-
BUILD_CONTEXT: './'
31-
DOCKERHUB_REPOSITORY: 'pinkrobin/gpr-docker-publish-example'
26+
BUILD_CONTEXT: '.'
27+
DOCKERHUB_REPOSITORY: 'pinkrobin/gpr-docker-publish-example'
28+
env:
29+
GITHUB_TOKEN: ${{ secrets.DOCKERHUB_PAT }}

.github/workflows/test.yaml

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: Tests
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@master
11+
12+
- name: Publish Docker Image to GPR
13+
uses: machine-learning-apps/gpr-docker-publish@master
14+
with:
15+
IMAGE_NAME: 'test-docker-action-v2'
16+
TAG: 'my-optional-tag-name'
17+
DOCKERFILE_PATH: 'Dockerfile'
18+
BUILD_CONTEXT: '.'
19+
env:
20+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Dockerfile

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ LABEL "com.github.actions.color"="purple"
77

88
RUN apk update \
99
&& apk upgrade \
10-
&& apk add --no-cache git
10+
&& apk add --no-cache git curl jq
1111

1212
ADD entrypoint.sh /entrypoint.sh
1313
RUN chmod +x /entrypoint.sh
1414

15-
ENTRYPOINT ["/entrypoint.sh"]
15+
ENTRYPOINT ["/entrypoint.sh"]

README.md

+10-9
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
![Actions Status](https://github.com/machine-learning-apps/gpr-docker-publish/workflows/Tests/badge.svg) [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://github.com/machine-learning-apps/gpr-docker-publish/blob/master/LICENSE)
2+
3+
14
## This Action Publishes Docker Images to the [GitHub Package Registry](https://github.com/features/package-registry).
25

36
### Background On The GitHub Package Registry (GPR):
@@ -52,12 +55,12 @@ jobs:
5255
uses: machine-learning-apps/gpr-docker-publish@master
5356
id: docker
5457
with:
55-
USERNAME: ${{ secrets.DOCKER_USERNAME }}
56-
PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
5758
IMAGE_NAME: 'test-docker-action'
58-
IMAGE_TAG: 'v0.0'
59+
TAG: 'my-optional-tag-name'
5960
DOCKERFILE_PATH: 'argo/gpu.Dockerfile'
6061
BUILD_CONTEXT: 'argo/'
62+
env:
63+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
6164

6265
#To access another docker registry like dockerhub you'll have to add `DOCKERHUB_UERNAME` and `DOCKERHUB_PAT` in github secrets.
6366
- name: Build and Publish Docker image to Dockerhub instead of GPR
@@ -83,16 +86,14 @@ jobs:
8386
8487
### Mandatory Inputs
8588
86-
1. `USERNAME` the login username, most likely your github handle. This username must have write access to the repo where the action is called. `x-access-token` should suffice.
87-
2. `PASSWORD` Your GitHub password that has write access to the repo where this action is called. `${{ secrets.GITHUB_TOKEN }}` should suffice.
88-
3. `IMAGE_NAME` is the name of the image you would like to push
89-
4. `DOCKERFILE_PATH`: The full path (including the filename) relative to the root of the repository that contains the Dockerfile that specifies your build.
90-
5. `BUILD_CONTEXT`: The directory for the build context. See these [docs](https://docs.docker.com/engine/reference/commandline/build/) for more information on the definition of build context.
89+
1. `IMAGE_NAME` is the name of the image you would like to push
90+
2. `DOCKERFILE_PATH`: The full path (including the filename) relative to the root of the repository that contains the Dockerfile that specifies your build.
91+
3. `BUILD_CONTEXT`: The directory for the build context. See these [docs](https://docs.docker.com/engine/reference/commandline/build/) for more information on the definition of build context.
9192

9293
## Optional Inputs
9394

9495
1. `cache`: if value is `true`, attempts to use the last pushed image as a cache. Default value is `false`.
95-
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.
96+
2. `tag`: a custom tag you wish to assign to the image.
9697
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.
9798
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
9899

action.yaml renamed to action.yml

+3-9
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,6 @@ name: 'gpr-docker-publish'
22
description: Publish a Docker image to GitHub Package Registry
33
author: Hamel Husain
44
inputs:
5-
password:
6-
description: Your GitHub password corresponding to write access to the repo where this action is called.
7-
required: true
8-
username:
9-
description: Your GitHub password corresponding to write access to the repo where this action is called.
10-
require: true
115
image_name:
126
description: name of the image. Example - myContainer
137
required: true
@@ -23,8 +17,8 @@ inputs:
2317
description: attempt to use last image as the cache
2418
required: false
2519
default: false
26-
image_tag:
27-
description: Optional input to set a tag name instead of a hash.
20+
tag:
21+
description: custom tag you want to assign to the image.
2822
required: false
2923
dockerhub_repository:
3024
description: Optional input to push image to dockerhub repository instead of GPR.
@@ -39,4 +33,4 @@ branding:
3933
icon: 'layers'
4034
runs:
4135
using: 'docker'
42-
image: 'Dockerfile'
36+
image: 'Dockerfile'

entrypoint.sh

+16-15
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,8 @@
77
set -e
88

99
#check inputs
10-
if [[ -z "$INPUT_USERNAME" ]]; then
11-
echo "Set the USERNAME input."
12-
exit 1
13-
fi
14-
15-
if [[ -z "$INPUT_PASSWORD" ]]; then
16-
echo "Set the PASSWORD input."
10+
if [[ -z "$GITHUB_TOKEN" ]]; then
11+
echo "You must supply the environment variable GITHUB_TOKEN."
1712
exit 1
1813
fi
1914

@@ -32,11 +27,6 @@ if [[ -z "$INPUT_BUILD_CONTEXT" ]]; then
3227
exit 1
3328
fi
3429

35-
if [[ -z "$INPUT_IMAGE_TAG" ]]; then
36-
IMAGE_TAG=$(echo "${GITHUB_SHA}" | cut -c1-12)
37-
else
38-
IMAGE_TAG=$INPUT_IMAGE_TAG
39-
fi
4030

4131
# The following environment variables will be provided by the environment automatically: GITHUB_REPOSITORY, GITHUB_SHA
4232

@@ -48,10 +38,14 @@ else
4838
fi
4939

5040
# send credentials through stdin (it is more secure)
51-
echo ${INPUT_PASSWORD} | docker login -u ${INPUT_USERNAME} --password-stdin ${DOCKER_REGISTRY}
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}
5245

5346
# Set Local Variables
54-
SHA_NAME="${BASE_NAME}:${IMAGE_TAG}"
47+
shortSHA=$(echo "${GITHUB_SHA}" | cut -c1-12)
48+
SHA_NAME="${BASE_NAME}:${shortSHA}"
5549

5650
# Build additional tags based on the GIT Tags pointing to the current commit
5751
ADDITIONAL_TAGS=
@@ -73,7 +67,14 @@ if [ "${INPUT_CACHE}" == "true" ]; then
7367
fi
7468

7569
# Build The Container
76-
docker build $BUILDPARAMS -t ${SHA_NAME} -t ${BASE_NAME}${ADDITIONAL_TAGS} -f ${INPUT_DOCKERFILE_PATH} ${INPUT_BUILD_CONTEXT}
70+
if [ "${INPUT_TAG}" ]; then
71+
CUSTOM_TAG="${BASE_NAME}:${INPUT_TAG}"
72+
docker build $BUILDPARAMS -t ${SHA_NAME} -t ${BASE_NAME}${ADDITIONAL_TAGS} -t ${CUSTOM_TAG} -f ${INPUT_DOCKERFILE_PATH} ${INPUT_BUILD_CONTEXT}
73+
docker push ${CUSTOM_TAG}
74+
else
75+
docker build $BUILDPARAMS -t ${SHA_NAME} -t ${BASE_NAME}${ADDITIONAL_TAGS} -f ${INPUT_DOCKERFILE_PATH} ${INPUT_BUILD_CONTEXT}
76+
fi
77+
7778

7879
# Push two versions, with and without the SHA
7980
docker push ${BASE_NAME}

0 commit comments

Comments
 (0)