diff --git a/README.md b/README.md index 9a1009f..24ab2f8 100644 --- a/README.md +++ b/README.md @@ -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: diff --git a/action.yml b/action.yml index 4430ff8..0c79246 100644 --- a/action.yml +++ b/action.yml @@ -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 @@ -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 }} @@ -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"