Resolve Docker build context and Dockerfile path for GitHub Actions workflows that run at repo root (e.g. under act) when the Dockerfile lives in a subdirectory.
When a workflow file lives in a subdirectory (e.g. some-mod/.github/workflows/docker-build.yaml) and you run it from the repo root (as act or some CI does), the job’s working directory is the repo root. The Dockerfile may be in that subdirectory. This action finds the Dockerfile under the workspace and sets the build context and file path so later steps (e.g. docker/build-push-action) work without change.
| Input | Required | Default | Description |
|---|---|---|---|
dockerfile |
No | Dockerfile |
Basename of the Dockerfile to locate. |
workspace |
No | (empty → GITHUB_WORKSPACE) |
Directory treated as repo root; only when pwd equals this do we search. |
set-env |
No | true |
If true, write DOCKER_BUILD_CONTEXT and DOCKER_FILE to GITHUB_ENV. |
verbose |
No | false |
Emit debug logs. |
| Output | Description |
|---|---|
workflow-dir |
Resolved directory: . or the directory containing the found Dockerfile. |
docker-build-context |
Same as workflow-dir; use as Docker build context. |
docker-file |
Resolved path to the Dockerfile (e.g. ./subdir/Dockerfile or Dockerfile). |
When set-env is true, the action also sets:
DOCKER_BUILD_CONTEXTDOCKER_FILE
so downstream steps can use env.DOCKER_BUILD_CONTEXT and env.DOCKER_FILE without change.
@v1— Floating tag: points to the latestv1.x.yrelease. Use for automatic minor/patch updates.@v1.0.0— Exact tag: pins to a specific version. Use for maximum reproducibility.
No special permissions. Default contents: read is sufficient (the action only reads the repository filesystem to locate a Dockerfile).
- name: Set workflow directory for act compatibility
id: workdir
uses: LiquidLogicLabs/git-action-docker-act-compatibility@v1
with:
dockerfile: ${{ env.DOCKER_FILE }}
set-env: true
verbose: ${{ env.DEBUG == 'true' || env.DEBUG == '1' }}
- name: Build and push image
uses: docker/build-push-action@v6
with:
context: ${{ env.DOCKER_BUILD_CONTEXT }}
file: ${{ env.DOCKER_FILE }}
# ...For contributor and development setup (lint, test, local act runs), see DEVELOPMENT.md.
- Dockerfile not found: Ensure the
dockerfileinput matches the actual filename (e.g.DockerfileorDockerfile.dev). If the job does not run from the repo root, setworkspaceto the directory that should be treated as root (e.g.${{ github.workspace }}). - No subdirectory detected under act: When
pwdequalsworkspace, the script searches from the current directory for the Dockerfile. Under act, the job often runs withcwd= repo root; leaveworkspaceempty so it defaults toGITHUB_WORKSPACEand the search runs as expected. - "GITHUB_OUTPUT is not set": Some runners (e.g. Gitea Actions or certain act setups) do not set
GITHUB_OUTPUT/GITHUB_ENVfor composite action steps. The action then exits with this message. Fix by configuring the runner to set these variables for steps, or use a runner/version that provides them (GitHub Actions does). - Verbose output: Set
verbose: true(orverbose: ${{ env.ACTIONS_STEP_DEBUG == 'true' }}) to see resolved paths and search behavior in the logs.
- The action only reads the repository filesystem (find Dockerfile by name) and writes to
GITHUB_OUTPUTand optionallyGITHUB_ENV. It does not make network calls or consume secrets. - Do not pass untrusted input as
dockerfileorworkspaceif the workflow runs in a context where those could escape the repo (e.g. path traversal). When used with standard workflow values, risk is minimal.
See repository license.