Instantly share code, notes, and snippets.

Embed
What would you like to do?
Automatic deployment to Google Cloud Functions with Travis-ci
# Use Dockerized infrastructure
sudo: false
# Use node_js environnement
language: node_js
node_js:
- "6"
# Cache Gcloud SDK between commands
cache:
yarn: true
directories:
- "$HOME/google-cloud-sdk/"
env:
global:
install:
- npm install
script:
- npm test
before_deploy:
- if [ ! -d "$HOME/google-cloud-sdk/bin" ]; then rm -rf $HOME/google-cloud-sdk; export CLOUDSDK_CORE_DISABLE_PROMPTS=1; curl https://sdk.cloud.google.com | bash; fi
- source /home/travis/google-cloud-sdk/path.bash.inc
- gcloud --quiet version
- gcloud --quiet components update
# use the decrypted service account credentials to authenticate the command line tool
# get the encrypted variable names from travis cli: https://docs.travis-ci.com/user/encrypting-files/
- openssl aes-256-cbc -K $TRAVIS_ENCRYPTED_key -iv $TRAVIS_ENCRYPTED_iv -in gcloud-service-key.json.enc -out gcloud-service-key.json -d
- gcloud auth activate-service-account --key-file gcloud-service-key.json
- gcloud config set project PROJECT
deploy:
- provider: script
script:
# change PROJECT and REPO to the values from the cloud console: https://console.cloud.google.com/code/develop
- gcloud --quiet beta functions deploy mailer --source-url https://source.developers.google.com/p/PROJECT/r/REPO --source-path / --trigger-http
skip_cleanup: true
on:
branch: master
@HarvsG

This comment has been minimized.

HarvsG commented Jun 6, 2017

# change PROJECT and REPO to the values from the cloud console: https://console.cloud.google.com/code/develop
      - gcloud --quiet beta functions deploy mailer --source-url https://source.developers.google.com/p/PROJECT/r/REPO --source-path / --trigger-http

could read

# change FUNCTION_NAME, PROJECT and REPO to the values from the cloud console: https://console.cloud.google.com/code/develop
      - gcloud --quiet beta functions deploy  FUNCTION_NAME --source-url https://source.developers.google.com/p/PROJECT/r/REPO --source-path / --trigger-http

where FUNCTION_NAME is the main function found in index.js in the format exports.FUNCTION_NAME = (request, response) => {

please see and feel free to copy my fork, as unfortunately, gist does not support pull requests

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment