/docker-webdev

Multi stage web development stack with centralized logging.

Primary LanguageDockerfileMIT LicenseMIT

Docker Web Development Stack (DWDS)

Docker Containers (as microservice approach), which are executed with docker-compose as a multi-container application (stack).

Develop only through the container.

Each container should have only one concern.

Images and Containers

  • Persistent storage (Application and Data Volume Container).
    • ./src/frontend
    • ./src/backend
    • ./storage/db.data
    • ./storage/gitea.data
  • NGINX Web server. Deliver the frontend ./application/frontend/dist and provide API access via proxy forwarder.
  • PHP 7.4.x (CLI) with Composer, PHP CodeSniffer, phpDocumentor, phpunit and XDebug (Multi Stage) for development.
  • MariaDB SQL database.
  • Adminer for database administration.
  • Grafana logging.
    • Loki: log aggregator
    • Promtail: Agent which will read up the contents of the log file/files and ship those logs to Loki
  • Gitea Repository and Issue tracker.
  • MailDev SMTP Server + Web Interface for viewing and testing emails during development.

Initial services configuration

Gitea

  • To access gitea from your development environment you should set SSH-Server-Domain and Gitea-Base-URL to an appropriate resolvable name or IP address.
  • Add the administration user on setup or the first user registered will be the admin
  • Gitea supports Git over SSH. You might be familiar with this when you work with GitHub repositories. You need to create a key pair on your computer and add the public key under Your Settings -> SSH / GPG Keys . Copy and paste the public key into the Content text field then click the green Add Key button.

Logging

The Docker plugin must be installed on each Docker host that will be running containers you want to collect logs from. Read Docker Driver Client

docker plugin install grafana/loki-docker-driver:latest --alias loki --grant-all-permissions

Add loki to docker container:

    logging:
      driver: loki
      options:
        loki-url: "http://loki:3100/loki/api/v1/push"
      driver: "json-file"
      options:
        tag: "{{.ImageName}}|{{.Name}}|{{.ImageFullID}}|{{.FullID}}"

Additional setup steps and informations:

.env Environment

Environment variables allow us to manage the configuration of our applications separate from our codebase. Separating configurations make it easier for our application to be deployed in different environments. Note: Values in the shell take precedence over those specified in the .env file.

Command line usage

Since everything that has to do with the stack, only runs in the container, you have to put the commands into the corresponding container.

To start/stop the stack, enter the following command in the terminal:

docker-compose -f "docker-compose.yml" up -d
docker-compose -f "docker-compose.yml" down

To open a shell in the application's container, use:

docker exec -it <container> /bin/bash

To execute a PHP script:

docker exec php /usr/local/bin/php /var/www/backend/public/index.php

Creating database dumps:

docker exec db sh -c 'exec mysqldump --all-databases -uroot -p"$MARIADB_ROOT_PASSWORD"' > /some/path/on/your/host/all-databases.sql

Restoring data from dump files

docker exec -i db sh -c 'exec mysql -uroot -p"$MARIADB_ROOT_PASSWORD"' < /some/path/on/your/host/all-databases.sql

Start node development mode

docker exec -it nodejs npm run serve

Build Frontend

docker exec -it nodejs npm run build`

Add packages to node.js

docker exec -it nodejs npm install dotenv --save

Add packages to php

docker exec -it php composer require vlucas/phpdotenv

License

MIT © Fabian Dennler