sec0uth / brick-abode-project-interview

The final project of interviewing process
0 stars 0 forks source link

Docker environment #14

Closed sec0uth closed 3 years ago

sec0uth commented 3 years ago

Description

You should consider how well organized is the development and production environment. The current project suffers from the same organization issues, and containers are used to minimize them.

Compose

Dockerfile is a special file for creating container images, but lacks a mechanism into running them. There is where docker-compose comes in play, it configures how images are executed, which volumes, networks and so on.

Problem

There are total of 4 environments.

I managed to solve this using docker-compose. For example, the following is the docker-compose configuration of juniper found juniper/docker-compose.yaml:

version: "2"

services:
  prod:
    build: ./juniper/
    working_dir: /juniper/
    volumes:
      - ./juniper:/juniper:Z,ro

  dev:
    build:
      dockerfile: ./juniper/Dockerfile.dev
    working_dir: /project/
    volumes:
      - ./juniper:/project/juniper:Z,ro
      - ./tests:/project/tests:Z,ro
      - ./tox.ini:/project/tox.ini:Z,ro

All these paths are hard-coded because all them references this very project. You can add custom volumes from the top level docker-compose.yaml, like in the docker-compose.yaml.example:

Note: truncated content for brevity

services:
  juniper:
    extends:
      file: ./juniper/docker-compose.yaml
      service: prod
    volumes:
      - ~/.ssh/config:/root/.ssh/config:Z,ro
      ## ssh public key authentication
      # - ~/.ssh/juniper_key:/root/.ssh/id_rsa:Z,ro

The extends keyword allows to create user-defined docker-compose configurations, so the file ./juniper/docker-compose.yaml keeps untouched. Using this concept, you should be able to create all 4 environment just extending each from the one provided by the developer, overriding the volumes with the required files/directories, and all this as a user configuration file.