Skip to content

Commit

Permalink
chore: code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
ParzivalEugene committed Aug 1, 2024
1 parent 8375fda commit 2b4b6d1
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 18 deletions.
5 changes: 2 additions & 3 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ config();

const envSchema = z.object({
DIGITALOCEAN_TOKEN: z.string(),
SSH_KEY_IDS: z.string(),
HELIOS_DOMAIN: z.string(),
DATABASE_CONNECTION_STRING: z.string(),
});
Expand Down Expand Up @@ -44,7 +43,7 @@ export const globalOptions = {
},
peers: {
message: "Provide number of peers",
placeholder: "1023",
defaultValue: "1023",
placeholder: "253",
defaultValue: "253",
},
};
33 changes: 19 additions & 14 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,17 @@ async function main() {
},
subnet: () => text(globalOptions.subnet),
port: () => text(globalOptions.port),
peers: () => text(globalOptions.peers),
peers: () =>
text({
...globalOptions.peers,
validate: (value) => {
if (parseInt(value) > 253) {
return "Peers cannot exceed 253";
} else if (parseInt(value) < 1) {
return "Peers cannot be less than 1";
}
},
}),
},
{
onCancel: ({ results }) => {
Expand Down Expand Up @@ -82,36 +92,31 @@ async function main() {

let envCreation = await spinner();
envCreation.start("Creating environment");
fs.writeFile(
"./temp/.env",
fs.writeFileSync(
"env",
`INTERNAL_SUBNET=${config.subnet}
PEERS=${config.peers}
WIREGUARD_PORT=${config.port}
THREADS=16
COUNTRY=${country[config.region as keyof typeof country]}
DOMAIN=agent-wireguard-${config.region}.${ENV.HELIOS_DOMAIN}
DATABASE_CONNECTION_STRING=${ENV.DATABASE_CONNECTION_STRING}`,
(err) => {
if (err) {
console.error(err);
process.exit(1);
}
}
DATABASE_CONNECTION_STRING=${ENV.DATABASE_CONNECTION_STRING}`
);
envCreation.stop("Environment created");

let chillBeforeFullSetup = await spinner();
chillBeforeFullSetup.start(
"Relax and chill before server will be fully setup"
);
await new Promise((resolve) => setTimeout(resolve, 5000));
await new Promise((resolve) => setTimeout(resolve, 40000));
chillBeforeFullSetup.stop("Server ready");

let startServer = await spinner();
startServer.start("Starting server");
await run(`scp ./temp/.env root@${ip}:~/.env
scp scripts/ root@${ip}:~/scripts
ssh root@${ip} ". ~/scripts/setup.sh"`);
await run(`scp env root@${ip}:~/.env
scp -r scripts/ root@${ip}:~/scripts/
ssh root@${ip} ". ~/scripts/server_setup.sh"
rm env`);
startServer.stop("Server started");

outro("Server setup complete");
Expand Down
1 change: 1 addition & 0 deletions src/requests/add-domain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export const addDomain = async (
);

if (!response.ok) {
console.log(await response.text());
throw new Error("Failed to add domain");
}

Expand Down
3 changes: 2 additions & 1 deletion src/requests/create-droplet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@ export const createDroplet = async (region: string): Promise<number> => {
region,
size: "s-1vcpu-1gb-amd",
image: "docker-20-04",
ssh_keys: getSshKeys(),
ssh_keys: await getSshKeys(),
}),
});

if (!response.ok) {
console.log(await response.text());
throw new Error("Failed to create droplet");
}

Expand Down
1 change: 1 addition & 0 deletions src/requests/fetch-droplets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export const fetchDropets = async (): Promise<Array<string>> => {
},
});
if (!response.ok) {
console.log(await response.text());
throw new Error("Failed to fetch droplets");
}
let data = await response.json();
Expand Down
1 change: 1 addition & 0 deletions src/requests/get-droplet-ip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export const getDropletIp = async (dropletId: number): Promise<string> => {
);

if (!response.ok) {
console.log(await response.text());
throw new Error("Failed to fetch droplet");
}

Expand Down
1 change: 1 addition & 0 deletions src/requests/get-ssh-keys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export const getSshKeys = async (): Promise<Array<number>> => {
});

if (!response.ok) {
console.log(await response.text());
throw new Error("Failed to fetch ssh keys");
}

Expand Down

0 comments on commit 2b4b6d1

Please sign in to comment.