Kamal Tip - Private Network only Database Server

Edit: In the original version of this post I made a mistake. This post has been corrected. See the details at the below for an explanation of the mistake and the solution. Mistake Summary & Solution In the original version of this post I had stated that the App servers IP in the Kamal configuration should be set to it’s public IP. This is incorrect. With the SSH proxy pointing at the public IP as well, this resulted in a jumphost connection problem, meaning it tried to connect to the public IP through a proxy of the public IP. This obviously didn’t work and resulted in inconsistent behavior with Kamal. The solution was to replace the App servers IP address to be the private IP instead. As a result, the only place the public IP of the server is referenced is in the Kamal SSH proxy configuration. ...

November 22, 2024 · 7 min · JD

Quick Tip: Git - Rebasing Branches

I’m a big believer in keeping a clean commit history. This practice isn’t always necessary depending on the type of work being done, but I frequently reference old commits, so keeping the merge commits out of my history just helps me to get rid of the noise. This means, that I rebase my branches often which can cause an issue when branching off branches, as once a branch is merged into the main branch, you need to catch up your currently working branch some how. ...

October 11, 2024 · 2 min · JD

State Design Pattern

Manging the state of objects and state specific behavior is always an interesting problem to deal with. The Rails community has done a great job of developing libraries to help manage this. Most of these libraries come in the form of State Machines. These typically have the pattern of defining states, events to change states, and constraints by which those states can or cannot change. Usually, this code is maintained in your model, and in some cases states can have their very own model and DB table and keep an audit history of some kind. ...

June 8, 2021 · 7 min · JD

Double Polymorphic Associations in Rails

Polymorphic associations is a common theme among many applications. Things can get complicated, especially as far as naming is concerned, when you consider having a double polymorphic association. Rails provides all the necessary mechanisms by which to manage this in a way that makes sense for most business needs as well as leaving it readable for future programmers that come by in the future. In programming languages and type theory, polymorphism is the provision of a single interface to entities of different types or the use of a single symbol to represent multiple different types. ...

May 31, 2021 · 3 min · JD

Thoughts on Interfaces for Models

I recently had to build an interesting model that stored values for a JWT in order to implement an allow list style revocation strategy. After some feedback from another developer it became clear the interface for that model needed to be optimized. Here’s a quick description of the “behavior” of that model: All of the columns are read only after creation It’s dependent on a User record assocation - thus requires a validation It has an expiration time that is also stored, but set to a pre-determined amount of time It’s jti column value is generated by the model itself since it is a “propietary” action per record Given this set of behavior we can infer that since the expires_at column and jti are both self generated in the model code, the only attribute required for creation is the associated User record. ...

February 11, 2021 · 2 min · JD

Resolving client side routes in Rails

There’s a quick and easy way to satisfy client side routing in a Rails application. Rails will automatically try to resolve it’s routing on the server side and throw an immediate 404 if no valid pages exist. Since my main application at work is a React SPA I needed a way to resolve routes to the client and not let them get caught by the server and throw a 404. The (/*path) method route ‘helper’ allows through any route so it can then be handled elsewhere. ...

January 9, 2021 · 2 min · JD

Dockerize Create React App

I’ve used Docker quite a bit but I haven’t really dived into configuring my own dockerized app. I recently needed to build a quick proof of concept with a React app and needed to share it easily without worrying too much about build dependencies or anything of the sort. So here’s a quick guide on dockerizing an app created with create-react-app. The guide I’ll assume you already have a CRA app created. If you’ve never used create-react-app, I recommend checking out the docs here. This tutorial will work from the top down and both the Dockerfile and docker-compose.yml files will be at the end in full. ...

January 2, 2021 · 4 min · JD