If you have, or plan to launch, a public facing website that asks users to log in then you need to be using HTTPS. Users expect security, and it’s the least you can provide if you’re asking them for their data. That said, SSL is traditionally a big pain in the ass. It’s not easy to setup and a trusted certificate can cost hundreds of dollars. Luckily all that has changed thanks to Let’s Encrypt and their ACME protocol . As mentioned on the about page, “Let’s Encrypt is a free, automated, and open certificate authority (CA), run for the public’s benefit.” In other…
16 CommentsTag: rails
As you may have read I like to use Postgres’ official image in my multi-container Docker environment. Out of the box it needs little configuration. I typically access it through my Rails app using rails db or rails console . The other day, however, I needed to craft some SQL and those tools weren’t cutting it. I wanted to use my SQL client so I could work directly with the schema on something better than the command line. That required some tweaking to my DB container. By default the Postgres image uses Docker’s EXPOSE instruction to open port 5432 for other Docker containers. EXPOSE does not make the port…
Leave a CommentI believe continuous deployment is a worthy goal for every development team. The practice requires discipline and minimizes the risks associated with releasing large swaths of new code into the wild. I agree with the mantra that deployments shouldn’t be a big deal; that they should be easy to roll back from, and require little ceremony. This tutorial is the last in a series of three that demonstrates how to use Docker in development, continuous integration, and continuous deployment. Follow all three and you’ll have a system where you can push code to master, watch your tests run in CI, and then have…
22 CommentsIf you’ve ever worked with continuous integration then you know it’s a valuable tool. Having a CI server run your test suite after each push to a branch is great for discovering integration bugs and for building team confidence. Maintaining a traditional CI server, however, can be a pain. It’s close to, but not quite, a production environment, and it is not a development environment. Instead it’s a nuanced version of both. That difference inevitably leads to someone saying “tests passed on my machine, not sure why they are failing in CI.” If you don’t want to hear those words then I suggest you…
Leave a CommentA few weeks ago I decided to take an existing Ruby on Rails application and configure it to work with Docker. I wanted a container-based development environment that fed into a continuous integration to continuous deployment pipeline. The hope is that this style of development would eliminate the differences in environment you typically find between work laptops running OS X and staging, testing, and production servers running Linux. I also wanted to simplify server configuration and maintenance, plus make it super easy for another person to jump on the project. Docker delivers on all these hopes, but with so many different ways to use Docker…
105 CommentsI found a bug in my code today that stems from my not remembering that ActiveRecord::Base will try to coerce values set on its attributes into whatever type is defined in the DB. Specifically I got burned by #id= coercing a String into a Fixnum. Check this out:
1 2 3 4 5 6 |
[10] pry(main)> record = ActiveRecordSubclass.new => #<ActiveRecordSubclass:0x00555d2e588a28 ... > [11] pry(main)> record.id = "09378476376282" => "09378476376282" [12] pry(main)> record.id => 9378476376282 |
Not only is the type of object changed by setting the attribute but the leading zero is lost. Luckily my specs caught this. I know, I know it’s a bad idea to set #id yourself. You should let ActiveRecord do that for you. In my case I was trying to cleverly avoid…
Leave a CommentI got bit by the Rails production environment today. Here’s the scenario: I have a set of classes that all mixin the same module.
1 2 3 4 5 6 7 8 9 10 11 12 13 |
module Syncable ... end class DownloadCars include Syncable ... end class DownloadTrucks include Syncable ... end |
Upon include the module “registers” the class with another class
1 2 3 4 5 6 7 8 |
module Syncable extend ActiveSupport::Concern included do |base| ApiCheck.registry[base.api_url] = base end ... end |
Once registered subclasses of ApiCheck can perform actions using the registry. Those actions are run via rake tasks. In development, when classes are autoloaded (i.e. only loaded when referenced), the rake tasks work fine. In production, however, the tasks fail because, in the context of a rake task, ApiCheck.registry is empty. None of my classes were registered. This struck me as odd because in production Rails eager loads…
2 Comments