Engineering
November 08, 2019

DC/OS series [Part 4] - Deploy simple application with backend & database

Create an application with Golang

First of all, we will go with Golang because Go is easy to implement backend server and deploy in 1 min. So we will have a few code to initialize todolist application that prodive GET tasks.

Above code allow us easy to customize configuration of database connection. When we deploy application, we just need to change these settings below which are environment variables:

  • DB_USER
  • DB_PASSWORD
  • DB_HOST
  • DB_NAME

After that, We need to do some stuffs to dockerize application and push it to docker hub or private docker registry. To do that, let’s create a Dockerfile first:

Following to these steps, you will be able to build and push your image to docker hub:

Setting up database on DC/OS

Let’s go to our DC/OS and create a postgres service

Go to DC/OS and choose package tab, then find postgres:

Customize your configuration after click Advance setting from pop-up page:

Finally, you need to wait a few minutes and get the result like this:

A very important thing is sharing volumes. You will need to set a specific node with public IP to make sure if service restart, it will only be deployed to a node that you have specified before. There are 2 things need to be config:

  1. Set a specific node in Service tab:

  1. Share volumes:

For me, I usually share volumes inside container to /srv in node: /srv/todolist/postgresql:/var/lib/postgresql/data

Then, you also need to enable LOAD BALANCED SERVICE ADDRESS, it will allow your application connect to postgres

After all, click REVIEW & RUN to change setting

Deploy application

As usual, we will need file marathon.json to define app and deploy:

You also need to replace your configuration DB_HOST, DB_USER, DB_PASSWORD, DB_NAME

OK, we can deploy now !

As my expectation, it will be like this :D :

Everything is available now. Let’s check it:

That’s all. Thanks for reading :)

Work with us

Drop us a message if you need any helps from the Dwarves

Let's build something