Skip to content

Instantly share code, notes, and snippets.

@BaconSoap
Last active October 15, 2020 21:40
Show Gist options
  • Save BaconSoap/b219d2e31b76fad494f8e9b508ca71df to your computer and use it in GitHub Desktop.
Save BaconSoap/b219d2e31b76fad494f8e9b508ca71df to your computer and use it in GitHub Desktop.
CircleCI config for building/deploying a GatsbyJS site
# 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
@yepstepz
Copy link

yepstepz commented Mar 31, 2020

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment