Skip to content

Make apify push work for monorepo Actors that set dockerContextDir #595

Description

@lhotanok

Problem

apify push uploads the files under the Actor folder (the cwd or --dir), so that folder is the root the platform builds from. Both Actors of apify/actor-monorepo-example set "dockerContextDir": "../../.." with dockerfile and input under ../../../shared/, so:

  • From the Actor folder, the build fails with Actor context path "../../.." is outside of Actor root directory! (exit code 1).
  • From the repository root, the push stops with A valid Actor could not be found in the current directory. Please make sure you are in the correct directory. (exit code 4).
  • On a version built from a Git repository (the documented route), --force replaces the Git source with that broken upload.

apify/push-actor-action only runs apify push in working-directory, so it inherits this. The local Actor runtime branch (#1496) resolves dockerContextDir but refuses the Apify platform (exit 255).

What we want

apify push from a monorepo Actor folder deploys that Actor, honoring dockerContextDir as the platform does. Push stays single-Actor; the Git repository is the upload root.

Stage 1, on master, no platform change:

  • The branch's resolveDockerContext, getContextFilePaths, and readGitProvenance land on master as src/lib/docker-context.ts; push runs the resolver right after reading actor.json, before any Actor read or write.
  • A dockerContextDir that is not a string, does not exist, does not contain the Actor folder, or lies outside the Git repository exits 5 (InvalidActorJson) with the branch's message (the branch checks existence only inside Git).
  • A context above the Actor folder exits 255 (NotImplemented) with the branch's message minus its runtime clause.
  • A context at or below the Actor folder ("..", ".", "../src") is an ordinary push; the branch returns invalid below the folder, which the platform accepts.

Stage 2, once SOURCE_FILES and TARBALL versions accept actorPath (the platform field sub-issue (apify/apify-core#31473)):

  • The push uploads the Git repository root with actorPath as that sub-issue defines it (POSIX, relative to that root, never empty); both example Actors build.
  • Under 3 MB (MAX_MULTIFILE_BYTES) the version is SOURCE_FILES with repository-relative names; otherwise the existing zip upload and TARBALL with the tarballUrl (signed when the store has a signing key).
  • In context mode, push runs the actor.json path check of the path validation sub-issue (Validate actor.json paths before push #1500) with the upload root; dockerfile must also lie inside the Docker context. Exit 5 before any upload.
  • A 400 naming actorPath (a platform without the field) maps to the stage 1 message and exit 255; a just-created Actor is deleted. --json keeps its envelope and a clean stdout.

Design notes

  • The upload is what a Git clone has, as on disk: tracked plus untracked-not-ignored files, symlinks kept, sibling Actors included, uncommitted changes uploaded with a warning, no .actorignore. Outside Git, the Docker context root is the upload root and the ordinary file list (with .actorignore) applies.
  • A repository upload can exceed 3 MB; the zip goes to the OS temp directory, not temp_file.zip in process.cwd(). The newer-changes check scans the upload root and, in context mode, also runs on the zip path; the Git-source prompt and --force are unchanged.
  • The platform's root .actor/actor.json readers (name rewrite, Standby auto-enable) look under actorPath once the platform field sub-issue ships; the CLI already sets actorStandby.
  • Stage 1 lands first; the path validation helper hooks in after the resolver.

Out of scope

How it's tested

  • test/local/lib/docker-context.test.ts (new): the resolver cases above, a missing context outside Git, / separators on Windows.
  • test/local/lib/docker-context-files.test.ts (new, modeled on utils-gitignore-fallback.test.ts): the file rules above, including the no-Git fallback (vi.mock('node:child_process')).
  • test/local/commands/push-monorepo.test.ts (new, from the branch's file, mocked client as in push-git-source.test.ts): every checklist item and the 400 rollback.
  • test/api/commands/push.test.ts: one [api] case pushing a two-Actor fixture like the example (needs TEST_USER_TOKEN and the platform change). pnpm run update-docs regenerates docs/reference.md.

Links

Activity

  1. added
    t-toolingIssues with this label are in the ownership of the tooling team.
    on Jul 10, 2024
  2. patrikbraborec commented on Jul 21, 2025

    @patrikbraborec
    Contributor

    I talked about it with @JJetmar, and here is the description of the actual problem:

    apify-cli push doesn't support monorepo structures because it only processes the current directory and ignores the dockerContextDir path specified in actor.json.

    • Actors in monorepos are typically in nested directories (e.g., actors/my-actor/)
    • When running apify push from actor directory, dependencies from parent directories (e.g., @packages/javascript-utils) aren't included

    Solution could be to correctly respect dockerContextDir in actor.json for proper build context.

    cc. @vladfrangu, @B4nan.

  3. patrikbraborec commented on Jul 23, 2025

    @patrikbraborec
    Contributor

    For the context, the current solution is that they push to the Git repository and build it in the Console with a Source set to Git.

  4. JJetmar commented on Dec 26, 2025

    @JJetmar

    This is still being requested by the devs in apify/actor-monorepo-example#3

  5. added
    t-buildersIssues owned by the Builders team.
    and removed
    t-toolingIssues with this label are in the ownership of the tooling team.
    on Apr 16, 2026
  6. changed the title [-]Support usage of `apify push` with monorepo projects[/-] [+]Make `apify push` work for monorepo Actors that set `dockerContextDir`[/+] on Oct 15, 2026
  7. DaveHanns commented on Oct 27, 2026

    @DaveHanns
    Contributor

    This work is now tracked in two smaller issues:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

t-buildersIssues owned by the Builders team.

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions