Repository navigation
fix(deployments): keep the source of template and VCS deployments - #13934
Conversation
Remote-source builds hand the sidecar a tarball URL or clone, so Appwrite never stored their source: sourcePath stayed empty and downloading it returned deployment_not_found. The sidecar now packs the root directory it builds into a flat tarball, the same shape as a manual upload. On S3 a post-job upload puts it on the function or site device; on the local device the worker stages it on the builds volume and the Jobs worker moves it. sourcePath is set once the file is there, and a failed upload never fails the build. sourceSize now measures that tarball instead of the whole repository archive the source was extracted from.
An empty sourcePath reached the storage device as the root path. The local device reports it missing, but an S3 device answers a HEAD on the bucket and lists it on read, so the download returned a bucket listing named as a tarball.
The build runs its own code with the builds volume mounted read-write, so the staged source can be swapped for a symlink to anything the Jobs worker can read, which would then be served as the deployment's source. The worker now moves only a regular file reached without symlinks, checks the opened inode against the one it inspected, and skips deployments that already have a source. A failed move is recorded on the span and never holds up the build, and a staged file left by a build that never completed is removed with its build files. On S3 the upload now runs before build.sh instead of after it, so the build cannot touch the file it uploads and readiness no longer waits on it. The separate jobs worker mounts the functions and sites volumes it now writes to.
A build could leave a file at the staged path large enough to exhaust the worker's memory limit when read whole, killing the worker and leaving the deployment building. The move now requires the recorded sourceSize and streams the copy. Cleanup unlinks only inside the builds tree, since the build can symlink a parent directory elsewhere, and removes dangling links that exists() does not see. A refused file is recorded on the span.
|
| // volume, which the build can write too (see the Jobs worker). | ||
| $stage = ''; | ||
| if ($source !== null) { | ||
| $sourceArtifacts[] = new ArchiveArtifact(id: 'sourceArchive', in: 'source', out: 'source-root.tar.gz', compression: ArchiveCompression::Gzip, depends: isset($source['clone']) ? 'source' : 'extract'); |
There was a problem hiding this comment.
Source retention lacks regression coverage
The new remote-source archive and storage flow has no automated test of a build followed by a source download or duplicate. Local verification will not catch a later regression in this user-visible behavior or the callback-ordering failure. An end-to-end test should check the downloaded bytes and persisted source path, not mirror the artifact configuration.
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/Appwrite/Deployment/Deployments.php
Line: 434
Comment:
**Source retention lacks regression coverage**
The new remote-source archive and storage flow has no automated test of a build followed by a source download or duplicate. Local verification will not catch a later regression in this user-visible behavior or the callback-ordering failure. An end-to-end test should check the downloaded bytes and persisted source path, not mirror the artifact configuration.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
The move required the staged file to match the recorded sourceSize, but the queue can deliver complete before the sourceSize callback, which dropped the source of a successful build. It is now bounded by the deployment size limit manual uploads use instead. Canceling a build also removes its staged source, since a canceled build never completes.
✨ Benchmark resultsComparing
Per-scenario breakdown & investigation detailsMetrics below reflect the current branch (after). Δ P95 compares against the base.
Top API waits (after)
|
Bounding the staged file by the deployment size limit dropped the sources of unlimited plans and of large repositories, and accepted a file the build had swapped for another size. The file again has to match the sourceSize the sidecar measured; the move runs when both that size and completion are known, from whichever callback arrives second.
Duplicating a VCS deployment rebuilds from the resource's current root directory. With a kept source it copied the old root's tarball instead, so duplicates of template and VCS deployments re-fetch as before; the kept source only serves downloads.
Duplicates of remote-source deployments re-fetch, so the kept source no longer serves them. Local::delete already ignores a missing path and removes a dangling link, so the staged cleanup only needs the builds-tree guard.
What
Template, "Deploy to Appwrite" and VCS deployments keep the source they were built from again, so Download source works for them. It has not worked for them since 2.0.0; only manual uploads kept a tarball.
Why
On the jobs-service backend a remote source never reaches Appwrite:
createFromRef/createFromVcshand the sidecar a codeload URL, presigned archive or clone, and nothing wrotesourcePath. The pre-2.0 builds worker tarred the root directory and stored it on the function/site device (a82dc6e386^:src/Appwrite/Platform/Modules/Functions/Workers/Builds.php). Downloads and Appwrite-to-Appwrite migrations of those deployments read that file.Changes
Deployments::payload()— for any remote source, a pre-jobArchiveArtifactpacks the extracted root directory into a flatsource-root.tar.gz(same shape as an uploaded tarball), and thesourceSizestat now measures it instead of the whole repository archive (362,239 → 3,059 bytes fornode/starter; clone-path deployments now report a size too).UploadArtifactputs it on the function/site device at{deploymentId}.gz, beforebuild.shstarts. The Jobs worker recordssourcePathwhen it lands.build.sh, and the Jobs worker moves it (below).sourceSize, reached without any symlink, whose opened inode is the one checked. It runs once the build has completed andsourceSizeis recorded, from whichever callback lands second, since the queue can reorder them. The copy is streamed. A refused file or error is recorded on the span and never holds up readiness. Cleanup unlinks only inside the builds tree.docker-compose.yml—appwrite-worker-jobs(separate topology) mounts the functions and sites volumes it now writes to.Verified
End to end on the local stack (orchestrator 2.1.1, local storage), with the API and worker running this branch in isolated containers:
node/starter): ready,sourcePathset,download?type=sourcereturns a flat tarball byte-identical to the stored file, size equal tosourceSize. Output download and execution unchanged.other/littlelink): source kept on the sites volume and downloadable.download?type=sourcereturns 404./proc/self/environor/etc/hostname, a dangling symlink, a symlinked deployment directory (the file behind it left untouched), a file of a different size, and a 600 MB file (no worker memory error).Known limits
sourceUpload) is not exercised locally; it follows the output upload's pattern. A failed pre-job upload fails the build, as a failed source fetch does, and as the pre-2.0 worker did when storing the source failed.sourcePathis set from the upload callback; if that callback is lost the file is not referenced and is not deleted with the deployment.sourceSizechange also addresses 🐛 Bug Report: VCS deployment sourceSize reports the whole cloned repo (.git included), inflating totalSize and deployments-storage metrics #13586, which fix(deployments): scope sourceSize to the extracted tree, not the provider archive #13614 targets in the same hunk.