Skip to content

Instantly share code, notes, and snippets.

@timoyuen
Forked from troyharvey/.gitlab-ci.yml
Created August 19, 2020 15:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save timoyuen/2e6076ed31039364068c49f233c306c8 to your computer and use it in GitHub Desktop.
Save timoyuen/2e6076ed31039364068c49f233c306c8 to your computer and use it in GitHub Desktop.
Deploy Google Cloud Functions: GitLab CI/CD Pipeline Config File
variables:
GCP_ZONE: us-central1-a
stages:
- npm-install
- push
npm-install:
image: node:8-alpine
stage: npm-install
only:
- master
script:
- cd replaceWithYourCloudFunction
- npm install
artifacts:
paths:
- replaceWithYourCloudFunction/node_modules/
push:
stage: push
image: docker:latest
only:
- master
dependencies:
- npm-install
script:
# Install CA certs, openssl to https downloads, python for gcloud sdk
- apk add --update make ca-certificates openssl python
- update-ca-certificates
# Download and install Google Cloud SDK
- wget https://dl.google.com/dl/cloudsdk/release/google-cloud-sdk.tar.gz
- tar zxvf google-cloud-sdk.tar.gz && ./google-cloud-sdk/install.sh --quiet --usage-reporting=false --path-update=true
- PATH="google-cloud-sdk/bin:${PATH}"
- gcloud --quiet components update
- gcloud components install beta
# Authenticate using the service account stored here: https://gitlab.com/groups/{YOUR_GITLAB_PROJECT}/-/settings/ci_cd
- echo $GCLOUD_SERVICE_KEY > ${HOME}/gcloud-service-key.json
- gcloud auth activate-service-account --key-file ${HOME}/gcloud-service-key.json
# Deploy
- gcloud beta functions deploy replaceWithYourCloudFunction --source=./replaceWithYourCloudFunction --trigger-http
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment