deploy self
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,4 +1,5 @@
|
|||||||
/config.ts
|
/config.ts
|
||||||
|
/Caddyfile
|
||||||
|
|
||||||
# ---> Node
|
# ---> Node
|
||||||
# Logs
|
# Logs
|
||||||
|
|||||||
2
Makefile
2
Makefile
@@ -1,6 +1,6 @@
|
|||||||
|
|
||||||
build:
|
build:
|
||||||
echo nothing to build!
|
pnpm run build
|
||||||
|
|
||||||
start:
|
start:
|
||||||
pnpm start
|
pnpm start
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "deployer2",
|
"name": "deployer2",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
"build": "bun run src/buildSelf.ts",
|
||||||
"dev": "NODE_ENV=development PORT=6001 bun run --hot src/index.ts",
|
"dev": "NODE_ENV=development PORT=6001 bun run --hot src/index.ts",
|
||||||
"start": "NODE_ENV=production bun run src/index.ts"
|
"start": "NODE_ENV=production bun run src/index.ts"
|
||||||
},
|
},
|
||||||
|
|||||||
13
src/buildSelf.ts
Normal file
13
src/buildSelf.ts
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
import fs from "fs";
|
||||||
|
import { indexedConfig } from "./config";
|
||||||
|
|
||||||
|
const Caddyfile = Object.values(indexedConfig)
|
||||||
|
.map(
|
||||||
|
({ host, port }) => `
|
||||||
|
${host}.drm.dev {
|
||||||
|
reverse_proxy localhost:${port}
|
||||||
|
}`
|
||||||
|
)
|
||||||
|
.join("\n");
|
||||||
|
|
||||||
|
fs.writeFileSync("Caddyfile", Caddyfile);
|
||||||
@@ -1,24 +1,17 @@
|
|||||||
|
import hash from "object-hash";
|
||||||
import { $ } from "bun";
|
import { $ } from "bun";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
import { config } from "./config";
|
import { config, indexedConfig } from "./config";
|
||||||
|
|
||||||
type DeployInstance = {
|
type DeployInstance = {
|
||||||
host: string;
|
host: string;
|
||||||
user: string;
|
|
||||||
repo: string;
|
|
||||||
branch: string;
|
|
||||||
commitHash: string;
|
commitHash: string;
|
||||||
port: number;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export const deploy = async ({
|
export const deploy = async ({ host, commitHash }: DeployInstance) => {
|
||||||
host,
|
const service = config.services[host];
|
||||||
user,
|
const { user, repo, branch, port } = indexedConfig[hash(service)];
|
||||||
repo,
|
|
||||||
branch,
|
|
||||||
port,
|
|
||||||
commitHash,
|
|
||||||
}: DeployInstance) => {
|
|
||||||
const deploymentId = new Date().toISOString();
|
const deploymentId = new Date().toISOString();
|
||||||
|
|
||||||
const serviceDir = path.join(config.directory, host);
|
const serviceDir = path.join(config.directory, host);
|
||||||
|
|||||||
6
src/deploySelf.ts
Normal file
6
src/deploySelf.ts
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
import { deploy } from "./deploy";
|
||||||
|
|
||||||
|
await deploy({
|
||||||
|
host: "deployer2",
|
||||||
|
commitHash: "",
|
||||||
|
});
|
||||||
@@ -34,7 +34,7 @@ new Elysia()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void deploy({ ...service, commitHash });
|
void deploy({ host: service.host, commitHash });
|
||||||
return "deploying";
|
return "deploying";
|
||||||
})
|
})
|
||||||
.listen(port);
|
.listen(port);
|
||||||
|
|||||||
Reference in New Issue
Block a user