0% found this document useful (0 votes)
26 views

Task L - Deployment and Production - Agile Web Development With Rails 81

This document discusses deployment and production tasks for a Rails 7 application. It covers configuring PostgresSQL for the database, securely storing secrets, building a Docker image, and deploying the application using Docker Compose. The Docker Compose file defines two services - one for the Postgres database and one for the web application, which will use Nginx and Phusion Passenger to serve the application from a Docker container.

Uploaded by

Taro Chilongoshi
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views

Task L - Deployment and Production - Agile Web Development With Rails 81

This document discusses deployment and production tasks for a Rails 7 application. It covers configuring PostgresSQL for the database, securely storing secrets, building a Docker image, and deploying the application using Docker Compose. The Docker Compose file defines two services - one for the Postgres database and one for the web application, which will use Nginx and Phusion Passenger to serve the application from a Docker container.

Uploaded by

Taro Chilongoshi
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

12/06/2023, 18:09 17.

Task L: Deployment and Production | Agile Web Development with Rails 7

We cover: Chapter 17
Running our application in a
production web server
Configuring the database for
PostGreSQL
Task L:
Securely deploying secrets
Placing all of the above into Deployment and
Docker containers

 
Production
Deployment is supposed to mark a happy point in the lifetime of our ap-
plication. It’s when we take the code that we’ve so carefully crafted and
upload it to a server so that other people can use it. It’s when the beer,
champagne, and hors d’oeuvres are supposed to flow. Shortly thereafter,
our application will be written about in Wired magazine, and we’ll be
overnight names in the geek community.

The reality, however, is that it often takes quite a bit of up-front planning
to pull off a smooth and repeatable deployment of your application.

A bewildering number of options are available for deployment: Ansible,


Capistrano, Chef, and Puppet are all popular choices. Covering all of them
would be the subject of several books. We’re going to focus this chapter
on what effectively is the defacto standard for cloud deployment: Docker.

If you’re not familiar with Docker images, they’re essentially self-con-


tained and portable runtimes that can be deployed by pretty much any
cloud-hosting provider. This means you can build and test your deploy-
ment locally and then choose your cloud provider later, and even change
your mind and move hosts at any time.

At the moment, we’ve been doing all of our work on one machine, though
user interaction with our web server could be done on a separate ma-
chine. On our machine you’ve been making use of the Puma web server,
SQLite 3, various gems you’ve installed, and your application code. Your
code may or may not have also been placed in Git by this point.
https://learning.oreilly.com/library/view/agile-web-development/9798888650288/f_0091.xhtml 1/3
12/06/2023, 18:09 17. Task L: Deployment and Production | Agile Web Development with Rails 7

For deployment, we’re going to make use of two Docker containers. The
web server container will be running a combination of nginx[80] and
Phusion Passenger.[81] This code will access a PostgreSQL database run-
ning in a separate container.[82]

That’s a lot of moving parts! To help us keep track of them all, we’ll be us-
ing Bundler to manage our dependencies and Docker Compose as the tool
to manage the containers.[83] And yet, despite all the moving parts, the
overall definition is remarkably compact:

rails7/depot_td/docker-compose.yml
 version: ​
​ "​3.8"​
 

 services:

 
​ db:
 
​ image: ​
postgres:14​
 
​ volumes:
 
​ - p
​gdata:/var/lib/postgresql/data​
 
​ environment:
 
​ POSTGRES_PASSWORD: ​
password​
 

 
​ web:
 
​ build: ​
.​
 
​ volumes:
 
​ - .
​/log:/home/app/depot/log​
 
​ secrets:
 
​ - source: ​
master_key​
 
​ target: ​
/home/app/depot/config/master.key​
 
​ ports:
 
​ - "
​​8001:80"​
 
​ depends_on:
 
​ - d
​b​
 

 secrets:

 
​ master_key:
 
​ file: .
​/config/master.key​
 

https://learning.oreilly.com/library/view/agile-web-development/9798888650288/f_0091.xhtml 2/3
12/06/2023, 18:09 17. Task L: Deployment and Production | Agile Web Development with Rails 7

 volumes:

 
​ pgdata:

Don’t let the size of the file fool you—there’s a lot to unpack here. We’ll
cover the following in subsequent sections:

Configuring the database


Keeping secrets
Building a docker image
Deploying the application

https://learning.oreilly.com/library/view/agile-web-development/9798888650288/f_0091.xhtml 3/3

You might also like