Note the keyout and out options. The jwilder/nginx-proxy Docker image won’t pick up the certificates unless they are named in accordance with the production site’s URL and subdomain (if any). For example, if you have a certificate for example.com, the keyout and out options must be named example.com.key and example.com.crt respectively.
Obtain a certificate for each app you wish to deploy (or just get one for the purposes of this tutorial).
# TODO: figure out how to install `node` modules without `sudo`
RUN sudo npm install
RUN sudo -u app RAILS_ENV=production rake assets:precompile
# Clean up APT when done.
RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
Note the ADD commands under the Configure Nginx header. These are copying configurations into the Docker image. Here I put them in the docker directory to keep them organized. From your app’s root directory:
Now, save the following to docker/my-app.conf:
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
Of course, change the server name as appropriate. Also note the /home/app directory. app is the username set up by the phusion/passenger-ruby22 image.
Next, save the following to docker/postgres-env.conf
This is some Docker magic that preserves these Postgres environment variables.
Now, build the app’s image from the project’s root directory:
docker build -t my-app-image .
This command reads the Dockerfile just created and executes the instructions contained therein.
Setup, migrate, and seed the database:
docker run --rm --link postgres:postgres my-app-image rake db:create
docker run --rm --link postgres:postgres my-app-image rake db:migrate
docker run --rm --link postgres:postgres my-app-image rake db:seed
I recently worked through Michael Hartl’s wonderful Ruby on Rails Tutorial as a refresher. The software implemented under his direction offers functionality that basically every modern website requires (e.g., user sign up, password retrieval, etc). That which follows documents the steps I took to deploy all the best parts of that tutorial in a production environment.
Get a server
Much of this post was ripped off from this article. They recommend Digital Ocean. I like cloudatcost.com for no other reason than because they’re cheap. For the purposes of this post, it doesn’t really matter as long as it’s installed with Ubuntu 14.04.
Add a user account
The templated Rails application is executed under this account:
You’ll need to set the database password in config/application.yml.
Configure the environment
Before deploying with capistrano, a few files have to be in place. As the deploy user:
mkdir -p rails-tutorial-template/shared/config
Get a secret key
If you have a rails project nearby, you can just type in
Or, you can generate one by running irb
and executing the following instructions:
Copy the string generated by the SecureRandom.hex(64) command.
This template uses figaro to manage all the sensitive stuff that sometimes goes into environment variables. The config/application.yml file it looks for isn’t committed to the repository, so you have to create it yourself: