How to deploy a Go application with Postgres on Patr

Aditi Shah
The Patr-onus Deployment Blog
5 min readJun 30, 2022

--

In this tutorial, we are going to deploy a Go application on Patr. For the sake of this tutorial, we will host our own instance of Miniflux for private use. It is written in Golang and uses Postgres as its database. Let’s see how Patr helps to host applications like Miniflux in minutes.

1. Create a Patr account

Patr is a code deployment platform that takes care of running and scaling your applications in a hassle-free way. Grab your free Patr account by signing up on app.patr.cloud

2. Create a Postgres DB on Patr

For persistence, Miniflux uses Postgres as its database so let’s create a new Postgres database.

i. Login to your Patr account at app.patr.cloud

ii. Go to Infrastructure -> Database -> Create new Database.

iii. Enter the instance name as “miniflux-instance”.

iv. Enter the database name as “miniflux”.

v. Select the database type as “postgres”.

vii. Choose a region nearest to your location in the dropdown menu.

viii. Select your plan based on your needs. (For demo purposes, a minimal resource plan is selected)

ix. Then click Create and within seconds a fresh Postgres database is ready for production usage.

3.1 Copy the Postgres Connection link

Once a database instance is created, click on the created database instance to view its details and keep a note of the connection string so that we can use this database with Miniflux.

4. Create a Docker Repo on Patr

Docker has become the preferred way to containerize modern applications and services. Patr provides first-class support for running docker images. We will use the dockerized version of Miniflux to host it on Patr.

For deploying docker images on Patr, first, we need to create a private Docker repository on Patr.

i. Go to Docker Repository -> Create Repository

ii. Enter the repository name as “miniflux”.

iii. Then click Create.

4.1 Copy the Postgres Connection link

Once the Docker repository is created, click on that created Docker repository to view details about it and note down the Docker repository URL to push Miniflux docker image.

5. Push Miniflux to Docker repo on Patr

Install docker on your computer. To push the miniflux docker image to your miniflux docker repo on Patr, run the following commands in the terminal.

# pull the official miniflux docker image
docker pull miniflux/miniflux
# tag the miniflux image to your patr's private miniflux repo
docker tag miniflux/miniflux:latest {link_to_your_miniflux_docker_repo_in_patr}:latest
# login to patr's docker registry with your patr credentials
docker login registry.patr.cloud
# push the tagged image to your patr's miniflux docker repo
docker push {link_to_your_miniflux_docker_repo_in_patr}:latest

Replace {link_to_your_miniflux_docker_repo_in_patr} with the link which you noted down in the previous step while creating the Docker repo on Patr.

6. Create a Miniflux Deployment on Patr

Go to Infrastructure -> Deployment -> Create new deployment.

  1. Enter the name as “miniflux”.
  2. Choose image details as “miniflux”.
  3. Choose tag as “latest”.
  4. Choose a region nearest to your location in the dropdown menu.
  5. Click “Next”.

Based on the Miniflux docker installation docs, these are the settings you need to provide from Patr to run the Miniflux docker image.

i. In the ports section, add 8080 port with HTTP as protocol.

ii. In the environmental variables section,

a. Add DATABASE_URL key with value as the database connection URL which you copied after creating the database.

b. Add ADMIN_USERNAME key with the value you wish to use as a username for your miniflux account.

c. Add ADMIN_PASSWORD key with the value you wish to use as a password for your miniflux account.

d. Add CREATE_ADMIN key with 1 as value.

e. Add RUN_MIGRATIONS key with 1 as value.

iii. Click “Next”.

a. Make sure the Deploy on Push and Deploy on Create boxes are checked.

b. Choose the scaling range as per your requirements. (For demo purpose, minimal scaling is selected)

c. Select the machine type for deployment as per your need. (For demo purpose, minimal resource is selected)

d. Then click Create.

6.1 Copy Deployment ID

Within seconds, patr will make your application live. To access your application from your browser, click on the created deployment and copy the deployment-id in the URL.

7. Using Miniflux

  1. Now you can access your application by using the URL

{port}-{deployment-id}.patr.cloud

where

  • {port} is the port which was allowed during the deployment (in our case 8080)
  • {deployment-id} is the ID which was copied in the previous step

2. Enter the username and password which you specified in the environment variables while creating a deployment.

3. Now let’s get updates on the funny cats subreddit by adding https://www.reddit.com/r/funnycats.rss feed URL in Miniflux.

4. Now we’ll receive updates about the funny cats subreddit in Miniflux.

Voila! We have successfully deployed an application in production.

--

--