-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdeploy.js
46 lines (34 loc) · 1.37 KB
/
deploy.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// deploy.js
const { LocalWorkspace } = require("@pulumi/pulumi/automation");
const path = require("path");
const fs = require("fs");
const { createPulumiProgram } = require("./pulumiProgram");
async function deploy(staticDir) {
if (!fs.existsSync(staticDir)) {
console.error(`Directory "${staticDir}" does not exist.`);
process.exit(1);
}
const configPath = path.resolve("config.json");
if (!fs.existsSync(configPath)) {
console.error("❌ Missing config.json – have you run `init`?");
process.exit(1);
}
const config = JSON.parse(fs.readFileSync(configPath, "utf8"));
//const token = process.env.PULUMI_ACCESS_TOKEN || config.pulumiAccessToken;
const stackName = config.stackName;
const projectName = config.projectName;
console.log("⏳ Initializing Pulumi stack...");
const stack = await LocalWorkspace.createOrSelectStack({
stackName,
projectName,
program: createPulumiProgram(staticDir),
});
console.log("✅ Stack initialized");
await stack.setConfig("aws:region", { value: config.region || "us-east-1" });
console.log("🚀 Deploying to AWS...");
const upRes = await stack.up();
console.log("\n✅ Deployment complete!");
console.log(`📦 Bucket Name: ${upRes.outputs.bucketName.value}`);
console.log(`🌐 Site URL: ${upRes.outputs.cloudfrontUrl.value}`);
}
module.exports = { deploy };