Skip to content

Commit

Permalink
Enhance setup script to set production environment variable and promp…
Browse files Browse the repository at this point in the history
…t for worker deployment, improving deployment process and user interaction.
  • Loading branch information
sergiodxa committed Dec 19, 2024
1 parent 9e69e7d commit 15d039b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
17 changes: 17 additions & 0 deletions scripts/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ try {
await Secret.create(cf, account, worker, "VERIFIER_API_KEY", verifier);
}

/** We want to set the APP_ENV to production in the Worker */
await Secret.create(cf, account, worker, "APP_ENV", "production");

consola.info("Creating .dev.vars file with the app environment variables.");

await write(
Expand Down Expand Up @@ -194,6 +197,20 @@ crons = ["* * * * *"]

await $`bun run db:seed ${db.name}`.quiet().nothrow();

if (
await consola.prompt("Do you want to deploy the worker now?", {
type: "confirm",
})
) {
consola.info("Running migrations against the production database.");
await $`bun run db:migrate --remote ${db.name}`.quiet().nothrow();
consola.info("Building the application.");
await $`bun run build`.quiet().nothrow();
consola.info("Deploying the worker.");
await $`bun run deploy`.quiet().nothrow();
consola.success("Worker deployed successfully.");
}

consola.success("Setup completed successfully.");

process.exit(0);
Expand Down
6 changes: 4 additions & 2 deletions scripts/setup/secret.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export class Secret extends Data<ObjectParser> {
consola.info(`Creating secret ${name}.`);

let path = generatePath(
"/client/v4/accounts/:accountId/workers/scripts/:name/secrets",
"/client/v4/accounts/:accountId/workers/services/:name/environments/production/secrets",
{ accountId: account.id, name: worker.name },
);

Expand All @@ -38,7 +38,9 @@ export class Secret extends Data<ObjectParser> {
},
});

if (!response.ok) throw new Error(`Failed to create secret ${name}.`);
if (!response.ok) {
throw new Error(`Failed to create secret ${name}.`);
}

let result = await response.json();
let parser = new ObjectParser(result);
Expand Down
2 changes: 1 addition & 1 deletion scripts/setup/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Data } from "@edgefirst-dev/data";
import { ObjectParser } from "@edgefirst-dev/data/parser";
import type { Cloudflare } from "cloudflare";
import consola from "consola";
import { generatePath, resolvePath } from "react-router";
import { generatePath } from "react-router";
import type { Account } from "./account";

export class Worker extends Data<ObjectParser> {
Expand Down

0 comments on commit 15d039b

Please sign in to comment.