From b93f6fad1d7d4bf9907b5121c4824e0a085abe81 Mon Sep 17 00:00:00 2001 From: Chase Pierce Date: Mon, 29 Jun 2020 19:47:16 -0600 Subject: [PATCH] add env compatibility with DOCKER_ prefixes --- README.md | 6 +++--- action.yml | 12 +++++++++++- entrypoint.sh | 22 +++++++++++++++++++++- 3 files changed, 35 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 72fcef7..91ee064 100644 --- a/README.md +++ b/README.md @@ -18,9 +18,9 @@ This is useful if you `docker push` your images to Docker Hub. It provides an ea #### Required environment variables -- `DOCKERHUB_USERNAME` - Docker Hub username. If updating a Docker Hub repository belonging to an organization, this user must have `Admin` permissions for the repository. -- `DOCKERHUB_PASSWORD` - Docker Hub password. -- `DOCKERHUB_REPOSITORY` - The Docker Hub repository to update in the format `/`. May also be passed as a secret if considered sensitive. +- `DOCKERHUB_USERNAME` - Docker Hub username. If updating a Docker Hub repository belonging to an organization, this user must have `Admin` permissions for the repository. Aliases: `DOCKER_USERNAME` +- `DOCKERHUB_PASSWORD` - Docker Hub password. Fallback to `DOCKER_PASSWORD` if set. Aliases: `DOCKER_PASSWORD` +- `DOCKERHUB_REPOSITORY` - The Docker Hub repository to update in the format `/`. May also be passed as a secret if considered sensitive. Aliases: `DOCKER_REPOSITORY`, `GITHUB_REPOSITORY` **Note**: Docker Hub [Personal Access Tokens](https://docs.docker.com/docker-hub/access-tokens/) cannot be used as they are not supported by the API. See [here](https://github.com/docker/hub-feedback/issues/1927) and [here](https://github.com/docker/hub-feedback/issues/1914) for further details. Unfortunately, this means that enabling the new 2FA feature on Docker Hub will prevent the action from working. diff --git a/action.yml b/action.yml index 1d99d5c..3010b66 100644 --- a/action.yml +++ b/action.yml @@ -5,5 +5,15 @@ runs: using: 'docker' image: 'docker://peterevans/dockerhub-description:2.1.1' branding: - icon: 'upload' + icon: 'upload' color: 'blue' +inputs: + dockerhubUsername: + description: Username to login to Docker Hub. Aliases: DOCKER_USERNAME + required: false + dockerhubPassword: + description: Password to login to Docker Hub. Aliases: DOCKER_PASSWORD + required: false + dockerhubRepository: + description: Explicit Docker Hub repository name. Aliases: DOCKER_REPOSITORY, GITHUB_REPOSITORY + required: false diff --git a/entrypoint.sh b/entrypoint.sh index f70aaf8..88d3db9 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,7 +1,27 @@ #!/bin/sh -l -set -euo pipefail +set -eo pipefail IFS=$'\n\t' +# Allow DOCKERHUB_* variables to be set from their DOCKER_* variant +DOCKERHUB_USERNAME=${DOCKERHUB_USERNAME:-${DOCKER_USERNAME}} +DOCKERHUB_PASSWORD=${DOCKERHUB_PASSWORD:-${DOCKER_PASSWORD}} +DOCKERHUB_REPOSITORY=${DOCKERHUB_REPOSITORY:-${DOCKER_REPOSITORY}} + +# If the repository isn't explicitly defined, infer it from GitHub if possible +DOCKERHUB_REPOSITORY=${DOCKERHUB_REPOSITORY:-${GITHUB_REPOSITORY}} + +# Validate we can authenticate +if [ -z "$DOCKERHUB_USERNAME" ] || [ -z "$DOCKERHUB_PASSWORD" ]; then + echo 'Unable to authenticate with Docker Hub, set a valid $DOCKERHUB_USERNAME and $DOCKERHUB_PASSWORD' + exit 1 +fi + +# Validate we have the repository name +if [ -z "$DOCKERHUB_REPOSITORY" ]; then + echo 'Unable to determine Docker Hub repository name, set with $DOCKERHUB_REPOSITORY' + exit 1 +fi + # Set the default path to README.md README_FILEPATH=${README_FILEPATH:="./README.md"}