π₯ Make videos programmatically with React
updated readme with terraform instructions
Matt McGillivray73bdfbf1c6c5
diff --git a/packages/gcp/readme.md b/packages/gcp/readme.mdindex d5b1882a9c..0d054a15a4 100644--- a/packages/gcp/readme.md+++ b/packages/gcp/readme.md@@ -15,7 +15,7 @@ Part of the CI/CD pipeline should be to push a new container image to the artifa# How to use the GCP CLI commands-### 1. Create a project in the Google Cloud Console+## 1. Create a project in the Google Cloud ConsoleNavigate to the [Manage Resources](https://console.cloud.google.com/cloud-resource-manager?walkthrough_id=resource-manager--create-project&start_index=1#step_index=1) screen in Google Cloud Console.@@ -25,7 +25,57 @@ Navigate to the [Manage Resources](https://console.cloud.google.com/cloud-resour- Enter the parent organization or folder resource in the Location box. That resource will be the hierarchical parent of the new project. If No organization is an option, you can select it to create your new project as the top level of its own resource hierarchy.- When you're finished entering new project details, click Create.-### 2. Create a new role with permissions required by the service account+## 2. Enable billing in the GCP Project++In order to enable the Cloud Run API, billing must be enabled in this project. Navigate to the [Billing](https://console.cloud.google.com/billing) screen in Google Cloud Console. Follow the on-screen prompts to create a billing account, and then link the new project to this billing account.++## 3. Setup Permissions / APIs / Service Account in GCP++This can be achieved by either following the instructions for using Terraform within GCP Cloud Shell (recommended) or following the instructions for clicking through the GCP Console. The former is the preferred method as it minimises the risk of missing an instruction.++### Using Terraform within GCP Cloud Shell:++_Note, this process does not require an understanding of Terraform._++**What is Google Cloud Shell?**+Google Cloud Shell is a browser-based command-line interface (CLI) for managing resources and applications hosted on Google Cloud Platform (GCP). It provides a virtual machine with pre-installed command-line tools and utilities, including the Google Cloud SDK and Terraform.++Google Cloud Shell is fully integrated with GCP, which means that you can access your projects, resources, and services directly from the command line without having to switch between multiple interfaces. Additionally, Cloud Shell offers a persistent disk for storing your data and files, as well as a web-based code editor for editing files and running scripts.++This means that you can clone a github repo, run a couple of Terraform commands, and have a Remotion ready GCP project in minutes π.++1. In the top right hand corner of the screen, click the Activate Cloud Shell icon+ <img src="readmeImages/selectCloudShell.jpg" width="200" />+2. Within the Cloud Shell, type+`git clone https://github.com/UmungoBungo/remotion-gcp-terraform.git remotion-gcp-terraform/`+<!-- ToDo - host this in the official Remotion repo -->+3. Change directory into the new folder+ `cd remotion-gcp-terraform/`+4. Within the terraform file, there is a variable named project_id. This needs to be set to your newly created Remotion project. Because we are already authenticated with GCP when using the Cloud Shell, we can set this variable using the following command:+ `export TF_VAR_project_id=$(gcloud config get-value project)`+5. As terraform is natively available in Cloud Shell, we can begin using terraform commands without further installation. Run the following command;+ `terraform init`+ _Explanation: When you run `terraform init`, Terraform will download any required provider plugins and modules and create a .terraform directory in your working directory._+6. Run the following command;+ `terraform plan`+ _Explanation: When you run `terraform plan`, Terraform checks your code to see what resources you're trying to create, update or delete, and then shows you what it will do without actually making any changes._+7. Check the output from the above to ensure you are happy with the changes about to be made to your project. If so, run the following command;+ `terraform apply`+ _Explanation: When you run `terraform apply`, Terraform deploys the resources as defined in the .tf files._+8. Now that the resources have been deployed, we need to get some credentials for the service account, so that we can run Remotion commands remotely. **Note that these keys need to remain secret.** Run the following command;+ `gcloud iam service-accounts keys create key.json [email protected]`+9. The key file has been generated on the virtual machine. Access the client_email using this command;+ `jq '.client_email' key.json`+ and copy that value into your local .env file at the root of your Remotion project, with the key `REMOTION_GCP_CLIENT_EMAIL`. Be sure to also copy over the quotation marks.+10. Access the .private_key using this command;+ `jq '.private_key' key.json`+ and copy that value into your local .env file at the root of your Remotion project, with the key `REMOTION_GCP_PRIVATE_KEY`+11. To be on the safe side, delete the key.json file from the virtual machine;+ `rm key.json`++### Clicking through the console:++### 1. Create a new role with permissions required by the service accountNavigate to the [Role](https://console.cloud.google.com/iam-admin/roles) screen in Google Cloud Console, within IAM & Admin.@@ -37,6 +87,7 @@ Navigate to the [Role](https://console.cloud.google.com/iam-admin/roles) screen- For Role launch stage, select `General Availability`- Click + Add Permissions, and add the following;- iam.serviceAccounts.actAs+ - run.operations.get- run.routes.invoke- run.services.create- run.services.list@@ -50,7 +101,7 @@ Navigate to the [Role](https://console.cloud.google.com/iam-admin/roles) screen- run.services.setIamPolicy- Click the CREATE button-#### 2a. Permission reasons+#### 1a. Permission reasonsFor information only, here are the reasons for the above permissions@@ -81,7 +132,7 @@ For information only, here are the reasons for the above permissions- run.services.setIamPolicy- used to set the IAM policy on a service, to allow unauthenticated invoking, or remove unauthenticated invoking.-### 3. Create a service account in the Google Cloud Console+### 2. Create a service account in the Google Cloud ConsoleNavigate to the [Service Accounts](https://console.cloud.google.com/projectselector2/iam-admin/serviceaccounts/create) screen in Google Cloud Console, within IAM & Admin.@@ -94,7 +145,7 @@ Navigate to the [Service Accounts](https://console.cloud.google.com/projectselec<img src="readmeImages/saRole.png" width="450" />- Click Done to finish creating the service account.-### 4. Save Service Account credentials+### 3. Save Service Account credentialsNavigate to the [Service Accounts](https://console.cloud.google.com/iam-admin/serviceaccounts) screen in Google Cloud Console, within IAM & Admin.@@ -111,7 +162,7 @@ Navigate to the [Service Accounts](https://console.cloud.google.com/iam-admin/se- Within the previously edited .env file in the root of your Remotion project, create a REMOTION_GCP_PROJECT_ID key, and set the key as the ID from the [Dashboard](https://console.cloud.google.com/home/dashboard), under the Project Info card.-### 5. Enable required APIs in the project+### 4. Enable required APIs in the project- Enable the Cloud Run API. Navigate to the [Cloud Run API](https://console.cloud.google.com/apis/library/run.googleapis.com) screen in Google Cloud Console, and click ENABLE. Make sure the correct project is selected in the dropdown in the top left. This is required in order to use Cloud Run.diff --git a/packages/gcp/readmeImages/selectCloudShell.jpg b/packages/gcp/readmeImages/selectCloudShell.jpgnew file mode 100644index 0000000000..f6beabfb9fBinary files /dev/null and b/packages/gcp/readmeImages/selectCloudShell.jpg differdiff --git a/packages/gcp/src/cli/commands/cloud-run/deploy.ts b/packages/gcp/src/cli/commands/cloud-run/deploy.tsindex 9462e5e7e4..a406ce92ab 100644--- a/packages/gcp/src/cli/commands/cloud-run/deploy.ts+++ b/packages/gcp/src/cli/commands/cloud-run/deploy.ts@@ -7,7 +7,6 @@ import {deployCloudRunRevision} from '../../../api/deploy-cloud-run-revision';import {deployNewCloudRun} from '../../../api/deploy-new-cloud-run';import {validateGcpRegion} from '../../../shared/validate-gcp-region';import {validateOverwrite} from '../../../shared/validate-overwrite';-import {validateProjectID} from '../../../shared/validate-project-id';import {validateRemotionVersion} from '../../../shared/validate-remotion-version';import {validateServiceName} from '../../../shared/validate-service-name';import {parsedGcpCli} from '../../args';@@ -20,7 +19,7 @@ export const CLOUD_RUN_DEPLOY_SUBCOMMAND = 'deploy';export const cloudRunDeploySubcommand = async () => {const region = getGcpRegion();const serviceName = parsedGcpCli['service-name'];- const projectID = parsedGcpCli['project-id'];+ const projectID = process.env.REMOTION_GCP_PROJECT_ID as string;const remotionVersion = VERSION;const allowUnauthenticated = parsedGcpCli['allow-unauthenticated'] ?? false;const overwriteService = parsedGcpCli['overwrite-service'] ?? false;@@ -50,10 +49,14 @@ Validating Deployment of Cloud Run Service:validateGcpRegion(region);validateServiceName(serviceName);- validateProjectID(projectID);validateRemotionVersion(remotionVersion);validateOverwrite(overwriteService);+ if (projectID === undefined) {+ Log.error(`REMOTION_GCP_PROJECT_ID not found in the .env file.`);+ quit(0);+ }+const existingService = await checkIfServiceExists({serviceNameToCheck: serviceName,projectID,