npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

gcp-functions

v0.1.4

Published

#### A package to help with deploying and managing Google Cloud Functions.

Downloads

16

Readme

gcp-functions

A package to help with deploying and managing Google Cloud Functions.

Getting started

Setup Google Cloud

Add .github/workflows/deploy.yml

name: Deploy

on:
  push:
    branches: [main]
  pull_request:
    branches: [main]

env:
  MY_ENV_VALUE: ${{ secrets.MY_ENV_VALUE }}

jobs:
  deploy:
    name: Deploy
    runs-on: ubuntu-latest
    permissions:
      contents: 'read'
      id-token: 'write'
    steps:
      - name: Checkout repository
        uses: actions/checkout@v3

      - name: Login
        uses: 'google-github-actions/auth@v1'
        with:
          token_format: 'access_token'
          credentials_json: ${{ secrets.GCP_CREDENTIALS }}

      - name: 'Set up Cloud SDK'
        uses: 'google-github-actions/setup-gcloud@v1'

      - name: Install dependencies
        run: npm i

      - name: Build GCP functions
        run: npm run gcp-functions build

      - name: Deploy GCP functions
        run: npm run gcp-functions deploy

Create service account

Go to google cloud console and create a service account named "Deploy Service Account" (IAM => Service Account) with the following roles:

  • Cloud Functions Admin
  • Service Account Token Creator
  • Service Account User
  • Cloud Functions Admin

Then go to "Keys" and create a new one. Add it to github secrets as "GCP_CREDENTIALS".

Enable these APIs in Google Cloud Console:

  • Cloud Functions API
  • Cloud Build API
  • Cloud Run API (if using gen2 functions)

Install the package:

npm i gcp-functions

Add the following scripts to your package.json:

{
  "scripts": {
    "functions:build": "npx gcp-functions build",
    "functions:serve": "npx gcp-functions serve",
    "functions:deploy": "npx gcp-functions deploy"
  }
}

Directory structure

- functions/
  - function1.ts
  - function2.ts

Content of the functions

import { Request, Response } from '@google-cloud/functions-framework'

export const contact = async (req: Request, res: Response) => {
  // ...
}

Config file

Create a .gcp-functions file at the root of your project:

{
  "functionsDir": "./functions",
  "buildDir": "./functions/build",
  "runtime": "nodejs20",
  "region": "europe-west6",
  "env": [],
}

Config options

| Option | Description | Default | | ------------ | ---------------------------------------------------------- | ------------------- | | functionsDir | The directory where the functions are located | ./functions | | buildDir | The directory where the functions will be built | ./functions/build | | runtime | The runtime to use for the functions | nodejs20 | | region | The region to deploy the functions to | europe-west6 | | env | An array of environment variables to pass to the functions | [] | | prefix | A prefix to add to the name of the functions in gcp | '' | | generation | The generation of the functions | (gcloud default) | | memory | The memory to allocate to the functions | (gcloud default) | | timeout | The timeout of the functions | (gcloud default) | | maxInstances | The maximum number of instances of the functions | (gcloud default) |