| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- using GLib;
- namespace Spry.Cli {
- /**
- * `spry deploy` — packages and deploys the application as a container
- * image through USM, delegating to `usm manifest deploy` in the
- * application directory.
- *
- * USM resolves the whole graph inside the image build: the system
- * package manager provides the platform libraries and toolchain, the
- * configured (or `--repository`-named) USM repositories provide the
- * Web-Stack, and the application's own `MANIFEST.usm`/`usm-scripts/`
- * (scaffolded by `spry new`) drive its build and install. Flags pass
- * through to `usm manifest deploy` verbatim; `--exec` defaults to
- * `<app> 8080` so the container serves on the documented port.
- */
- public class Deploy : GLib.Object {
- /**
- * Runs `usm manifest deploy` in {@link app_dir} with the collected
- * flags. The USM binary is resolved from `--usm` or PATH; a missing
- * binary is reported with install guidance rather than a raw spawn
- * error. Returns the delegate process's exit status.
- */
- public static int run(string app_dir, string app_name, string? usm_path,
- string? exec_command, string? base_image, string[] repositories,
- string? installer_url, bool no_build, bool verbose = false) throws Error {
- var usm = usm_path != null ? (!)usm_path : Environment.find_program_in_path("usm");
- if (usm == null) {
- stderr.printf("Error: usm not found on PATH — install USM (or pass --usm <path-to-usm>) to deploy.\n");
- return 1;
- }
- string[] argv = { (!)usm, "manifest", "deploy",
- "--exec", exec_command ?? @"$app_name 8080" };
- if (base_image != null) {
- argv += "--base";
- argv += base_image;
- }
- foreach (var repository in repositories) {
- argv += "--repository";
- argv += repository;
- }
- if (installer_url != null) {
- argv += "--installer-url";
- argv += installer_url;
- }
- if (no_build) {
- argv += "--no-build";
- }
- if (verbose) {
- argv += "--verbose";
- }
- var shown = "";
- foreach (var word in argv[1:argv.length]) {
- shown += (shown.length > 0 ? " " : "") + (word.contains(" ") ? "\"" + word + "\"" : word);
- }
- stdout.printf("Running: %s\n", shown);
- var launcher = new SubprocessLauncher(SubprocessFlags.INHERIT_FDS);
- launcher.set_cwd(app_dir);
- var process = launcher.spawnv(argv);
- try {
- process.wait_check();
- return 0;
- }
- catch(Error e) {
- return process.get_exit_status();
- }
- }
- }
- }
|