Skip to content

Instantly share code, notes, and snippets.

@zerojuan
Last active February 3, 2021 21:29
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zerojuan/91c4990284a49fc8b689266e92518411 to your computer and use it in GitHub Desktop.
Save zerojuan/91c4990284a49fc8b689266e92518411 to your computer and use it in GitHub Desktop.
CircleCI build and deploy to Google Cloud Storage website
#!/bin/bash
echo $GCLOUD_SERVICE_KEY > ${HOME}/gcloud-service-key.json
gcloud auth activate-service-account --key-file=${HOME}/gcloud-service-key.json
gcloud --quiet config set project ${GOOGLE_PROJECT_ID}
version: 2
defaults:
working_directory: /tmp
jobs:
build:
docker:
- image: circleci/node:chakracore-8.11.1
steps:
- checkout
- restore_cache:
keys:
- v1-dependencies-{{ checksum "package.json" }}
- run:
name: Install dependencies
command: npm install
- save_cache:
paths:
- node_modules
key: v1-dependencies-{{ checksum "package.json" }}
- run:
name: Try to install
command: npm run build
- run:
name: Make build directory
command: mkdir /tmp/workspace
- run:
name: Copy dist to the workspace directory
command: cp -r dist /tmp/workspace
- run:
name: Copy build scripts to workspace
command: cp -r build /tmp/workspace
- persist_to_workspace:
root: /tmp/workspace
paths:
- dist
- build
deploy:
docker:
- image: google/cloud-sdk
environment:
STORAGE_BUCKET: website.com
steps:
- attach_workspace:
at: /tmp/workspace
- run:
name: Initialize gcloud
command: /tmp/workspace/build/authgcloud.sh
- run:
name: list files
command: ls /tmp/workspace/dist
- run:
name: deploy
command: /tmp/workspace/build/deploy.sh
workflows:
version: 2
build_deploy:
jobs:
- build
- deploy:
requires:
- build
filters:
branches:
only: master
#!/bin/bash
echo "Copying build to Storage"
gsutil defacl ch -u AllUsers:READER gs://$STORAGE_BUCKET
gsutil rsync -R /tmp/workspace/dist gs://$STORAGE_BUCKET
gsutil setmeta -h "Cache-Control:private, max-age=0, no-transform" \
gs://$STORAGE_BUCKET/*.js
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment