I have/want a workflow like so:
- Push branch to Bitbucket
- Pull request branch into Master in Bitbucket
- This triggers CircleCI to do a build
- CircleCI deploys the successful build to AWS EC2 instance
I have steps 1-3 working but can't understand what syntax/files I need for the deployment step.
.circleci/config.yml
version: 2
jobs:
- build:
docker:
- image: circleci/node:10.7
steps:
- checkout
- restore_cache:
keys:
- v1-dependencies-{{ checksum "package.json" }}
- v1-dependencies-
- run:
name: Install dependencies
command: npm install
- save_cache:
key: v1-dependencies-{{ checksum "package.json" }}
paths:
- node_modules
- run:
name: Lint code
command: npm run lint
- run:
name: Build app
command: npm run build
- save_cache:
key: v1-build-{{ .Environment.CIRCLE_BRANCH }}-{{ .Environment.CIRCLE_SHA1 }}
paths:
- .next
- deploy:
requires:
- build
workflows:
version: 2
build_and_deploy:
jobs:
- build
- deploy:
requires:
- build
filters:
branches:
only:
- master
I have no idea what is meant to go in the deploy job so as you can see it's nearly empty. I can't find any examples of this online (I find plenty of S3 examples).
Should I somehow link to a deploy script? If so, I found an example that looks a little like this:
#!/bin/bash
BUILD_NUMBER=${CIRCLE_BUILD_NUM}
BRANC_NAME=${CIRCLE_BRANCH}
IMAGE_TAG=${CIRCLE_SHA1}
# Change to project root
cd ../
# Create an archive you make an archive
tar -zcvf project-name.tar.gz .next/
# Upload build to AWS
scp your_project_name.tar.gz ubuntu@your_instance_IP:/home/ubuntu
# Here you extract your archive on EC2 using SSH
ssh ubuntu@your_instance_IP tar -xvzf your_project_name.tar.gz
Can anyone help explain how this all pieces together?