Last active
January 8, 2024 00:38
-
-
Save troyharvey/bae82c86c27a3aa539dea83857ee9ecd to your computer and use it in GitHub Desktop.
Deploy Google Cloud Functions: GitLab CI/CD Pipeline Config File
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
# Update Jan 2024 | |
# Deploying Cloud Functions is much simpler than it was 6 years ago. | |
# I'm leaving the gist in it's original 2018 state for now, | |
# but skip the the recent comments below for a simpler solution. | |
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 |
@muratcorlu, Thanks a lot, I found it later in the day, i've already switched it for the credential part :)
This was a helpful page if you are not familiar with gcloud deploy
https://cloud.google.com/sdk/gcloud/reference/functions/deploy
This + the comments helped me as a template. Thank you so much.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@linceaerian File variable is the type of Pipeline Variable as shown below:
Content will be same. In that case your variable will hold file path of the temporary file that is autmatically created by Gitlab CI. So you will not need to manually create a file and put the content in it.