Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
Binary file modified bun.lockb
Binary file not shown.
3 changes: 1 addition & 2 deletions commands/log-in-to-docker-registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}` : ""
}...`,
);

Expand Down
47 changes: 41 additions & 6 deletions index.ts
Original file line number Diff line number Diff line change
@@ -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")
Expand All @@ -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", {
Expand All @@ -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],
Expand All @@ -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,
Expand All @@ -83,4 +118,4 @@ Clerc.create()
},
});
})
.parse();
.parse();
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
12 changes: 9 additions & 3 deletions utils/ssh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
}