Last active
October 15, 2020 21:40
-
-
Save BaconSoap/b219d2e31b76fad494f8e9b508ca71df to your computer and use it in GitHub Desktop.
CircleCI config for building/deploying a GatsbyJS site
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
# Javascript Node CircleCI 2.0 configuration file | |
# | |
# Check https://circleci.com/docs/2.0/language-javascript/ for more details | |
# | |
version: 2 | |
jobs: | |
build-job: | |
docker: | |
- image: circleci/node:8.9.3 | |
working_directory: ~/repo | |
steps: | |
- checkout | |
# Download and cache dependencies | |
- restore_cache: | |
keys: | |
- v1-dependencies-{{ checksum "yarn.lock" }} | |
- v1-dependencies- | |
- run: yarn install | |
- save_cache: | |
paths: | |
- node_modules | |
key: v1-dependencies-{{ checksum "yarn.lock" }} | |
# build | |
- run: | |
name: Compile gatsbyjs site | |
command: yarn build | |
- persist_to_workspace: | |
root: ./ | |
paths: | |
- public | |
deploy-staging-job: | |
docker: | |
- image: circleci/node:8.9.3 | |
working_directory: ~/repo | |
steps: | |
- attach_workspace: | |
at: ./ | |
- add_ssh_keys | |
- run: | |
name: known_hosts sadness | |
command: ssh-keyscan -H $SITE_SSH_HOST >> ~/.ssh/known_hosts | |
- run: | |
name: remove existing files | |
command: ssh "$SITE_SSH_USER@$SITE_SSH_HOST" "rm -rf /var/www/$STAGING_URL/*" | |
- run: | |
name: scp files | |
command: scp -r public "$SITE_SSH_USER@$SITE_SSH_HOST:/var/www/$STAGING_URL/" | |
deploy-prod-job: | |
docker: | |
- image: circleci/node:8.9.3 | |
working_directory: ~/repo | |
steps: | |
- attach_workspace: | |
at: ./ | |
- add_ssh_keys | |
- run: | |
name: known_hosts sadness | |
command: ssh-keyscan -H $SITE_SSH_HOST >> ~/.ssh/known_hosts | |
- run: | |
name: remove existing files | |
command: ssh "$SITE_SSH_USER@$SITE_SSH_HOST" "rm -rf /var/www/$PROD_URL/*" | |
- run: | |
name: scp files | |
command: scp -r public "$SITE_SSH_USER@$SITE_SSH_HOST:/var/www/$PROD_URL/" | |
workflows: | |
version: 2 | |
build_and_deploy: | |
jobs: | |
- build-job: | |
filters: | |
branches: | |
only: | |
- master | |
- develop | |
- deploy-staging-job: | |
filters: | |
branches: | |
only: | |
- develop | |
requires: | |
- build-job | |
- deploy-prod-job: | |
filters: | |
branches: | |
only: | |
- master | |
requires: | |
- build-job |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
i've served my gatsby build by docker container with nginx, and found out that 74 line makes nginx fall with 403 error.
i rewrote it like this:
- run:
name: remove existing files
command: ssh "$SITE_SSH_USER@$SITE_SSH_HOST" "rm -rf /var/www/$PROD_URL/public/*"
you don't need restart full container than, it just works