Hi @Sanjay_io ,
Welcome to Google Cloud Community!
Here is the Cloud Run Rest API reference document available from google cloud.
Here's how to enable the Cloud Run API from the Cloud Shell.
gcloud services enable run.googleapis.com
That should produce a successful message similar to this one:
Operation "operations/acf.cc11852d-40af-47ad-9d59-477a12847c9e" finished successfully.
Check out this quickstart in building and deploying a Node.js service in Cloud Run.
Hope this helps.
@anjelisa Thanks lot's 👏 for your response.
I am using the google official node js package
I wan to create Cloud run service from the my code.
I have already node docker image that was i am using.
I have query about create cloud run service from code.
Issue
1. I have I can't able to create cloud run 128Mi. it taking by default 512 Mi, from the Gcp cloud console i was able to create cloud with 128Mi.
2. how to pass the config parameter like allow unauthenticated request,
3. Currency node cloud-run package assign CPU allocated but i want set based on the how to set CPU based on CPU allocation and pricing CPU is only allocated during request processing.
4. how to link the domain.
Hi,
One trick for figuring out commands/methods of libraries/packages is to look at the tests.
From the Google Cloud Run Nodejs Library, there is a test for creating a service - see link. Take a look and see if it helps you out.
To use gRPC include the option {fallback : true} when you invoke the call to create the service (see test, documentation ). Also refer to this doc for more explanation.
To switch to public, you have to set the Iam Policy . See this and this for how to invoke the call and this for the properties of the policy
-- adding working code ---
Newly created cloud run services are private by default. You have to make them public by adding the special allUsers member type to a service and granting it the roles/run.invoker role (see reference). You do this by setting an Iam policy.
Below is working Code (I tested this and it worked)
1. First I created a new cloud run service using the Nodejs library and confirmed it was private by default (i.e. it required authentication)
2. Then I ran the code below to make it public (and I confirmed it became public after running the code below)
const project = <your_project_name>
const location = <location_where_cloud_run_service_was_created> // eg us-east1
const cloud_run_service = <name_of_your_cloud_run_service> // This is the service that you created
// Instantiate a client
const {ServicesClient} = require('@google-cloud/run').v2;
const runClient = new ServicesClient({projectId:project});
async function callSetIamPolicy() {
const resource = `projects/${project}/locations/${location}/services/${cloud_run_service}`
const policy = {
"bindings": [
{
"role": "roles/run.invoker",
"members": ["allUsers"]
}
]
}
// Construct request
const request = {
resource,
policy,
};
// Run request
try{
const response = await runClient.setIamPolicy(request);
return (response)
}catch(err){
console.log('There was an error')
console.log(err)
}
// Invoke the function
callSetIamPolicy()
.then(data =>{
console.log(data);
})
To specify a memory of 128Mi when creating a new service...
The template attribute has a child attribute called containers which in turn has a child attribute called resources. Set it as follows
"resources": {
"limits": {
"memory": "128Mi"
}
}