├── .env_example ├── .github └── workflows │ └── dockerpush.yml ├── .gitignore ├── .gitmodules ├── README.md ├── docker-codeception-run ├── Dockerfile ├── docker-compose.test.yml ├── docker-compose.yml └── run_tests.sh ├── docker-compose.yml ├── docker-run └── docker-compose.yml ├── docs ├── codeception.md ├── install.md ├── mysql-proxy.md └── nginx-proxy.md ├── mysql-proxy-conf ├── log.lua └── main.lua └── nginx-conf └── nginx.conf /.env_example: -------------------------------------------------------------------------------- 1 | DEV_REMOTE_HOST=host.docker.internal 2 | DEV_REMOTE_PORT=9001 3 | DEV_REMOTE_PORT_CODECEPTION=9002 4 | DEV_SERVER_NAME=yii2advanced 5 | DEV_SERVER_NAME_CODECEPTION=codeception 6 | TZ=Europe/Moscow 7 | -------------------------------------------------------------------------------- /.github/workflows/dockerpush.yml: -------------------------------------------------------------------------------- 1 | name: Docker 2 | 3 | on: 4 | push: 5 | # Publish `master` as Docker `latest` image. 6 | branches: 7 | - master 8 | 9 | # Publish `v1.2.3` tags as releases. 10 | tags: 11 | - v* 12 | 13 | # Run tests for any PRs. 14 | pull_request: 15 | 16 | env: 17 | # TODO: Change variable to your image's name. 18 | IMAGE_NAME: docker-yii2-app-advanced 19 | 20 | jobs: 21 | # Run tests. 22 | # See also https://docs.docker.com/docker-hub/builds/automated-testing/ 23 | test: 24 | runs-on: ubuntu-latest 25 | 26 | steps: 27 | - uses: actions/checkout@v2 28 | 29 | - name: Run tests 30 | run: | 31 | docker-compose --file docker-codeception-run/docker-compose.test.yml build 32 | docker-compose --file docker-codeception-run/docker-compose.test.yml run sut 33 | 34 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # phpstorm project files 2 | .idea 3 | 4 | # netbeans project files 5 | nbproject 6 | 7 | # zend studio for eclipse project files 8 | .buildpath 9 | .project 10 | .settings 11 | 12 | # windows thumbnail cache 13 | Thumbs.db 14 | 15 | # Mac DS_Store Files 16 | .DS_Store 17 | 18 | # nginx logs dir 19 | /nginx-logs 20 | 21 | # mysql data dir 22 | /mysql-data 23 | # mysql test data dir 24 | /mysql-data-test 25 | 26 | # mysql-proxy logs dir 27 | /mysql-proxy-logs 28 | 29 | # IDE autocomplite for the codeception classes (within core and vendors) 30 | .codecept 31 | 32 | # docker-compose local config 33 | .env -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "php-data"] 2 | path = php-data 3 | url = https://github.com/yiisoft/yii2-app-advanced.git 4 | [submodule "docker-run/docker-php"] 5 | path = docker-run/docker-php 6 | url = https://github.com/bscheshirwork/docker-php.git 7 | [submodule "docker-codeception-run/docker-codeception-yii2"] 8 | path = docker-codeception-run/docker-codeception-yii2 9 | url = https://github.com/bscheshirwork/docker-codeception-yii2.git 10 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Dockerized docker-yii2-advanced 2 | =============================== 3 | 4 | ![Docker](https://github.com/bscheshir/docker-yii2-app-advanced/workflows/Docker/badge.svg) 5 | 6 | Docker image composition (docker-compose) for [yii2-app-advanced](https://github.com/yiisoft/yii2-app-advanced): 7 | 8 | Simplify your way to start with pure yii2-app-advanced template. 9 | 10 | Use `docker-compose up -d` for run without any debug tools. We can use `nginx-proxy` in same `docker network`. 11 | 12 | You can also use `./docker-compose.yml` (`docker-compose up -d`) in production. 13 | 14 | Create your own local config `cp .env_example .env` and... 15 | 16 | Use `docker-compose -f docker-codeception-run/docker-compose.yml up -d` for built-in image `Codeception`'s tests 17 | 18 | Use `docker-compose -f docker-run/docker-compose.yml up -d` for debug you project through `XDebug`; `mysql-proxy` for show sql-query log. 19 | 20 | * [Install](./docs/install.md) 21 | * [Codeception](/docs/codeception.md). 22 | * [mysql-proxy](/docs/mysql-proxy.md). 23 | * [nginx-proxy](/docs/nginx-proxy.md). 24 | 25 | All Rights Reserved. 26 | 27 | 2020 © bscheshir.work@gmail.com 28 | -------------------------------------------------------------------------------- /docker-codeception-run/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM bscheshir/codeception:php7.4.3-fpm-alpine-yii2 2 | # note: this Dockerfile will be used for autotest reason only. We can use RUN on each line as marker of potentially error breakpoint. 3 | COPY ./run_tests.sh /run_tests.sh 4 | RUN /bin/bash -c 'chmod +x /run_tests.sh' 5 | RUN cat /run_tests.sh 6 | RUN ls -luha /run_tests.sh 7 | RUN curl -L https://raw.githubusercontent.com/vishnubob/wait-for-it/master/wait-for-it.sh -o /usr/local/bin/wait-for-it.sh 8 | RUN /bin/bash -c 'chmod +x /usr/local/bin/wait-for-it.sh' 9 | RUN ls -luha /usr/local/bin/wait-for-it.sh 10 | ENTRYPOINT ["/usr/local/bin/wait-for-it.sh", "db:3306", "--", "/run_tests.sh"] 11 | RUN git clone https://github.com/yiisoft/yii2-app-advanced.git /var/www/html 12 | RUN composer install --no-dev 13 | # replace some config same to docker-compose.test.yml 14 | RUN sed -i -e "s/.*dsn.*/"\'"dsn"\'" => "\'"mysql:host=db;dbname=yii2advanced"\'",/" -e "s/.*username.*/"\'"username"\'" => "\'"yii2advanced"\'",/" -e "s/.*password.*/"\'"password"\'" => "\'"yii2advanced"\'",/" -e "s/.*charset.*/"\'"charset"\'" => "\'"utf8mb4"\'",/" /var/www/html/environments/dev/common/config/main-local.php 15 | RUN sed -i -e "s/.*dsn.*/"\'"dsn"\'" => "\'"mysql:host=db;dbname=yii2advanced"\'",/" /var/www/html/environments/dev/common/config/test-local.php 16 | # use --env=Development both with not use gii and debug modules 17 | RUN cp /var/www/html/environments/prod/console/config/main-local.php /var/www/html/environments/dev/console/config/main-local.php 18 | RUN cp /var/www/html/environments/prod/frontend/config/main-local.php /var/www/html/environments/dev/frontend/config/main-local.php 19 | RUN cp /var/www/html/environments/prod/backend/config/main-local.php /var/www/html/environments/dev/backend/config/main-local.php 20 | RUN ./init --env=Development --overwrite=All 21 | -------------------------------------------------------------------------------- /docker-codeception-run/docker-compose.test.yml: -------------------------------------------------------------------------------- 1 | version: '3.7' 2 | services: 3 | sut: 4 | build: . 5 | depends_on: 6 | - db 7 | volumes: 8 | - php-data:/var/www/html #php-data must populate 9 | - ~/.composer/cache:/root/.composer/cache 10 | environment: 11 | TZ: "${TZ:-Europe/Moscow}" 12 | nginx: 13 | image: nginx:1.17.8-alpine 14 | restart: always 15 | depends_on: 16 | - sut 17 | volumes: 18 | - php-data:/var/www/html:ro #php-data 19 | - ../nginx-conf-test:/etc/nginx/conf.d #nginx-conf 20 | - ../nginx-logs:/var/log/nginx #nginx-logs 21 | networks: 22 | default: 23 | aliases: 24 | - backend.dev 25 | - frontend.dev 26 | environment: 27 | TZ: "${TZ:-Europe/Moscow}" 28 | db: 29 | image: mysql:8.0.19 30 | entrypoint: 31 | - '/entrypoint.sh' 32 | - '--default-authentication-plugin=mysql_native_password' # https://dev.mysql.com/doc/refman/8.0/en/server-system-variables.html#sysvar_default_authentication_plugin 33 | restart: always 34 | ports: 35 | - "33006:3306" 36 | volumes: 37 | - ../mysql-data-test/db:/var/lib/mysql #mysql-data 38 | environment: 39 | TZ: "${TZ:-Europe/Moscow}" 40 | MYSQL_ROOT_PASSWORD: yii2advanced 41 | MYSQL_DATABASE: yii2advanced 42 | MYSQL_USER: yii2advanced 43 | MYSQL_PASSWORD: yii2advanced 44 | browser: 45 | image: selenium/standalone-chrome-debug:3.141.59 46 | volumes: 47 | - /dev/shm:/dev/shm # the docker run instance may use the default 64MB, that may not be enough in some cases 48 | ports: 49 | - '4444' 50 | - '5900' 51 | environment: 52 | TZ: "${TZ:-Europe/Moscow}" 53 | volumes: 54 | php-data: 55 | -------------------------------------------------------------------------------- /docker-codeception-run/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '3.7' 2 | services: 3 | php: 4 | image: bscheshir/php:7.4.3-fpm-alpine-4yii2-xdebug 5 | restart: always 6 | volumes: 7 | - ../php-data:/var/www/html #php-data 8 | - ~/.composer/cache:/root/.composer/cache 9 | depends_on: 10 | - db 11 | environment: 12 | TZ: "${TZ:-Europe/Moscow}" 13 | XDEBUG_CONFIG: "remote_host=${DEV_REMOTE_HOST} remote_port=${DEV_REMOTE_PORT} remote_enable=On var_display_max_data=1024 var_display_max_depth=5" 14 | PHP_IDE_CONFIG: "serverName=${DEV_SERVER_NAME}" 15 | nginx: 16 | image: nginx:1.17.8-alpine 17 | restart: always 18 | depends_on: 19 | - php 20 | volumes: 21 | - ../php-data:/var/www/html #php-data 22 | - ../nginx-conf-test:/etc/nginx/conf.d #nginx-conf 23 | - ../nginx-logs:/var/log/nginx #nginx-logs 24 | networks: 25 | default: 26 | aliases: 27 | - backend.dev 28 | - frontend.dev 29 | environment: 30 | TZ: "${TZ:-Europe/Moscow}" 31 | db: 32 | image: mysql:8.0.19 33 | entrypoint: 34 | - '/entrypoint.sh' 35 | - '--default-authentication-plugin=mysql_native_password' # https://dev.mysql.com/doc/refman/8.0/en/server-system-variables.html#sysvar_default_authentication_plugin 36 | restart: always 37 | ports: 38 | - "33006:3306" 39 | volumes: 40 | - ../mysql-data-test/db:/var/lib/mysql #mysql-data 41 | environment: 42 | TZ: "${TZ:-Europe/Moscow}" 43 | MYSQL_ROOT_PASSWORD: yii2advanced 44 | MYSQL_DATABASE: yii2advanced 45 | MYSQL_USER: yii2advanced 46 | MYSQL_PASSWORD: yii2advanced 47 | codecept: 48 | image: bscheshir/codeception:php7.4.3-fpm-alpine-yii2 49 | depends_on: 50 | - nginx 51 | - browser 52 | volumes: 53 | - ../php-data:/var/www/html #php-data 54 | environment: 55 | TZ: "${TZ:-Europe/Moscow}" 56 | XDEBUG_CONFIG: "remote_host=${DEV_REMOTE_HOST} remote_port=${DEV_REMOTE_PORT_CODECEPTION} remote_enable=On" 57 | PHP_IDE_CONFIG: "serverName=${DEV_SERVER_NAME_CODECEPTION}" 58 | browser: 59 | image: selenium/standalone-chrome-debug:3.141.59 60 | volumes: 61 | - /dev/shm:/dev/shm # the docker run instance may use the default 64MB, that may not be enough in some cases 62 | ports: 63 | - '4444' 64 | - '5900' 65 | environment: 66 | TZ: "${TZ:-Europe/Moscow}" 67 | -------------------------------------------------------------------------------- /docker-codeception-run/run_tests.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | echo "composer global show" 3 | composer global show 4 | cd /repo 5 | echo "codeception: composer show" 6 | composer show 7 | cd /var/www/html 8 | echo "testing code: composer show" 9 | composer show 10 | ls -luha 11 | ./yii migrate/up --interactive=0 12 | codecept run --no-redirect 13 | -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '3.7' 2 | services: 3 | php: 4 | image: bscheshir/php:7.4.3-fpm-alpine-4yii2 5 | restart: always 6 | volumes: 7 | - ./php-data:/var/www/html #php-data 8 | - ~/.composer/cache:/root/.composer/cache 9 | depends_on: 10 | - db 11 | environment: 12 | TZ: "${TZ:-Europe/Moscow}" 13 | XDEBUG_CONFIG: "remote_enable=Off remote_autostart=Off" 14 | nginx: 15 | image: nginx:1.17.8-alpine 16 | restart: always 17 | expose: 18 | - "8080" 19 | - "8081" 20 | # ports: # use nginx-proxy in same network (see ./docs/nginx-proxy.md) 21 | # - "8080:8080" 22 | # - "8081:8081" 23 | depends_on: 24 | - php 25 | volumes: 26 | - ./php-data:/var/www/html #php-data 27 | - ./nginx-conf:/etc/nginx/conf.d #nginx-conf 28 | - ./nginx-logs:/var/log/nginx #nginx-logs 29 | environment: 30 | TZ: "${TZ:-Europe/Moscow}" 31 | db: 32 | image: mysql:8.0.19 33 | entrypoint: 34 | - '/entrypoint.sh' 35 | - '--default-authentication-plugin=mysql_native_password' # https://dev.mysql.com/doc/refman/8.0/en/server-system-variables.html#sysvar_default_authentication_plugin 36 | restart: always 37 | volumes: 38 | - ./mysql-data/db:/var/lib/mysql #mysql-data 39 | environment: 40 | TZ: "${TZ:-Europe/Moscow}" 41 | MYSQL_ROOT_PASSWORD: yii2advanced 42 | MYSQL_DATABASE: yii2advanced 43 | MYSQL_USER: yii2advanced 44 | MYSQL_PASSWORD: yii2advanced 45 | -------------------------------------------------------------------------------- /docker-run/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '3.7' 2 | services: 3 | php: 4 | image: bscheshir/php:7.4.3-fpm-alpine-4yii2-xdebug 5 | restart: always 6 | volumes: 7 | - ../php-data:/var/www/html #php-data 8 | - ~/.composer/cache:/root/.composer/cache 9 | depends_on: 10 | - db 11 | environment: 12 | TZ: "${TZ:-Europe/Moscow}" 13 | XDEBUG_CONFIG: "remote_host=${DEV_REMOTE_HOST} remote_port=${DEV_REMOTE_PORT} var_display_max_data=1024 var_display_max_depth=5" 14 | PHP_IDE_CONFIG: "serverName=${DEV_SERVER_NAME}" 15 | nginx: 16 | image: nginx:1.17.8-alpine 17 | restart: always 18 | ports: 19 | - "8080:8080" 20 | - "8081:8081" 21 | depends_on: 22 | - php 23 | volumes: 24 | - ../php-data:/var/www/html #php-data 25 | - ../nginx-conf:/etc/nginx/conf.d #nginx-conf 26 | - ../nginx-logs:/var/log/nginx #nginx-logs 27 | environment: 28 | TZ: "${TZ:-Europe/Moscow}" 29 | mysql: 30 | image: mysql:8.0.19 31 | entrypoint: 32 | - '/entrypoint.sh' 33 | - '--default-authentication-plugin=mysql_native_password' # https://dev.mysql.com/doc/refman/8.0/en/server-system-variables.html#sysvar_default_authentication_plugin 34 | restart: always 35 | expose: 36 | - "3306" #for service mysql-proxy 37 | ports: 38 | - "3307:3306" #for external connection 39 | volumes: 40 | - ../mysql-data/db:/var/lib/mysql #mysql-data 41 | environment: 42 | TZ: "${TZ:-Europe/Moscow}" 43 | MYSQL_ROOT_PASSWORD: yii2advanced 44 | MYSQL_DATABASE: yii2advanced 45 | MYSQL_USER: yii2advanced 46 | MYSQL_PASSWORD: yii2advanced 47 | db: #mysql-proxy 48 | image: bscheshir/mysql-proxy:0.8.5 49 | expose: 50 | - "3306" #for service php 51 | ports: 52 | - "3308:3306" #for external connection 53 | restart: always 54 | volumes: 55 | - ../mysql-proxy-conf:/opt/mysql-proxy/conf 56 | - ../mysql-proxy-logs:/opt/mysql-proxy/logs 57 | depends_on: 58 | - mysql 59 | environment: 60 | TZ: "${TZ:-Europe/Moscow}" 61 | PROXY_DB_HOST: 62 | PROXY_DB_PORT: 3306 63 | REMOTE_DB_HOST: mysql 64 | REMOTE_DB_PORT: 3306 65 | LUA_SCRIPT: "/opt/mysql-proxy/conf/log.lua" 66 | LOG_FILE: "/opt/mysql-proxy/logs/mysql.log" 67 | -------------------------------------------------------------------------------- /docs/codeception.md: -------------------------------------------------------------------------------- 1 | 2 | ## Codeception docker image 3 | 4 | Use [bscheshir/codeception:php-fpm-yii2](https://github.com/bscheshirwork/docker-codeception-yii2) 5 | 6 | submodule in `docker-codeception-run/docker-codeception-yii2` 7 | 8 | [Parallel Execution](http://codeception.com/docs/12-ParallelExecution) 9 | 10 | [How to start testing](https://github.com/yiisoft/yii2-app-advanced/blob/master/docs/guide/start-testing.md) 11 | -------------------------------------------------------------------------------- /docs/install.md: -------------------------------------------------------------------------------- 1 | 2 | Install [docker](https://docs.docker.com/engine/getstarted/step_one/) and [docker-compose](https://docs.docker.com/compose/install/) 3 | > Note: we need the latest version (read this instruction!) 4 | 5 | 1.Clone project 6 | ```sh 7 | $ git clone https://github.com/bscheshirwork/docker-yii2-advanced newproject 8 | ``` 9 | 10 | 2.Start the `php` service 11 | 12 | ```sh 13 | $ cd newproject/docker-run 14 | $ docker-compose run php /bin/bash 15 | Creating network "dockerrun_default" with the default driver 16 | Creating dockerrun_db_1 17 | root@abfe3b3ca645:/var/www/html# 18 | ``` 19 | 20 | Inside the container: 21 | ```sh 22 | root@abfe3b3ca645:/var/www/html# 23 | ``` 24 | 2.1.Run `composer update` and use github token (see `https://github.com/settings/tokens`) 25 | 26 | cache folder simply linked into containers 27 | `- ~/.composer/cache:/root/.composer/cache` 28 | 29 | ```sh 30 | composer update -vv 31 | ``` 32 | 33 | 2.2.Run yii2 init script (0 - Development) to create local settings (see [preparing-application](https://github.com/yiisoft/yii2-app-advanced/blob/master/docs/guide/start-installation.md#preparing-application) 1-3) 34 | ```sh 35 | ./init 36 | ``` 37 | 38 | 2.3.Synchronize db settings (`docker-run/docker-compose.yml`, `php-data/common/config/main-local.php`; `docker-codeception-run/docker-compose.yml`, `php-data/common/config/test-local.php`) 39 | `php-data/common/config/main-local.php` 40 | ```sh 41 | 'db' => [ 42 | 'class' => 'yii\db\Connection', 43 | 'dsn' => 'mysql:host=db;dbname=yii2advanced', 44 | 'username' => 'yii2advanced', 45 | 'password' => 'yii2advanced', 46 | 'charset' => 'utf8', 47 | ], 48 | ``` 49 | 50 | For tests we're using the same component `db` with the same connection string because we're using 51 | another folder to sync with docker contaner (`mysql-data-test`) 52 | `php-data/common/config/test-local.php` 53 | ```sh 54 | 'db' => [ 55 | ], 56 | ``` 57 | 58 | 2.4.Run migration 59 | ```sh 60 | ./yii migrate 61 | ``` 62 | > Note: error? `docker-compose down` and `sudo rm -rf ../mysql-data/*` 63 | 64 | > Note: you can use mysqldump (in another terminal) this way: 65 | ```sh 66 | docker exec dockerrun_db_1 sh -c 'exec mysqldump -uroot -p"$MYSQL_ROOT_PASSWORD" yii2advanced' > /some/path/on/your/host/yii2advanced.sql 67 | ``` 68 | 69 | 2.5.Leave container (`exit`, ctrl+c) 70 | 71 | 3.Run the composition 72 | ```sh 73 | $ docker-compose up -d 74 | Creating network "dockerrun_default" with the default driver 75 | Creating dockerrun_db_1 76 | Creating dockerrun_php_1 77 | Creating dockerrun_nginx_1 78 | ``` 79 | 80 | 4.See url `0.0.0.0:8080` - frontend, `0.0.0.0:8081` - backend 81 | 82 | For xdebug we can use environment 83 | ```yml 84 | XDEBUG_CONFIG: "remote_host=dev-Aspire-V3-772 remote_port=9001" 85 | PHP_IDE_CONFIG: "serverName=docker-yii2-advanced" 86 | ``` 87 | `remote_host` can be your IP address (outside of docker network) or your DNS if you have a dns-server (for example - local dns server or dns-server in your router; possibly you have a domain name like your machine name). Docker will connect to this DNS server from the running php container and resolve it. 88 | 89 | > In `mac OS` you can use docker special name `host.docker.internal`. 90 | 91 | 92 | PHPStorm settings: 93 | 94 | Create new Service named 95 | `Settings > Languages & Frameworks > PHP > Servers: [Name => yii2advanced]` 96 | value is equal to `serverName` https://github.com/bscheshirwork/docker-yii2-app-advanced/blob/3cca9ab6521040fffd6fae4c6a8d485fde083b66/docker-run/docker-compose.yml#L14 97 | (other values (`ip`, `port`) doesn't matter). 98 | 99 | Use path mapping: 100 | `Settings > Languages & Frameworks > PHP > Servers: [Use path mapping => True, /your/machine/path/to/php-data => /var/www/html]` 101 | Change debug port from 9000 to 9001 102 | `Settings > Languages & Frameworks > PHP > Debug: [Debug port => 9001]` 103 | https://github.com/bscheshirwork/docker-yii2-app-advanced/blob/3cca9ab6521040fffd6fae4c6a8d485fde083b66/docker-run/docker-compose.yml#L13 104 | `remote_port=9001` 105 | 106 | # Upgrade to latest MySQL 107 | 108 | For existing projects with `MySQL 8.0.12`: 109 | ```sh 110 | docker-compose up -d 111 | docker-compose exec mysql mysql_upgrade -uroot -p 112 | ``` 113 | https://dev.mysql.com/doc/relnotes/mysql/8.0/en/news-8-0-13.html -------------------------------------------------------------------------------- /docs/mysql-proxy.md: -------------------------------------------------------------------------------- 1 | # mysql-proxy 2 | https://github.com/bscheshirwork/docker-mysql-proxy 3 | 4 | # Usage with docker-compose 5 | 6 | without 7 | ```yml 8 | version: '2' 9 | 10 | services: 11 | db: 12 | image: mysql:8.0.19 13 | restart: always 14 | ports: 15 | - "3306:3306" 16 | volumes: 17 | - ../mysql-data/db:/var/lib/mysql #mysql-data 18 | environment: 19 | MYSQL_ROOT_PASSWORD: yii2advanced 20 | MYSQL_DATABASE: yii2advanced 21 | MYSQL_USER: yii2advanced 22 | MYSQL_PASSWORD: yii2advanced 23 | ``` 24 | 25 | within 26 | ```yml 27 | version: '2' 28 | 29 | services: 30 | mysql: 31 | image: mysql:8.0.19 32 | restart: always 33 | expose: 34 | - "3306" #for service mysql-proxy 35 | ports: 36 | - "3307:3306" #for external connection 37 | volumes: 38 | - ../mysql-data/db:/var/lib/mysql #mysql-data 39 | environment: 40 | MYSQL_ROOT_PASSWORD: yii2advanced 41 | MYSQL_DATABASE: yii2advanced 42 | MYSQL_USER: yii2advanced 43 | MYSQL_PASSWORD: yii2advanced 44 | db: 45 | image: bscheshir/mysqlproxy:0.8.5 46 | expose: 47 | - "3306" #for service php 48 | ports: 49 | - "3308:3306" #for external connection 50 | restart: always 51 | volumes: 52 | - ../mysql-proxy/main.lua:/opt/main.lua 53 | environment: 54 | PROXY_DB_PORT: 3306 55 | REMOTE_DB_HOST: mysql 56 | REMOTE_DB_PORT: 3306 57 | PROXY_LUA_SCRIPT: "/opt/main.lua" 58 | depends_on: 59 | - mysql 60 | ``` 61 | 62 | # Query to stdout 63 | For `docker-compose up` without `-d` (`../mysql-proxy/main.lua`) 64 | ```lua 65 | function read_query(packet) 66 | if string.byte(packet) == proxy.COM_QUERY then 67 | print(string.sub(packet, 2)) 68 | end 69 | end 70 | ``` 71 | 72 | # Query logging for mysql-proxy 73 | 74 | ```yml 75 | ... 76 | volumes: 77 | - ../mysql-proxy/log.lua:/opt/log.lua 78 | - ../mysql-proxy/mysql.log:/opt/mysql-proxy/mysql.log 79 | environment: 80 | PROXY_DB_PORT: 3306 81 | REMOTE_DB_HOST: mysql 82 | REMOTE_DB_PORT: 3306 83 | PROXY_LUA_SCRIPT: "/opt/log.lua" 84 | ... 85 | ``` 86 | 87 | `/mysql-proxy/log.lua` https://gist.github.com/simonw/1039751 88 | ```lua 89 | local log_file = '/opt/mysql-proxy/mysql.log' 90 | 91 | local fh = io.open(log_file, "a+") 92 | 93 | function read_query( packet ) 94 | if string.byte(packet) == proxy.COM_QUERY then 95 | local query = string.sub(packet, 2) 96 | fh:write( string.format("%s %6d -- %s \n", 97 | os.date('%Y-%m-%d %H:%M:%S'), 98 | proxy.connection.server["thread_id"], 99 | query)) 100 | fh:flush() 101 | end 102 | end 103 | ``` 104 | # thanks 105 | 106 | https://hub.docker.com/r/zwxajh/mysql-proxy 107 | https://hub.docker.com/r/gediminaspuksmys/mysqlproxy/ 108 | 109 | # troubleshooting 110 | If you can't create the chain `mysql` -> `mysql-proxy` -> `external client liten 0.0.0.0:3308` 111 | check extends ports on the `mysql` service and/or add `expose` directly 112 | ```yml 113 | expose: 114 | - "3306" #for service mysql-proxy 115 | ``` 116 | 117 | You can create 118 | ```sh 119 | touch mysql-proxy/mysql.log 120 | ``` 121 | before run the suite -------------------------------------------------------------------------------- /docs/nginx-proxy.md: -------------------------------------------------------------------------------- 1 | # Nginx-proxy 2 | 3 | You can use `nginx-proxy` docker-compose in same docker network to resolve virtual hosts 4 | 5 | Make `nginx-proxy` folder and use it. 6 | Make files like this 7 | 8 | ### `nginx-conf/nginx.conf` 9 | ```conf 10 | server { 11 | listen 80; 12 | server_name frontend.dev www.frontend.dev; 13 | 14 | access_log /var/log/nginx/proxy-access.log; 15 | error_log /var/log/nginx/proxy-error.log; 16 | 17 | location / { 18 | proxy_pass http://nginx:8080/; 19 | proxy_set_header X-Real-IP $remote_addr; 20 | proxy_set_header Host $http_host; 21 | proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 22 | } 23 | 24 | location ~ /\.(ht|svn|git) { 25 | deny all; 26 | } 27 | } 28 | 29 | server { 30 | listen 80; 31 | server_name backend.dev www.backend.dev; 32 | 33 | access_log /var/log/nginx/proxy-access.log; 34 | error_log /var/log/nginx/proxy-error.log; 35 | 36 | location / { 37 | proxy_pass http://nginx:8081/; 38 | proxy_set_header X-Real-IP $remote_addr; 39 | proxy_set_header Host $http_host; 40 | proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 41 | } 42 | 43 | location ~ /\.(ht|svn|git) { 44 | deny all; 45 | } 46 | } 47 | ``` 48 | 49 | ### `docker-compose.yml` 50 | ```yml 51 | version: '2' 52 | services: 53 | nginx-proxy: 54 | image: nginx:1.17.8-alpine 55 | restart: always 56 | ports: 57 | - "80:80" 58 | volumes: 59 | - ./nginx-conf:/etc/nginx/conf.d #nginx-conf 60 | - ./nginx-logs:/var/log/nginx #nginx-logs 61 | networks: 62 | default: 63 | external: 64 | name: dockeryii2appadvanced_default 65 | ``` 66 | 67 | Use 68 | ```sh 69 | docker-compose -f nginx-proxy/docker-compose.yml up -d 70 | ``` 71 | command after `docker-compose up -d` of main composition. -------------------------------------------------------------------------------- /mysql-proxy-conf/log.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | 3 | Copyright (C) 2007 MySQL AB 4 | 5 | This program is free software; you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation; version 2 of the License. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program; if not, write to the Free Software 16 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 | 18 | --]] 19 | 20 | --- 21 | -- Uses MySQL-Proxy to log your queries 22 | -- Downloaded from http://ronaldbradford.com/mysql-dba/mysql-proxy/log.lua 23 | -- 24 | -- Written by Giuseppe Maxia, based on examples provided 25 | -- by Jan Knesckhe 26 | -- 27 | -- This script will log the current date and time, the connection id 28 | -- and the query to a file named "mysql.log" 29 | -- 30 | local log_file = os.getenv("LOG_FILE") 31 | 32 | local fh = io.open(log_file, "a+") 33 | 34 | function read_query( packet ) 35 | if string.byte(packet) == proxy.COM_QUERY then 36 | local query = string.sub(packet, 2) 37 | fh:write( string.format("%s %6d -- %s \n", 38 | os.date('%Y-%m-%d %H:%M:%S'), 39 | proxy.connection.server["thread_id"], 40 | query)) 41 | fh:flush() 42 | end 43 | end -------------------------------------------------------------------------------- /mysql-proxy-conf/main.lua: -------------------------------------------------------------------------------- 1 | function read_query(packet) 2 | if string.byte(packet) == proxy.COM_QUERY then 3 | print(string.sub(packet, 2)) 4 | end 5 | end 6 | -------------------------------------------------------------------------------- /nginx-conf/nginx.conf: -------------------------------------------------------------------------------- 1 | server { 2 | charset utf-8; 3 | client_max_body_size 128M; 4 | 5 | listen 8080; ## listen for ipv4 6 | #listen [::]:80 default_server ipv6only=on; ## слушаем ipv6 7 | 8 | server_name frontend.dev; 9 | root /var/www/html/frontend/web; 10 | index index.php; 11 | 12 | access_log /var/log/nginx/frontend-access.log; 13 | error_log /var/log/nginx/frontend-error.log; 14 | 15 | location / { 16 | # Перенаправляем все запросы к несуществующим директориям и файлам на index.php 17 | try_files $uri $uri/ /index.php?$args; 18 | } 19 | 20 | # раскомментируйте строки ниже во избежание обработки Yii обращений к несуществующим статическим файлам 21 | location ~ \.(js|css|png|jpg|gif|swf|ico|pdf|mov|fla|zip|rar)$ { 22 | try_files $uri =404; 23 | } 24 | #error_page 404 /404.html; 25 | 26 | # deny accessing php files for the /assets directory 27 | location ~ ^/assets/.*\.php$ { 28 | deny all; 29 | } 30 | 31 | location ~ \.php$ { 32 | include fastcgi.conf; 33 | fastcgi_pass php:9000; 34 | #fastcgi_pass unix:/var/run/php5-fpm.sock; 35 | } 36 | 37 | location ~ /\.(ht|svn|git) { 38 | deny all; 39 | } 40 | } 41 | 42 | server { 43 | charset utf-8; 44 | client_max_body_size 128M; 45 | 46 | listen 8081; ## listen for ipv4 47 | #listen [::]:80 default_server ipv6only=on; ## слушаем ipv6 48 | 49 | server_name backend.dev; 50 | root /var/www/html/backend/web; 51 | index index.php; 52 | 53 | access_log /var/log/nginx/backend-access.log; 54 | error_log /var/log/nginx/backend-error.log; 55 | 56 | location / { 57 | # Перенаправляем все запросы к несуществующим директориям и файлам на index.php 58 | try_files $uri $uri/ /index.php?$args; 59 | } 60 | 61 | # раскомментируйте строки ниже во избежание обработки Yii обращений к несуществующим статическим файлам 62 | location ~ \.(js|css|png|jpg|gif|swf|ico|pdf|mov|fla|zip|rar)$ { 63 | try_files $uri =404; 64 | } 65 | #error_page 404 /404.html; 66 | 67 | # deny accessing php files for the /assets directory 68 | location ~ ^/assets/.*\.php$ { 69 | deny all; 70 | } 71 | 72 | location ~ \.php$ { 73 | include fastcgi.conf; 74 | fastcgi_pass php:9000; 75 | #fastcgi_pass unix:/var/run/php5-fpm.sock; 76 | } 77 | 78 | location ~ /\.(ht|svn|git) { 79 | deny all; 80 | } 81 | } 82 | --------------------------------------------------------------------------------