Basically, Continuous Deployment
8 |10 |
12 | This project was created to help introduce the concept of Continuous Deployment to anyone 13 | interested. 14 |
15 |18 | Basically how it works is: 19 |
20 |-
21 |
-
22 | You
git pushto a GitHub (or something else) server. 23 |
24 | -
25 | The
gitserver uses a WebHook to connect with a CI/CD system. 26 |
27 | - The CI/CD thing builds your project, and deploys it somewhere. 28 |
Simple, right? This webpage actually, was built with a Continuous Deployment script!
32 |35 | 36 | Check out the source code 37 | {" "} 38 | to understand how it works. 39 |
40 |42 |
43 | How does this project work? 44 |
45 |Glad you asked!
47 |-
49 |
-
50 | It was created with{" "}
51 |
52 | 53 | create-react-app 54 | 55 |. 56 |
57 | -
58 | It uses Travis CI as the CI/CD thing, which starts a new build on{" "}
59 |
git push. 60 |
61 | -
62 | When Travis starts a new build, it executes{" "}
63 | this script.
64 |
-
65 |
- 66 | It is instructed to use the script, with{" "} 67 | 68 | this script. 69 | 70 | 71 |
73 | - 74 | I highly recommend reading the deploy script above. It is heavily documented for you in true{" "} 75 | Basically fashion, in order to help you understand what's actually happening. 76 | 77 |
-
78 | After Travis is done, everything's deployed on{" "}
79 |
80 | gh-pages 81 |, and things are live. 82 |
83 |
85 |
What's this about keys? 🗝
86 |88 | Basically, Travis is going to be pushing to your GitHub account. Travis needs to be able to say HEY IM TEJAS 89 | in order to use Tejas' GitHub: it needs my key; my SSH key. 90 |
91 |And so, I've got to:
94 |-
95 |
-
96 | Generate some keys:
97 |
-
98 |
-
99 | In a terminal, type:
100 |ssh-keygen -t rsa -b 4096 -C "hello@tej.as" # YOUR EMAIL HERE101 |
102 | - It'll ask you where to save it. Save the key somewhere familiar. 103 |
- It'll ask you for a passphrase. I usually leave this blank. 104 |
-
105 | It'll generate 2 files for you:
106 |
-
107 |
- 108 | One ending with .pub (make a note of this). 109 | 110 |
- And one with the name you gave it. 111 |
113 |
115 | -
99 | In a terminal, type:
-
116 | Encrypt them with Travis:
117 |
-
118 |
- 119 | Make sure you have the{" "} 120 | 121 | Travis CLI 122 | {" "} 123 | installed. 124 | 125 |
-
126 | In the terminal, run:
127 |travis encrypt-file WHATEVER_YOU_NAMED_YOUR_KEY128 |
129 | -
130 | It will then create a
.encfile based your key's filename. 131 |
132 | -
133 | It'll also say something back to you like:
134 |135 | openssl aes-256-cbc -K $encrypted_ 136 | 0a6446eb3ae3 137 | _key -iv $encrypted_0a6446eb3ae3_key -blah blah 138 |139 |
140 | - 141 | Copy the portion where we have green text above. You'll need 142 | it. 143 | 144 |
146 | -
147 | Add them (the encrypted ones!) to my project:
148 |
-
149 |
- At this point, you have add your .enc file to your git repo and commit it. 150 |
- You can throw away your key at this point. 151 |
153 | -
154 | Tell Travis how to decrypt them:
155 |
-
156 |
-
157 | In your{" "}
158 |
159 | .travis.yml
160 | , you'll want to add an
ENCRYPTION_LABELwith that red thing you copied above. 161 |
162 | - 163 | See{" "} 164 | 165 | this project's .travis.yml 166 | {" "} 167 | as an example. 168 | 169 |
171 | -
157 | In your{" "}
158 |
159 | .travis.yml
160 | , you'll want to add an
-
172 | Add the keys to my GitHub account:
173 |
-
174 |
- 175 | The last step is actually adding the public part of your key to your GitHub profile to say "yes, the 176 | Travis thing using my key is basically me". 177 | 178 |
-
179 |
180 | Go here
181 | , click the green New SSH Key, and paste the contents of your .pub file in the{" "}
182 |
keyfield, giving it an appropriate title. 183 |
184 | - Bam! 185 |
187 |
191 | Whew! Now, Travis can properly push your shiny new gh-pages to your GitHub project.
192 |