Giter Site home page Giter Site logo

foxfabi / docker-webdev Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 105 KB

Multi stage web development stack with centralized logging.

License: MIT License

PHP 9.27% Dockerfile 64.32% Shell 21.47% JavaScript 4.94%
php mariadb nginx nodejs grafana mailcatcher adminer xdebug

docker-webdev's Introduction

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

docker-webdev's People

Contributors

foxfabi avatar

Stargazers

 avatar

Watchers

 avatar

docker-webdev's Issues

Container with different persistent storages

It would be nice to use the same containers with different persistent storages, but following approaches didn't work:

  • Using a symbolic link like src -> /DATA/yourapp/src/ and storage -> /DATA/yourapp/storage/
  • Using external volumes defined via .env with ARG/ENV
      args:
        VOLUME: ${CODE_VOLUME}/backend # from .env file
ARG VOLUME
ENV VOLUME $VOLUME
RUN echo $VOLUME
COPY /var/www/backend .
Step 13/32 : ENV VOLUME $VOLUME
 ---> Running in ca0e750133a1
Removing intermediate container ca0e750133a1
 ---> 26acc2042d20
Step 14/32 : RUN echo $VOLUME
 ---> Running in d51dc3439085
/DATA/c0met/src/backend
Removing intermediate container d51dc3439085
 ---> f8265423cab3
Step 15/32 : COPY $VOLUME/backend .
ERROR: Service 'php' failed to build: COPY failed

Maybe I missed something ⭕

Check again:

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.