Skip to content

eatrisno/compose-framework

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

DEVOPS TOOLS - DOCKER COMPOSE FRAMEWORK

Try not to become a man of success, but rather try to become a man of value.

This pipeline project template is created to support containerization faster.

Concept

                      loadbalancer (80,443)
                                |
        --------------------------------------------------
        |                                                |
development_network                            production_network
        |                                                |
        |                                  ---------------------------
        |                                 |                          |
    myapp (80)                      myfront (80)                 myback (80)
 (dev.myapp.com)                   (myfront.com)                (myback.com)

What you need to start this project

  • Server, PC or laptop
  • Internet access
  • git installed
  • little bit of ✨Magic ✨

What we are using

  • Docker
  • Docker Compose
  • Nginx
  • Git

Features

  • loadbalancer with nginx alpine
  • docker-compose network managed

Folder Map

    - services/
        - development/                  <-- project / app folder
            - .env                      <-- env file for docker-compose
            - docker-compose.yaml       <-- docker-compose config
        - production/
            - .env
            - docker-compose.yaml
    - loadbalancer/
        - docker-compose.yaml
        - certs/
        - nginx.tmpl                    
    - start.sh                          <-- ✨Magic ✨

note

you need to add to your /etc/hosts to run sample.local domain

127.0.0.1 dev.myapp.com myfront.com myback.com

Installation

git clone https://github.com/eatrisno/compose-framework.git
cd compose-framework

./start.sh

What you need to do when

how to add new environment (staging)

  • Step 1

    cd compose-framework
    mkdir staging
    cd staging
  • Step 2

    Create docker-compose.yaml file

    nano docker-compose.yaml

    docker-compose.yaml :

    version: '3.7'
    
    services:
      backend-api:                                   #<-- app name, for e.g: backend-api
        restart: always                              #<-- keep start docker when down / error
        image: "${BACKEND_API_REGISTERY}"            #<-- image registery variable loaded from .env file
        networks:                                    #
         - staging                                   #<-- network alias ---------------------------------|
        environment:                                 #                                                   |
          - VIRTUAL_HOST="api.mycompany.com"         #<-- app domain alias (http://api.mycompany.com)    |
          - VIRTUAL_PORT=80
        expose:
          - 80
    networks:                                        #                                                   |
      staging:                                       #<-- network alias for attach to service -----------|
        name: "staging_network"                      #<-- your network name
  • Step 3

    Create .env file

    nano .env

    .env :

    BACKEND_API_REGISTERY=nginx:alpine
  • Step 4

    Start service with this command:

    docker-compose up -d backend-api

    output:

    Creating network "develop_network" with the default driver
    Creating develop_backend-api_1 ... done
  • Step 6

    add network to loadbalancer docker-compose.yaml :

    version: '3.7'
    
    services:
        nginx-proxy:
            restart: always
            image: nginxproxy/nginx-proxy:alpine
            volumes:
                - "./certs:/etc/nginx/certs"
            ports:
                - 80:80
                - 443:443
            volumes:
                - /var/run/docker.sock:/tmp/docker.sock:ro
            networks:
                - development
                - production
                - staging                      #<---- add this alias network
    
    networks:
    production:
        name: "production_network"
    development:                                #<---- alias network
        name: "development_network"             #<---- network name
    staging:
        name: "staging_network"

    SSL support

    add your certificate to certs folder with domain format, for example your domain is : mywebsite.com, your cert file name is mywebsite.com.cert your key file name is mywebsite.com.key

    loadbalancer/
        certs/
            - mywebsite.com.cert
            - mywebsite.com.key
  • Step 7

    restart your nginx loadbalancer

    docker-compose up -d

    (optional) add to your local /etc/hosts:

    sudo nano /etc/hosts
    echo "127.0.0.1 api.mycompany.com"

License

MIT

Free Software, Hell Yeah!

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages