{"id":23359791,"url":"https://github.com/firehed/multistage-docker-build-action","last_synced_at":"2026-05-04T01:10:26.775Z","repository":{"id":40241835,"uuid":"379418833","full_name":"Firehed/multistage-docker-build-action","owner":"Firehed","description":"Github Action for optimized multi-stage docker builds","archived":false,"fork":false,"pushed_at":"2024-09-26T21:34:51.000Z","size":10953,"stargazers_count":12,"open_issues_count":14,"forks_count":3,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-24T09:21:12.670Z","etag":null,"topics":["actions","docker","github-actions"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Firehed.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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}},"created_at":"2021-06-22T22:46:20.000Z","updated_at":"2025-02-20T03:08:39.000Z","dependencies_parsed_at":"2024-11-23T18:38:16.527Z","dependency_job_id":null,"html_url":"https://github.com/Firehed/multistage-docker-build-action","commit_stats":{"total_commits":25,"total_committers":4,"mean_commits":6.25,"dds":0.56,"last_synced_commit":"69ae61a900ea45b43e5ac41b3e20c04c111ccbe0"},"previous_names":[],"tags_count":23,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Firehed%2Fmultistage-docker-build-action","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Firehed%2Fmultistage-docker-build-action/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Firehed%2Fmultistage-docker-build-action/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Firehed%2Fmultistage-docker-build-action/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Firehed","download_url":"https://codeload.github.com/Firehed/multistage-docker-build-action/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248199136,"owners_count":21063641,"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","docker","github-actions"],"created_at":"2024-12-21T11:11:58.343Z","updated_at":"2026-05-04T01:10:26.736Z","avatar_url":"https://github.com/Firehed.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Multistage Docker Build Action\n\nThis action is designed to perform multistage Docker builds in a straightforward and fast way.\nAs it turns out, this is surprisingly difficult to do well in CI, since the host machine performing the build typically starts in a clean slate each time, which means most of the layer caching used by Docker becomes moot.\nTrying to use Github's `actions/cache` to work around this can be quite challenging, and manually dealing with each stage in the build requires a lot of repetition in the Action YAML.\n\nThe inputs to this action allow you to specify the various build stage names as cache targets that will be created and pushed to the registry for future re-use.\nEach stage will be tagged using the branch name and full commit hash.\nWhile the initial build will, of course, be performed from scratch, subsequent builds will pull the previously-built images that the layer caching can use.\n\nWhile the action allows many stages to be pushed to the registry for future re-use, two final stages are defined for different purposes:\n* The `testenv-stage` is a stage specially labeled for use in testing your software.  It usually includes all the runtime dependencies for your software and any additional dependencies that may only be required for testing.  \n* The `server-stage` is a stage specially labeled for deployment of your software.  It usually includes a fully installed version of your software.  This stage can be used in different ways depending on the purpose of your software.  If your software is a server, then this stage can be the basis for deployment in production.  If your software is for individual users to process data, then this stage can be luanched to use the software.\n\n## Inputs\n\n| Input | Required | Default | Description |\n|---|---|---|---|\n| `repository` | **yes** | | Repository name for pushed images |\n| `stages` | **yes** | | Comma-separarted list of build stages. Each of these will be an explicit cache target for subsequent builds |\n| `server-stage` | **yes** | | Name of stage for server |\n| `tag-latest-on-default` | no | `true` | Automatically create a `latest` tag when run on the default branch |\n| `testenv-stage` | no | | Name of stage for test environment |\n| `context` | no | `.` | Build context |\n| `dockerfile` | no | `Dockerfile` | Path to the Dockerfile |\n| `quiet` | no | `true` | Should docker commands be passed `--quiet` (this will always be `false` when running an action with debug logging enabled) |\n| `parallel` | no | `false` | Should stages be built in parallel (via BuildX) |\n| `build-args` | no | | Comma-separated list of `--build-arg` flags. |\n\n### Parallel builds\nThe new `parallel` option, added in `v1.7`, defaults to off.\nIn the next major version (v2), it will default to on.\n\nChanging to the opposite build mode, either implicitly or explicitly, *will break your layer cache for the first build*.\nThe internal image formats are incompatible, and are tagged accordingly to avoid conflicts.\nThis is a Docker limitation at this time.\nPlease note that all images not produced in `outputs` (see below) are considered internal implementation details, subject to change, and **should never be deployed**.\n\nThe current parallel build implementation uses `docker buildx` with very specific `--cache-from` flags to encourage layer reuse.\nNote that this is considered an internal implementation detail, and is subject to change during a minor and/or point release.\nHowever such a change is unlikely and will be documented.\n\nIf you have explicly set `DOCKER_BUILDKIT=1` or `DOCKER_BUILDKIT=0`, it will override the input setting.\nUse of this is **not recommended**.\n\n## Outputs\n\n| Output | Description |\n|---|---|\n| `commit` | The full commit hash used for tags |\n| `server-tag` | Commit-specific tag for server |\n| `testenv-tag` | Commit-specific tag for test env (`''` if `testenv-stage` is omitted) |\n\n## Example\n\nThe following Actions workflow file will:\n\n- Check out the code\n- Authenticate to the Docker registry\n- Perform the multistage build (pulling previous images as needed)\n- Run the test image\n- Deploy the server if tests pass\n\n```yaml\non:\n  push:\n    branches:\n      - main\n  pull_request:\n\njobs:\n  build-and-test:\n    name: Build and test\n    runs-on: ubuntu-latest\n    steps:\n      - uses: actions/checkout@v2\n\n      # This step MUST be performed before multistage-docker-build\n      - name: Auth to GH registry\n        uses: docker/login-action@v1\n        with:\n          registry: ghcr.io\n          username: ${{ github.repository_owner }}\n          password: ${{ secrets.GITHUB_TOKEN }}\n\n      - uses: firehed/multistage-docker-build-action@v1\n        id: build\n        with:\n          dockerfile: examples/Dockerfile\n          repository: ghcr.io/firehed/actions\n          stages: env, configured\n          testenv-stage: testenv\n          server-stage: server\n          build-args: arg1=val1, arg2=val2\n\n      # This assumes your testenv actually runs the tests, and\n      # exits 0 if they all pass and nonzero on failure\n      - name: Run tests\n        run: docker run ${{ steps.build.outputs.testenv-tag }}\n        \n      # This can be any command, and you will probably need to\n      # do additional setup first\n      - name: Deploy\n        run: kubectl set image deploy myapp server=${{ steps.build.outputs.server-tag }}\n```\n\nThe following images will exist:\n\n- `ghcr.io/firehed/actions/server:{commit-hash}`\n- `ghcr.io/firehed/actions/server:latest` (if the action runs on the default branch, e.g. \"main\" or \"master\")\n- `ghcr.io/firehed/actions/testenv:{commit-hash}` (if `testenv-stage` is provided)\n\nThe intended use-case is that the `testenv` will be used for further testing in CI, and the `server` will eventually be deployed.\nYou may want remove the intermediate branch images when the branch is closed to save on storage.\n\nThe following images will also be created, but they are for internal use only (relating to layer caching).\nYou should not use, deploy, or otherwise depend on them - they may change at any time!\n\n- `ghcr.io/firehed/actions/env:{branch-related-name}`\n- `ghcr.io/firehed/actions/configured:{branch-related-name}`\n\ntl:dr: If it comes from one of the `outputs` of this action, go ahead and use it. If not, don't!\n\n## Known issues/Future features\n\n- Make a straightforward mechanism to do cleanup\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffirehed%2Fmultistage-docker-build-action","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffirehed%2Fmultistage-docker-build-action","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffirehed%2Fmultistage-docker-build-action/lists"}