Building an RSS Feed with Phoenix

Posted by Daniel Wachtel in Phoenix, updated on 10 October, 2020

Introduction

I wanted to add an RSS feed to this blog but decided that instead of installing a dependency I'll build one myself! Here's how you can set one up in a Phoenix application:

Creating the RSS view

First let's define a new route in lib/your_app_web/router.ex...

Read more

Dockerizing a Ruby on Rails app with a PostgreSQL Database

Posted by Daniel Wachtel in Rails, updated on 06 September, 2020

Introduction

These are the configurations I use to deploy a Rails 6 app. Note that this is a small hobby app so I'm using docker-compose to deploy it, for more serious apps you'd want to use docker swarm or kubernetes. If you don't have a server ready or docker and docker-compose installed on your local dev machine then have a read through this blog post first.

For this build I'm not going to dockerize NGINX as I have it installed on the server.

Create a Dockerfile

Step one is to create a Dockerfile in the root directory of your project. For this build I'll be using...

Read more

Adding Global View Helpers to a Phoenix Application

Posted by Daniel Wachtel in Phoenix, updated on 06 September, 2020

Introduction

If you come from a Ruby on Rails background you might be used to having view helpers such as number_with_delimiter up your sleeve and ready to use. Here's how to configure functions that are accessible in your Phoenix views:

Create a helper module

I usually create a helpers directory under the my_app_web directory. Next create a new module, let's call it application_helper.ex...

Read more

Enabling GZIP Compression on a Phoenix Application

Posted by Daniel Wachtel in Phoenix, updated on 27 August, 2020

The other day I ran my blog through GTmetrix website speed test and realised that I had turned on GZIP compression for static assets, but not for dynamic content. This is easily fixed however with 2 lines of code:

Enabling GZIP compression for static assets

To enable compression for static assets add gzip: true (or gzip: Mix.env == :prod for production only) to the Plug.Static config in...

Read more

Dockerizing a WordPress site with a MySQL database

Posted by Daniel Wachtel in DevOps, updated on 03 May, 2020

Introduction

I had a couple of WordPress sites I wanted to dockerize and move over to my new server. This is the configuration I used to deploy them to my new server as described here.

I'm using the official wordpress and mysql images and don't need to build anything, so all I need to deploy the app is a docker-compose.yml file and a couple of .env files.

The docker-compose.yml file

I'm using the wordpress:5.4.1 (also tagged as wordpress:5.4.1-apache) which uses an Apache server and serves the app on port 80. Port 8080 is mapped to my host...

Read more

Dockerizing a Matomo (formerly Piwik) web analytics app

Posted by Daniel Wachtel in DevOps, updated on 03 May, 2020

Introduction

Matomo (formerly known as Piwik) is an open source web analytics application that runs on PHP and a MySQL database, which I've been using instead of Google Analytics.

This is the configuration I use to deploy it as described here.

I'm using the official matomo and mariadb images and don't need to build anything, so all I need to deploy the app is a docker-compose.yml file and a .env file.

The docker-compose.yml file

I'm using the matomo:3.13.5 (also tagged as matomo:3.13.5-apache) which uses an Apache server and serves the app on port 80...

Read more

ERROR: Secsh channel open FAILED: Connect failed

Posted by Daniel Wachtel in SSH, updated on 30 April, 2020

I recently ran into the following error when trying to deploy remotely using docker-compose:

ERROR: Secsh channel 14 open FAILED: open failed: Connect failed

The issue is that the default SSH connections allowed is set to 10 and the command I was running was trying to use more connections then that.

Fixing the error

To fix this error you'll need to connect to your server...

Read more

How to fix oh-my-zsh plugin autocomplete feature

Posted by Daniel Wachtel in ZSH, updated on 25 April, 2020

I recently ran into an issue after installing docker and adding it to the plugins section in my .zshrc file, autocomplete just wouldn't work (even though oh-my-zsh plugin installation is so straightforward).

First make sure your syntax is OK, plugins should be separated by a space only and no commas:

plugins=(git docker docker-compose)

After reloading my zshrc file with source ~/.zshrc it still didn't work. I had to delete ZSH's .zcompdump file...

Read more

Dockerizing a Phoenix app with a PostgreSQL database

Posted by Daniel Wachtel in DevOps, updated on 01 September, 2020

Introduction

These are the configurations I use for a Phoenix 1.4 app to deploy it to production using docker-compose contexts. If you don't have a server ready or docker and docker-compose installed on your local dev machine then have a read through that blog post first.

For this build I'm not going to dockerize NGINX as I have it installed on the server.

Create a Dockerfile

Step one is to create a Dockerfile in the root directory of your project. For this build I'll be using elixir:X.X.X-alpine image. alpine is a much slimmer Linux docker image and will reduce our overall image sizes.

# ./Dockerfile

# Extend from the official Elixir image
FROM elixir:1.10.2-alpine

# Install required libraries on Alpine
# note: build-base required to run mix “make” for
# one of my dependecies (bcrypt)
RUN apk update && apk upgrade && \
apk add postgresql-client && \
apk add nodejs npm && \
apk add...

Read more

Deploying multiple dockerized apps to a single DigitalOcean droplet using docker-compose contexts

Posted by Daniel Wachtel in DevOps, updated on 06 September, 2020

Introduction

In this post we'll go over setting up a DigitalOcean Droplet to run multiple dockerized apps which we'll deploy to production using docker-compose and docker contexts. We'll also set up NGINX reverse proxies for the apps we want to expose externally.

Using docker-compose with contexts let's us run builds and deployments to remote servers from our local dev machine. This feature is available to docker-compose starting with release 1.26.0-rc2.

Note: this feature is relatively easy to use, especially if you've used docker-contexts before however is more suited for deploying small/hobby apps to a single server. There will be some downtime as you're releasing new builds (generally a few seconds) so if you require zero downtime deployments, rolling updates and multiple server orchestration then you should look at docker's swarm feature or kubernetes.

Create a DigitalOcean Droplet

First sign up at DigitialOcean and create a new project. You can name the project anything you want...

Read more