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.