We already had "Enabled Billing" Simarjot Singh's account using our mentor's credit card. So we decided to host the express app on Google Cloud. The problem was that the google cloud project on which billing was enabled was on Simarjot's account. So he added me as a collaborator in the project and I started the horing process.
Start by creating a Google Cloud account. With this account, you get $300 in free credits, plus free usage of over 20 products, up to monthly limits.
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
Make sure that billing is enabled for your Google Cloud project.
To initialize the gcloud CLI, run the following command:
gcloud init
gcloud config set projectPROJECT_ID
If you are under a domain restriction organization policy restricting unauthenticated invocations for your project, you will need to access your deployed service as described under Testing private services.
Enable the Cloud Run Admin API and the Cloud Build API:
gcloud services enable run.googleapis.com \ cloudbuild.googleapis.com
After the Cloud Run Admin API is enabled, the Compute Engine default service account is automatically created.
gcloud projects add-iam-policy-bindingPROJECT_ID \ --member=serviceAccount:PROJECT_NUMBER -compute@developer.gserviceaccount.com \ --role=roles/cloudbuild.builds.builder
Replace PROJECT_NUMBER
with
your Google Cloud
project number, and PROJECT_ID
with your Google Cloud
project ID. For detailed instructions on how to find your project ID, and project number,
see Creating
and managing projects.
Granting the Cloud Build Service Account role to the Compute Engine default service account takes a couple of minutes to propagate.
To create and deploy a Node.js service, follow these steps:
Create a new directory named helloworld
and change
directory
into it:
mkdir helloworld
cd helloworld
Create a package.json
file with the following contents:
In the same directory, create a index.js
file, and copy
the following
lines into it:
This code creates a basic web server that listens on the port defined by the
PORT
environment variable.
Your app is finished and ready to be deployed.
Important: This quickstart assumes that you have owner or editor roles in the project you are using for the quickstart. Otherwise, refer to the Cloud Run Source Developer role for the required permissions for deploying a Cloud Run resource from source.
Deploy from source automatically builds a container image from source code and deploys it.
To deploy from source:
In your source code directory, deploy the current folder using the following command:
gcloud run deploy --source .
When you are prompted for the service name, press Enter to accept the
default name, for example helloworld
.
If you are prompted to enable additional APIs on the project,
for example, the Artifact Registry API, respond by pressing
y
.
When you are prompted for region: select the region
of your choice, for example us-central1
.
If you are prompted to create a repository in the specified region, respond by
pressing y
.
If you are prompted to allow unauthenticated invocations:
respond y
. You might not see this prompt if
there is a domain
restriction organization policy that prevents it; for more details see the
Before you begin section.
Then wait a few moments until the deployment is complete. On success, the command line displays the service URL.
Visit your deployed service by opening the service URL in a web browser.
During the initialization step, I was encountering the following error Basically, it is saying that I do not have the access to activate googleapis for this project from my account. That means I did not have administrative previliges. Even though Simarjot had granted me complete access to the project, this error message kept on showing. Then after so many attempts, one time it suddenly worked and out endpoint is now hosted on https://punjabi-transcript-82115345315.asia-southeast2.run.app/transcript.