diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..26a3116 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,11 @@ +FROM oven/bun:1.1.16 + +WORKDIR / + +COPY . . + +RUN apt-get clean && apt-get update +RUN apt-get install openssh-server sshpass -y +RUN bun install + +ENTRYPOINT ["bun", "run", "deploy"] \ No newline at end of file diff --git a/bun.lockb b/bun.lockb index b3d76f2..83e63b0 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/commands/log-in-to-docker-registry.ts b/commands/log-in-to-docker-registry.ts index f20bb85..353967f 100644 --- a/commands/log-in-to-docker-registry.ts +++ b/commands/log-in-to-docker-registry.ts @@ -12,8 +12,7 @@ export async function logInToDockerRegistry( { server, username, password }: DockerRegistry, ) { console.log( - `Logging in to Docker registry${server ? ` at ${server}` : ""}${ - username ? ` with username ${username}` : "" + `Logging in to Docker registry${server ? ` at ${server}` : ""}${username ? ` with username ${username}` : "" }...`, ); diff --git a/index.ts b/index.ts index aa36670..92158e9 100644 --- a/index.ts +++ b/index.ts @@ -1,7 +1,7 @@ import { Clerc, helpPlugin, versionPlugin } from "clerc"; import { deploy } from "./commands/deploy"; import { setup } from "./commands/setup"; -import { ssh } from "./utils/ssh"; +import { setSshPass, ssh } from "./utils/ssh"; Clerc.create() .scriptName("deploytool") @@ -18,6 +18,22 @@ Clerc.create() default: "root", description: "SSH user", }, + sshPassword: { + type: String, + description: "SSH pass", + }, + interactive: { + alias: "i", + type: Boolean, + default: false, + description: "Interactive mode", + }, + verbose: { + alias: "v", + type: Boolean, + default: false, + description: "Verbose mode", + } }, }) .command("deploy", "Deploy a new version of a service", { @@ -40,6 +56,21 @@ Clerc.create() default: "root", description: "SSH user", }, + sshPassword: { + type: String, + description: "SSH pass", + }, + interactive: { + alias: "i", + type: Boolean, + default: false, + description: "Interactive mode", + }, + verbose: { + type: Boolean, + default: false, + description: "Verbose mode", + }, environment: { alias: "e", type: [String], @@ -61,15 +92,19 @@ Clerc.create() }) .on("setup", async (context) => { const { ip } = context.parameters; - const { sshUser } = context.flags; + const { sshUser, interactive, sshPassword, verbose } = context.flags; - await setup(ssh(ip, sshUser), { ip }); + setSshPass(sshPassword); + + await setup(ssh(ip, sshUser, interactive, verbose), { ip }); }) .on("deploy", async (context) => { const { ip, domain, image, name } = context.parameters; - const { port, path, sshUser, environment } = context.flags; + const { port, path, sshUser, interactive, verbose, sshPassword, environment } = context.flags; + + setSshPass(sshPassword); - await deploy(ssh(ip, sshUser), { + await deploy(ssh(ip, sshUser, interactive, verbose), { domain, image, name, @@ -83,4 +118,4 @@ Clerc.create() }, }); }) - .parse(); + .parse(); \ No newline at end of file diff --git a/package.json b/package.json index aaba107..c02ffe1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,9 @@ { "name": "deploy-tool", "module": "index.ts", + "scripts": { + "deploy": "bun run /index.ts deploy" + }, "devDependencies": { "@biomejs/biome": "1.7.0", "@types/bun": "latest" diff --git a/utils/ssh.ts b/utils/ssh.ts index 279a96f..d5a018a 100644 --- a/utils/ssh.ts +++ b/utils/ssh.ts @@ -3,6 +3,12 @@ import { $, type ShellPromise } from "bun"; export type SSHRunner = (command: string) => ShellPromise; export const ssh = - (ip: string, sshUser: string): SSHRunner => - (command: string) => - $`ssh ${sshUser}@${ip} ${command}`.throws(true); + (ip: string, sshUser: string, interactive: boolean, verbose: boolean): SSHRunner => + (command: string) => + interactive + ? $`ssh ${verbose ? '-v' : ''} ${sshUser}@${ip} ${command}`.throws(true) + : $`sshpass -e ssh ${verbose ? '-v' : ''} -o StrictHostKeyChecking=no ${sshUser}@${ip} ${command}`.throws(true); + +export function setSshPass(sshPassword?: string) { + $.env({ SSHPASS: sshPassword }); +} \ No newline at end of file