This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export TRIGGER_NAME=events-cal-trigger | |
export RUN_SERVICE=helloworld-events | |
export PROJECT_NUMBER="$(gcloud projects describe $(gcloud config get-value project) --format='value(projectNumber)')" | |
gcloud eventarc triggers create $TRIGGER_NAME \ | |
--destination-run-service=$RUN_SERVICE \ | |
--service-account=${PROJECT_NUMBER}-compute@developer.gserviceaccount.com \ | |
--event-filters="type=google.cloud.audit.log.v1.written" \ | |
--event-filters="serviceName=cloudfunctions.googleapis.com" \ | |
--event-filters="methodName=google.cloud.functions.v1.CloudFunctionsService.CreateFunction" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Use the official Node.js 12 image. | |
# https://hub.docker.com/_/node | |
FROM node:12 | |
# Create and change to the app directory. | |
WORKDIR /usr/src/app | |
# Copy application dependency manifests to the container image. | |
# A wildcard is used to ensure both package.json AND package-lock.json are copied. | |
# Copying this separately prevents re-running npm install on every code change. | |
COPY package*.json ./ | |
# Install production dependencies. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { serve } from "https://deno.land/std@0.89.0/http/server.ts"; | |
import "https://deno.land/x/dotenv/mod.ts"; | |
const PORT = Deno.env.get('PORT') || 8080; | |
const s = serve(`0.0.0.0:${PORT}`); | |
const body = new TextEncoder().encode("Hello, Deno\n"); | |
console.log(`Server started on port ${PORT}`); | |
for await (const req of s) { | |
req.respond({ body }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <google/cloud/functions/http_request.h> | |
#include <google/cloud/functions/http_response.h> | |
#include <nlohmann/json.hpp> | |
namespace gcf = ::google::cloud::functions; | |
gcf::HttpResponse hello_world_http(gcf::HttpRequest request) { | |
auto greeting = [r = std::move(request)] { | |
auto request_json = nlohmann::json::parse(r.payload(), /*cb=*/nullptr, | |
/*allow_exceptions=*/false); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "run-workflow-function", | |
"main": "index.js", | |
"scripts": { | |
"start": "functions-framework --target=runWorkflow" | |
}, | |
"dependencies": { | |
"@google-cloud/functions-framework": "^1.7.1", | |
"@google-cloud/workflows": "^1.1.0" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const projectId = process.env.PROJECT_ID; | |
/** | |
* Run Workflow Cloud Function | |
*/ | |
exports.runWorkflow = async (req, res) => { | |
if (req.method !== 'POST') { | |
return res.status(405).send('Only POST method is allowed'); | |
} | |
const workflowsAPI = await callWorkflowsAPI(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Configuration | |
export PROJECT_ID=$(gcloud config get-value core/project) | |
# Deploy Workflow | |
gcloud workflows deploy myFirstWorkflow \ | |
--source=myFirstWorkflow.yaml | |
# Deploy (private) Function | |
gcloud functions deploy runWorkflowFunction \ | |
--runtime nodejs12 \ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const vision = require('@google-cloud/vision'); | |
const visionClient = new vision.ImageAnnotatorClient(); | |
const {Firestore} = require('@google-cloud/firestore'); | |
const firestore = new Firestore(); | |
const trackedAnimals = ['raccoon', 'alpaca', 'peacock', 'dog', 'gecko', 'squirrel', 'red panda']; | |
/** | |
* Triggered from a change to a Cloud Storage bucket. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "sheets-on-run", | |
"main": "index.js", | |
"scripts": { | |
"start": "functions-framework --target=addRow" | |
}, | |
"dependencies": { | |
"@google-cloud/functions-framework": "^1.6.0", | |
"googleapis": "^58.0.0" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const path = require('path'); | |
const {google} = require('googleapis'); | |
const sheets = google.sheets('v4'); | |
// TODO: Add your Sheet ID | |
// https://docs.google.com/spreadsheets/d/2L2LpYPyxJQTf14OLM6mVuiou88MsEi4Q-IUUxswNlfe/edit | |
const SPREADSHEET_ID = '2L2LpYPyxJQTf14OLM6mVuiou88MsEi4Q-IUUxswNlfe'; | |
/** | |
* Appends row data to the Google Sheet |