10 Deploy your application

 

This chapter covers

  • Setting your application up to read environment variables.
  • Optimizing your built binary for production.
  • Cross-compiling your service to different operating systems.
  • Creating a more complex build process before releasing your code.
  • Creating optimized Docker files.
  • Setting up a local Docker environment with docker-compose.

After adding authentication and authorization in chapter 9, we can shift gears and leave writing business logic behind. We are at a stage where all code is written and done, and it is time to show the world what we built. The compiler didn’t just help us greatly in creating a solid codebase, it also shines when thinking about shipping your code to production. Cross-compiling the binary for different architectures, creating the smallest binary possible and deploying it via Docker (or without) to different services.

Before we can do that, however, we must go through the code and look for parameters we hardcoded in our application, which we have to extract and feed it either from environment variables or through CLI commands. Once we move our code from the local machine to a third-party hosting provider, we lose control over on which port we have to listen to and how the database URL is defined. These settings are getting fed by the third-party-provider (or DevOps teams) through environment variables.

10.1 Setting up your application through environment variables

 
 
 
 

10.1.1 Setting up config files

 
 
 

10.1.2 Accept command line inputs for your application

 
 
 
 

10.1.3 Read and parse environment variables into your web service

 

10.2 Compile your web service for different environments

 
 
 

10.2.1 Development vs release flag when building your binary

 
 

10.2.2 Cross compile your binary for different environments

 
 
 

10.3 Using build.rs in your build process

 
 
 
 

10.4 Creating the right Docker image for your web service

 
 
 

10.4.1 Create a statically linked Docker image

 

10.4.2 Setting up a local Docker environment with docker-compose

 
 
 

10.4.3 Extracting the configuration of the web server into a new module

 
 

10.5 Summary

 
 
 
sitemap

Unable to load book!

The book could not be loaded.

(try again in a couple of minutes)

manning.com homepage
test yourself with a liveTest