Skip to content

Commit 22a45ce

Browse files
authored
Merge pull request #23 from macbre/add/docker_io_user
Introduce "docker_io_user" input
2 parents db75a4b + a25f5bc commit 22a45ce

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,25 @@ jobs:
4242
github_token: ${{ secrets.GITHUB_TOKEN }}
4343
# optionally push to the Docker Hub (docker.io)
4444
# docker_io_token: ${{ secrets.DOCKER_IO_ACCESS_TOKEN }} # see https://hub.docker.com/settings/security
45+
# customize the username to be used when pushing to the Docker Hub
46+
# docker_io_user: foobar # see https://github.com/macbre/push-to-ghcr/issues/14
4547
```
4648

4749
This action assumes that your **`Dockerfile` is in the root directory of your repository**.
4850

4951
However, you can use `dockerfile` input to **specify a different path** (relative to the root directory of your repository). Additionaly, `context` input can also be provided. [Docker docs should provide more context on `context` ;)](https://docs.docker.com/engine/reference/commandline/build/).
5052

53+
## Input parameters
54+
55+
* `github_token` (**required**): Your `secrets.GITHUB_TOKEN`
56+
* `image_name` (**required**): Image name, e.g. `my-user-name/my-repo`
57+
* `dockerfile` (defaults to `./Dockerfile`): A path to the Dockerfile (if it's not in the repository's root directory)
58+
* `context` (defaults to `.`): A path to the context in which the build will happen, see https://docs.docker.com/engine/reference/commandline/build/
59+
* `repository` (defaults to `ghcr.io`): Docker repository to push an image to
60+
* `docker_io_user`: A username to use when pushing an image to `docker.io` (defaults to the `github.actor`)
61+
* `docker_io_token`: Your `docker.io` token created via https://hub.docker.com/settings/security
62+
* `image_tag`: Image tag, e.g. `latest`. Will overwrite the tag latest tag on a push, and have no effect on a release
63+
5164
## Labels and build args
5265

5366
The image that is pushed is labelled with `org.label-schema` [and `org.opencontainers` schema](https://github.com/opencontainers/image-spec/blob/master/annotations.md#pre-defined-annotation-keys). For instance:

action.yml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ inputs:
3030
required: true
3131
default: "ghcr.io"
3232

33+
docker_io_user:
34+
description: "A username to use when pushing an image to docker.io (defaults to the github.actor)"
35+
required: false
36+
3337
docker_io_token:
3438
description: "Your docker.io token created via https://hub.docker.com/settings/security"
3539
required: false
@@ -47,6 +51,7 @@ runs:
4751
env:
4852
GITHUB_TOKEN: ${{ inputs.github_token }}
4953
DOCKER_BUILDKIT: 1
54+
DOCKER_IO_USER: ${{ inputs.docker_io_user }}
5055
DOCKER_IO_TOKEN: ${{ inputs.docker_io_token }}
5156
IMAGE_TAG: ${{ inputs.image_tag }}
5257

@@ -120,8 +125,12 @@ runs:
120125
if [ -z "${DOCKER_IO_TOKEN}" ]; then
121126
echo "::notice::NOT pushing the Docker image to docker.io ... Provide 'docker_io_token' if needed."
122127
else
123-
echo "::group::Pushing the Docker image to docker.io ..."
124-
echo "${DOCKER_IO_TOKEN}" | docker login docker.io -u "${{ github.actor }}" --password-stdin
128+
if [ -z ${DOCKER_IO_USER} ]; then
129+
export DOCKER_IO_USER="${{ github.actor }}"
130+
fi
131+
132+
echo "::group::Pushing the Docker image to docker.io as ${DOCKER_IO_USER}..."
133+
echo "${DOCKER_IO_TOKEN}" | docker login docker.io -u "${DOCKER_IO_USER}" --password-stdin
125134
126135
>&0 docker push docker.io/${{ inputs.image_name }}:${COMMIT_TAG} && echo "Pushed"
127136

0 commit comments

Comments
 (0)