# O Hai --- ## Introduction For those who don't know me, I am: -- * [Recently married to Norma](http://redlinernotes.com/images/married.jpg) * I like when she makes fun of me. -- * [Really into dogs, esp mine](http://redlinernotes.com/images/puppers.jpg) * I like when I make fun of them, which is always. -- * [Really into synths](https://www.instagram.com/p/B-7Of3tBapk/) * I like when they go "boop" -- * [Really into melee](https://gfycat.com/exaltedniftyamericanrobin-melee) * I like when I hit them harder than they hit me -- * Currently a Senior Engineer at [Calendly][calendly] -- * Former Instructor @ [FIS ATL](http://redlinernotes.com/images/graduation_day.jpg) and [TIY ATL](https://www.instagram.com/p/BljO_N4ApN5/) * I like talking to people about code and why computers are ridiculous [calendly]: https://calendly.com/ --- ## The Deployment Lecture -- ### Incoming Hot Take -- I don't like the idea of a deployment lecture. -- What's the transferable skill? Mostly implementation details. -- Use a different language or framework and you're likely to encounter entirely different errors. -- But it's still important to get your apps up. -- #### Outline * Intro * Hot Take / Outline <-- you are here * System Architecture: A Transferable Lesson * Why is this hard? * Wildly try to deploy something live and maybe finish * Q & A / AMA / Let's talk about computers --- ## System Architecture Let's compare and contrast our local environment to a production environment.
-- What are some reasons companies might separate the apps in production? -- * Biggest motivator is probably performance. Scale pieces independently. -- * Frontend changes shouldn't require rebooting rails / full CI run, etc. --- ## Why is this hard? It's not dissimilar the first time you tried to do group work with git. Why was that hard? -- You could previous model the code as being in a _single_ state, but now it's in _multiple_ states depending on whose clone it is! -- Now we revisit that in a new light: the code is running on your machine in one state _under one environment_ and running on a production machine _under another environment_. -- The assumption that your local view is the authoritative one is no longer accurate. -- You will be tempted to debug issues assuming that something is wrong in the code. We've been building this habit in you and it is a good one! -- **It will never help you debug an environment difference.** (Aside: Emcien horror story.) --- ## Deployment Steps -- 0. You installed [Heroku CLI](https://devcenter.heroku.com/articles/heroku-cli) right? -- 1. Update backend to use postgres if not using it already. -- 2. `heroku create $APPNAME && git push heroku master` -- 3. `heroku run rails db:migrate` -- 4. `heroku run rails db:seed` -- 5. Update frontend to parameterize API_ROOT based on NODE_ENV. -- 6. `heroku create $APPNAME --buildpack mars/create-react-app && git push heroku master` -- * Wait, why do I need some special buildpack option? 🤔 -- 7. Don't forget to [enable CORS][enable-cors]! -- 8. 🎉🎉🎉 - Profit [enable-cors]: https://medium.com/@admatbandara/setting-up-cors-to-my-rails-api-a6184e461a0f --- ## Your Life in Production * `heroku logs --tail` - your best friend -- * `heroku run rails c` - the console is also still helpful -- * `heroku run bash` - and you thought you couldn't get to terminal -- * `debugger` and `byebug` - not even once * Consider adding a [pre-commit hook](https://fuzzyblog.io/blog/rails/2019/09/17/tiny-rails-tip-don-t-let-byebug-into-production.html) -- ### Some other gotchas * File uploads on Heroku need to go to S3 or a cloud storage service * Why? Because every heroku deploy creates a brand new server and _throws away the old one_ * API tokens must be specified with `heroku env`! * Why? Because they shouldn't be committed to your code for security reasons. * How to run Rails app? Investigate [foreman][foreman] or do `MY_SECRET=foo rails s` * I get errors deploying about my ruby/bundler version. * This is a mess. Talk to friends or instructors. Suggestion: Switch your repo to whatever is supported. [foreman]: https://thoughtbot.com/blog/foreman-as-process-manager --- ## Q & A ### Let's talk about computers. ## <3 ✨<3