Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Environment Configuration for JavaScript Apps

Environment Configuration for JavaScript Apps

For traditional server-side web apps, environment-specific configuration is handled in a variety of ways, including environment variables, configuration files or password stores. But a front-end web app running in a framework like React or Vue can’t really use these same techniques since they typically run in the browser, not in the server environment. Yet they still need environment-specific configurations.

Fortunately, this problem can be breached at either build-time or run-time. This session demonstrates techniques for both, allowing you to manage your DevOps pipelines to create environment configurations appropriate to your situation.

David Truxall

January 10, 2020
Tweet

More Decks by David Truxall

Other Decks in Technology

Transcript

  1. Why? • Move an app between environments v Different URLs

    v Feature flags v Different server names v Different ports v Different keys v Different certificates • DevOps and Automation
  2. Some Solutions Build Time • .env files • WebPack Run

    Time • Server injection • Mapped with Docker/Kubernetes • Server-side Rendering (SSR)
  3. Kubernetes Container Container Container Container Container Apartment Complex Container Container

    Container Container Container Container Container Container Container Container Container Main Office
  4. .env files Pros • Built-in plumbing Cons • Managed manually

    • Changes not propagated • New devs • Ops problem • Environment-specific builds
  5. WebPack Basics JS JS JS JS CSS Bundle.css CSS JPG

    Optimized PNG WebPack Bundle.js PNG Optimized JPG JS
  6. WebPack Configuration Pros • New team members • Changes propagate

    • Flexibility • Least moving parts • No deployment steps • Default of 2 environments Cons • Hack-y for React • Manual config or eject • Environment-specific builds -> many images • Information may be in the repo • Default of 2 environments
  7. Server-Side Injection Pros • New team members • Changes propagate

    • Management of data • Many environments easier Cons • Node.js vs nginx • Server-side is now code • Server needed for local dev • Hot reloading
  8. K8s Injection Pros • New team members • Changes propagate

    • Management of data • One Image -> many environments • Local vs server separation Cons • Complexity • Testing locally
  9. JavaScript Environment Configuration Build Time • .env files • WebPack

    Runtime • Server injection • Mapped with Docker/Kubernetes