Skip to content

Latest commit

 

History

History
258 lines (154 loc) · 6.76 KB

File metadata and controls

258 lines (154 loc) · 6.76 KB

Deployment Environments: Ship Early, Ship Often

➡️ Slides

Agenda

  1. [5m] Objectives
  2. [10m] Overview: Environments
  3. [15m] Activity: Hiding Secrets
  4. [10m] BREAK
  5. [25m] Activity: Deployment Definitions
  6. [15m] Activity: Playlister Reflection
  7. [20m] Wrap Up: Define a Deployment Plan
  8. Resources & Credits

Objectives

By the end of this class, you'll be able to...

  1. Identify go-to strategies to release web applications.
  2. Recognize and name the environments used during the development life cycle.
  3. Protect private keys and other secrets using dotenv.
  4. Create and deploy live Flask applications on Heroku.

Overview: Environments

1️⃣ Development

  • On your computer, otherwise known as "locally".
  • Where ALL code updates occur.
  • Connects to a database on your computer.
  • Run your tests here before pushing your code.
  • Changes will not affect the live website.
  • EXAMPLE: http://localhost:5000

2️⃣ Test / Staging

  • All of the code now lives on a server.
  • As similar to production as possible.
  • EXAMPLE: https://projectname-test.herokuapp.com

3️⃣ Production

  • Highest priority environment.
  • Where we "go live", "launch", or "ship" our website.
  • Real live people will find bugs you missed while coding!
  • EXAMPLE: https://www.projectname.com

Minor Differences Allowed

Environments can vary, but should be as similar as possible.

Acceptable differences include:

  • Environment variables and other configuration settings.
  • Different data in your local database versus production.
  • Static assets in staging and production (.css, .js) are typically minified into a single, large file.

Public Service Announcement

When an unhandled exception occurs in your application, your website will go offline. This is known as downtime.

Even minor differences can cause these kinds of unanticipated failures in production --- even if it worked perfectly in development!

Environment Variables

Sometimes you can't save everything into your code files because that would be insecure. For example, if you use a third party service like Amazon Web Services (AWS), then there will be sensitive keys that if you expose to the world on a public Github repo, hackers will steal them and use your codes to rack up hundreds of dollars in fees.

To secure such data, developers use environment variables,stored locally and in production.

Activity: Hiding Secrets

Protect Your OpenWeather API Key

Why is it important to hide your API key?

  1. More secure
  1. Industry-standard practice

Install Dotenv

Add the python-dotenv package to your Gif Search project:

$ pip3 install python-dotenv

Add your API Key

Add a .env file with the following key-value pair:

TENOR_API_KEY=yourapikeyvalue
  • Keys and their values are separated by =
  • No spaces in the key
  • PROTIP: Don't use quotes in this file!

Load Dotenv

Add the following code at the very top of your app.py file:

import os

from dotenv import load_dotenv
load_dotenv()

This code imports the python-dotenv library and loads all the settings in your .env file!

Access our Key

Grab any setting you defined in the .env file via os.getenv():

import os

from dotenv import load_dotenv
load_dotenv()

TENOR_API_KEY = os.getenv("TENOR_API_KEY")

Ignore Dotenv

Add .env to the bottom of your .gitignore file.

BREAK [10m]

Heroku

What is Heroku?

Heroku is a turn-key server solution that serves as the staging and production servers for many, including Make School!

It combines web hosting functionality with a rich marketplace of plugins to extend and enhance your server --- like an app store for your web application!

Activity: Deployment Definitions [25m]

Using the Glossary of Heroku Terminology, use your own words to define the following terms:

  1. App
  2. Add-On
  3. Config Var
  4. Dyno
  1. Process Type
  2. Procfile
  3. Release

Discuss, then spend about 15 minutes writing one short sentence for each term.

[15m] Activity: Playlister Reflection

Write down any issues you had while deploying Playlister.

  • What broke?
  • What didn't make sense?
  • Did anyone around you face the same issues?

After a few minutes, we'll talk about the challenges you encountered!

Define a Deployment Plan [15m]

  1. Consider the features you'll be developing for your contractor project.
  2. Write down three opportunities to push to staging during your development cycle.
  3. Review these potential deployments with someone you haven't worked with yet!

Announcements

Contractor Project MVP due on Monday, Dec. 9

Quiz 3 on Thursday, Dec. 5 - Study Guide now available

There will be a Quiz Make-up/Retake session on Friday, Dec. 6 at 12:30PM - Or schedule with me individually.

Vibe Check

Go to https://make.sc/bew1.1-vibe-check and fill out the form.

Resources & Credits