liveBook · Manning

Chapter 10: Deploy your application

What you will learn in chapter 10 of Rust Web Development

The introduction explains why deployment requires externally supplied configuration and previews production build and packaging topics.

After this chapter you will be able to

What it builds on

Section by section

Introduction

The introduction explains why deployment requires externally supplied configuration and previews production build and packaging topics.

Key terms: environment variables, CLI commands, hardcoded, database URL

10.1 Setting up your application through environment variables

This section explains why a deployable binary needs external configuration and compares config files, command-line inputs, and dotenv files.

Key terms: binary, database port, logging levels, API keys, config files, JSON, TOML, secrets, command-line inputs, CLI inputs

10.1.1 Set up config files

This section shows how to move web service configuration into a TOML file using config-rs and explains the benefits of separating settings from code.

Key terms: config-rs, toml feature flag, setup.toml, main.rs, parameters, source code, local setup

10.1.2 Accept command-line inputs for your application

This section explains how command-line arguments provide flexible application configuration and how the example parses them with clap.

Key terms: CLI parameters, config file, std::env::args, clap, Args, Cargo.toml, cargo run, compiled binary, arguments

10.1.3 Read and parse environment variables into your web service

This section configures the web service with environment variables loaded from a .env file and discusses handling secrets and missing values.

Key terms: environment variables, dotenv, .env, port, host IP, .gitignore, paseto encryption key, BAD_WORDS_API_KEY, profanity.rs, environment variable

10.2 Compiling your web service for different environments

This section introduces Cargo build profiles and why cross-compilation matters when development and production environments differ.

Key terms: Cargo, dev profile, release profile, cargo build, --release, cross-compilation, binary, operating system, production

10.2.1 Development vs. release flag when building your binary

This section compares Cargo’s development and release build profiles and explains how optimization settings affect compilation and the resulting binary.

Key terms: cargo build, dev profile, release profile, --release, Cargo.toml, opt-level, optimization, compile times, binary size

10.2.2 Cross-compile your binary for different environments

This section explains Rust compilation targets, static versus dynamic linking, and using musl to build a Linux binary.

Key terms: targets, rustup target list, Rustup, dynamically linked, statically linked, libraries, musl, x86_64-unknown-linux-musl, standard C library

10.3 Using build.rs in your build process

This section explains how to use a Cargo build script to generate a build version and log it when the application starts.

Key terms: build.rs, Cargo, business logic, cargo:rustc-env, platforms, build-dependencies, env!, Tracing, commit hash, log level

10.4 Creating the right Docker image for your web service

This section introduces Docker containers as a way to package the Rust web service for local development and deployment.

Key terms: Docker container, local development environment, deployment pipeline

10.4.1 Create a statically linked Docker image

This section explains why and how to build a statically linked Rust binary for a Docker container using a musl target.

Key terms: statically linked, self-contained binary, Docker image, musl target, Rustup, statically link, Cargo, release profile, cross-compilation, Docker container

10.4.2 Set up a local Docker environment with docker-compose

This section sets up a local Docker Compose environment for the web service and PostgreSQL, adjusts container configuration, and checks the resulting service.

Key terms: Docker Compose, docker-compose.yml, docker-compose up, curl, connection URL, localhost, 127.0.0.1, 0.0.0.0, PostgreSQL, .env

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

The section extracts server configuration into a module and prepares environment-specific settings for running the service with or without Docker.

Key terms: config module, main.rs, configuration parameters, PostgreSQL, PSQL, .env, rustwebdev, environment variables, .gitignore, API keys

10.5 Summary

Where this is used later

Concepts explained in this chapter

← Chapter 9: Add authentication and authorization Chapter 11: Testing your Rust application →

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.