Becoming a software developer – episode XXIII

Becoming a software developer – episode XXIII

Welcome to the twenty-third episode of my course “Becoming a software developer” in which we will focus on the vast topic of DevOps which is all about building, testing and deploying the application. And we will use Docker to help with the overall process.

All of the materials including videos and sample projects can be downloaded from here.
The source code repository is being hosted on GitHub.


 

Scope

  • Publishing
  • Docker
  • Deployment
  • Automation

Abstract

Publishing

When we want to run our application in a proper manner, we should not really use dotnet run and run the app based on the provided source code written in C#. Instead, we should only use the assemblies compiled into the .dll files and then execute dotnet application_name.dll which will run the actual application that was already compiled, not the project with its source code. This can be done by running dotnet publish -c Release where the -c defines the configuration that should be used. We want to use Release so that the compiler can include some optimizations for this environment in order to ensure that our application will be truly prepared for the production mode.

Docker

Docker is the most popular engine for running the applications within so-called containers, although the containers itself have been used since the 70s. You can read about the differences between virtual machines and containers, the important part is that container is very lightweight, runs on top of the current operating system (e.g. Windows or Linux), has its own and separate environment and most importantly it will behave in the same way as on our development machine, which means that we can be certain that regardless of the infrastructure, our application will work and behave as expected. Below is the sample Dockerfile for the .NET Core applications:

We can build such image and run it by using the following commands:

We can also use the Docker Compose to define the whole system that can be built with many different services (application, databases etc).

And run it simply by typing docker-compose up command. Finally, we can publish our own Docker image to the registry e.g. Docker Hub, by creating an account here, adding a new repository (e.g. passenger-api) and then running the following commands:

docker login
docker tag passenger.api spetz/passenger.api
docker push spetz/passenger.api

Deployment

In this episode, I did deploy the application to the virtual machine based on Ubuntu Server running in the Digital Ocean cloud. I logged in to the VM by typing: ssh root@46.101.203.190 and then executed the following commands:

Then, we could edit the Nginx configuration under the /etc/nginx/sites-enabled directory simply by editing the default file:

Eventually, I did restart the Nginx with service nginx restart command, executed the docker-compose command up and our application was available under the http://46.101.203.190 URL.

Automation

Is it possible to somehow automate this process of building, testing, publishing and deploying the application? Of course, and this is where tools like build servers come in handy. There are many of them and you can browse my previous posts where I did describe how to make use of such services. Here, I chose the Travis CI which is a really cool build server and its free for the open source projects. Just sign in using the GitHub account, mark the selected repository integration, and place the .travis.yml file in the root folder of the solution:

The actual content of the build scripts can be found in the project repository, just keep in mind that you could also use the pure bash commands instead.

Next

In the next episode, which will be the final one, we will do something special :).

6 Comments Becoming a software developer – episode XXIII

  1. Pingback: Dew Drop - July 31, 2017 (#2531) - Morning Dew

  2. Damian

    Witaj Piotrze,
    Kiedy planujesz wrzucić ostatni odcinek ? 🙂 I masz jakieś ramy czasowe odnośnie jwt i refresh token’a ?
    Ps. Świetna robota z każdym kursem i postem na blogu 🙂 Planujesz ogólnie aktywizacje mocniejsza na YT ? Np jakaś seria kolejna niekonieczni cały kurs ale seria zwykła która by była systematycznie prowadzona ? 🙂

    Pozdrawiam Damian.

    Reply
    1. Piotr Gankiewicz

      Cześć, dzięki, ostatni odcinek najwcześniej w nadchodzącym tygodniu, nie wiem jeszcze kiedy wrzucę materiał o odświeżaniu JWT, bo mam trochę zaległości.
      Odnośnie YT to mam sporo pomysłów i prawdopodobnie będzie fajna seria we współpracy z pewną bardzo doświadczoną osobą :).

      Reply
  3. Arek

    Witaj Piotrze,

    kiedy planujesz wrzucić kolejny odcinek ?
    Oraz jakieś plany odnośnie wrzucenia refresh tokena i .net core 2.0 ?

    Pozdrawiam
    Arek

    Reply

Leave a Reply to Arek Cancel reply

Your email address will not be published. Required fields are marked *