{"id":14985907,"url":"https://github.com/elgohr/publish-docker-github-action","last_synced_at":"2025-04-10T23:27:56.032Z","repository":{"id":35183678,"uuid":"172209713","full_name":"elgohr/Publish-Docker-Github-Action","owner":"elgohr","description":"A Github Action used to build and publish Docker images","archived":false,"fork":false,"pushed_at":"2024-10-21T08:40:09.000Z","size":276,"stargazers_count":780,"open_issues_count":0,"forks_count":209,"subscribers_count":13,"default_branch":"main","last_synced_at":"2024-10-29T15:22:22.038Z","etag":null,"topics":["actions","aws-ecr","build","continuous-delivery","docker","github-actions","publishing","push"],"latest_commit_sha":null,"homepage":"","language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/elgohr.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"elgohr","custom":["https://www.paypal.me/elgohr"]}},"created_at":"2019-02-23T12:07:01.000Z","updated_at":"2024-10-21T08:40:12.000Z","dependencies_parsed_at":"2023-12-04T09:25:26.713Z","dependency_job_id":"e5d0fa5d-704c-435e-9772-27cb92f22c8f","html_url":"https://github.com/elgohr/Publish-Docker-Github-Action","commit_stats":{"total_commits":239,"total_committers":19,"mean_commits":"12.578947368421053","dds":0.7364016736401673,"last_synced_commit":"977fe38375c65e8e3b01d226d72c1f7d488e45dc"},"previous_names":[],"tags_count":50,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elgohr%2FPublish-Docker-Github-Action","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elgohr%2FPublish-Docker-Github-Action/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elgohr%2FPublish-Docker-Github-Action/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elgohr%2FPublish-Docker-Github-Action/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/elgohr","download_url":"https://codeload.github.com/elgohr/Publish-Docker-Github-Action/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248314213,"owners_count":21083009,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["actions","aws-ecr","build","continuous-delivery","docker","github-actions","publishing","push"],"created_at":"2024-09-24T14:11:53.617Z","updated_at":"2025-04-10T23:27:56.001Z","avatar_url":"https://github.com/elgohr.png","language":"Shell","readme":"# Publishes docker containers\n[![Release](https://github.com/elgohr/Publish-Docker-Github-Action/workflows/Release/badge.svg)](https://github.com/elgohr/Publish-Docker-Github-Action/actions/workflows/release.yml)\n\nThis Action for [Docker](https://www.docker.com/) uses the Git branch as the [Docker tag](https://docs.docker.com/engine/reference/commandline/tag/) for building and pushing the container.\nHereby the master-branch is published as the latest-tag.\n\n## Usage\n\n## Example pipeline\n```yaml\nname: Publish Docker\non: [push]\njobs:\n  build:\n    runs-on: ubuntu-latest\n    steps:\n    - uses: actions/checkout@v3\n    - name: Publish to Registry\n      uses: elgohr/Publish-Docker-Github-Action@v5\n      with:\n        name: myDocker/repository\n        username: ${{ secrets.DOCKER_USERNAME }}\n        password: ${{ secrets.DOCKER_PASSWORD }}\n```\n\n## Mandatory Arguments\n\n`name` is the name of the image you would like to push  \n`username` the login username for the registry  \n`password` the authentication token [preferred] or login password for the registry.\n\nIf you would like to publish the image to other registries, these actions might be helpful  \n\n| Registry                                             | Action                                        |\n|------------------------------------------------------|-----------------------------------------------|\n| Amazon Webservices Elastic Container Registry (ECR)  | https://github.com/elgohr/ecr-login-action    |\n| Google Cloud Container Registry                      | https://github.com/elgohr/gcloud-login-action |\n\n## Outputs\n\n`tag` is the tag, which was pushed  \n`snapshot-tag` is the tag that is generated by the [snapshot-option](https://github.com/elgohr/Publish-Docker-Github-Action#snapshot) and pushed  \n`digest` is the digest of the image, which was pushed  \n\n## Optional Arguments\n\n### registry\nUse `registry` for pushing to a custom registry.  \n\nAs GitHub Packages Docker registry uses a different path format to GitHub Container Registry or Docker Hub. See [Configuring Docker for use with GitHub Package Registry](https://help.github.com/en/github/managing-packages-with-github-package-registry/configuring-docker-for-use-with-github-package-registry#publishing-a-package) for more information.  \nFor publishing to GitHub Container Registry please see [Migrating to GitHub Container Registry for Docker images](https://docs.github.com/en/packages/getting-started-with-github-container-registry/migrating-to-github-container-registry-for-docker-images).\n\nIf you're using GitHub Packages Docker or GitHub Container Registry, you might also want to use `${{ github.actor }}` as the `username`.  \n\n```yaml\nwith:\n  name: owner/repository/image\n  username: ${{ github.actor }}\n  password: ${{ secrets.GITHUB_TOKEN }}\n  registry: ghcr.io\n```\n\n### snapshot\nUse `snapshot` to push an additional image, which is tagged with  \n`{YEAR}{MONTH}{DAY}{HOUR}{MINUTE}{SECOND}{first 6 digits of the git sha}`.  \nThe date was inserted to prevent new builds with external dependencies override older builds with the same sha.\nWhen you would like to think about versioning images, this might be useful.  \n\n```yaml\nwith:\n  name: myDocker/repository\n  username: ${{ secrets.DOCKER_USERNAME }}\n  password: ${{ secrets.DOCKER_PASSWORD }}\n  snapshot: true\n```\n\n### default_branch\nUse `default_branch` when you want to use a different branch than `master` as the default branch.\n\n```yaml\nwith:\n  name: myDocker/repository\n  username: ${{ secrets.DOCKER_USERNAME }}\n  password: ${{ secrets.DOCKER_PASSWORD }}\n  default_branch: trunk\n```\n\n### dockerfile\nUse `dockerfile` when you would like to explicitly build a Dockerfile.  \nThis might be useful when you have multiple DockerImages.  \n\n```yaml\nwith:\n  name: myDocker/repository\n  username: ${{ secrets.DOCKER_USERNAME }}\n  password: ${{ secrets.DOCKER_PASSWORD }}\n  dockerfile: MyDockerFileName\n```\n\n### workdir\nUse `workdir` when you would like to change the directory for building.\n\n```yaml\nwith:\n  name: myDocker/repository\n  username: ${{ secrets.DOCKER_USERNAME }}\n  password: ${{ secrets.DOCKER_PASSWORD }}\n  workdir: mySubDirectory\n```\n\n### context\nUse `context` when you would like to change the Docker build context.\n\n```yaml\nwith:\n  name: myDocker/repository\n  username: ${{ secrets.DOCKER_USERNAME }}\n  password: ${{ secrets.DOCKER_PASSWORD }}\n  context: myContextDirectory\n```\n\n### buildargs\nUse `buildargs` when you want to pass a list of environment variables as [build-args](https://docs.docker.com/engine/reference/commandline/build/#set-build-time-variables---build-arg). Identifiers are separated by comma.   \nAll `buildargs` will be masked, so that they don't appear in the logs.  \n\n```yaml\n- name: Publish to Registry\n  uses: elgohr/Publish-Docker-Github-Action@v5\n  env:\n    MY_FIRST: variableContent\n    MY_SECOND: variableContent\n  with:\n    name: myDocker/repository\n    username: ${{ secrets.DOCKER_USERNAME }}\n    password: ${{ secrets.DOCKER_PASSWORD }}\n    buildargs: MY_FIRST,MY_SECOND\n```\n\n### buildoptions\nUse `buildoptions` when you want to configure [options](https://docs.docker.com/engine/reference/commandline/build/#options) for building.  \n\n```yaml\n- name: Publish to Registry\n  uses: elgohr/Publish-Docker-Github-Action@v5\n  with:\n    name: myDocker/repository\n    username: ${{ secrets.DOCKER_USERNAME }}\n    password: ${{ secrets.DOCKER_PASSWORD }}\n    buildoptions: \"--compress --force-rm\"\n```\n\n### platforms\nUse `platforms` when you would like to build for specific target architectures.  \nArchitectures are separated by comma.  \n\n`docker/setup-buildx-action` must be executed before a step that contains `platforms`.\n\n```yaml\n- name: Set up Docker Buildx\n  uses: docker/setup-buildx-action@v2\n- name: Publish to Registry\n  uses: elgohr/Publish-Docker-Github-Action@v5\n  with:\n    name: myDocker/repository\n    username: ${{ secrets.DOCKER_USERNAME }}\n    password: ${{ secrets.DOCKER_PASSWORD }}\n    platforms: linux/amd64,linux/arm64\n```\n\n### cache\nUse `cache` when you have big images, that you would only like to build partially (changed layers).  \n\u003e CAUTION: Docker builds will cache non-repoducable commands, such as installing packages. If you use this option, your packages will never update. To avoid this, run this action on a schedule with caching **disabled** to rebuild the cache periodically.\n\n```yaml\nname: Publish to Registry\non:\n  push:\n    branches:\n      - master\n  schedule:\n    - cron: '0 2 * * 0' # Weekly on Sundays at 02:00\njobs:\n  update:\n    runs-on: ubuntu-latest\n    steps:\n    - uses: actions/checkout@v3\n    - name: Publish to Registry\n      uses: elgohr/Publish-Docker-Github-Action@v5\n      with:\n        name: myDocker/repository\n        username: ${{ secrets.DOCKER_USERNAME }}\n        password: ${{ secrets.DOCKER_PASSWORD }}\n        cache: ${{ github.event_name != 'schedule' }}\n```\n\n### no_push\nUse `no_push` when you want to build an image, but not push it to a registry.\n\n```yaml\nwith:\n  name: myDocker/repository\n  username: ${{ secrets.DOCKER_USERNAME }}\n  password: ${{ secrets.DOCKER_PASSWORD }}\n  no_push: ${{ github.event_name == 'push' }}\n```\n\n### Tags\n\nThis action supports multiple options that tags are handled.  \nBy default a tag is pushed as `latest`.  \nFurthermore, one of the following options can be used. \n\n#### tags\nUse `tags` when you want to bring your own tags (separated by comma).  \n\n```yaml\n- name: Publish to Registry\n  uses: elgohr/Publish-Docker-Github-Action@v5\n  with:\n    name: myDocker/repository\n    username: ${{ secrets.DOCKER_USERNAME }}\n    password: ${{ secrets.DOCKER_PASSWORD }}\n    tags: \"latest,another\"\n```\n\nWhen using dynamic tag names the environment variable must be set via echo, as variables set in the environment will not auto resolve by convention.  \nThis example illustrates how you would push to latest along with creating a custom version tag in a release. Setting it to only run on published events will keep your tags from being filled with commit hashes and will only publish when a GitHub release is created, so if the GitHub release is 2.14 this will publish to the latest and 2.14 tags.\n\n```yaml\nname: Publish to Registry\non:    \n  release:\n      types: [published]\n  push:\n    branches:\n      - master\n  schedule:\n    - cron: '0 2 * * 0' # Weekly on Sundays at 02:00\njobs:\n  update:\n    runs-on: ubuntu-latest\n    steps:\n    - uses: actions/checkout@v3\n    - id: pre-step\n      shell: bash\n      run: echo \"release-version=$(echo ${GITHUB_REF:10})\" \u003e\u003e $GITHUB_OUTPUT\n    - name: Publish to Registry\n      uses: elgohr/Publish-Docker-Github-Action@v5\n      with:\n        name: myDocker/repository\n        username: ${{ secrets.DOCKER_USERNAME }}\n        password: ${{ secrets.DOCKER_PASSWORD }}\n        tags: \"latest,${{ steps.pre-step.outputs.release-version }}\"\n```\n\n#### tag_names\nUse `tag_names` when you want to push tags/release by their git name (e.g. `refs/tags/MY_TAG_NAME`).  \n\u003e CAUTION: Images produced by this feature can be override by branches with the same name - without a way to restore.\n\n```yaml\nwith:\n  name: myDocker/repository\n  username: ${{ secrets.DOCKER_USERNAME }}\n  password: ${{ secrets.DOCKER_PASSWORD }}\n  tag_names: true\n```\n\n#### tag_semver\nUse `tag_semver` when you want to push tags using the semver syntax by their git name (e.g. `refs/tags/v1.2.3`). This will push four\ndocker tags: `1.2.3`, `1.2` and `1`. A prefix 'v' will automatically be removed.\n\u003e CAUTION: Images produced by this feature can be override by branches with the same name - without a way to restore.\n\n```yaml\nwith:\n  name: myDocker/repository\n  username: ${{ secrets.DOCKER_USERNAME }}\n  password: ${{ secrets.DOCKER_PASSWORD }}\n  tag_semver: true\n```\n\n## Sponsors\n\nA big \"Thank you!\" to the people that help to make this code sustainable:  \n\u003ca target=\"_blank\" href=\"https://github.com/SerhatG\"\u003e\u003cimg src=\"https://github.com/SerhatG.png\" width=\"50px\" alt=\"SerhatG\" /\u003e\n\u003ca target=\"_blank\" href=\"https://github.com/edgedb\"\u003e\u003cimg src=\"https://github.com/edgedb.png\" width=\"50px\" alt=\"EdgeDB\" /\u003e\n\u003ca target=\"_blank\" href=\"https://github.com/psanders\"\u003e\u003cimg src=\"https://github.com/psanders.png\" width=\"50px\" alt=\"Pedro Sanders\" /\u003e\n","funding_links":["https://github.com/sponsors/elgohr","https://www.paypal.me/elgohr"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felgohr%2Fpublish-docker-github-action","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Felgohr%2Fpublish-docker-github-action","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felgohr%2Fpublish-docker-github-action/lists"}