{"id":18026380,"url":"https://github.com/mr-smithers-excellent/docker-build-push","last_synced_at":"2026-04-11T04:20:07.341Z","repository":{"id":38376359,"uuid":"215693159","full_name":"mr-smithers-excellent/docker-build-push","owner":"mr-smithers-excellent","description":"Docker Build \u0026 Push GitHub Action","archived":false,"fork":false,"pushed_at":"2025-05-05T10:58:18.000Z","size":2087,"stargazers_count":301,"open_issues_count":6,"forks_count":63,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-05-05T19:52:27.490Z","etag":null,"topics":["docker","docker-hub","ecr","flux","fluxcd","gcr","github-actions"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","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/mr-smithers-excellent.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2019-10-17T03:12:35.000Z","updated_at":"2025-05-05T03:21:35.000Z","dependencies_parsed_at":"2023-02-13T02:30:27.392Z","dependency_job_id":"c6e13932-98c2-4844-bf4d-6c3ffb81c81a","html_url":"https://github.com/mr-smithers-excellent/docker-build-push","commit_stats":{"total_commits":237,"total_committers":12,"mean_commits":19.75,"dds":0.5147679324894514,"last_synced_commit":"8ba7ce10836273d893fb9f050ebf25979d871ee1"},"previous_names":[],"tags_count":28,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mr-smithers-excellent%2Fdocker-build-push","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mr-smithers-excellent%2Fdocker-build-push/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mr-smithers-excellent%2Fdocker-build-push/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mr-smithers-excellent%2Fdocker-build-push/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mr-smithers-excellent","download_url":"https://codeload.github.com/mr-smithers-excellent/docker-build-push/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254264766,"owners_count":22041793,"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":["docker","docker-hub","ecr","flux","fluxcd","gcr","github-actions"],"created_at":"2024-10-30T08:06:29.903Z","updated_at":"2026-04-11T04:20:07.318Z","avatar_url":"https://github.com/mr-smithers-excellent.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Docker Build \u0026 Push Action\n\n[![Unit Tests](https://github.com/mr-smithers-excellent/docker-build-push/actions/workflows/ci.yml/badge.svg)](https://github.com/mr-smithers-excellent/docker-build-push/actions/workflows/ci.yml)\n[![e2e Tests](https://github.com/mr-smithers-excellent/docker-build-push/actions/workflows/nightly-e2e.yml/badge.svg)](https://github.com/mr-smithers-excellent/docker-build-push/actions/workflows/nightly-e2e.yml)\n[![Maintainability](https://qlty.sh/gh/mr-smithers-excellent/projects/docker-build-push/maintainability.svg)](https://qlty.sh/gh/mr-smithers-excellent/projects/docker-build-push)\n[![Test Coverage](https://qlty.sh/gh/mr-smithers-excellent/projects/docker-build-push/coverage.svg)](https://qlty.sh/gh/mr-smithers-excellent/projects/docker-build-push)\n\nBuilds a Docker image and pushes it to the private registry of your choosing.\n\n## Supported Docker registries\n\n- Docker Hub\n- Google Container Registry (GCR)\n- AWS Elastic Container Registry (ECR)\n- GitHub Docker Registry\n\n## Features\n\n- [Auto-tagging with GitOps](#auto-tagging-with-gitops)\n- [BuildKit support](#buildkit-support)\n- [Multi-platform builds](#multi-platform-builds)\n\n## Breaking changes\n\nIf you're experiencing issues, be sure you are using the [latest stable release](https://github.com/mr-smithers-excellent/docker-build-push/releases/latest) (currently v6).\n\n### v6\n- Multi-platform builds now supported\n- SSH agent forwarding\n\n### v5\n- AWS ECR [get-login command](https://docs.aws.amazon.com/cli/latest/reference/ecr/get-login.html) became deprecated, migrated to [get-login-password command](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/ecr/get-login-password.html)\n- Support for multiple tags added\n- BuildKit support added\n\n## Basic usage\n\n- Ensure you run the [checkout action](https://github.com/actions/checkout) before using this action\n- Add the following to a workflow `.yml` file in the `/.github` directory of your repo\n\n```yaml\nsteps:\n  - uses: actions/checkout@v3\n    name: Check out code\n\n  - uses: mr-smithers-excellent/docker-build-push@v6\n    name: Build \u0026 push Docker image\n    with:\n      image: repo/image\n      tags: v1, latest\n      registry: registry-url.io\n      dockerfile: Dockerfile.ci\n      username: ${{ secrets.DOCKER_USERNAME }}\n      password: ${{ secrets.DOCKER_PASSWORD }}\n```\n\n## Inputs\n\n| Name           | Description                                                                                              | Required | Type    |\n|----------------|----------------------------------------------------------------------------------------------------------|----------|---------|\n| image          | Docker image name                                                                                        | Yes      | String  |\n| tags           | Comma separated docker image tags (see [Auto-tagging with GitOps](#auto-tagging-with-gitops))            | No       | List    |\n| appendMode     | Append tags to auto-generated GitOps tags instead of replacing them                                      | No       | Boolean |\n| addLatest      | Adds the `latest` tag to the GitOps-generated tags                                                       | No       | Boolean |\n| addTimestamp   | Suffixes a build timestamp to the branch-based Docker tag                                                | No       | Boolean |\n| registry       | Docker registry host                                                                                     | Yes      | String  |\n| dockerfile     | Location of Dockerfile (defaults to `Dockerfile`)                                                        | No       | String  |\n| directory      | Directory to pass to `docker build` command, if not project root                                         | No       | String  |\n| buildArgs      | Docker build arguments passed via `--build-arg`                                                          | No       | List    |\n| labels         | Docker build labels passed via `--label`                                                                 | No       | List    |\n| target         | Docker build target passed via `--target`                                                                | No       | String  |\n| platform       | Docker build platform passed via `--platform`                                                            | No       | String  |\n| username       | Docker registry username                                                                                 | No       | String  |\n| password       | Docker registry password or token                                                                        | No       | String  |\n| githubOrg      | GitHub organization to push image to (if not current)                                                    | No       | String  |\n| enableBuildKit | Enables Docker BuildKit support                                                                          | No       | Boolean |\n| cacheFrom      | Docker cache source passed via `--cache-from` (e.g. `type=gha` or `type=registry,ref=myimage:cache`). Requires `enableBuildKit: true` for advanced cache types.    | No       | String  |\n| cacheTo        | Docker cache destination passed via `--cache-to` (e.g. `type=gha,mode=max`). Requires `enableBuildKit: true`.                              | No       | String  |\n| multiPlatform  | Enables Docker buildx support                                                                            | No       | Boolean |\n| overrideDriver | Disables setting up docker-container driver (if `true`, alternative docker driver must be set up)        | No       | Boolean |\n| pushImage      | Flag for disabling the push step, set to `true` by default                                               | No       | Boolean |\n\n## Outputs\n\n| Name          | Description                                        | Format                 |\n|---------------|----------------------------------------------------|------------------------|\n| imageFullName | Full name of the Docker image with registry prefix | `registry/owner/image` |\n| imageName     | Name of the Docker image with owner prefix         | `owner/image`          |\n| tags          | Tags for the Docker image                          | `v1,latest`            |\n\n## Storing secrets\n\nIt is strongly recommended that you store all Docker credentials as GitHub [encrypted secrets](https://docs.github.com/en/actions/security-guides/encrypted-secrets). Secrets can be referenced in workflow files using the syntax `${{ secrets.SECRET_NAME }}`.\n\nThere is a distinction between secrets at the [repository](https://docs.github.com/en/actions/security-guides/encrypted-secrets#creating-encrypted-secrets-for-a-repository), [environment](https://docs.github.com/en/actions/security-guides/encrypted-secrets#creating-encrypted-secrets-for-an-environment) and [organization](https://docs.github.com/en/actions/security-guides/encrypted-secrets#creating-encrypted-secrets-for-an-organization) level. In general, you should store secrets at the repository or organization level, depending on your security posture. It is only recommended that you utilize environment-level secrets if your Docker credentials differ per environment (dev, staging, etc.).\n\n## Examples\n\n### Docker Hub\n\n- Save your Docker Hub username (`DOCKER_USERNAME`) and password (`DOCKER_PASSWORD`) as secrets in your GitHub repo\n- Modify sample below and include in your workflow `.github/workflows/*.yml` file\n\n```yaml\nuses: mr-smithers-excellent/docker-build-push@v6\nwith:\n  image: docker-hub-repo/image-name\n  registry: docker.io\n  username: ${{ secrets.DOCKER_USERNAME }}\n  password: ${{ secrets.DOCKER_PASSWORD }}\n```\n\n### Google Container Registry (GCR)\n\n- Create a service account with the ability to push to GCR (see [configuring access control](https://cloud.google.com/container-registry/docs/access-control))\n- Create and download JSON key for new service account\n- Save content of `.json` file as a secret called `DOCKER_PASSWORD` in your GitHub repo\n- Modify sample below and include in your workflow `.github/workflows/*.yml` file\n- Ensure you set the username to `_json_key`\n\n```yaml\nuses: mr-smithers-excellent/docker-build-push@v6\nwith:\n  image: gcp-project/image-name\n  registry: gcr.io\n  username: _json_key\n  password: ${{ secrets.DOCKER_PASSWORD }}\n```\n\n### AWS Elastic Container Registry (ECR)\n\n- Create an IAM user with the ability to push to ECR (see [example policies](https://docs.aws.amazon.com/AmazonECR/latest/userguide/ecr_managed_policies.html))\n- Create and download access keys\n- Save `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY` as secrets in your GitHub repo\n- Ensure the repo you are trying to push to already exists, if not create with `aws ecr create-repository` before pushing\n- Modify sample below and include in your workflow `.github/workflows/*.yml` file\n\n```yaml\nuses: mr-smithers-excellent/docker-build-push@v6\nwith:\n  image: image-name\n  registry: [aws-account-number].dkr.ecr.[region].amazonaws.com\nenv:\n  AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}\n  AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}\n```\n\n### GitHub Container Registry\n\n- GitHub recently [migrated their container registry](https://docs.github.com/en/packages/guides/migrating-to-github-container-registry-for-docker-images) from docker.pkg.github.com to ghcr.io\n- It is assumed you'll be pushing the image to a repo inside your GitHub organization, unless you set `githubOrg`\n- If using ghcr.io, provide the image name in `ghcr.io/OWNER/IMAGE_NAME` format\n- If using docker.pkg.github.com, provide the image name in `docker.pkg.github.com/OWNER/REPOSITORY/IMAGE_NAME` format\n- Provide either the `${{ github.actor }}` or an alternate username for Docker login (with associated token below)\n- Pass the default GitHub Actions token or custom secret with [proper push permissions](https://docs.github.com/en/packages/guides/pushing-and-pulling-docker-images#authenticating-to-github-container-registry)\n\n#### New ghcr.io\n\n```yaml\nuses: mr-smithers-excellent/docker-build-push@v6\nwith:\n  image: image-name\n  registry: ghcr.io\n  githubOrg: override-org # optional\n  username: ${{ secrets.GHCR_USERNAME }}\n  password: ${{ secrets.GHCR_TOKEN }}\n```\n\n#### Legacy docker.pkg.github.com\n\n```yaml\nuses: mr-smithers-excellent/docker-build-push@v6\nwith:\n  image: github-repo/image-name\n  registry: docker.pkg.github.com\n  username: ${{ github.actor }}\n  password: ${{ secrets.GITHUB_TOKEN }}\n```\n\n## Auto-tagging with GitOps\n\nBy default, if you do not pass a `tags` input this action will use an algorithm based on the state of your git repo to determine the Docker image tag(s). This is designed to enable developers to more easily use [GitOps](https://www.weave.works/technologies/gitops/) in their CI/CD pipelines. Below is a table detailing how the GitHub trigger (branch or tag) determines the Docker tag(s).\n\n| Trigger                  | Commit SHA | addLatest | addTimestamp | Docker Tag(s)                          |\n|--------------------------|------------|-----------|--------------|----------------------------------------|\n| /refs/tags/v1.0          | N/A        | false     | N/A          | v1.0                                   |\n| /refs/tags/v1.0          | N/A        | true      | N/A          | v1.0,latest                            |\n| /refs/heads/dev          | 1234567    | false     | true         | dev-1234567-2021-09-01.195027          |\n| /refs/heads/dev          | 1234567    | true      | false        | dev-1234567,latest                     |\n| /refs/heads/main         | 1234567    | false     | true         | main-1234567-2021-09-01.195027         |\n| /refs/heads/main         | 1234567    | true      | false        | main-1234567,latest                    |\n| /refs/heads/SOME-feature | 1234567    | false     | true         | some-feature-1234567-2021-09-01.195027 |\n| /refs/heads/SOME-feature | 1234567    | true      | false        | some-feature-1234567,latest            |\n\n### Adding custom tags to GitOps tags\n\nThe `appendMode` input allows you to add additional tags while keeping the auto-generated GitOps tags:\n\n```yaml\nuses: mr-smithers-excellent/docker-build-push@v6\nwith:\n  image: repo/image\n  registry: docker.io\n  tags: stable,production\n  appendMode: true\n  username: ${{ secrets.DOCKER_USERNAME }}\n  password: ${{ secrets.DOCKER_PASSWORD }}\n```\n\nFor a `main` branch build with commit `1234567`, this would produce tags: `main-1234567,stable,production`\n\n## BuildKit support\n\nEnables [Docker BuildKit](https://docs.docker.com/build/buildkit/)\n\n\u003e **Note:** BuildKit is required when using advanced cache types such as `type=gha` or `type=registry` with the `cacheFrom` and `cacheTo` inputs. Set `enableBuildKit: true` to avoid errors like `unknown flag: --cache-to`.\n\n```yaml\nsteps:\n  - uses: actions/checkout@v3\n    name: Check out code\n\n  - uses: mr-smithers-excellent/docker-build-push@v6\n    name: Build \u0026 push Docker image\n    with:\n      image: repo/image\n      registry: docker.io\n      enableBuildKit: true\n      username: ${{ secrets.DOCKER_USERNAME }}\n      password: ${{ secrets.DOCKER_PASSWORD }}\n```\n\n## Multi-platform builds\n\nEnables [multi-platform builds](https://docs.docker.com/build/building/multi-platform/) with the default [docker-container driver](https://docs.docker.com/build/drivers/docker-container/)\n\n```yaml\nsteps:\n  - uses: actions/checkout@v3\n    name: Check out code\n\n  - uses: mr-smithers-excellent/docker-build-push@v6\n    name: Build \u0026 push Docker image\n    with:\n      image: repo/image\n      registry: docker.io\n      multiPlatform: true\n      platform: linux/amd64,linux/arm64,linux/arm/v7\n      username: ${{ secrets.DOCKER_USERNAME }}\n      password: ${{ secrets.DOCKER_PASSWORD }}\n```\n\nEnables [multi-platform builds](https://docs.docker.com/build/building/multi-platform/) with custom driver\n\n```yaml\nsteps:\n  - uses: actions/checkout@v3\n    name: Check out code\n\n  # Required when overrideDriver is set to true\n  - uses: docker/setup-buildx-action@v2\n    name: Customize Docker driver\n    with:\n      driver-opts: image=moby/buildkit:v0.11.0\n\n  - uses: mr-smithers-excellent/docker-build-push@v6\n    name: Build \u0026 push Docker image\n    with:\n      image: repo/image\n      registry: docker.io\n      multiPlatform: true\n      platform: linux/amd64,linux/arm64,linux/arm/v7\n      overrideDriver: true\n      username: ${{ secrets.DOCKER_USERNAME }}\n      password: ${{ secrets.DOCKER_PASSWORD }}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmr-smithers-excellent%2Fdocker-build-push","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmr-smithers-excellent%2Fdocker-build-push","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmr-smithers-excellent%2Fdocker-build-push/lists"}