-
Notifications
You must be signed in to change notification settings - Fork 0
feat: replace deployment shell scripts with TS/Node alternatives (COW-977) #66
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
lgahdl
merged 4 commits into
develop
from
luizhatem/cow-977-replace-shell-scripts-in-deployment-with-typescriptnode-or
May 28, 2026
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
1709c91
Merge pull request #53 from bleu/develop
jeffersonBastos ee1fc0d
Merge pull request #63 from bleu/develop
lgahdl f807846
feat: replace deployment shell scripts with TypeScript/Node alternati…
lgahdl a0dde97
docs: add bleu-context note to deployment scripts (COW-977)
lgahdl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,128 @@ | ||
| #!/usr/bin/env tsx | ||
| /** | ||
| * deploy-remotely.ts — rsync + SSH deploy or local deploy. | ||
| * Replaces deploy-remotely.sh. | ||
| * | ||
| * NOTE: This script is specific to Bleu's internal deployment workflow. | ||
| * It assumes a particular server layout and SSH setup. Adapt as needed for | ||
| * your own hosting environment. | ||
| * | ||
| * Usage: | ||
| * npx tsx deployment/deploy-remotely.ts <deploy_target> [env_file_path] | ||
| * | ||
| * deploy_target: | ||
| * - Local deployment (runs manage.ts in this repo) | ||
| * host:path Remote deployment via SSH (rsync + scp + ssh) | ||
| * | ||
| * Note: Remote deployment requires Node 18+ and pnpm installed on the remote host. | ||
| * Run `pnpm install` on the remote after the first deploy to install tsx. | ||
| */ | ||
|
|
||
| import { spawnSync } from "node:child_process"; | ||
| import { resolve } from "node:path"; | ||
|
|
||
| function run( | ||
| cmd: string, | ||
| args: string[], | ||
| opts: { cwd?: string; ignoreError?: boolean } = {} | ||
| ): void { | ||
| console.log(`+ ${cmd} ${args.join(" ")}`); | ||
| const result = spawnSync(cmd, args, { | ||
| stdio: "inherit", | ||
| cwd: opts.cwd, | ||
| }); | ||
| if (!opts.ignoreError && result.status !== 0) { | ||
| process.exit(result.status ?? 1); | ||
| } | ||
| } | ||
|
|
||
| function runCapture(cmd: string, args: string[]): string { | ||
| const result = spawnSync(cmd, args, { encoding: "utf-8" }); | ||
| if (result.status !== 0) { | ||
| console.error(`Command failed: ${cmd} ${args.join(" ")}`); | ||
| console.error(result.stderr); | ||
| process.exit(result.status ?? 1); | ||
| } | ||
| return result.stdout.trim(); | ||
| } | ||
|
|
||
| function usage(): never { | ||
| console.error( | ||
| `Usage: tsx deployment/deploy-remotely.ts <deploy_target> [env_file_path] | ||
|
|
||
| deploy_target: | ||
| - Local deployment | ||
| host:path Remote deployment via SSH | ||
|
|
||
| env_file_path: path to .env file (default: .env) | ||
| ` | ||
| ); | ||
| process.exit(1); | ||
| } | ||
|
|
||
| const [deployTarget, envFilePath = ".env"] = process.argv.slice(2); | ||
|
|
||
| if (!deployTarget) { | ||
| usage(); | ||
| } | ||
|
|
||
| const appRevision = runCapture("git", ["rev-parse", "--short", "HEAD"]); | ||
| const repoRootDir = runCapture("git", ["rev-parse", "--show-toplevel"]); | ||
| const manageCmd = process.env["MANAGE_CMD_OVERRIDE"] ?? "up"; | ||
|
|
||
| if (deployTarget === "-") { | ||
| // Local deployment | ||
| const absoluteEnvFile = resolve(envFilePath); | ||
| run( | ||
| "npx", | ||
| [ | ||
| "tsx", | ||
| "deployment/manage.ts", | ||
| manageCmd, | ||
| "--env-file", | ||
| absoluteEnvFile, | ||
| "--revision", | ||
| appRevision, | ||
| ], | ||
| { cwd: repoRootDir } | ||
| ); | ||
| } else if (/^[^:]+:.+/.test(deployTarget)) { | ||
| // Remote deployment via SSH | ||
| const colonIdx = deployTarget.indexOf(":"); | ||
| const sshHost = deployTarget.slice(0, colonIdx); | ||
| const remotePath = deployTarget.slice(colonIdx + 1); | ||
|
|
||
| // rsync repo to remote host | ||
| run("rsync", [ | ||
| "-avz", | ||
| "--delete", | ||
| "--mkpath", | ||
| "--exclude=.git", | ||
| "--exclude=node_modules", | ||
| "--exclude=.env", | ||
| "--exclude=.env.local", | ||
| "--exclude=.vite", | ||
| "--exclude=*.log", | ||
| "--exclude=tmp/", | ||
| `${repoRootDir}/`, | ||
| `${sshHost}:${remotePath}/`, | ||
| ]); | ||
|
|
||
| // Copy env file to remote deployment directory | ||
| const remoteEnvPath = `${remotePath}/deployment/.env`; | ||
| run("scp", [envFilePath, `${sshHost}:${remoteEnvPath}`]); | ||
|
|
||
| // Run manage.ts on the remote host | ||
| // Note: The remote host must have Node 18+ and pnpm installed. | ||
| // After the first deploy, run `pnpm install` on the remote to install tsx. | ||
| const remoteDeployDir = `${remotePath}/deployment`; | ||
| run("ssh", [ | ||
| sshHost, | ||
| `cd ${remoteDeployDir} && npx tsx manage.ts ${manageCmd} --env-file .env --revision ${appRevision}`, | ||
| ]); | ||
| } else { | ||
| console.error( | ||
| "Error: <deploy_target> must be '-' (local) or SSH_HOST:PATH (remote)" | ||
| ); | ||
| usage(); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would add a comment that this file is only for bleu development context
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good call, added a note at the top of the file clarifying this is specific to Bleu's internal deployment workflow.