Skip to content

Commit

Permalink
Update deployment script to:
Browse files Browse the repository at this point in the history
- Revert any local changes to config files before running
- Display the current config value per key if maintained

This change also includes updating npm packages to resolve security vulnerabilities.

Change-Id: I0fec42645cfe737582dcb6baea154eb9354a5fd8
  • Loading branch information
mohabfekry committed Jan 8, 2025
1 parent 523fa18 commit c3e0949
Show file tree
Hide file tree
Showing 7 changed files with 96 additions and 29 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ node_modules
dist/
build/
**/.DS_Store
.config.json
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,6 @@ Please make sure you have fulfilled all prerequisites mentioned under [Requireme
* When deploying GCP components, you will be prompted to enter an optional [Cloud Function region](https://cloud.google.com/functions/docs/locations) (defaults to `us-central1`) and an optional [GCS location](https://cloud.google.com/storage/docs/locations) (defaults to `us`).
* When deploying the UI, you will be asked if you are a Google Workspace user and if you want others in your Workspace domain to access your deployed web app (defaults to `No`). By default, the web app is only accessible by you, and that is controlled by the [web app access settings](https://developers.google.com/apps-script/manifest/web-app-api-executable#webapp) in the project's [manifest file](./ui/appsscript.json), which defaults to `MYSELF`. If you answer `Yes` here, this value will be changed to `DOMAIN` to allow other individuals within your organisation to access the web app without having to deploy it themselves.

> Note: If you have already run the script and you notice that there was a typo in one of the inputs, or if you would like to change the Cloud region, GCS location, or the UI access settings for Google Workspace users, you **must** first run `git reset --hard` before rerunning `npm start`.
The `npm start` script will then proceed to perform the deployments you requested (GCP, UI, or both), where GCP is deployed first, followed by the UI. For GCP, the script will first create a bucket named <code>*<gcp_project_id>*-vigenair</code> (if it doesn't already exist), then enable all necessary Cloud APIs and set up the right access roles, before finally deploying the `vigenair` Cloud Function to your Cloud project. The script would then deploy the Angular UI web app to a new Apps Script project, outputting the URL of the web app at the end of the deployment process, which you can use to run the app.

See [How Vigenair Works](#how-vigenair-works) for more details on the different components of the solution.
Expand Down
40 changes: 40 additions & 0 deletions common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ export const DEFAULT_GCP_REGION = "us-central1";
export const DEFAULT_GCS_LOCATION = "us";
const GCS_BUCKET_NAME_SUFFIX = "-vigenair";

interface Config {
gcpProjectId?: string;
gcpRegion?: string;
gcsLocation?: string;
vertexAiRegion?: string;
}

interface ConfigReplace {
regex: string;
replacement: string;
Expand Down Expand Up @@ -200,6 +207,23 @@ export class UserConfigManager {
};

console.log();
console.log("Reverting local changes...");
spawn.sync("git checkout -- ./service/.env.yaml", {
stdio: "inherit",
shell: true,
});
spawn.sync("git checkout -- ./service/deploy.sh", {
stdio: "inherit",
shell: true,
});
spawn.sync("git checkout -- ./ui/src/config.ts", {
stdio: "inherit",
shell: true,
});
spawn.sync("git checkout -- ./ui/appsscript.json", {
stdio: "inherit",
shell: true,
});
console.log("Setting user configuration...");
const gcpProjectId = response.gcpProjectId;
const gcpRegion = response.gcpRegion || DEFAULT_GCP_REGION;
Expand Down Expand Up @@ -252,6 +276,22 @@ export class UserConfigManager {
paths: ["./ui/src/config.ts"],
});
}
fs.writeFileSync(
".config.json",
JSON.stringify({
gcpProjectId,
gcpRegion,
gcsLocation,
vertexAiRegion,
})
);
console.log();
}

static getUserConfig(): Config {
if (fs.existsSync(".config.json")) {
return JSON.parse(fs.readFileSync(".config.json"));
}
return {};
}
}
33 changes: 26 additions & 7 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,19 @@ import {
UserConfigManager,
} from "./common.js";

const config = UserConfigManager.getUserConfig();

(async () => {
const response = await prompts([
{
type: "text",
name: "gcpProjectId",
message: "Enter your GCP Project ID (e.g. my-project-123):",
message: `Enter your GCP Project ID - [${
config.gcpProjectId
? `Current: ${config.gcpProjectId}`
: "e.g. my-project-123"
}]:`,
initial: config.gcpProjectId ?? "",
validate: (value: string) => (!value ? "Required" : true),
},
{
Expand All @@ -46,15 +53,23 @@ import {
type: (prev: boolean, values: PromptsResponse, prompt: unknown) =>
values.deployGcpComponents ? "text" : null,
name: "gcpRegion",
message: `Enter a GCP region for the 'vigenair' service to run in (defaults to '${DEFAULT_GCP_REGION}'):`,
intitial: DEFAULT_GCP_REGION,
message: `Enter a GCP region for the 'vigenair' service to run in - [${
config.gcpRegion
? `Current: ${config.gcpRegion}`
: `Default: ${DEFAULT_GCP_REGION}`
}]:`,
intitial: config.gcpRegion ?? DEFAULT_GCP_REGION,
},
{
type: (prev: boolean, values: PromptsResponse, prompt: unknown) =>
values.deployGcpComponents ? "text" : null,
name: "gcsLocation",
message: `Enter a GCS location to store videos in (can be multi-region like 'us' or 'eu' or single region like 'us-central1' or 'europe-west4' - defaults to '${DEFAULT_GCS_LOCATION}'):`,
intitial: DEFAULT_GCS_LOCATION,
message: `Enter a GCS location to store videos in (can be multi-region like 'us' or 'eu' or single region like 'us-central1' or 'europe-west4') - [${
config.gcsLocation
? `Current: ${config.gcsLocation}`
: `Default: ${DEFAULT_GCS_LOCATION}`
}]:`,
intitial: config.gcsLocation ?? DEFAULT_GCS_LOCATION,
},
{
type: "toggle",
Expand All @@ -78,8 +93,12 @@ import {
type: (prev: boolean, values: PromptsResponse, prompt: unknown) =>
values.deployUi ? "text" : null,
name: "vertexAiRegion",
message: `Enter a GCP region to access Vertex AI generative models. Refer to https://cloud.google.com/vertex-ai/generative-ai/docs/learn/locations#available-regions for available regions (defaults to '${DEFAULT_GCP_REGION}'):`,
intitial: DEFAULT_GCP_REGION,
message: `Enter a GCP region to access Vertex AI generative models. Refer to https://cloud.google.com/vertex-ai/generative-ai/docs/learn/locations#available-regions for available regions - [${
config.vertexAiRegion
? `Current: ${config.vertexAiRegion}`
: `Default: ${DEFAULT_GCP_REGION}`
}]:`,
intitial: config.vertexAiRegion ?? DEFAULT_GCP_REGION,
},
]);
UserConfigManager.setUserConfig(response);
Expand Down
7 changes: 4 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions ui/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 21 additions & 14 deletions ui/src/ui/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit c3e0949

Please sign in to comment.