Software Architecture and Docker

Software Architecture and Docker

"Software architecture? What is it?"

"Is it something like the architects do?"

"I haven't heard docker, so what is it?"

Whenever I try to explain software architecture and docker to my fellow friends who are rarely or never experienced software development, they probably will ask those questions above. So, in this article I will try to explain you all about software architecture and docker.

Software Architecture

Software architecture refers to the fundamental and the discipline of creating software or application structures and systems. Software architecture serves as a blueprint for a system, making the coordination mechanism among components and manage the system complexity. Each structure contains software elements, relations among them, and properties of both elements and relations. It usually drawn in a diagram.

Why is it important?

There are some reasons why creating software architecture is important.

  1. Communication among stakeholders — Software architecture represents a common abstraction of a system that mostly can be used as a basis for mutual understanding, negotiation, consensus, and communication.
  2. Early design decisions — Software architecture manifests the earliest design decisions about a system, and also the earliest point at which design decisions governing the system to be built can be analyzed.

Any examples?

To illustrate this, let's see one of my website project called Sistem Informasi Penilaian dan Evaluasi Praktikum, a website to help FISIP (Faculty of Social and Political Sciences) UI's students and lecturers to submit and score the practical work's (internship) reports. This project is being developed by my team, MK-PPL.

Below is the digram of our software architecture.

No alt text provided for this image

Our system is built with microservice architecture. It splits into two services: back-end (temporarily hosted on https://si-praktikum-backend.herokuapp.com/) and front-end (temporarily hosted on https://ppl-mkppl-inos.herokuapp.com/). We use this kind of architecture to accelerate product iteration, continuous deployment, and developer productivity.

For back-end framework, we use Django while we use React JS for the front-end. We also use Nginx as a Reverse Proxy and Load Balancer. SSO UI (integrated with JWT) is a third party CAS/SSO provided by the University of Indonesia. For the database needs, we use PostgreSQL because it has a lot of support and available in Heroku. All services are hosted on Heroku because it's free (yes, we are still a student). They also all wrapped in Docker as the container (if you haven't heard about it, let's see the next topic: Docker)

Docker

No alt text provided for this image

Docker is a tool that can reduce the gap between development and deployment in the iteration phase of Software Development. Docker is a set of platform as a service products that uses OS-level virtualization to deliver software in packages called containers. By doing so, the developer can rest assured that the application will run on any other Linux machine regardless of any customized settings that machine might have. Using docker might help us to solve problems such as dependencies, database set up, line break (linter), and other problems.

Why should we use Docker?

There are at least 5 advantages if we use Docker.

  1. Portability — we can deploy it to any other system where Docker is running and we can be sure that your application will perform exactly the same as when we tested it.
  2. Performance — unlike virtual machines, containers do not contain an OS, which means that containers have much smaller footprints and faster than virtual machines.
  3. Agility — the portability and performance benefits offered by containers can help you make your development process more agile and responsive.
  4. Isolation — if other containers contain applications with different versions of the same supporting software, it won't be a problem because the different containers are totally independent.
  5. Scalability — you can quickly create new containers if demand for your applications requires them. 

Okay, now how to implement Docker?

To illustrate this, let's see one of my website project called Sistem Informasi Penilaian dan Evaluasi Praktikum, a website to help FISIP (Faculty of Social and Political Sciences) UI's students and lecturers to submit and score the practical work's (internship) reports. This project is being developed by my team, MK-PPL.

First, we should install Docker. You can get the latest version of Docker via this link: https://www.docker.com/. Then, we should prepare the Dockerfile. Don't forget to define how our app will be executed by the proper syntax. Below is one example of Dockerfile that is used for my project.

# Dockerfile
FROM python:3.8
ENV PYTHONUNBUFFERED
ENV PYTHONDONTWRITEBYTECODE 1
RUN mkdir /app
WORKDIR /app
COPY requirements.txt /app/
RUN pip install -r requirements.txt
COPY . /app/

Then, we should build and run the container (image) from our working directory. You can follow the syntax below.

docker build -t mkppl-backend:latest .
docker run -p 8000:8000 mkppl-backend:latest

Now, docker container is built and already run in your host.

Docker Compose

Yest, it's still not the end. To make it better, we should create a docker-compose.yml because we could configure and run our application services with a command by creating that file.

Docker Compose is a tool for defining and running multi-container Docker applications. So, here we use it for hosting both DBMS (PostgreSQL) port and back-end (Django) port simultaneously. Here is what we write in our docker-compose.yml

version: "3.7"
services:
  db:
    image: postgres
    restart: always
    environment:
      POSTGRES_USER: ${POSTGRES_USER}
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
      POSTGRES_DB: ${POSTGRES_DB}
    ports:
      - "5432"
    volumes:
      - ./db_backend:/var/lib/postgresql/data/
    networks:
      - backend
  web:
    build: .
    command: python3 manage.py runserver 0.0.0.0:9000 --settings=sip.settings.staging
    volumes:
      - .:/app
      - ./sip/settings/static:/app/static
    environment:
      SECRET_KEY: ${SECRET_KEY}
      DB_NAME: ${DB_NAME}
      DB_USER: ${DB_USER}
      DB_PASS: ${DB_PASS}
      DB_HOST: ${DB_HOST}
      DB_PORT: ${DB_PORT}
    ports:
      - "8001:9000"
    depends_on:
      - db
    networks:
      - backend
networks:
  backend:
    driver: bridge


From that, we could see that the DBMS runs on port 5432, while the back-end runs on 8001/9000. After writing these codes, don't forget to serve the app and migrate all the database by running these syntax.

docker-compose build
docker-compose up -d
docker exec -it <container_id> /bin/bash
python manage.py makemigrations
python manage.py migrate

Finally, we can access the back-end service on port 8001.

No alt text provided for this image

That wraps up the article. If you have any suggestions, don’t hesitate to comment :)

Thanks for reading!

要查看或添加评论,请登录

Razaqa Dhafin Haffiyan的更多文章

社区洞察

其他会员也浏览了