Skip to content

Instantly share code, notes, and snippets.

Avatar

Grant Timmerman grant

View GitHub Profile
@grant
grant / package.json
Last active Dec 19, 2021
Hot Reload Node Functions
View package.json
{
"main": "index.js",
"dependencies": {
"@google-cloud/functions-framework": "^2.1.0"
},
"watch": {
"start": "*.js"
},
"devDependencies": {
"npm-watch": "^0.11.0"
@grant
grant / package.json
Created Dec 19, 2021
Simple Node Function package.json
View package.json
{
"main": "index.js",
"dependencies": {
"@google-cloud/functions-framework": "^2.1.0"
},
"scripts": {
"start": "npx @google-cloud/functions-framework --target=helloWorld"
}
}
@grant
grant / index.js
Created Dec 19, 2021
Simple Node Function
View index.js
const FunctionsFramework = require('@google-cloud/functions-framework');
FunctionsFramework.http('helloWorld', (req, res) => {
res.send('Hot-reload me?');
});
View out.sh
> npm start
> nodejs-docs-samples-esm@0.0.1 start /Users/timmerman/Documents/github/googlecloudplatform/functions-framework-nodejs/docs/esm
> functions-framework --target=esm
Serving function...
Function: esm
Signature type: http
URL: http://localhost:8080/
View index.js
export function esm(req, res) {
res.send(`Hello, ${MY_CONST}!`);
};
View index.js
import {MY_CONST} from './consts.js';
View consts.js
export const MY_CONST = 'ESM';
View package.json
{
"name": "nodejs-ff-esm",
"type": "module",
"engines": {
"node": ">=12.0.0"
},
"scripts": {
"start": "functions-framework --target=esm"
},
"dependencies": {
@grant
grant / setup_iam.sh
Created May 16, 2021
A script that sets up Workflows IAM for a GitHub Action
View setup_iam.sh
# Add secret for project
PROJECT=$(gcloud config get-value project)
gh secret set GCP_PROJECT_ID -b $PROJECT
# Create service account
SERVICE_ACCOUNT=my-wf-service-account
gcloud iam service-accounts create $SERVICE_ACCOUNT
gcloud projects add-iam-policy-binding $PROJECT \
--member "serviceAccount:$SERVICE_ACCOUNT@$PROJECT.iam.gserviceaccount.com" \
--role "roles/workflows.editor"
@grant
grant / deploy-cloud-workflow.yaml
Last active May 18, 2021
A GitHub Workflow that deploys a Cloud Workflow
View deploy-cloud-workflow.yaml
name: Deploy Cloud Workflow
on:
push:
branches:
- main
jobs:
deploy:
name: Deploy Cloud Workflow
runs-on: ubuntu-18.04
steps: