ObrienlabsDev / eventstream

eventstream app
Apache License 2.0
0 stars 0 forks source link

eventstream serverless GCP example #6

Open obriensystems opened 1 month ago

obriensystems commented 1 month ago

moved tohttps://github.com/ObrienlabsDev/biometric-gcp-functions/issues/1 see https://github.com/ObrienlabsDev/rest-client-java/blob/main/gcp-cloud-functions/HelloHttpFunction.java

20240520

obriensystems commented 1 month ago

project creation/deletion


ichael@cloudshell:~/eventstream-biometric-old/eventstream/eventstream-nbi/src (eventstream-biometric-9885)$ ./deployment.sh -c true -d false -b eventstream-biometric
-old 
existing project: 
Date: Mon May 20 06:45:54 PM UTC 2024
Timestamp: 1716230754
old
running with create=true delete=false boot_project_id=eventstream-biometric-old
Creating project: eventstream-biometric-3732
STREAM_PROJECT_ID: eventstream-biometric-3732
Updated property [core/project].
Creating KCC project: eventstream-biometric-3732 on folder: 205060695395
Create in progress for [https://cloudresourcemanager.googleapis.com/v1/projects/eventstream-biometric-3732].
Waiting for [operations/cp.6915041450534105295] to finish...done.                                                                                                    
Enabling service [cloudapis.googleapis.com] on project [eventstream-biometric-3732]...
Operation "operations/acat.p2-462231970168-78d439bc-e7dd-4068-b6bf-bb9f117f5dd3" finished successfully.
Updated property [core/project] to [eventstream-biometric-3732].
billingAccountName: billingAccounts/019283-6F1AB5-7AD576
billingEnabled: true
name: projects/eventstream-biometric-3732/billingInfo
projectId: eventstream-biometric-3732
Updated property [core/project].
Updated property [core/project].
Total Duration: 1716230773 sec
Date: Mon May 20 06:46:13 PM UTC 2024
Timestamp: 1716230773
**** Done ****
michael@cloudshell:~/eventstream-biometric-old/eventstream/eventstream-nbi/src (eventstream-biometric-old)$ 

michael@cloudshell:~/eventstream-biometric-old/eventstream/eventstream-nbi/src (eventstream-biometric-9885)$ ./deployment.sh -c false -d true -b eventstream-biometric-old -s eventstream-biometric-9885
existing project: 
Date: Mon May 20 06:44:34 PM UTC 2024
Timestamp: 1716230674
old
running with create=false delete=true boot_project_id=eventstream-biometric-old
Reusing project: eventstream-biometric-9885
STREAM_PROJECT_ID: eventstream-biometric-9885
billingAccountName: ''
billingEnabled: false
name: projects/eventstream-biometric-9885/billingInfo
projectId: eventstream-biometric-9885
Deleted [https://cloudresourcemanager.googleapis.com/v1/projects/eventstream-biometric-9885].

You can undo this operation for a limited period by running the command below.
    $ gcloud projects undelete eventstream-biometric-9885

See https://cloud.google.com/resource-manager/docs/creating-managing-projects for information on shutting down projects.
Total Duration: 1716230681 sec
Date: Mon May 20 06:44:41 PM UTC 2024
Timestamp: 1716230681
**** Done ****
obriensystems commented 1 month ago

cloud function deployment

michael@cloudshell:~/eventstream-biometric-old/eventstream/eventstream-nbi/src (eventstream-biometric-old)$ cd functions/ michael@cloudshell:~/eventstream-biometric-old/eventstream/eventstream-nbi/src/functions (eventstream-biometric-old)$ ls EventstreamBiometricGet.java

michael@cloudshell:~/eventstream-biometric-old/eventstream/eventstream-nbi/src (eventstream-biometric-3732)$ ./deployment.sh -c false -d false -p true -b eventstream-biometric-old -s eventstream-biometric-3732 existing project: Date: Mon May 20 07:02:27 PM UTC 2024 Timestamp: 1716231747 old running with create=false delete=false boot_project_id=eventstream-biometric-old Reusing project: eventstream-biometric-3732 STREAM_PROJECT_ID: eventstream-biometric-3732 provisioning to eventstream-biometric-3732 Preparing function...done.

ERROR: (gcloud.functions.deploy) OperationError: code=3, message=Build failed with status: FAILURE and message: function has neither pom.xml nor already-built jar file; directory has these entries: .googlebuild, EventstreamBiometricGet.java. For more details see the logs at https://console.cloud.google.com/cloud-build/builds;region=us-central1/c884ee61-7447-4673-9791-a7767016bf25?project=462231970168. Total Duration: 1716231801 sec Date: Mon May 20 07:03:21 PM UTC 2024 Timestamp: 1716231801 Done

obriensystems commented 1 month ago

wizard approach

package gcfv2;

import java.io.BufferedWriter;

import com.google.cloud.functions.HttpFunction;
import com.google.cloud.functions.HttpRequest;
import com.google.cloud.functions.HttpResponse;

public class HelloHttpFunction implements HttpFunction {
  public void service(final HttpRequest request, final HttpResponse response) throws Exception {
    final BufferedWriter writer = response.getWriter();
    writer.write("Hello world!");
  }
}

pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
 <modelVersion>4.0.0</modelVersion>

 <groupId>gcfv2</groupId>
 <artifactId>http</artifactId>
 <version>0.0.1</version>
 <name>HTTP Function for Cloud Functions 2nd gen</name>

 <properties>
  <maven.compiler.release>17</maven.compiler.release>
 </properties>

 <dependencies>
   <dependency>
     <groupId>com.google.cloud.functions</groupId>
     <artifactId>functions-framework-api</artifactId>
     <version>1.0.4</version>
   </dependency>
 </dependencies>

</project>
Screenshot 2024-05-20 at 20 06 16
obriensystems commented 1 month ago

moved to https://github.com/ObrienlabsDev/biometric-gcp-functions/issues/1

obriensystems commented 6 days ago

Getting a periodic issue with the logWriter role on the compute service account when running the cloud build under the cloud functions deployment

image

image

adding

# The service account running this build does not have permission to write logs. To fix this, grant the Logs Writer (roles/logging.logWriter) role to the service account.
# set roles/logging.logWriter on project id service account - -compute@developer.gserviceaccount.com

 PROJECT_NUMBER=$(gcloud projects list --filter="${STREAM_PROJECT_ID}" '--format=value(PROJECT_NUMBER)')
 echo "PROJECT_NUMBER: $PROJECT_NUMBER"
 SA_EMAIL=$PROJECT_NUMBER-compute@developer.gserviceaccount.com
 echo "bind $SA_EMAIL"
 gcloud organizations add-iam-policy-binding "${ORG_ID}" --member="serviceAccount:${SA_EMAIL}" --role=roles/logging.logWriter --condition=None --quiet

 echo "wait 60 sec"
 sleep 60