Local environment

Ready to Dev logo

Introduction

Requirements

How to set up

  1. Clone the project: git clone git@github.com:jfgomes/site-jgomes.git

  2. cd site-jgomes

  3. Ensure to have the file env_var_list_local.zip in the root of the project and the password to open it. This is not versioned, and you need to request this to the owner.

  4. In the first run the command is './serve.sh load-env-vars' ( after the first run only './serve.sh' is enough as the env vars are loaded in the first run )

  5. And is done.

Details about the ./serve.sh script

./serve.sh details

Services and other information

docker-compose.yml

version: "3.9"
services:
    mysql:
        container_name: jgomes_site_dev_mysql
        build: './mysql'
        env_file:
            - .env
        ports:
            - "3406:3306"
        environment:
            MYSQL_ALLOW_EMPTY_PASSWORD: yes
        volumes:
            - dbData:/var/lib/mysql

    phpmyadmin:
        container_name: jgomes_site_dev_phpmyadmin
        image: phpmyadmin/phpmyadmin
        platform: linux/amd64
        env_file:
            - .env
        ports:
            - "8090:80"
        environment:
            PMA_HOST: mysql
            MYSQL_ALLOW_EMPTY_PASSWORD: yes

    rabbitmq:
        container_name: jgomes_site_dev_rabbit
        build:
            context: './rabbitmq'
        env_file:
            - .env
        ports:
            - "5672:5672"
            - "15672:15672"
        environment:
            -  RABBITMQ_USER=${RABBIT_USER}
            -  RABBITMQ_PASSWORD=${RABBIT_PASS}
            -  RABBITMQ_DEFAULT_USER=${RABBIT_USER}
            -  RABBITMQ_DEFAULT_PASS=${RABBIT_PASS}

    redis:
        container_name: jgomes_site_dev_redis
        restart: always
        image: redis:latest
        command: ["redis-server", "--bind", "${REDIS_HOST}", "--port", "${REDIS_PORT}"]
        volumes:
            - redis:/var/lib/redis
            - redis-config:/usr/local/etc/redis/redis.conf
        ports:
            - "6379:6379"
        networks:
            - redis-network

    redis-commander:
        container_name: jgomes_site_dev_redis-commander
        build: './redis-commander'
        platform: linux/amd64
        restart: always
        ports:
            - "8081:8081"
        networks:
            - redis-network
        depends_on:
            - redis
        environment:
            - REDIS_HOSTS=${REDIS_HOSTS}
            - HTTP_USER=${REDIS_USER}
            - HTTP_PASSWORD=${REDIS_PASS}
networks:
    redis-network:
        driver: bridge
volumes:
    dbData:
    redis:
    redis-config:

List of customized services:


Mysql service:

Dockerfile

    # Use an official MySQL runtime as a parent image
    FROM mysql:latest
    
    # Copy the database initialization script to the docker-entrypoint-initdb.d directory
    COPY init-local.sql /tmp/init.sql
    
    # Expose the MySQL port
    EXPOSE 3306
    
    # Start MySQL service
    CMD ["mysqld", "--init-file=/tmp/init.sql"]

init.sql

    -- Drop the development user and database if they exist
    DROP USER IF EXISTS '${DB_USERNAME}'@'%';
    
    -- Create the development database if it doesn't exist
    CREATE DATABASE IF NOT EXISTS ${DB_DATABASE};
    
    -- Create the development user and grant permissions
    CREATE USER '${DB_USERNAME}'@'%' IDENTIFIED BY '${DB_PASSWORD}';
    GRANT ALL PRIVILEGES ON ${DB_DATABASE}.* TO '${DB_USERNAME}'@'%';
    
    -- Flush privileges to apply changes
    FLUSH PRIVILEGES;

NOTE: The './serve.sh' script will get the init.sql file and will create a new file called init-local.sql with all the credential in place based on the zip. The Dockerfile for mysql will use this file. The init-local.sql is not versioned.


Rabbitmq service:

Dockerfile

    FROM rabbitmq:latest
    
    ADD rabbitmq.config /etc/rabbitmq/
    ADD definitions-local.json /etc/rabbitmq/definitions.json
    
    RUN chmod 666 /etc/rabbitmq/*
    RUN rabbitmq-plugins enable rabbitmq_management

definitions.jsom

    {
        "exchanges": [
            {
                "name": "${RABBIT_MESSAGE_QUEUE}",
                "vhost": "/",
                "type": "direct",
                "durable": true,
                "auto_delete": false,
                "internal": false,
                "arguments": {}
            }
        ],
        "users": [
            {
                "name": "${RABBIT_USER}",
                "password": "${RABBIT_PASS}",
                "tags": "administrator"
            }
        ],
        "vhosts": [
            {
                "name": "/"
            }
        ],
        "permissions": [
            {
                "user": "${RABBIT_USER}",
                "vhost": "/",
                "configure": ".*",
                "write": ".*",
                "read": ".*"
            }
        ],
        "queues": [
            {
                "name": "${RABBIT_MESSAGE_QUEUE}",
                "vhost": "/",
                "durable": true,
                "auto_delete": false,
                "arguments": {}
            }
        ],
        "bindings": [
            {
                "source": "${RABBIT_MESSAGE_QUEUE}",
                "vhost": "/",
                "destination": "${RABBIT_MESSAGE_QUEUE}",
                "destination_type": "queue",
                "routing_key": "${RABBIT_MESSAGE_QUEUE}",
                "arguments": {}
            }
        ]
    }

NOTE: The './serve.sh' script will get the definitions.json file and will create a new file called definitions-local.json with all the credential in place based on the zip. The Dockerfile for rabbitmq will use this file. The definitions-local.json is not versioned.

rabbitmq.config

    [
      {rabbit,
        [
          {loopback_users, []}
        ]
      },
      {rabbitmq_management,
        [
          {load_definitions, "/etc/rabbitmq/definitions.json"}
        ]
      }
    ].

NOTE: this will load the definitions in order to make the setup, create, the user. create the user, etc..


Redis-commander service:

Dockerfile

    # redis-commander base image
    FROM rediscommander/redis-commander:latest
    
    # Defined here the env vars
    ENV REDIS_HOSTS=${REDIS_HOSTS}
    ENV HTTP_USER ${REDIS_USER}
    ENV HTTP_PASSWORD ${REDIS_PASS}
    
    # Port expose
    EXPOSE 8081

Ready to Dev! diagram

Ready to Dev! flow diagram

Demonstration

( Click on the image to watch the video )

Demonstration video