Last active
May 19, 2024 15:05
-
-
Save zerojuan/91c4990284a49fc8b689266e92518411 to your computer and use it in GitHub Desktop.
CircleCI build and deploy to Google Cloud Storage website
This file contains hidden or 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
#!/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} |
This file contains hidden or 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
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 |
This file contains hidden or 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
#!/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