Continuous Deployment
Basically,This project was created to help introduce the concept of Continuous Deployment to anyone interested.
Basically how it works is:
- You
git push
to a GitHub (or something else) server. - The
git
server uses a WebHook to connect with a CI/CD system. - The CI/CD thing builds your project, and deploys it somewhere.
Simple, right? This webpage actually, was built with a Continuous Deployment script!
Check out the source code to understand how it works.
How does this project work?
Glad you asked!
- It was created with
create-react-app
. - It uses Travis CI as the CI/CD thing, which starts a new build on
git push
. - When Travis starts a new build, it executes this script.
- It is instructed to use the script, with this script.
- I highly recommend reading the deploy script above. It is heavily documented for you in true Basically fashion, in order to help you understand what's actually happening.
- After Travis is done, everything's deployed on
gh-pages
, and things are live.
🗝
What's this about keys? Basically, Travis is going to be pushing to your GitHub account. Travis needs to be able to say HEY IM TEJAS in order to use Tejas' GitHub: it needs my key; my SSH key.
And so, I've got to:
- Generate some keys:
- In a terminal, type:
ssh-keygen -t rsa -b 4096 -C "[email protected]" # YOUR EMAIL HERE
- It'll ask you where to save it. Save the key somewhere familiar.
- It'll ask you for a passphrase. I usually leave this blank.
- It'll generate 2 files for you:
- One ending with .pub (make a note of this).
- And one with the name you gave it.
- In a terminal, type:
- Encrypt them with Travis:
- Make sure you have the Travis CLI installed.
- In the terminal, run:
travis encrypt-file WHATEVER_YOU_NAMED_YOUR_KEY
- It will then create a
.enc
file based your key's filename. - It'll also say something back to you like:
openssl aes-256-cbc -K $encrypted_0a6446eb3ae3_key -iv $encrypted_0a6446eb3ae3_key -blah blah
- Copy the portion where we have
0a6446eb3ae3
written above. You'll need it.
- Add them (the encrypted ones!) to my project:
- At this point, you have add your .enc file to your git repo and commit it.
- You can throw away your key at this point.
- Tell Travis how to decrypt them:
- In your .travis.yml, you'll want to add an
ENCRYPTION_LABEL
with that red thing you copied above. - See this project's .travis.yml as an example.
- In your .travis.yml, you'll want to add an
- Add the keys to my GitHub account:
- The last step is actually adding the public part of your key to your GitHub profile to say "yes, the Travis thing using my key is basically me".
- Go here, click the green New SSH Key, and paste the contents of your .pub file in the
key
field, giving it an appropriate title. - Bam!
Whew! Now, Travis can properly push your shiny new gh-pages
to your GitHub project.
Thanks to
- ThoughtWorks for an excellent article on the subject.