Skip to content

Commit

Permalink
Merge pull request #23 from macbre/add/docker_io_user
Browse files Browse the repository at this point in the history
Introduce "docker_io_user" input
  • Loading branch information
macbre authored Nov 21, 2022
2 parents db75a4b + a25f5bc commit 22a45ce
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,25 @@ jobs:
github_token: ${{ secrets.GITHUB_TOKEN }}
# optionally push to the Docker Hub (docker.io)
# docker_io_token: ${{ secrets.DOCKER_IO_ACCESS_TOKEN }} # see https://hub.docker.com/settings/security
# customize the username to be used when pushing to the Docker Hub
# docker_io_user: foobar # see https://github.com/macbre/push-to-ghcr/issues/14
```

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

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/).

## Input parameters

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

## Labels and build args

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:
Expand Down
13 changes: 11 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ inputs:
required: true
default: "ghcr.io"

docker_io_user:
description: "A username to use when pushing an image to docker.io (defaults to the github.actor)"
required: false

docker_io_token:
description: "Your docker.io token created via https://hub.docker.com/settings/security"
required: false
Expand All @@ -47,6 +51,7 @@ runs:
env:
GITHUB_TOKEN: ${{ inputs.github_token }}
DOCKER_BUILDKIT: 1
DOCKER_IO_USER: ${{ inputs.docker_io_user }}
DOCKER_IO_TOKEN: ${{ inputs.docker_io_token }}
IMAGE_TAG: ${{ inputs.image_tag }}

Expand Down Expand Up @@ -120,8 +125,12 @@ runs:
if [ -z "${DOCKER_IO_TOKEN}" ]; then
echo "::notice::NOT pushing the Docker image to docker.io ... Provide 'docker_io_token' if needed."
else
echo "::group::Pushing the Docker image to docker.io ..."
echo "${DOCKER_IO_TOKEN}" | docker login docker.io -u "${{ github.actor }}" --password-stdin
if [ -z ${DOCKER_IO_USER} ]; then
export DOCKER_IO_USER="${{ github.actor }}"
fi
echo "::group::Pushing the Docker image to docker.io as ${DOCKER_IO_USER}..."
echo "${DOCKER_IO_TOKEN}" | docker login docker.io -u "${DOCKER_IO_USER}" --password-stdin
>&0 docker push docker.io/${{ inputs.image_name }}:${COMMIT_TAG} && echo "Pushed"
Expand Down

0 comments on commit 22a45ce

Please sign in to comment.