Skip to content

Where people and agents ship software together. The open-source git platform for the whole job: issues, agents, checks and deploys to the edge.

g1t.sh
2,174 linesCodeBlameRaw
1//! Builds one commit of a repository and hands the result to Cloudflare, as
2//! a preview of a pull request or as the repository's production.
3//!
4//! The sandbox never holds a Cloudflare credential that could touch anything
5//! else. The deployments service opens an upload for exactly the files
6//! this build produced and gives back a key that can only upload those;
7//! the sandbox uploads them with it, and sends the Worker's code to the
8//! service, which puts the app in place.
9//!
10//! What gets built:
11//!
12//! - A Workers project (a `wrangler.jsonc`, `wrangler.json` or
13//! `wrangler.toml`): bundled by `wrangler deploy --dry-run`, with its
14//! static assets, compatibility settings and `vars`. Other bindings (D1,
15//! KV, R2, Durable Objects…) are not provisioned yet; the deployment says
16//! which were left out.
17//! - A framework g1t knows (deploy/frameworks.rs: Vite, Astro, Next.js,
18//! SvelteKit, Nuxt, Hugo, Jekyll and the rest), found by the package's
19//! dependencies and config files: built with its own command and served
20//! from the folder it writes. A Cloudflare adapter's Worker (Astro's
21//! `dist/_worker.js`, SvelteKit's `.svelte-kit/cloudflare/_worker.js`) is
22//! bundled as a Workers project's is, without a Wrangler config of its
23//! own. A framework set up to need a server fails before anything is
24//! installed, saying what to change.
25//! - A container (deploy/container.rs): a project with a `Dockerfile` (or
26//! `Containerfile`, or the path it chose) and no framework that builds a
27//! static site or a Worker, a framework set up to need a server, or a
28//! Node.js, Python, Go, Ruby or PHP server, for which g1t writes a
29//! Dockerfile and shows it in the log. The image is built with Docker
30//! and pushed to Cloudflare's registry with a push-only login the
31//! deployments service gives this build alone, for minutes (the
32//! `registry` step); the service runs it.
33//! - Anything else: a static site. Its `build` script runs, and the first
34//! of `dist`, `build`, `out`, `public`, `_site` or `.output/public` that
35//! exists is served, or the repository itself if it has an `index.html`.
36//!
37//! The project's own **Build as** (`BUILD_AS`: auto, static, workers or
38//! docker), **Dockerfile** (`DOCKERFILE`), **Build command** and **Output
39//! directory** win over what is detected.
40//!
41//! Configuration comes from the environment:
42//!
43//! - `G1T_API`, `DEPLOY_ID`, `DEPLOY_TOKEN`: where and how to report.
44//! - `GIT_REMOTE`, `GIT_COMMIT`, `G1T_USER`, `G1T_TOKEN`: what to check out.
45//! - `ROOT_DIR`: where in the repository the project lives; empty for all
46//! of it. Everything below is relative to it.
47//! - `BUILD_COMMAND`, `OUTPUT_DIR`: the project's own choices, if any.
48//! - `BUILD_ENV`, `BUILD_SECRETS`: JSON objects of the repository's
49//! variables and secrets for deploy builds. Both are set for the build;
50//! secrets' values are redacted from its log.
51//!
52//! From a workflow step, `g1t-runner deploy` runs the same build in the
53//! job's own checkout: without `GIT_REMOTE` nothing is cloned, and the
54//! project is the current directory (`ROOT_DIR` below it). The build's id
55//! and token come from `POST /repos/{owner}/{repo}/deployments/builds`,
56//! which the `g1t/deploy` action calls (actions/deploy). Its output goes
57//! to the step's log as well as the deployment's. `g1t-runner detect`
58//! says what the build would find, as `key=value` lines for
59//! `$GITHUB_OUTPUT`, without building anything.
60
61use std::collections::{BTreeMap, BTreeSet};
62use std::path::{Path, PathBuf};
63use std::time::Instant;
64
65use anyhow::{Context, Result, bail};
66use base64::Engine;
67use base64::engine::general_purpose::STANDARD;
68use serde::{Deserialize, Serialize};
69use serde_json::{Value, json};
70use sha2::{Digest, Sha256};
71
72use crate::checks::{redact, run_command};
73use crate::{WORKDIR, auth_option, env, git};
74
75mod container;
76mod frameworks;
77
78use container::BuildAs;
79use frameworks::{Adapter, Framework};
80
81/// Where `wrangler deploy --dry-run` writes the bundle in a sandbox.
82const BUNDLE_DIR: &str = "/work/g1t-bundle";
83/// Cloudflare's limits on a Worker's static assets.
84const MAX_FILES: usize = 20_000;
85const MAX_FILE_BYTES: u64 = 25 * 1024 * 1024;
86/// How much of the build's output is kept for the deployment's log.
87const MAX_LOG_CHARS: usize = 20_000;
88/// Directories a static build usually writes to, in the order they are tried.
89const OUTPUT_DIRS: [&str; 6] = ["dist", "build", "out", "public", "_site", ".output/public"];
90/// Bindings a Workers project may declare that are not provisioned yet.
91const UNSUPPORTED_BINDINGS: [&str; 10] = [
92 "kv_namespaces",
93 "d1_databases",
94 "r2_buckets",
95 "durable_objects",
96 "services",
97 "queues",
98 "vectorize",
99 "hyperdrive",
100 "ai",
101 "workflows",
102];
103
104struct Reporter {
105 base: String,
106 token: String,
107}
108
109impl Reporter {
110 fn send(&self, step: &str, mut body: Value) -> Result<Value> {
111 body["token"] = self.token.clone().into();
112 let response = ureq::post(&format!("{}/{step}", self.base))
113 .send_json(body)
114 .with_context(|| format!("could not report `{step}` to g1t"))?;
115 Ok(response.into_json().unwrap_or(Value::Null))
116 }
117}
118
119/// The build's log, kept to its end; also printed, in a workflow step.
120#[derive(Default)]
121struct Log {
122 text: String,
123 /// Each line to standard output as well, redacted.
124 echo: Option<Vec<String>>,
125}
126
127impl Log {
128 fn line(&mut self, line: &str) {
129 self.text.push_str(line);
130 self.text.push('\n');
131 if let Some(secrets) = &self.echo {
132 println!("{}", redact(line, secrets));
133 }
134 }
135
136 fn tail(&self) -> String {
137 let length = self.text.chars().count();
138 if length <= MAX_LOG_CHARS {
139 return self.text.clone();
140 }
141 let kept: String = self.text.chars().skip(length - MAX_LOG_CHARS).collect();
142 format!("… (earlier output not shown)\n{kept}")
143 }
144}
145
146/// Runs a command in the checkout, logging it; fails if it fails.
147fn step(log: &mut Log, command: &str, secrets: &[String]) -> Result<()> {
148 log.line(&format!("$ {command}"));
149 let result = run_command(command, &project_dir(), secrets);
150 if !result.output_text().is_empty() {
151 log.line(result.output_text());
152 }
153 if !result.passed {
154 bail!("`{command}` failed");
155 }
156 Ok(())
157}
158
159/// A Workers project's settings, from whichever config file it has.
160#[derive(Debug, Default, Deserialize)]
161struct WranglerConfig {
162 main: Option<String>,
163 compatibility_date: Option<String>,
164 #[serde(default)]
165 compatibility_flags: Vec<String>,
166 assets: Option<AssetsConfig>,
167 #[serde(default)]
168 vars: BTreeMap<String, Value>,
169 #[serde(flatten)]
170 rest: BTreeMap<String, Value>,
171}
172
173#[derive(Debug, Default, Deserialize)]
174struct AssetsConfig {
175 directory: Option<String>,
176 binding: Option<String>,
177 html_handling: Option<String>,
178 not_found_handling: Option<String>,
179}
180
181/// JSON with comments and trailing commas, as `wrangler.jsonc` allows.
182fn strip_jsonc(text: &str) -> String {
183 let mut out = String::with_capacity(text.len());
184 let mut chars = text.chars().peekable();
185 let mut in_string = false;
186 while let Some(c) = chars.next() {
187 if in_string {
188 out.push(c);
189 if c == '\\' {
190 if let Some(next) = chars.next() {
191 out.push(next);
192 }
193 } else if c == '"' {
194 in_string = false;
195 }
196 continue;
197 }
198 match (c, chars.peek()) {
199 ('"', _) => {
200 in_string = true;
201 out.push(c);
202 }
203 ('/', Some('/')) => {
204 for c in chars.by_ref() {
205 if c == '\n' {
206 out.push('\n');
207 break;
208 }
209 }
210 }
211 ('/', Some('*')) => {
212 chars.next();
213 let mut last = ' ';
214 for c in chars.by_ref() {
215 if last == '*' && c == '/' {
216 break;
217 }
218 last = c;
219 }
220 }
221 _ => out.push(c),
222 }
223 }
224 // Trailing commas before a closing bracket.
225 let mut cleaned = String::with_capacity(out.len());
226 let chars: Vec<char> = out.chars().collect();
227 let mut in_string = false;
228 let mut i = 0;
229 while i < chars.len() {
230 let c = chars[i];
231 if c == '"' && (i == 0 || chars[i - 1] != '\\') {
232 in_string = !in_string;
233 }
234 if c == ',' && !in_string {
235 let next = chars[i + 1..].iter().find(|c| !c.is_whitespace());
236 if matches!(next, Some('}') | Some(']')) {
237 i += 1;
238 continue;
239 }
240 }
241 cleaned.push(c);
242 i += 1;
243 }
244 cleaned
245}
246
247fn read_wrangler(dir: &Path) -> Result<Option<WranglerConfig>> {
248 for name in ["wrangler.jsonc", "wrangler.json"] {
249 let path = dir.join(name);
250 if path.exists() {
251 let text = std::fs::read_to_string(&path)?;
252 return Ok(Some(
253 serde_json::from_str(&strip_jsonc(&text)).with_context(|| format!("could not read {name}"))?,
254 ));
255 }
256 }
257 let path = dir.join("wrangler.toml");
258 if path.exists() {
259 let text = std::fs::read_to_string(&path)?;
260 return Ok(Some(toml::from_str(&text).context("could not read wrangler.toml")?));
261 }
262 Ok(None)
263}
264
265/// How to install the project's dependencies, judged by its lockfile.
266fn install_command(dir: &Path) -> Option<&'static str> {
267 if !dir.join("package.json").exists() {
268 return None;
269 }
270 Some(if dir.join("pnpm-lock.yaml").exists() {
271 "corepack enable && pnpm install --frozen-lockfile"
272 } else if dir.join("yarn.lock").exists() {
273 "corepack enable && yarn install"
274 } else if dir.join("bun.lockb").exists() || dir.join("bun.lock").exists() {
275 "npx --yes bun install"
276 } else if dir.join("package-lock.json").exists() {
277 "npm ci"
278 } else {
279 "npm install"
280 })
281}
282
283fn has_build_script(dir: &Path) -> bool {
284 std::fs::read_to_string(dir.join("package.json"))
285 .ok()
286 .and_then(|text| serde_json::from_str::<Value>(&text).ok())
287 .is_some_and(|package| package["scripts"]["build"].is_string())
288}
289
290/// One file of the site, as Cloudflare's asset upload names it.
291struct Asset {
292 path: String,
293 hash: String,
294 size: u64,
295 file: PathBuf,
296}
297
298fn content_type(path: &str) -> &'static str {
299 let extension = path.rsplit('.').next().unwrap_or("").to_ascii_lowercase();
300 match extension.as_str() {
301 "html" | "htm" => "text/html",
302 "css" => "text/css",
303 "js" | "mjs" => "application/javascript",
304 "json" | "map" => "application/json",
305 "svg" => "image/svg+xml",
306 "png" => "image/png",
307 "jpg" | "jpeg" => "image/jpeg",
308 "gif" => "image/gif",
309 "webp" => "image/webp",
310 "avif" => "image/avif",
311 "ico" => "image/x-icon",
312 "woff" => "font/woff",
313 "woff2" => "font/woff2",
314 "ttf" => "font/ttf",
315 "txt" => "text/plain",
316 "xml" => "application/xml",
317 "wasm" => "application/wasm",
318 "pdf" => "application/pdf",
319 "mp4" => "video/mp4",
320 "webm" => "video/webm",
321 _ => "application/octet-stream",
322 }
323}
324
325/// What is never served from the top of a site: a Pages-style Worker
326/// (`_worker.js`, its server code, which a Cloudflare adapter writes beside
327/// the site's files), `_routes.json`, and `.assetsignore`, with each name
328/// that `.assetsignore` lists, as wrangler leaves them out.
329fn ignored_at_root(root: &Path) -> BTreeSet<String> {
330 let mut ignored: BTreeSet<String> = ["_worker.js", "_routes.json", ".assetsignore"].map(str::to_owned).into();
331 if let Ok(text) = std::fs::read_to_string(root.join(".assetsignore")) {
332 ignored.extend(
333 text.lines()
334 .map(|line| line.trim().trim_matches('/'))
335 .filter(|line| !line.is_empty() && !line.starts_with('#') && !line.contains(['*', '/', '!']))
336 .map(str::to_owned),
337 );
338 }
339 ignored
340}
341
342/// Every file of the site at `root`, but for what never belongs in one.
343fn collect_site(root: &Path, skip_project: bool) -> Result<Vec<Asset>> {
344 let mut assets = Vec::new();
345 collect(root, root, skip_project, &ignored_at_root(root), &mut assets)?;
346 Ok(assets)
347}
348
349fn collect(root: &Path, dir: &Path, skip_project: bool, ignored: &BTreeSet<String>, out: &mut Vec<Asset>) -> Result<()> {
350 for entry in std::fs::read_dir(dir)? {
351 let entry = entry?;
352 let name = entry.file_name().to_string_lossy().into_owned();
353 let path = entry.path();
354 let kind = entry.file_type()?;
355 if name == ".git" || (skip_project && (name == "node_modules" || name.starts_with(".g1t"))) {
356 continue;
357 }
358 if dir == root && ignored.contains(&name) {
359 continue;
360 }
361 if kind.is_dir() {
362 collect(root, &path, skip_project, ignored, out)?;
363 continue;
364 }
365 if !kind.is_file() || name == "_headers" || name == "_redirects" {
366 continue;
367 }
368 let size = entry.metadata()?.len();
369 let relative = path
370 .strip_prefix(root)?
371 .to_string_lossy()
372 .replace('\\', "/");
373 if size > MAX_FILE_BYTES {
374 bail!("{relative} is larger than Cloudflare's 25 MiB limit for one file");
375 }
376 let bytes = std::fs::read(&path)?;
377 let digest = hex::encode(Sha256::digest(&bytes));
378 out.push(Asset {
379 path: format!("/{relative}"),
380 hash: digest[..32].to_owned(),
381 size,
382 file: path,
383 });
384 if out.len() > MAX_FILES {
385 bail!("the site has more than {MAX_FILES} files, Cloudflare's limit");
386 }
387 }
388 Ok(())
389}
390
391/// The upload, as the API sends it: `snake_case`, or `uploadUrl` from
392/// before its bodies were.
393#[derive(Deserialize)]
394struct UploadSession {
395 jwt: String,
396 #[serde(default)]
397 buckets: Vec<Vec<String>>,
398 #[serde(alias = "uploadUrl")]
399 upload_url: String,
400}
401
402/// Sends one bucket of files with the upload's key. The last bucket's
403/// answer carries the key that completes the upload.
404fn upload_bucket(session: &UploadSession, bucket: &[String], by_hash: &BTreeMap<&str, &Asset>) -> Result<Option<String>> {
405 let boundary = format!("g1t-{}", hex::encode(Sha256::digest(bucket.join(",").as_bytes()))[..24].to_owned());
406 let mut body: Vec<u8> = Vec::new();
407 for hash in bucket {
408 let asset = by_hash
409 .get(hash.as_str())
410 .with_context(|| format!("Cloudflare asked for a file this build does not have ({hash})"))?;
411 let bytes = std::fs::read(&asset.file)?;
412 body.extend_from_slice(
413 format!(
414 "--{boundary}\r\nContent-Disposition: form-data; name=\"{hash}\"; filename=\"{hash}\"\r\nContent-Type: {}\r\n\r\n",
415 content_type(&asset.path)
416 )
417 .as_bytes(),
418 );
419 body.extend_from_slice(STANDARD.encode(bytes).as_bytes());
420 body.extend_from_slice(b"\r\n");
421 }
422 body.extend_from_slice(format!("--{boundary}--\r\n").as_bytes());
423 let response = ureq::post(&session.upload_url)
424 .set("authorization", &format!("Bearer {}", session.jwt))
425 .set("content-type", &format!("multipart/form-data; boundary={boundary}"))
426 .send_bytes(&body);
427 let response = match response {
428 Ok(response) => response,
429 Err(ureq::Error::Status(code, response)) => {
430 bail!("Cloudflare refused the upload ({code}): {}", response.into_string().unwrap_or_default())
431 }
432 Err(error) => bail!("could not upload to Cloudflare: {error}"),
433 };
434 let answer: Value = response.into_json().unwrap_or(Value::Null);
435 Ok(answer["result"]["jwt"].as_str().map(str::to_owned))
436}
437
438#[derive(Serialize)]
439#[serde(rename_all = "camelCase")]
440struct Module {
441 name: String,
442 content_base64: String,
443 content_type: String,
444}
445
446/// The bundle `wrangler deploy --dry-run` wrote, main module first.
447fn bundle_modules(main: &str, bundle: &Path) -> Result<(String, Vec<Module>)> {
448 let stem = Path::new(main)
449 .file_stem()
450 .map(|stem| stem.to_string_lossy().into_owned())
451 .unwrap_or_else(|| "index".to_owned());
452 let mut modules = Vec::new();
453 let mut files = Vec::new();
454 collect_files(bundle, &mut files)?;
455 for file in files {
456 let name = file
457 .strip_prefix(bundle)?
458 .to_string_lossy()
459 .replace('\\', "/");
460 let kind = match name.rsplit('.').next().unwrap_or("") {
461 "js" | "mjs" => "application/javascript+module",
462 "wasm" => "application/wasm",
463 "map" | "md" => continue,
464 _ => "text/plain",
465 };
466 modules.push(Module {
467 content_base64: STANDARD.encode(std::fs::read(&file)?),
468 content_type: kind.to_owned(),
469 name,
470 });
471 }
472 let main_name = modules
473 .iter()
474 .map(|module| module.name.clone())
475 .find(|name| *name == format!("{stem}.js") || *name == format!("{stem}.mjs"))
476 .or_else(|| {
477 modules
478 .iter()
479 .find(|module| module.content_type == "application/javascript+module")
480 .map(|module| module.name.clone())
481 })
482 .context("wrangler wrote no JavaScript module")?;
483 Ok((main_name, modules))
484}
485
486fn collect_files(dir: &Path, out: &mut Vec<PathBuf>) -> Result<()> {
487 for entry in std::fs::read_dir(dir)? {
488 let entry = entry?;
489 if entry.file_type()?.is_dir() {
490 collect_files(&entry.path(), out)?;
491 } else {
492 out.push(entry.path());
493 }
494 }
495 Ok(())
496}
497
498/// What a Workers config asks for that g1t.page does not provision, said
499/// as the deployment's warnings: bindings it runs without, and scheduled
500/// (`triggers.crons`) runs that never fire.
501fn config_warnings(config: &WranglerConfig) -> Vec<String> {
502 // An empty list, as a config a framework's build writes has for each
503 // kind of binding (`"d1_databases": []`), declares nothing.
504 fn declares(value: &Value) -> bool {
505 match value {
506 Value::Null => false,
507 Value::Array(items) => !items.is_empty(),
508 Value::Object(fields) => fields.values().any(declares),
509 _ => true,
510 }
511 }
512 let mut warnings = Vec::new();
513 for binding in UNSUPPORTED_BINDINGS {
514 if config.rest.get(binding).is_some_and(declares) {
515 warnings.push(format!("`{binding}` is not provisioned on g1t.page yet, so the app runs without it."));
516 }
517 }
518 let crons = config
519 .rest
520 .get("triggers")
521 .and_then(|triggers| triggers.get("crons"))
522 .and_then(Value::as_array)
523 .map_or(0, |crons| crons.iter().filter(|cron| cron.as_str().is_some_and(|c| !c.trim().is_empty())).count());
524 if crons > 0 {
525 let schedules = if crons == 1 { "schedule" } else { "schedules" };
526 warnings.push(format!(
527 "`triggers.crons` ({crons} {schedules}) is not set up on g1t.page yet, so the Worker's `scheduled` handler never runs."
528 ));
529 }
530 warnings
531}
532
533/// What was built: the Worker's code and settings, and where its site is.
534struct Built {
535 worker: Value,
536 assets_dir: Option<PathBuf>,
537 warnings: Vec<String>,
538 /// What kind of project it was found to be, for its settings page:
539 /// `workers`, `static` (a build's output), `html` (the files as they
540 /// are) or `container`.
541 detected: &'static str,
542 /// The framework it was found to be built with, if any (`astro`…), or
543 /// for a container what it was built from (`dockerfile`, `flask`…).
544 framework: Option<&'static str>,
545 /// For a container: the image pushed, its digest, port and size.
546 container: Option<Value>,
547}
548
549/// What a project without a Workers config is: a site it built, or its own
550/// files served as they are.
551fn static_kind(project: &Path, assets_dir: &Path, built: bool) -> &'static str {
552 if !built && assets_dir == project { "html" } else { "static" }
553}
554
555/// The command that bundles a Workers project, without deploying it,
556/// into `bundle` when given, by the config at `config` when given.
557fn wrangler_build(bundle: Option<&Path>, config: Option<&Path>) -> String {
558 let mut command = "npx --yes wrangler@4 deploy --dry-run".to_owned();
559 if let Some(config) = config {
560 command.push_str(&format!(" --config {}", config.display()));
561 }
562 if let Some(bundle) = bundle {
563 command.push_str(&format!(" --outdir {}", bundle.display()));
564 }
565 command
566}
567
568/// The config a framework's build wrote for wrangler, which wrangler reads
569/// in place of the project's own (`.wrangler/deploy/config.json`, as
570/// `@cloudflare/vite-plugin` writes it), with the folder its paths are
571/// relative to.
572fn redirected_config(dir: &Path) -> Result<Option<(WranglerConfig, PathBuf)>> {
573 let pointer = dir.join(".wrangler/deploy/config.json");
574 let Ok(text) = std::fs::read_to_string(&pointer) else { return Ok(None) };
575 let Some(path) = serde_json::from_str::<Value>(&text).ok().and_then(|v| v["configPath"].as_str().map(str::to_owned)) else {
576 return Ok(None);
577 };
578 let path = dir.join(".wrangler/deploy").join(path);
579 let path = path.canonicalize().unwrap_or(path);
580 let text = std::fs::read_to_string(&path).with_context(|| format!("could not read {}", path.display()))?;
581 let config = serde_json::from_str(&strip_jsonc(&text)).with_context(|| format!("could not read {}", path.display()))?;
582 Ok(Some((config, path.parent().map_or_else(|| dir.to_path_buf(), Path::to_path_buf))))
583}
584
585/// The entry of the Worker a framework's adapter wrote, once it has built:
586/// the file, or a directory's `index.js`.
587fn adapter_entry(dir: &Path, adapter: &Adapter) -> Option<PathBuf> {
588 let entry = dir.join(adapter.entry);
589 if entry.is_file() {
590 return Some(entry);
591 }
592 ["index.js", "index.mjs"].iter().map(|name| entry.join(name)).find(|index| index.is_file())
593}
594
595/// The first of the usual output directories a static build wrote (or the
596/// project's own `index.html`), relative to the project: `.` for itself.
597fn find_output(dir: &Path) -> Option<String> {
598 OUTPUT_DIRS
599 .iter()
600 .find(|name| {
601 let path = dir.join(name);
602 path.join("index.html").exists() || (path.is_dir() && **name != "public")
603 })
604 .map(|name| (*name).to_owned())
605 .or_else(|| dir.join("index.html").exists().then(|| ".".to_owned()))
606}
607
608/// What a build of the project at `dir` does, found before anything runs:
609/// what it is, how its dependencies are installed, what builds it, and
610/// where what it serves is. For a site with a build of its own, the output
611/// directory may only exist once it has run; then `output_dir` is `None`
612/// unless one was chosen or the framework says where it writes.
613#[derive(Debug, PartialEq, Eq)]
614pub(crate) struct Detected {
615 /// `workers`, `static`, `html`, `container`, or `none` when there is
616 /// nothing to serve.
617 pub kind: &'static str,
618 /// The framework it is built with, if g1t knows it.
619 pub framework: Option<Framework>,
620 pub install: Option<String>,
621 pub build: Option<String>,
622 pub output_dir: Option<String>,
623 /// Why it cannot be served as it is set up, and what to change: the
624 /// kind is then `none`.
625 pub problem: Option<String>,
626 /// What runs before wrangler bundles a Workers project; for anything
627 /// else, `build`.
628 pre_build: Option<String>,
629 /// For a container: its Dockerfile, or the one g1t writes.
630 pub container: Option<ContainerBuild>,
631 /// What it would be served as without its Dockerfile, when it is a
632 /// container only for having one: built so while g1t.page runs no
633 /// containers (`not_enabled` from the registry step).
634 fallback: Option<Box<Detected>>,
635}
636
637/// How a container is built.
638#[derive(Debug, Clone, PartialEq, Eq)]
639pub(crate) struct ContainerBuild {
640 /// The project's own Dockerfile, relative to the project; none when
641 /// g1t writes one.
642 pub dockerfile: Option<String>,
643 /// The Dockerfile g1t writes, for a server it recognises.
644 pub generated: Option<container::Server>,
645 /// What it listens on: its Dockerfile's `EXPOSE`, else 8080. `PORT`
646 /// is set to it.
647 pub port: u16,
648}
649
650impl Detected {
651 fn nothing(framework: Option<Framework>, install: Option<String>, problem: String) -> Detected {
652 Detected {
653 kind: "none",
654 framework,
655 install,
656 build: None,
657 output_dir: None,
658 problem: Some(problem),
659 pre_build: None,
660 container: None,
661 fallback: None,
662 }
663 }
664
665 /// The `framework` `g1t-runner detect` prints: the framework, else for
666 /// a container the server g1t wrote a Dockerfile for (`flask`…) or
667 /// `dockerfile`.
668 pub(crate) fn framework_id(&self) -> Option<&'static str> {
669 self.framework.as_ref().map(|f| f.id).or_else(|| {
670 self.container.as_ref().map(|c| c.generated.as_ref().map_or("dockerfile", |server| server.id))
671 })
672 }
673}
674
675/// Why nothing could be found to serve, and what to add.
676const NOTHING_TO_SERVE: &str = "found nothing to serve: no Workers config, no Dockerfile, no index.html, and none of dist, build, out, \
677 public, _site or .output/public. Add a `Dockerfile` to deploy it as a container, or set **Build command** and \
678 **Output directory** for a static site.";
679
680/// The project as a container: its own Dockerfile, else one g1t writes
681/// for `framework` or for a server it recognises. None when it has neither.
682fn as_container(dir: &Path, framework: Option<Framework>, own: Option<String>) -> Option<Detected> {
683 let build = match own {
684 Some(path) => {
685 let text = std::fs::read_to_string(dir.join(&path)).unwrap_or_default();
686 ContainerBuild { port: container::exposed_port(&text).unwrap_or(container::DEFAULT_PORT), dockerfile: Some(path), generated: None }
687 }
688 None => {
689 let server = match &framework {
690 // One set up for Workers (OpenNext's adapter) is not run as a server.
691 Some(framework) if framework.workers => None,
692 Some(framework) => container::for_framework(dir, framework.id),
693 None => container::server(dir),
694 }?;
695 ContainerBuild { dockerfile: None, generated: Some(server), port: container::DEFAULT_PORT }
696 }
697 };
698 let file = build.dockerfile.clone().unwrap_or_else(|| "Dockerfile (written by g1t)".to_owned());
699 Some(Detected {
700 kind: "container",
701 framework,
702 // The image installs what it needs: nothing runs before its build.
703 install: None,
704 build: Some(format!("docker build -f {file} .")),
705 output_dir: None,
706 problem: None,
707 pre_build: None,
708 container: Some(build),
709 fallback: None,
710 })
711}
712
713#[cfg(test)]
714pub(crate) fn detect(dir: &Path, custom_build: Option<&str>, chosen_output: Option<&str>) -> Result<Detected> {
715 detect_as(dir, custom_build, chosen_output, BuildAs::Auto, None)
716}
717
718/// What the project is, by its **Build as** setting (`build_as`) and its
719/// Dockerfile's path (`dockerfile`, when it chose one):
720///
721/// - **Docker**: a container, from its Dockerfile or one g1t writes.
722/// - **Static site**: built and served as files, whatever else it has.
723/// - **Workers**: its Wrangler config or a framework adapter's Worker.
724/// - **Auto**: a Wrangler config is a Workers project; a framework that
725/// builds a static site or a Worker is that, which costs nothing while
726/// no one visits; a framework set up to need a server is a container
727/// when it has a Dockerfile, or when g1t can write one; a project with
728/// no framework g1t knows is a container when it has a Dockerfile or is
729/// a server g1t recognises (a Node.js, Python, Go, Ruby or PHP app),
730/// else a static site, else nothing, saying to add a Dockerfile.
731pub(crate) fn detect_as(
732 dir: &Path,
733 custom_build: Option<&str>,
734 chosen_output: Option<&str>,
735 build_as: BuildAs,
736 dockerfile: Option<&str>,
737) -> Result<Detected> {
738 let own = container::own_dockerfile(dir, dockerfile)?;
739 match build_as {
740 BuildAs::Docker => {
741 let framework = frameworks::detect(dir, read_wrangler(dir)?.is_some());
742 Ok(as_container(dir, framework.clone(), own).unwrap_or_else(|| {
743 Detected::nothing(
744 framework,
745 None,
746 "**Build as** is Docker, but this project has no Dockerfile and g1t doesn't recognise a server it can write \
747 one for. Add a `Dockerfile` (or set its path under Settings, Deployments)."
748 .to_owned(),
749 )
750 }))
751 }
752 BuildAs::Static => detect_site(dir, custom_build, chosen_output, true),
753 BuildAs::Workers => {
754 let site = detect_site(dir, custom_build, chosen_output, false)?;
755 if site.kind == "workers" {
756 return Ok(site);
757 }
758 Ok(Detected::nothing(
759 site.framework,
760 site.install,
761 "**Build as** is Workers, but this project has no Wrangler config (`wrangler.jsonc`, `wrangler.json` or \
762 `wrangler.toml`) and no framework adapter that writes a Worker."
763 .to_owned(),
764 ))
765 }
766 BuildAs::Auto => {
767 let site = detect_site(dir, custom_build, chosen_output, false)?;
768 if site.kind == "workers" || (site.framework.is_some() && site.problem.is_none()) {
769 return Ok(site);
770 }
771 if let Some(problem) = site.problem.clone() {
772 // A framework set up to need a server.
773 let found = as_container(dir, site.framework.clone(), own);
774 return Ok(found.unwrap_or_else(|| {
775 Detected::nothing(site.framework, site.install, format!("{problem} Or add a `Dockerfile` to run it as a container."))
776 }));
777 }
778 let has_own = own.is_some();
779 if let Some(mut found) = as_container(dir, None, own) {
780 // A Dockerfile beside a site that could be served as it is.
781 if has_own && (site.kind == "static" || site.kind == "html") {
782 found.fallback = Some(Box::new(site));
783 }
784 return Ok(found);
785 }
786 if site.kind == "none" {
787 return Ok(Detected::nothing(site.framework, site.install, NOTHING_TO_SERVE.to_owned()));
788 }
789 Ok(site)
790 }
791 }
792}
793
794/// What the project is as a static site or Workers project: `as_static`
795/// ignores its Wrangler config and any framework adapter, and builds it
796/// even when its framework is set up to need a server.
797fn detect_site(dir: &Path, custom_build: Option<&str>, chosen_output: Option<&str>, as_static: bool) -> Result<Detected> {
798 let custom_build = custom_build.map(str::trim).filter(|c| !c.is_empty());
799 let chosen_output = chosen_output.map(|d| d.trim().trim_matches('/')).filter(|d| !d.is_empty());
800 let config = if as_static { None } else { read_wrangler(dir)? };
801 let framework = frameworks::detect(dir, config.is_some());
802 let installs: Vec<&str> = [install_command(dir), framework.as_ref().and_then(|f| f.install)].into_iter().flatten().collect();
803 let install = (!installs.is_empty()).then(|| installs.join(" && "));
804 let framework_build = framework.as_ref().and_then(|f| f.build.clone());
805 if let Some(config) = config {
806 // A framework built for Workers builds before wrangler bundles what
807 // it wrote; any other project's config builds it, as it always has.
808 let pre_build = custom_build
809 .map(str::to_owned)
810 .or_else(|| framework.as_ref().filter(|f| f.workers).and(framework_build));
811 let mut steps: Vec<String> = pre_build.clone().into_iter().collect();
812 if config.main.is_some() {
813 steps.push(wrangler_build(None, None));
814 }
815 return Ok(Detected {
816 kind: "workers",
817 framework,
818 install,
819 build: (!steps.is_empty()).then(|| steps.join(" && ")),
820 output_dir: config.assets.and_then(|assets| assets.directory),
821 problem: None,
822 pre_build,
823 container: None,
824 fallback: None,
825 });
826 }
827 let build = custom_build
828 .map(str::to_owned)
829 .or(framework_build)
830 .or_else(|| has_build_script(dir).then(|| "npm run build".to_owned()));
831 // An adapter's Worker, unless the project chose a folder to serve.
832 if !as_static && chosen_output.is_none() && framework.as_ref().is_some_and(|f| f.adapter.is_some()) {
833 // Where its files are is known once it has built: the adapter's
834 // own folder, or where the config it writes says.
835 return Ok(Detected {
836 kind: "workers",
837 output_dir: None,
838 framework,
839 install,
840 pre_build: build.clone(),
841 build,
842 problem: None,
843 container: None,
844 fallback: None,
845 });
846 }
847 // A command or a folder of the project's own says it knows better, as
848 // does **Build as** set to Static site.
849 let problem = framework
850 .as_ref()
851 .and_then(|f| f.problem.clone())
852 .filter(|_| !as_static && custom_build.is_none() && chosen_output.is_none());
853 if let Some(problem) = problem {
854 return Ok(Detected::nothing(framework, install, problem));
855 }
856 let output_dir = chosen_output
857 .map(str::to_owned)
858 .or_else(|| framework.as_ref().and_then(|f| f.output.clone()))
859 .or_else(|| find_output(dir));
860 // `.` is the project itself: its own files, served as they are.
861 let kind = match (&build, output_dir.as_deref()) {
862 (None, Some(".")) => "html",
863 (None, None) => "none",
864 _ => "static",
865 };
866 Ok(Detected { kind, framework, install, pre_build: build.clone(), build, output_dir, problem: None, container: None, fallback: None })
867}
868
869/// The compatibility date a Worker gets when its config names none.
870const COMPATIBILITY_DATE: &str = "2026-09-26";
871
872/// A Workers project bundled by wrangler: `config` with its paths relative
873/// to `base`, read by wrangler from `config_file` when given (else the
874/// project's own, or the one its build wrote).
875fn build_worker(
876 log: &mut Log,
877 secrets: &[String],
878 config: WranglerConfig,
879 base: &Path,
880 config_file: Option<&Path>,
881) -> Result<(Value, Option<PathBuf>, Vec<String>)> {
882 let bundle = bundle_dir();
883 let warnings = config_warnings(&config);
884 let mut worker = json!({
885 "compatibilityDate": config.compatibility_date.clone().unwrap_or_else(|| COMPATIBILITY_DATE.to_owned()),
886 "compatibilityFlags": config.compatibility_flags,
887 "vars": config.vars,
888 });
889 if let Some(main) = &config.main {
890 // `--dry-run` runs the config's own build and bundles it, without
891 // deploying anywhere.
892 let _ = std::fs::remove_dir_all(&bundle);
893 step(log, &wrangler_build(Some(&bundle), config_file), secrets)?;
894 let (main_module, modules) = bundle_modules(main, &bundle)?;
895 worker["mainModule"] = main_module.into();
896 worker["modules"] = serde_json::to_value(modules)?;
897 }
898 let assets = config.assets.unwrap_or_default();
899 let assets_dir = assets.directory.as_ref().map(|directory| base.join(directory));
900 worker["assetsBinding"] = assets.binding.into();
901 worker["htmlHandling"] = assets.html_handling.into();
902 worker["notFoundHandling"] = assets.not_found_handling.into();
903 Ok((worker, assets_dir, warnings))
904}
905
906/// Where the config for an adapter's Worker is written: beside the
907/// bundle, never in the checkout.
908fn adapter_config_path() -> PathBuf {
909 let bundle = bundle_dir();
910 bundle.with_file_name(format!("{}.wrangler.json", bundle.file_name().unwrap_or_default().to_string_lossy()))
911}
912
913/// What a container build says when g1t.page runs no containers.
914const CONTAINERS_OFF: &str = "This project deploys as a container, and Docker deployments are not switched on for g1t.page yet. \
915 Set **Build as** to Static site or Workers under Settings, Deployments if it can be built as one.";
916
917/// Where a container's registry login is kept for the build: its own
918/// folder, never the job's `~/.docker`.
919fn docker_config_dir() -> PathBuf {
920 bundle_dir().with_file_name(format!("{}.docker", bundle_dir().file_name().unwrap_or_default().to_string_lossy()))
921}
922
923/// Where the Dockerfile g1t writes for a project without one goes: beside
924/// the bundle, never in the checkout.
925fn generated_dockerfile_path() -> PathBuf {
926 bundle_dir().with_file_name(format!("{}.Dockerfile", bundle_dir().file_name().unwrap_or_default().to_string_lossy()))
927}
928
929/// What the deployments service answers the `registry` step with: where
930/// to push the app's image, with a login good for pushing only and only
931/// for minutes, and the largest image the app's instance can run.
932#[derive(Debug, Deserialize)]
933struct RegistryGrant {
934 registry: String,
935 repository: String,
936 tag: String,
937 username: String,
938 password: String,
939 #[serde(alias = "maxImageBytes")]
940 max_image_bytes: u64,
941 #[serde(default, alias = "instanceType")]
942 instance_type: Option<String>,
943}
944
945/// `name@sha256:…` for `repository` among an image's repository digests,
946/// as `docker image inspect` lists them, one a line.
947fn pushed_digest(repo_digests: &str, registry: &str, repository: &str) -> Option<String> {
948 let prefix = format!("{registry}/{repository}@sha256:");
949 repo_digests
950 .lines()
951 .map(str::trim)
952 .find(|line| line.starts_with(&prefix) && line.len() == prefix.len() + 64)
953 .map(str::to_owned)
954}
955
956/// Bytes, as a person reads them: `1.4 GB`.
957fn size_text(bytes: u64) -> String {
958 format!("{:.1} GB", bytes as f64 / 1_000_000_000.0)
959}
960
961/// Runs `docker` with `args`, signed in through `config`; its output, or
962/// why it failed, redacted.
963fn docker(args: &[&str], config: &Path, input: Option<&str>, secrets: &[String]) -> Result<String> {
964 use std::io::Write;
965 use std::process::{Command, Stdio};
966 let mut command = Command::new("docker");
967 command.args(args).env("DOCKER_CONFIG", config).stdout(Stdio::piped()).stderr(Stdio::piped());
968 command.stdin(if input.is_some() { Stdio::piped() } else { Stdio::null() });
969 let mut child = command.spawn().context("could not run docker")?;
970 if let (Some(input), Some(mut stdin)) = (input, child.stdin.take()) {
971 stdin.write_all(input.as_bytes())?;
972 }
973 let output = child.wait_with_output()?;
974 let text = redact(&format!("{}{}", String::from_utf8_lossy(&output.stdout), String::from_utf8_lossy(&output.stderr)), secrets);
975 if !output.status.success() {
976 bail!("`docker {}` failed: {}", args.first().copied().unwrap_or_default(), text.trim());
977 }
978 Ok(text)
979}
980
981/// Builds the project's container image with Docker and pushes it to
982/// Cloudflare's registry, at the place and with the short-lived push-only
983/// login the deployments service gives for this build (`registry`). The
984/// sandbox never holds g1t's own Cloudflare token. None when g1t.page runs
985/// no containers (the service answers `not_enabled`).
986fn container_build(reporter: &Reporter, log: &mut Log, secrets: &[String], dir: &Path, plan: &Detected) -> Result<Option<Value>> {
987 let build = plan.container.as_ref().context("not a container")?;
988 // Asked first: a build that could not be pushed is not run.
989 let answer = reporter.send("registry", json!({}))?;
990 if answer["ok"] == false {
991 if answer["error"]["code"] == "not_enabled" {
992 return Ok(None);
993 }
994 bail!("{}", answer["error"]["message"].as_str().unwrap_or("g1t refused the image's upload"));
995 }
996 let grant: RegistryGrant =
997 serde_json::from_value(answer["value"].clone()).context("g1t's answer to the image's upload was not understood")?;
998 let mut secrets = secrets.to_vec();
999 secrets.push(grant.password.clone());
1000 let dockerfile = match (&build.dockerfile, &build.generated) {
1001 (Some(own), _) => {
1002 log.line(&format!("Building a container from {own}, listening on port {}.", build.port));
1003 dir.join(own)
1004 }
1005 (None, Some(server)) => {
1006 // Shown whole, so it can be committed and changed.
1007 log.line(&format!("This {} project has no Dockerfile, so g1t wrote this one (commit it as `Dockerfile` to change it):", server.name));
1008 for line in server.dockerfile.lines() {
1009 log.line(&format!(" {line}"));
1010 }
1011 let path = generated_dockerfile_path();
1012 std::fs::write(&path, &server.dockerfile)?;
1013 // BuildKit reads `<Dockerfile>.dockerignore` beside it.
1014 std::fs::write(path.with_file_name(format!("{}.dockerignore", path.file_name().unwrap_or_default().to_string_lossy())), container::DOCKERIGNORE)?;
1015 path
1016 }
1017 (None, None) => bail!("nothing to build the container from"),
1018 };
1019 if std::env::var("BUILD_COMMAND").is_ok_and(|c| !c.trim().is_empty()) {
1020 log.line("Build command is not used for a container: its Dockerfile builds it.");
1021 }
1022 // A sandbox's own Docker Engine, started for the build; in a workflow
1023 // step, the job's.
1024 if clones() {
1025 crate::docker::engine::enable(crate::docker::engine::Options::default())
1026 .map_err(|problem| anyhow::anyhow!("Docker is not available in this sandbox: {problem}"))?;
1027 let started = crate::docker::engine::ensure_started();
1028 for note in crate::docker::take_notes() {
1029 log.line(&note);
1030 }
1031 started.map_err(|problem| anyhow::anyhow!("Docker could not start: {problem}"))?;
1032 }
1033 let config = docker_config_dir();
1034 std::fs::create_dir_all(&config)?;
1035 let image = format!("{}/{}:{}", grant.registry, grant.repository, grant.tag);
1036 let quote = |path: &Path| format!("'{}'", path.display().to_string().replace('\'', r"'\''"));
1037 let built = step(
1038 log,
1039 &format!("docker build --platform linux/amd64 --pull -f {} -t {image} .", quote(&dockerfile)),
1040 &secrets,
1041 );
1042 let pushed = built.and_then(|()| {
1043 let size: u64 = docker(&["image", "inspect", "--format", "{{.Size}}", &image], &config, None, &secrets)?.trim().parse().unwrap_or(0);
1044 log.line(&format!("The image is {}.", size_text(size)));
1045 if size > grant.max_image_bytes {
1046 bail!(
1047 "The image is {}, more than the {} an app of its size ({}) can hold. Make it smaller (a slim base image, a multi-stage build), or choose a larger instance under Settings, Deployments.",
1048 size_text(size),
1049 size_text(grant.max_image_bytes),
1050 grant.instance_type.as_deref().unwrap_or("its instance type"),
1051 );
1052 }
1053 docker(&["login", &grant.registry, "--username", &grant.username, "--password-stdin"], &config, Some(&grant.password), &secrets)?;
1054 log.line(&format!("$ docker push {image}"));
1055 let output = docker(&["push", &image], &config, None, &secrets)?;
1056 log.line(output.trim_end());
1057 let digests = docker(&["image", "inspect", "--format", "{{join .RepoDigests \"\\n\"}}", &image], &config, None, &secrets)?;
1058 let reference = pushed_digest(&digests, &grant.registry, &grant.repository).context("the pushed image's digest was not found")?;
1059 Ok(json!({
1060 "image": reference,
1061 "port": build.port,
1062 "sizeBytes": size,
1063 "dockerfile": build.dockerfile,
1064 "generated": build.generated.as_ref().map(|server| server.id),
1065 }))
1066 });
1067 let _ = std::fs::remove_dir_all(&config);
1068 let _ = std::fs::remove_file(generated_dockerfile_path());
1069 pushed.map(Some)
1070}
1071
1072fn build(reporter: &Reporter, log: &mut Log, secrets: &[String]) -> Result<Built> {
1073 let project = project_dir();
1074 let dir = project.as_path();
1075 let custom_build = std::env::var("BUILD_COMMAND").ok();
1076 let chosen = std::env::var("OUTPUT_DIR").ok().filter(|d| !d.trim().is_empty());
1077 let build_as = BuildAs::parse(&std::env::var("BUILD_AS").unwrap_or_default());
1078 let dockerfile = std::env::var("DOCKERFILE").ok();
1079 let mut plan = detect_as(dir, custom_build.as_deref(), chosen.as_deref(), build_as, dockerfile.as_deref())?;
1080 if let Some(framework) = &plan.framework {
1081 log.line(&format!("Detected {}: framework={}.", framework.name, framework.id));
1082 }
1083 // Said before anything is installed: it would fail after, less clearly.
1084 if let Some(problem) = &plan.problem {
1085 bail!("{problem}");
1086 }
1087 if plan.container.is_some() {
1088 match container_build(reporter, log, secrets, dir, &plan)? {
1089 Some(image) => {
1090 return Ok(Built {
1091 worker: json!({}),
1092 assets_dir: None,
1093 warnings: Vec::new(),
1094 detected: "container",
1095 framework: plan.framework_id(),
1096 container: Some(image),
1097 });
1098 }
1099 // g1t.page runs no containers yet: the site it is without its
1100 // Dockerfile, as it was built before.
1101 None => match plan.fallback.take() {
1102 Some(site) => {
1103 log.line(&format!("Building it as a {} site instead, as it is without its Dockerfile.", if site.kind == "html" { "plain HTML" } else { "static" }));
1104 plan = *site;
1105 }
1106 None => bail!("{CONTAINERS_OFF}"),
1107 },
1108 }
1109 }
1110 let framework_id = plan.framework.as_ref().map(|f| f.id);
1111 if let Some(install) = &plan.install {
1112 step(log, install, secrets)?;
1113 }
1114 if let Some(command) = &plan.pre_build {
1115 step(log, command, secrets)?;
1116 }
1117 // A static site (by **Build as**, or found to be one) never reads a
1118 // Workers config.
1119 let workers = plan.kind == "workers";
1120 let own_config = if workers { read_wrangler(dir)? } else { None };
1121 // A framework built for Workers may write the config wrangler reads
1122 // (`@cloudflare/vite-plugin` does, and Astro's adapter with it), with
1123 // or without one of the project's own.
1124 let written = if own_config.is_some() || (workers && plan.framework.as_ref().is_some_and(|f| f.workers)) {
1125 redirected_config(dir)?
1126 } else {
1127 None
1128 };
1129 if let Some((config, base)) = written {
1130 log.line(&format!("Using the Workers config the build wrote, in {}.", base.display()));
1131 let (worker, assets_dir, warnings) = build_worker(log, secrets, config, &base, None)?;
1132 return Ok(Built { worker, assets_dir, warnings, detected: "workers", framework: framework_id, container: None });
1133 }
1134 if let Some(config) = own_config {
1135 let (worker, assets_dir, warnings) = build_worker(log, secrets, config, dir, None)?;
1136 return Ok(Built { worker, assets_dir, warnings, detected: "workers", framework: framework_id, container: None });
1137 }
1138 let adapter = plan.framework.as_ref().and_then(|f| f.adapter.as_ref()).filter(|_| workers && chosen.is_none());
1139 if let Some(adapter) = adapter
1140 && let Some(entry) = adapter_entry(dir, adapter)
1141 {
1142 // The adapter's Worker, bundled as a Workers project's is. Its
1143 // static files are uploaded by g1t, so wrangler is given none.
1144 let file = adapter_config_path();
1145 let flags = vec!["nodejs_compat".to_owned()];
1146 std::fs::write(
1147 &file,
1148 serde_json::to_string_pretty(&json!({
1149 "name": "g1t-app",
1150 "main": entry,
1151 "compatibility_date": COMPATIBILITY_DATE,
1152 "compatibility_flags": flags,
1153 }))?,
1154 )?;
1155 log.line(&format!("Bundling the Worker the adapter wrote, {}.", adapter.entry));
1156 let config = WranglerConfig {
1157 main: Some(entry.to_string_lossy().into_owned()),
1158 compatibility_flags: flags,
1159 assets: Some(AssetsConfig {
1160 directory: Some(adapter.assets.to_owned()),
1161 binding: Some("ASSETS".to_owned()),
1162 ..AssetsConfig::default()
1163 }),
1164 ..WranglerConfig::default()
1165 };
1166 let built = build_worker(log, secrets, config, dir, Some(&file));
1167 let _ = std::fs::remove_file(&file);
1168 let (worker, assets_dir, warnings) = built?;
1169 return Ok(Built { worker, assets_dir, warnings, detected: "workers", framework: framework_id, container: None });
1170 }
1171 if let (Some(adapter), Some(framework)) = (adapter, &plan.framework)
1172 && framework.output.is_none()
1173 {
1174 bail!("{}'s build did not write its Worker, `{}`", framework.name, adapter.entry);
1175 }
1176 let assets_dir = match &chosen {
1177 Some(chosen) => {
1178 let path = dir.join(chosen.trim().trim_matches('/'));
1179 if !path.is_dir() {
1180 bail!("the output directory `{chosen}` does not exist after the build");
1181 }
1182 path
1183 }
1184 None => {
1185 let expected = plan.framework.as_ref().and_then(|f| f.output.as_deref());
1186 match expected.filter(|output| dir.join(output).is_dir()) {
1187 Some(output) => dir.join(output),
1188 None => {
1189 let found = find_output(dir).with_context(|| match (&plan.framework, expected) {
1190 (Some(framework), Some(expected)) => format!(
1191 "found nothing to serve: {} writes its site to `{expected}`, which the build did not write. \
1192 Set **Output directory** if it writes somewhere else.",
1193 framework.name
1194 ),
1195 (Some(framework), None) if framework.problem.is_some() => {
1196 format!("found nothing to serve. {}", framework.problem.as_deref().unwrap_or_default())
1197 }
1198 _ => "found nothing to serve: no Workers config, no index.html, and none of dist, build, out, public, _site or .output/public".to_owned(),
1199 })?;
1200 if let Some(expected) = expected {
1201 log.line(&format!("`{expected}` was not written; serving `{found}`."));
1202 }
1203 if found == "." { dir.to_path_buf() } else { dir.join(found) }
1204 }
1205 }
1206 }
1207 };
1208 let spa = !assets_dir.join("404.html").exists();
1209 Ok(Built {
1210 worker: json!({
1211 "compatibilityDate": COMPATIBILITY_DATE,
1212 "compatibilityFlags": [],
1213 "vars": {},
1214 "notFoundHandling": if spa { "single-page-application" } else { "404-page" },
1215 }),
1216 detected: static_kind(dir, &assets_dir, plan.build.is_some()),
1217 assets_dir: Some(assets_dir),
1218 warnings: Vec::new(),
1219 framework: framework_id,
1220 container: None,
1221 })
1222}
1223
1224/// Whether the build checks out its own commit (a sandbox, given
1225/// `GIT_REMOTE`) rather than building the checkout it runs in.
1226fn clones() -> bool {
1227 std::env::var("GIT_REMOTE").is_ok_and(|remote| !remote.trim().is_empty())
1228}
1229
1230/// The checkout the build runs in: the sandbox's clone, or, from a
1231/// workflow step, the current directory.
1232fn checkout_dir() -> PathBuf {
1233 if clones() {
1234 PathBuf::from(WORKDIR)
1235 } else {
1236 std::env::current_dir().unwrap_or_else(|_| PathBuf::from("."))
1237 }
1238}
1239
1240/// Where `wrangler deploy --dry-run` writes the bundle: in a workflow
1241/// step, a directory of the job's temporary space, never the checkout.
1242fn bundle_dir() -> PathBuf {
1243 if clones() {
1244 return PathBuf::from(BUNDLE_DIR);
1245 }
1246 let base = std::env::var_os("RUNNER_TEMP").map(PathBuf::from).unwrap_or_else(std::env::temp_dir);
1247 base.join(format!("g1t-bundle-{}", std::process::id()))
1248}
1249
1250/// Where the project lives in the checkout `base`: its root directory,
1251/// never above the checkout.
1252fn project_dir_in(base: &Path, root: &str) -> PathBuf {
1253 let root = root.trim().trim_matches('/');
1254 if root.is_empty() || root == "." || root.split('/').any(|part| part == "..") {
1255 base.to_path_buf()
1256 } else {
1257 base.join(root)
1258 }
1259}
1260
1261/// Where the project lives: `ROOT_DIR` in the checkout.
1262fn project_dir() -> PathBuf {
1263 project_dir_in(&checkout_dir(), &std::env::var("ROOT_DIR").unwrap_or_default())
1264}
1265
1266fn check_out(secrets: &[String]) -> Result<()> {
1267 let remote = env("GIT_REMOTE")?;
1268 let commit = env("GIT_COMMIT")?;
1269 let auth = auth_option(&env("G1T_USER")?, &env("G1T_TOKEN")?);
1270 std::fs::create_dir_all("/work")?;
1271 let workdir = Path::new(WORKDIR);
1272 // The clone is shallow and of the default branch; a preview's commit is
1273 // often on another one, so it is fetched before checking out.
1274 let cloned = crate::clone::clone(Path::new("/work"), &auth, &[], &remote, WORKDIR)
1275 .and_then(|_| git(workdir, &["rev-parse", "--abbrev-ref", "HEAD"]))
1276 .and_then(|branch| crate::clone::ensure(workdir, &auth, "origin", &branch, &commit))
1277 .and_then(|_| git(workdir, &["-c", "advice.detachedHead=false", "checkout", "--quiet", &commit]));
1278 if let Err(error) = cloned {
1279 bail!("{}", redact(&format!("{error:#}"), secrets));
1280 }
1281 Ok(())
1282}
1283
1284fn deploy(reporter: &Reporter, log: &mut Log, secrets: &[String]) -> Result<Value> {
1285 if clones() {
1286 check_out(secrets).context("the commit could not be checked out")?;
1287 } else {
1288 let dir = project_dir();
1289 if !dir.is_dir() {
1290 bail!("the project's directory {} does not exist in this checkout", dir.display());
1291 }
1292 log.line(&format!("Building {} as it is checked out.", dir.display()));
1293 }
1294 // The repository's variables and secrets for deploy builds.
1295 for source in ["BUILD_ENV", "BUILD_SECRETS"] {
1296 if let Ok(vars) = std::env::var(source)
1297 && let Ok(Value::Object(vars)) = serde_json::from_str::<Value>(&vars)
1298 {
1299 for (name, value) in vars {
1300 if let Some(value) = value.as_str() {
1301 // SAFETY: single-threaded; set before any command runs.
1302 unsafe { std::env::set_var(name, value) };
1303 }
1304 }
1305 }
1306 }
1307 let built = build(reporter, log, secrets)?;
1308 let mut finish = json!({
1309 "worker": built.worker,
1310 "warnings": built.warnings,
1311 "detected": built.detected,
1312 // What it is built with, shown beside `detected` on its settings.
1313 "framework": built.framework,
1314 });
1315 if let Some(image) = built.container {
1316 finish["container"] = image;
1317 }
1318 for warning in &built.warnings {
1319 log.line(&format!("Warning: {warning}"));
1320 }
1321 if let Some(dir) = &built.assets_dir {
1322 let skip_project = *dir == project_dir();
1323 let assets = collect_site(dir, skip_project)?;
1324 if assets.is_empty() {
1325 bail!("the site to serve is empty");
1326 }
1327 log.line(&format!("Uploading {} files.", assets.len()));
1328 for special in ["_headers", "_redirects"] {
1329 if let Ok(text) = std::fs::read_to_string(dir.join(special)) {
1330 finish["worker"][special] = text.into();
1331 }
1332 }
1333 let manifest: BTreeMap<&str, Value> = assets
1334 .iter()
1335 .map(|asset| (asset.path.as_str(), json!({ "hash": asset.hash, "size": asset.size })))
1336 .collect();
1337 let answer = reporter.send("session", json!({ "manifest": manifest }))?;
1338 if answer["ok"] == false {
1339 bail!("{}", answer["error"]["message"].as_str().unwrap_or("g1t refused the upload"));
1340 }
1341 let session: UploadSession =
1342 serde_json::from_value(answer["value"].clone()).context("g1t's answer to the upload was not understood")?;
1343 let by_hash: BTreeMap<&str, &Asset> = assets.iter().map(|asset| (asset.hash.as_str(), asset)).collect();
1344 let mut completion = session.jwt.clone();
1345 for bucket in &session.buckets {
1346 if let Some(jwt) = upload_bucket(&session, bucket, &by_hash)? {
1347 completion = jwt;
1348 }
1349 }
1350 finish["completionJwt"] = completion.into();
1351 }
1352 Ok(finish)
1353}
1354
1355/// A sandbox's build (`MODE=deploy`).
1356pub fn main() -> i32 {
1357 run(false)
1358}
1359
1360/// `g1t-runner deploy`, from a workflow step: the build in the job's own
1361/// checkout, its log in the step's as well. Exits 1 when the build fails,
1362/// after reporting it, so the step fails too.
1363pub fn cli(args: &[String]) -> i32 {
1364 if args.iter().any(|arg| arg == "--help" || arg == "-h") {
1365 println!("{CLI_HELP}");
1366 return 0;
1367 }
1368 run(true)
1369}
1370
1371const CLI_HELP: &str = "g1t-runner deploy: builds the project in this checkout and puts it on g1t.page.
1372
1373Reads DEPLOY_ID and DEPLOY_TOKEN (from POST /repos/{owner}/{repo}/deployments/builds),
1374G1T_API (https://api.g1t.sh), and optionally ROOT_DIR, BUILD_COMMAND, OUTPUT_DIR,
1375BUILD_AS (auto, static, workers or docker), DOCKERFILE, and BUILD_ENV and
1376BUILD_SECRETS (JSON objects). The g1t/deploy action sets them all. A container
1377is built with the docker on PATH.
1378
1379g1t-runner detect prints what the build would find, as key=value lines.";
1380
1381fn run(step_log: bool) -> i32 {
1382 let reporter = match (env("G1T_API"), env("DEPLOY_ID"), env("DEPLOY_TOKEN")) {
1383 (Ok(api), Ok(id), Ok(token)) => Reporter {
1384 base: format!("{}/deployments/jobs/{id}", api.trim_end_matches('/')),
1385 token,
1386 },
1387 _ => {
1388 eprintln!("g1t-runner: G1T_API, DEPLOY_ID and DEPLOY_TOKEN must be set");
1389 return 2;
1390 }
1391 };
1392 let mut secrets: Vec<String> = ["G1T_TOKEN", "DEPLOY_TOKEN"]
1393 .iter()
1394 .filter_map(|name| std::env::var(name).ok())
1395 .filter(|secret| !secret.is_empty())
1396 .collect();
1397 // The repository's build secrets never appear in the log.
1398 if let Ok(Value::Object(build)) = serde_json::from_str::<Value>(&std::env::var("BUILD_SECRETS").unwrap_or_default()) {
1399 secrets.extend(build.values().filter_map(Value::as_str).filter(|v| v.len() >= 4).map(str::to_owned));
1400 }
1401 if let Err(error) = reporter.send("started", json!({})) {
1402 eprintln!("g1t-runner: {error:#}");
1403 return 1;
1404 }
1405 let started = Instant::now();
1406 let mut log = Log { echo: step_log.then(|| secrets.clone()), ..Log::default() };
1407 let outcome = deploy(&reporter, &mut log, &secrets);
1408 let seconds = started.elapsed().as_secs();
1409 if step_log {
1410 let _ = std::fs::remove_dir_all(bundle_dir());
1411 let _ = std::fs::remove_file(adapter_config_path());
1412 let _ = std::fs::remove_dir_all(docker_config_dir());
1413 }
1414 let (sent, failed) = match outcome {
1415 Ok(mut finish) => {
1416 finish["log"] = redact(&log.tail(), &secrets).into();
1417 finish["buildSeconds"] = seconds.into();
1418 (reporter.send("finish", finish), false)
1419 }
1420 Err(error) => {
1421 let message = redact(&format!("{error:#}"), &secrets);
1422 log.line(&format!("The build failed: {message}"));
1423 let sent = reporter.send(
1424 "fail",
1425 json!({ "message": message, "log": redact(&log.tail(), &secrets), "buildSeconds": seconds }),
1426 );
1427 (sent, true)
1428 }
1429 };
1430 match sent {
1431 // A sandbox's build has said how it ended; a step fails with its build.
1432 Ok(answer) if step_log && (failed || answer["ok"] == false || answer["value"] == false) => {
1433 if !failed {
1434 eprintln!("g1t-runner: g1t did not take the build; its deployment says why");
1435 }
1436 1
1437 }
1438 Ok(_) => 0,
1439 Err(error) => {
1440 eprintln!("g1t-runner: {error:#}");
1441 1
1442 }
1443 }
1444}
1445
1446/// `g1t-runner detect`: what a build of the project would find, as
1447/// `key=value` lines for `$GITHUB_OUTPUT`: `kind`, `install`, `build`,
1448/// `output-dir`, and `framework` when one is found. Reads `ROOT_DIR`,
1449/// `BUILD_COMMAND` and `OUTPUT_DIR` as the build does; `--root-dir DIR` is
1450/// the same as `ROOT_DIR`. A framework set up to need a server is `none`,
1451/// with what to change on standard error.
1452pub fn detect_cli(args: &[String]) -> i32 {
1453 let mut root = std::env::var("ROOT_DIR").unwrap_or_default();
1454 let mut rest = args.iter();
1455 while let Some(arg) = rest.next() {
1456 match arg.as_str() {
1457 "--root-dir" => root = rest.next().cloned().unwrap_or_default(),
1458 "--help" | "-h" => {
1459 println!(
1460 "g1t-runner detect [--root-dir DIR]: prints kind, install, build, output-dir and framework (when one is found), and for a container dockerfile and port, as key=value lines. Reads ROOT_DIR, BUILD_COMMAND, OUTPUT_DIR, BUILD_AS (auto, static, workers or docker) and DOCKERFILE as a build does."
1461 );
1462 return 0;
1463 }
1464 other => {
1465 eprintln!("g1t-runner detect: unknown argument {other}");
1466 return 2;
1467 }
1468 }
1469 }
1470 let dir = project_dir_in(&checkout_dir(), &root);
1471 let custom = std::env::var("BUILD_COMMAND").ok();
1472 let output = std::env::var("OUTPUT_DIR").ok();
1473 let build_as = BuildAs::parse(&std::env::var("BUILD_AS").unwrap_or_default());
1474 let dockerfile = std::env::var("DOCKERFILE").ok();
1475 match detect_as(&dir, custom.as_deref(), output.as_deref(), build_as, dockerfile.as_deref()) {
1476 Ok(found) => {
1477 print!("{}", output_lines(&found));
1478 if let Some(problem) = &found.problem {
1479 eprintln!("g1t-runner detect: {problem}");
1480 }
1481 0
1482 }
1483 Err(error) => {
1484 eprintln!("g1t-runner detect: {error:#}");
1485 1
1486 }
1487 }
1488}
1489
1490/// `Detected` as `$GITHUB_OUTPUT` lines; a value on one line, empty when
1491/// there is none. `framework` is left out when none was found, which a
1492/// step's outputs read as empty all the same.
1493fn output_lines(found: &Detected) -> String {
1494 let one_line = |value: Option<&str>| value.unwrap_or_default().replace(['\r', '\n'], " ");
1495 let mut lines = format!(
1496 "kind={}\ninstall={}\nbuild={}\noutput-dir={}\n",
1497 found.kind,
1498 one_line(found.install.as_deref()),
1499 one_line(found.build.as_deref()),
1500 one_line(found.output_dir.as_deref()),
1501 );
1502 if let Some(framework) = found.framework_id() {
1503 lines.push_str(&format!("framework={framework}\n"));
1504 }
1505 // A container's Dockerfile (empty when g1t writes one) and its port.
1506 if let Some(container) = &found.container {
1507 lines.push_str(&format!("dockerfile={}\nport={}\n", one_line(container.dockerfile.as_deref()), container.port));
1508 }
1509 lines
1510}
1511
1512#[cfg(test)]
1513mod tests {
1514 use super::*;
1515
1516 #[test]
1517 fn the_upload_session_is_read_in_either_spelling() {
1518 for answer in [
1519 json!({ "jwt": "j", "buckets": [["a"]], "upload_url": "https://u" }),
1520 json!({ "jwt": "j", "uploadUrl": "https://u" }),
1521 ] {
1522 let session: UploadSession = serde_json::from_value(answer).unwrap();
1523 assert_eq!(session.upload_url, "https://u");
1524 }
1525 }
1526
1527 #[test]
1528 fn jsonc_comments_and_trailing_commas_are_dropped() {
1529 let text = r#"{
1530 // a comment
1531 "main": "src/index.ts", /* another */
1532 "vars": { "URL": "https://x.dev//not-a-comment", },
1533 }"#;
1534 let config: WranglerConfig = serde_json::from_str(&strip_jsonc(text)).unwrap();
1535 assert_eq!(config.main.as_deref(), Some("src/index.ts"));
1536 assert_eq!(config.vars["URL"], "https://x.dev//not-a-comment");
1537 }
1538
1539 #[test]
1540 fn unsupported_bindings_are_noticed() {
1541 let config: WranglerConfig =
1542 serde_json::from_str(r#"{ "main": "a.js", "d1_databases": [{ "binding": "DB" }] }"#).unwrap();
1543 assert!(config.rest.contains_key("d1_databases"));
1544 }
1545
1546 #[test]
1547 fn crons_g1t_does_not_run_are_warned_about() {
1548 let config: WranglerConfig =
1549 serde_json::from_str(r#"{ "main": "a.js", "triggers": { "crons": ["*/5 * * * *", "0 3 * * *"] }, "kv_namespaces": [{ "binding": "KV" }] }"#)
1550 .unwrap();
1551 let warnings = config_warnings(&config);
1552 assert_eq!(warnings.len(), 2);
1553 assert!(warnings.iter().any(|w| w.contains("kv_namespaces")));
1554 assert!(warnings.iter().any(|w| w.contains("triggers.crons") && w.contains("2 schedules")));
1555 let none: WranglerConfig = serde_json::from_str(r#"{ "main": "a.js", "triggers": { "crons": [] } }"#).unwrap();
1556 assert!(config_warnings(&none).is_empty());
1557 let toml: WranglerConfig = toml::from_str("main = \"a.js\"
1558[triggers]
1559crons = [\"0 * * * *\"]
1560").unwrap();
1561 assert!(config_warnings(&toml)[0].contains("1 schedule)"));
1562 // A config a build wrote lists every kind of binding, mostly empty.
1563 let written: WranglerConfig = serde_json::from_str(
1564 r#"{ "main": "entry.mjs", "d1_databases": [], "durable_objects": { "bindings": [] }, "triggers": {}, "kv_namespaces": [{ "binding": "SESSION" }] }"#,
1565 )
1566 .unwrap();
1567 assert_eq!(config_warnings(&written).len(), 1);
1568 }
1569
1570 #[test]
1571 fn a_site_is_plain_html_only_when_its_own_files_are_served_unbuilt() {
1572 let project = Path::new("/w/site");
1573 assert_eq!(static_kind(project, project, false), "html");
1574 assert_eq!(static_kind(project, project, true), "static");
1575 assert_eq!(static_kind(project, &project.join("dist"), false), "static");
1576 }
1577
1578 #[test]
1579 fn files_are_typed_by_extension() {
1580 assert_eq!(content_type("/index.HTML"), "text/html");
1581 assert_eq!(content_type("/a/b.woff2"), "font/woff2");
1582 assert_eq!(content_type("/LICENSE"), "application/octet-stream");
1583 }
1584
1585 /// A fresh directory with `files` (path, contents) in it.
1586 fn project(name: &str, files: &[(&str, &str)]) -> PathBuf {
1587 let dir = std::env::temp_dir().join(format!("g1t-detect-{name}-{}", std::process::id()));
1588 let _ = std::fs::remove_dir_all(&dir);
1589 for (path, text) in files {
1590 let path = dir.join(path);
1591 std::fs::create_dir_all(path.parent().unwrap()).unwrap();
1592 std::fs::write(path, text).unwrap();
1593 }
1594 std::fs::create_dir_all(&dir).unwrap();
1595 dir
1596 }
1597
1598 #[test]
1599 fn detect_finds_a_workers_project_and_how_it_builds() {
1600 let dir = project(
1601 "workers",
1602 &[
1603 ("wrangler.jsonc", r#"{ "main": "src/index.ts", "assets": { "directory": "./public" }, }"#),
1604 ("package.json", "{}"),
1605 ("pnpm-lock.yaml", ""),
1606 ],
1607 );
1608 let found = detect(&dir, None, None).unwrap();
1609 assert_eq!(found.kind, "workers");
1610 assert_eq!(found.install.as_deref(), Some("corepack enable && pnpm install --frozen-lockfile"));
1611 assert_eq!(found.framework, None);
1612 assert_eq!(found.build.as_deref(), Some("npx --yes wrangler@4 deploy --dry-run"));
1613 assert_eq!(found.output_dir.as_deref(), Some("./public"));
1614 // The project's own build command runs first.
1615 let custom = detect(&dir, Some("npm run codegen"), None).unwrap();
1616 assert_eq!(custom.build.as_deref(), Some("npm run codegen && npx --yes wrangler@4 deploy --dry-run"));
1617 }
1618
1619 #[test]
1620 fn detect_finds_a_static_build_and_a_plain_site() {
1621 let built = project("static", &[("package.json", r#"{ "scripts": { "build": "vite build" } }"#), ("package-lock.json", "{}")]);
1622 let found = detect(&built, None, None).unwrap();
1623 assert_eq!(found.kind, "static");
1624 assert_eq!(found.install.as_deref(), Some("npm ci"));
1625 assert_eq!(found.build.as_deref(), Some("npm run build"));
1626 assert_eq!(found.output_dir, None, "its output is found once it has built");
1627 assert_eq!(found.framework, None, "a build script alone names no framework");
1628 std::fs::create_dir_all(built.join("dist")).unwrap();
1629 std::fs::write(built.join("dist/index.html"), "<h1>hi</h1>").unwrap();
1630 assert_eq!(detect(&built, None, None).unwrap().output_dir.as_deref(), Some("dist"));
1631 assert_eq!(detect(&built, None, Some("/site/")).unwrap().output_dir.as_deref(), Some("site"));
1632
1633 let html = project("html", &[("index.html", "<h1>hi</h1>")]);
1634 let found = detect(&html, None, None).unwrap();
1635 assert_eq!((found.kind, found.install, found.build, found.output_dir.as_deref()), ("html", None, None, Some(".")));
1636 // A `public` folder alone, without an index.html, is not a site.
1637 let empty = project("empty", &[("public/robots.txt", ""), ("README.md", "")]);
1638 assert_eq!(detect(&empty, None, None).unwrap().kind, "none");
1639 }
1640
1641 #[test]
1642 fn detect_prints_lines_for_github_output() {
1643 let mut found = Detected {
1644 kind: "static",
1645 framework: None,
1646 install: Some("npm ci".into()),
1647 build: Some("a\nb".into()),
1648 output_dir: None,
1649 problem: None,
1650 pre_build: None,
1651 container: None,
1652 fallback: None,
1653 };
1654 assert_eq!(output_lines(&found), "kind=static\ninstall=npm ci\nbuild=a b\noutput-dir=\n");
1655 let vite = project("lines", &[("package.json", r#"{ "devDependencies": { "vite": "7" } }"#)]);
1656 found.framework = frameworks::detect(&vite, false);
1657 assert!(output_lines(&found).ends_with("output-dir=\nframework=vite\n"));
1658 }
1659
1660 /// One project of the table below: its files, the project's own
1661 /// settings, and what detect should say.
1662 struct Case {
1663 name: &'static str,
1664 files: &'static [(&'static str, &'static str)],
1665 custom_build: Option<&'static str>,
1666 chosen_output: Option<&'static str>,
1667 kind: &'static str,
1668 framework: Option<&'static str>,
1669 build: Option<&'static str>,
1670 output_dir: Option<&'static str>,
1671 /// A phrase the problem says, if there is one.
1672 problem: Option<&'static str>,
1673 }
1674
1675 const CASE: Case = Case {
1676 name: "",
1677 files: &[],
1678 custom_build: None,
1679 chosen_output: None,
1680 kind: "static",
1681 framework: None,
1682 build: Some("npm run build"),
1683 output_dir: None,
1684 problem: None,
1685 };
1686
1687 #[test]
1688 fn detect_knows_each_framework() {
1689 let cases = [
1690 Case {
1691 name: "vite",
1692 files: &[("package.json", r#"{ "devDependencies": { "vite": "7" } }"#)],
1693 framework: Some("vite"),
1694 build: Some("npx vite build"),
1695 output_dir: Some("dist"),
1696 ..CASE
1697 },
1698 Case {
1699 name: "vite-react",
1700 files: &[
1701 ("package.json", r#"{ "scripts": { "build": "tsc && vite build" }, "dependencies": { "react": "19" }, "devDependencies": { "vite": "7", "@vitejs/plugin-react": "5" } }"#),
1702 ("vite.config.ts", "export default defineConfig({ plugins: [react()], build: { outDir: 'site' } })"),
1703 ],
1704 framework: Some("vite-react"),
1705 output_dir: Some("site"),
1706 ..CASE
1707 },
1708 Case {
1709 name: "vite-vue",
1710 files: &[("package.json", r#"{ "scripts": { "build": "vite build" }, "devDependencies": { "vite": "7", "@vitejs/plugin-vue": "6" } }"#)],
1711 framework: Some("vite-vue"),
1712 output_dir: Some("dist"),
1713 ..CASE
1714 },
1715 Case {
1716 name: "vite-svelte",
1717 files: &[("package.json", r#"{ "devDependencies": { "vite": "7", "@sveltejs/vite-plugin-svelte": "6" } }"#)],
1718 framework: Some("vite-svelte"),
1719 build: Some("npx vite build"),
1720 output_dir: Some("dist"),
1721 ..CASE
1722 },
1723 Case {
1724 name: "vite-solid",
1725 files: &[("package.json", r#"{ "devDependencies": { "vite": "7", "vite-plugin-solid": "2" } }"#)],
1726 framework: Some("vite-solid"),
1727 build: Some("npx vite build"),
1728 output_dir: Some("dist"),
1729 ..CASE
1730 },
1731 Case {
1732 name: "vite-cloudflare",
1733 files: &[
1734 ("package.json", r#"{ "scripts": { "build": "vite build" }, "devDependencies": { "vite": "7", "@cloudflare/vite-plugin": "1" } }"#),
1735 ("wrangler.jsonc", r#"{ "main": "worker/index.ts" }"#),
1736 ],
1737 kind: "workers",
1738 framework: Some("vite"),
1739 build: Some("npm run build && npx --yes wrangler@4 deploy --dry-run"),
1740 ..CASE
1741 },
1742 Case {
1743 name: "astro",
1744 files: &[("package.json", r#"{ "scripts": { "build": "astro build" }, "dependencies": { "astro": "5" } }"#), ("astro.config.mjs", "export default defineConfig({ site: 'https://x.dev' })")],
1745 framework: Some("astro"),
1746 output_dir: Some("dist"),
1747 ..CASE
1748 },
1749 Case {
1750 name: "astro-server",
1751 files: &[("package.json", r#"{ "dependencies": { "astro": "5", "@astrojs/node": "9" } }"#), ("astro.config.mjs", "export default { output: \"server\" }")],
1752 kind: "container",
1753 framework: Some("astro"),
1754 build: Some(GENERATED),
1755 ..CASE
1756 },
1757 Case {
1758 name: "astro-cloudflare",
1759 files: &[("package.json", r#"{ "scripts": { "build": "astro build" }, "dependencies": { "astro": "5", "@astrojs/cloudflare": "12" } }"#)],
1760 kind: "workers",
1761 framework: Some("astro"),
1762 ..CASE
1763 },
1764 Case {
1765 name: "astro-cloudflare-folder",
1766 files: &[("package.json", r#"{ "scripts": { "build": "astro build" }, "dependencies": { "astro": "5", "@astrojs/cloudflare": "12" } }"#)],
1767 chosen_output: Some("dist"),
1768 framework: Some("astro"),
1769 output_dir: Some("dist"),
1770 ..CASE
1771 },
1772 Case {
1773 name: "next-export",
1774 files: &[("package.json", r#"{ "scripts": { "build": "next build" }, "dependencies": { "next": "16" } }"#), ("next.config.ts", "const config: NextConfig = {\n output: 'export',\n};")],
1775 framework: Some("nextjs"),
1776 output_dir: Some("out"),
1777 ..CASE
1778 },
1779 Case {
1780 name: "next-server",
1781 files: &[("package.json", r#"{ "scripts": { "build": "next build" }, "dependencies": { "next": "16" } }"#), ("next.config.mjs", "export default {}")],
1782 kind: "container",
1783 framework: Some("nextjs"),
1784 build: Some(GENERATED),
1785 ..CASE
1786 },
1787 Case {
1788 name: "next-server-own-folder",
1789 files: &[("package.json", r#"{ "scripts": { "build": "next build" }, "dependencies": { "next": "16" } }"#)],
1790 chosen_output: Some("out"),
1791 framework: Some("nextjs"),
1792 output_dir: Some("out"),
1793 ..CASE
1794 },
1795 Case {
1796 name: "opennext",
1797 files: &[
1798 ("package.json", r#"{ "scripts": { "build": "next build" }, "dependencies": { "next": "16", "@opennextjs/cloudflare": "1" } }"#),
1799 ("wrangler.jsonc", r#"{ "main": ".open-next/worker.js", "assets": { "directory": ".open-next/assets", "binding": "ASSETS" } }"#),
1800 ],
1801 kind: "workers",
1802 framework: Some("nextjs"),
1803 build: Some("npx opennextjs-cloudflare build && npx --yes wrangler@4 deploy --dry-run"),
1804 output_dir: Some(".open-next/assets"),
1805 ..CASE
1806 },
1807 Case {
1808 name: "opennext-no-config",
1809 files: &[("package.json", r#"{ "dependencies": { "next": "16", "@opennextjs/cloudflare": "1" } }"#)],
1810 kind: "none",
1811 framework: Some("nextjs"),
1812 build: None,
1813 problem: Some("`.open-next/worker.js`"),
1814 ..CASE
1815 },
1816 Case {
1817 name: "sveltekit-static",
1818 files: &[
1819 ("package.json", r#"{ "scripts": { "build": "vite build" }, "devDependencies": { "@sveltejs/kit": "2", "@sveltejs/adapter-static": "3", "vite": "7" } }"#),
1820 ("svelte.config.js", "import adapter from '@sveltejs/adapter-static';\nexport default { kit: { adapter: adapter() } };"),
1821 ],
1822 framework: Some("sveltekit"),
1823 output_dir: Some("build"),
1824 ..CASE
1825 },
1826 Case {
1827 name: "sveltekit-3-static",
1828 files: &[
1829 ("package.json", r#"{ "scripts": { "build": "vite build" }, "devDependencies": { "@sveltejs/kit": "3", "@sveltejs/adapter-static": "4", "@sveltejs/adapter-cloudflare": "8" } }"#),
1830 ("vite.config.js", "import adapter from '@sveltejs/adapter-static';\nexport default defineConfig({ plugins: [sveltekit({ adapter: adapter({ pages: 'www' }) })] });"),
1831 ],
1832 framework: Some("sveltekit"),
1833 output_dir: Some("www"),
1834 ..CASE
1835 },
1836 Case {
1837 name: "sveltekit-cloudflare",
1838 files: &[("package.json", r#"{ "scripts": { "build": "vite build" }, "devDependencies": { "@sveltejs/kit": "2", "@sveltejs/adapter-cloudflare": "7" } }"#)],
1839 kind: "workers",
1840 framework: Some("sveltekit"),
1841 ..CASE
1842 },
1843 Case {
1844 name: "sveltekit-auto",
1845 files: &[("package.json", r#"{ "scripts": { "build": "vite build" }, "devDependencies": { "@sveltejs/kit": "2", "@sveltejs/adapter-auto": "6" } }"#)],
1846 kind: "none",
1847 framework: Some("sveltekit"),
1848 build: None,
1849 problem: Some("Or add a `Dockerfile`"),
1850 ..CASE
1851 },
1852 Case {
1853 name: "nuxt",
1854 files: &[("package.json", r#"{ "scripts": { "build": "nuxt build", "generate": "nuxt generate" }, "dependencies": { "nuxt": "4" } }"#)],
1855 framework: Some("nuxt"),
1856 build: Some("npm run generate"),
1857 output_dir: Some(".output/public"),
1858 ..CASE
1859 },
1860 Case {
1861 name: "nuxt-no-generate",
1862 files: &[("package.json", r#"{ "scripts": { "build": "nuxt build" }, "dependencies": { "nuxt": "4" } }"#)],
1863 framework: Some("nuxt"),
1864 build: Some("npx nuxi generate"),
1865 output_dir: Some(".output/public"),
1866 ..CASE
1867 },
1868 Case {
1869 name: "react-router-spa",
1870 files: &[
1871 ("package.json", r#"{ "scripts": { "build": "react-router build" }, "devDependencies": { "@react-router/dev": "7", "vite": "7" } }"#),
1872 ("react-router.config.ts", "export default {\n // Server-side render by default\n ssr: false,\n} satisfies Config;"),
1873 ],
1874 framework: Some("react-router"),
1875 output_dir: Some("build/client"),
1876 ..CASE
1877 },
1878 Case {
1879 name: "react-router-ssr",
1880 files: &[("package.json", r#"{ "devDependencies": { "@react-router/dev": "7" } }"#), ("react-router.config.ts", "export default { ssr: true }")],
1881 kind: "container",
1882 framework: Some("react-router"),
1883 build: Some(GENERATED),
1884 ..CASE
1885 },
1886 Case {
1887 name: "remix-spa",
1888 files: &[
1889 ("package.json", r#"{ "scripts": { "build": "remix vite:build" }, "devDependencies": { "@remix-run/dev": "2", "vite": "5" } }"#),
1890 ("vite.config.ts", "export default defineConfig({ plugins: [remix({ ssr: false })] })"),
1891 ],
1892 framework: Some("remix"),
1893 output_dir: Some("build/client"),
1894 ..CASE
1895 },
1896 Case {
1897 name: "gatsby",
1898 files: &[("package.json", r#"{ "scripts": { "build": "gatsby build" }, "dependencies": { "gatsby": "5" } }"#)],
1899 framework: Some("gatsby"),
1900 output_dir: Some("public"),
1901 ..CASE
1902 },
1903 Case {
1904 name: "docusaurus",
1905 files: &[("package.json", r#"{ "scripts": { "build": "docusaurus build" }, "dependencies": { "@docusaurus/core": "3" } }"#)],
1906 framework: Some("docusaurus"),
1907 output_dir: Some("build"),
1908 ..CASE
1909 },
1910 Case {
1911 name: "eleventy",
1912 files: &[("package.json", r#"{ "devDependencies": { "@11ty/eleventy": "3" } }"#)],
1913 framework: Some("eleventy"),
1914 build: Some("npx @11ty/eleventy"),
1915 output_dir: Some("_site"),
1916 ..CASE
1917 },
1918 Case {
1919 name: "angular",
1920 files: &[
1921 ("package.json", r#"{ "scripts": { "build": "ng build" }, "dependencies": { "@angular/core": "20" } }"#),
1922 ("angular.json", r#"{ "projects": { "shop": { "projectType": "application", "architect": { "build": { "builder": "@angular/build:application", "options": { "outputPath": "dist/shop" } } } } } }"#),
1923 ],
1924 framework: Some("angular"),
1925 output_dir: Some("dist/shop/browser"),
1926 ..CASE
1927 },
1928 Case {
1929 name: "angular-default",
1930 files: &[
1931 ("package.json", r#"{ "dependencies": { "@angular/core": "20" } }"#),
1932 ("angular.json", r#"{ "projects": { "app": { "projectType": "application", "architect": { "build": { "builder": "@angular/build:application", "options": {} } } } } }"#),
1933 ],
1934 framework: Some("angular"),
1935 build: Some("npx ng build"),
1936 output_dir: Some("dist/app/browser"),
1937 ..CASE
1938 },
1939 Case {
1940 name: "hugo",
1941 files: &[("hugo.toml", "baseURL = 'https://example.org/'\ntitle = 'Site'\n")],
1942 framework: Some("hugo"),
1943 build: Some(frameworks_hugo()),
1944 output_dir: Some("public"),
1945 ..CASE
1946 },
1947 Case {
1948 name: "hugo-config-toml",
1949 files: &[("config.toml", "baseURL = \"https://example.org/\"\npublishDir = \"site\"\n")],
1950 framework: Some("hugo"),
1951 build: Some(frameworks_hugo()),
1952 output_dir: Some("site"),
1953 ..CASE
1954 },
1955 Case {
1956 name: "not-hugo",
1957 files: &[("config.toml", "base_url = \"https://example.org\"\n"), ("index.html", "")],
1958 kind: "html",
1959 build: None,
1960 output_dir: Some("."),
1961 ..CASE
1962 },
1963 Case {
1964 name: "jekyll",
1965 files: &[("_config.yml", "title: Blog\n"), ("Gemfile", "gem 'jekyll'\n")],
1966 framework: Some("jekyll"),
1967 build: Some("bundle exec jekyll build"),
1968 output_dir: Some("_site"),
1969 ..CASE
1970 },
1971 Case {
1972 name: "mdbook",
1973 files: &[("book.toml", "[book]\ntitle = \"Guide\"\n")],
1974 framework: Some("mdbook"),
1975 build: Some(frameworks_mdbook()),
1976 output_dir: Some("book"),
1977 ..CASE
1978 },
1979 Case {
1980 name: "mdbook-build-dir",
1981 files: &[("book.toml", "[book]\ntitle = \"Guide\"\n[build]\nbuild-dir = \"site\"\n")],
1982 framework: Some("mdbook"),
1983 build: Some(frameworks_mdbook()),
1984 output_dir: Some("site"),
1985 ..CASE
1986 },
1987 // The project's own settings win.
1988 Case {
1989 name: "own-settings",
1990 files: &[("package.json", r#"{ "scripts": { "build": "vite build" }, "devDependencies": { "vite": "7" } }"#)],
1991 custom_build: Some("make site"),
1992 chosen_output: Some("www"),
1993 framework: Some("vite"),
1994 build: Some("make site"),
1995 output_dir: Some("www"),
1996 ..CASE
1997 },
1998 ];
1999 for case in cases {
2000 let dir = project(&format!("fw-{}", case.name), case.files);
2001 let found = detect(&dir, case.custom_build, case.chosen_output).unwrap();
2002 let name = case.name;
2003 assert_eq!(found.kind, case.kind, "{name}: kind");
2004 assert_eq!(found.framework.as_ref().map(|f| f.id), case.framework, "{name}: framework");
2005 assert_eq!(found.build.as_deref(), case.build, "{name}: build");
2006 assert_eq!(found.output_dir.as_deref(), case.output_dir, "{name}: output-dir");
2007 match case.problem {
2008 Some(phrase) => assert!(found.problem.as_deref().is_some_and(|p| p.contains(phrase)), "{name}: {:?}", found.problem),
2009 None => assert_eq!(found.problem, None, "{name}: problem"),
2010 }
2011 let _ = std::fs::remove_dir_all(&dir);
2012 }
2013 }
2014
2015 #[test]
2016 fn build_as_and_dockerfiles_decide_in_order() {
2017 let detect_with = |dir: &Path, build_as: BuildAs, dockerfile: Option<&str>| detect_as(dir, None, None, build_as, dockerfile).unwrap();
2018 // A framework that builds a static site stays one beside a
2019 // Dockerfile: it costs nothing while no one visits.
2020 let vite = project("p-vite", &[("package.json", r#"{ "devDependencies": { "vite": "7" } }"#), ("Dockerfile", "FROM nginx\nEXPOSE 80\n")]);
2021 assert_eq!(detect_with(&vite, BuildAs::Auto, None).kind, "static");
2022 // Unless the project says Docker.
2023 let found = detect_with(&vite, BuildAs::Docker, None);
2024 assert_eq!((found.kind, found.framework_id()), ("container", Some("vite")));
2025 let container = found.container.unwrap();
2026 assert_eq!((container.dockerfile.as_deref(), container.port), (Some("Dockerfile"), 80));
2027 // A Wrangler config wins in Auto, and not when it says Static site.
2028 let workers = project("p-workers", &[("wrangler.jsonc", r#"{ "assets": { "directory": "public" } }"#), ("index.html", "")]);
2029 assert_eq!(detect_with(&workers, BuildAs::Auto, None).kind, "workers");
2030 assert_eq!(detect_with(&workers, BuildAs::Static, None).kind, "html");
2031 // Workers, without a config or adapter, says what is missing.
2032 let html = project("p-html", &[("index.html", "<h1>hi</h1>")]);
2033 let found = detect_with(&html, BuildAs::Workers, None);
2034 assert_eq!(found.kind, "none");
2035 assert!(found.problem.unwrap().contains("no Wrangler config"));
2036 // No framework and a Dockerfile: a container, built as the site it
2037 // is without one while g1t.page runs no containers.
2038 let both = project("p-both", &[("index.html", ""), ("Containerfile", "FROM nginx")]);
2039 let found = detect_with(&both, BuildAs::Auto, None);
2040 assert_eq!((found.kind, found.framework_id()), ("container", Some("dockerfile")));
2041 assert_eq!(found.container.as_ref().unwrap().port, 8080);
2042 assert_eq!(found.fallback.as_ref().map(|site| site.kind), Some("html"));
2043 // A Dockerfile at a path of the project's choosing.
2044 let chosen = project("p-chosen", &[("ops/web.Dockerfile", "FROM node\nEXPOSE 3000")]);
2045 assert_eq!(detect_with(&chosen, BuildAs::Auto, None).kind, "none");
2046 let found = detect_with(&chosen, BuildAs::Auto, Some("ops/web.Dockerfile"));
2047 assert_eq!((found.kind, found.container.unwrap().port), ("container", 3000));
2048 assert!(detect_as(&chosen, None, None, BuildAs::Auto, Some("nope")).is_err());
2049 // A server g1t recognises gets a Dockerfile written for it.
2050 let express = project("p-express", &[("package.json", r#"{ "scripts": { "start": "node index.js" }, "dependencies": { "express": "5" } }"#)]);
2051 let found = detect_with(&express, BuildAs::Auto, None);
2052 assert_eq!((found.kind, found.framework_id(), found.install.as_deref()), ("container", Some("node"), None));
2053 assert!(found.fallback.is_none());
2054 assert!(output_lines(&found).ends_with("framework=node\ndockerfile=\nport=8080\n"));
2055 // Nothing at all says to add a Dockerfile.
2056 let nothing = project("p-nothing", &[("README.md", "")]);
2057 let found = detect_with(&nothing, BuildAs::Auto, None);
2058 assert_eq!(found.kind, "none");
2059 assert!(found.problem.as_deref().unwrap().starts_with("found nothing to serve"));
2060 assert!(found.problem.unwrap().contains("Add a `Dockerfile`"));
2061 let found = detect_with(&nothing, BuildAs::Docker, None);
2062 assert!(found.problem.unwrap().contains("**Build as** is Docker"));
2063 // A framework set up for a server, with a Dockerfile of its own.
2064 let next = project("p-next", &[("package.json", r#"{ "dependencies": { "next": "16" } }"#), ("Dockerfile", "FROM node")]);
2065 let found = detect_with(&next, BuildAs::Auto, None);
2066 assert_eq!((found.kind, found.framework_id()), ("container", Some("nextjs")));
2067 assert_eq!(found.container.unwrap().dockerfile.as_deref(), Some("Dockerfile"));
2068 // OpenNext's adapter means Workers: it is not run as a server.
2069 let opennext = project("p-opennext", &[("package.json", r#"{ "dependencies": { "next": "16", "@opennextjs/cloudflare": "1" } }"#)]);
2070 assert_eq!(detect_with(&opennext, BuildAs::Auto, None).kind, "none");
2071 for dir in [vite, workers, html, both, chosen, express, nothing, next, opennext] {
2072 let _ = std::fs::remove_dir_all(dir);
2073 }
2074 }
2075
2076 #[test]
2077 fn the_pushed_digest_is_the_one_in_the_apps_repository() {
2078 let digest = "a".repeat(64);
2079 let lines = format!("docker.io/x@sha256:{digest}\nregistry.cloudflare.com/acc/other@sha256:{digest}\nregistry.cloudflare.com/acc/g1t-web@sha256:{digest}\n");
2080 assert_eq!(
2081 pushed_digest(&lines, "registry.cloudflare.com", "acc/g1t-web"),
2082 Some(format!("registry.cloudflare.com/acc/g1t-web@sha256:{digest}"))
2083 );
2084 assert_eq!(pushed_digest("registry.cloudflare.com/acc/g1t-web@sha256:short", "registry.cloudflare.com", "acc/g1t-web"), None);
2085 let grant: RegistryGrant = serde_json::from_value(json!({
2086 "registry": "registry.cloudflare.com", "repository": "acc/g1t-web", "tag": "dpl_1",
2087 "username": "u", "password": "p", "max_image_bytes": 2_000_000_000u64, "instance_type": "lite"
2088 }))
2089 .unwrap();
2090 assert_eq!((grant.max_image_bytes, grant.instance_type.as_deref()), (2_000_000_000, Some("lite")));
2091 assert_eq!(size_text(1_450_000_000), "1.4 GB");
2092 }
2093
2094 /// What a container g1t writes the Dockerfile for is built with.
2095 const GENERATED: &str = "docker build -f Dockerfile (written by g1t) .";
2096
2097 fn frameworks_hugo() -> &'static str {
2098 "if command -v hugo >/dev/null 2>&1; then hugo --minify; else npx --yes hugo-extended@0.166.0 --minify; fi"
2099 }
2100
2101 fn frameworks_mdbook() -> &'static str {
2102 "if ! command -v mdbook >/dev/null 2>&1; then cargo install mdbook --version 0.5.4 --locked --quiet; fi && mdbook build"
2103 }
2104
2105 #[test]
2106 fn jekyll_installs_its_gems_after_the_packages() {
2107 let dir = project("jekyll-install", &[("_config.yml", ""), ("Gemfile", ""), ("package.json", "{}")]);
2108 let found = detect(&dir, None, None).unwrap();
2109 assert_eq!(found.install.as_deref(), Some("npm install && bundle config set --local path vendor/bundle && bundle install"));
2110 }
2111
2112 #[test]
2113 fn an_adapters_worker_is_found_once_built_and_never_served() {
2114 let dir = project(
2115 "adapter",
2116 &[
2117 ("dist/_worker.js/index.js", "export default {}"),
2118 ("dist/_routes.json", "{}"),
2119 ("dist/.assetsignore", "_worker.js\nsecret.txt\n"),
2120 ("dist/secret.txt", "no"),
2121 ("dist/index.html", "<h1>hi</h1>"),
2122 ("dist/about/_worker.js", "a page's own file"),
2123 ("kit/.svelte-kit/cloudflare/_worker.js", "export default {}"),
2124 ],
2125 );
2126 let astro = Adapter { entry: "dist/_worker.js", assets: "dist" };
2127 assert_eq!(adapter_entry(&dir, &astro), Some(dir.join("dist/_worker.js/index.js")));
2128 let kit = Adapter { entry: ".svelte-kit/cloudflare/_worker.js", assets: ".svelte-kit/cloudflare" };
2129 assert_eq!(adapter_entry(&dir.join("kit"), &kit), Some(dir.join("kit/.svelte-kit/cloudflare/_worker.js")));
2130 assert_eq!(adapter_entry(&dir.join("missing"), &kit), None);
2131 let mut served: Vec<String> = collect_site(&dir.join("dist"), false).unwrap().into_iter().map(|a| a.path).collect();
2132 served.sort();
2133 assert_eq!(served, ["/about/_worker.js", "/index.html"]);
2134 }
2135
2136 #[test]
2137 fn a_config_the_build_wrote_is_read_in_place_of_the_projects() {
2138 let dir = project(
2139 "redirected",
2140 &[
2141 ("wrangler.jsonc", r#"{ "main": "worker/index.ts" }"#),
2142 (".wrangler/deploy/config.json", r#"{ "configPath": "../../dist/app/wrangler.json" }"#),
2143 ("dist/app/wrangler.json", r#"{ "main": "index.js", "assets": { "directory": "../client" } }"#),
2144 ],
2145 );
2146 let (config, base) = redirected_config(&dir).unwrap().unwrap();
2147 assert_eq!(config.main.as_deref(), Some("index.js"));
2148 assert_eq!(base, dir.join("dist/app").canonicalize().unwrap());
2149 assert!(base.join(config.assets.unwrap().directory.unwrap()).ends_with("dist/app/../client"));
2150 assert!(redirected_config(&project("not-redirected", &[])).unwrap().is_none());
2151 }
2152
2153 #[test]
2154 fn the_root_directory_stays_inside_the_checkout() {
2155 let base = Path::new("/w/repo");
2156 assert_eq!(project_dir_in(base, ""), base);
2157 assert_eq!(project_dir_in(base, "."), base);
2158 assert_eq!(project_dir_in(base, "/apps/site/"), base.join("apps/site"));
2159 assert_eq!(project_dir_in(base, "../etc"), base);
2160 assert_eq!(project_dir_in(base, "apps/../../x"), base);
2161 }
2162
2163 #[test]
2164 fn a_step_prints_the_log_redacted() {
2165 let mut log = Log { echo: Some(vec!["hunter22".to_owned()]), ..Log::default() };
2166 log.line("token hunter22 used");
2167 assert!(log.text.contains("hunter22"), "the deployment's log is redacted when it is sent");
2168 assert_eq!(wrangler_build(Some(Path::new("/tmp/b")), None), "npx --yes wrangler@4 deploy --dry-run --outdir /tmp/b");
2169 assert_eq!(
2170 wrangler_build(Some(Path::new("/tmp/b")), Some(Path::new("/tmp/w.json"))),
2171 "npx --yes wrangler@4 deploy --dry-run --config /tmp/w.json --outdir /tmp/b"
2172 );
2173 }
2174}