-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 0093369
Showing
23 changed files
with
800 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
TIMEZONE=Europe/Moscow | ||
APP_PROJECT_ROOT=../app | ||
LOGS_ROOT=../logs | ||
APP_PHPFPM_PORT=9000 | ||
APP_NGINX_SERVER_NAME=app.localhost | ||
NGINX_PORT=80 | ||
DB_HOST=mysql | ||
DB_PORT=3306 | ||
DB_ROOT_PASSWORD=root | ||
DB_USER=dbuser | ||
DB_PASSWORD=somePassword | ||
DB_DIR=/var/lib/mysql | ||
REDIS_HOST=redis | ||
REDIS_PORT=6379 | ||
RABBITMQ_HOST=rabbitmq | ||
RABBITMQ_PORT=5672 | ||
RABBITMQ_MANAGEMENT_PORT=15672 | ||
RABBITMQ_USER=rabbitmq | ||
RABBITMQ_PASSWORD=rabbitmq | ||
RABBITMQ_ERLANG_COOKIE=4e15a2412b6fa28647396c2a81e0fb21 | ||
ELK_PORT=81 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
## 0BSD license | ||
|
||
Copyright (C) 2006 by Rob Landley <[email protected]> | ||
|
||
Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
SELF_DIR := $(abspath $(dir $(lastword $(MAKEFILE_LIST)))) | ||
PHP_SERVICE := docker-compose exec webapp sh -c | ||
|
||
# Define a static project name that will be prepended to each service name | ||
export COMPOSE_PROJECT_NAME := symfony | ||
|
||
# Create configuration files needed by the environment | ||
SETUP_ENV := $(shell (test -f $(SELF_DIR).env || cp $(SELF_DIR).env.dist $(SELF_DIR).env)) | ||
|
||
# Extract environment variables needed by the environment | ||
export DB_DIR := $(shell grep DB_DIR $(SELF_DIR).env | awk -F '=' '{print $$NF}') | ||
|
||
|
||
## | ||
## ---------------------------------------------------------------------------- | ||
## Environment | ||
## ---------------------------------------------------------------------------- | ||
## | ||
|
||
backup: ## Backup the "db" volume | ||
docker run --rm \ | ||
--volumes-from $$(docker-compose ps -q db) \ | ||
-v $(dir $(SELF_DIR))backup:/backup \ | ||
busybox sh -c "tar cvf /backup/backup.db.tar $(DB_DIR)" | ||
|
||
build: ## Build the environment | ||
docker-compose build | ||
|
||
cache: ## Flush the Symfony cache | ||
$(PHP_SERVICE) "bin/console cache:clear" | ||
|
||
logs: ## Follow logs generated by all containers + 10 most recent entries. | ||
docker-compose logs -f --tail=10 | ||
|
||
logs-full: ## Follow logs generated by all containers + 50 most recent entries. | ||
docker-compose logs -f --tail=50 | ||
|
||
nginx: ## Open a terminal in the "nginx" container | ||
docker-compose exec nginx sh | ||
|
||
app: ## Open a terminal in the "app" container | ||
docker-compose exec app sh | ||
|
||
db: ## Open a terminal in the "db" container | ||
docker-compose exec db sh | ||
|
||
redis: ## Open a terminal in the "redis" container | ||
docker-compose exec redis sh | ||
|
||
rabbit: ## Open a terminal in the "rabbitmq" container | ||
docker-compose exec rabbitmq sh | ||
|
||
elk: ## Open a terminal in the "elk" container | ||
docker-compose exec elk sh | ||
|
||
ps: ## List all containers managed by the environment | ||
docker-compose ps | ||
|
||
restore: ## Restore the "db" volume | ||
docker run --rm \ | ||
--volumes-from $$(docker-compose ps -q db) \ | ||
-v $(dir $(SELF_DIR))backup:/backup \ | ||
busybox sh -c "tar xvf /backup/backup.db.tar /var/lib/mysql" | ||
docker-compose restart db | ||
|
||
start: ## Start the environment | ||
docker-compose build | ||
docker-compose up -d --remove-orphans | ||
|
||
stats: ## Print real-time statistics about containers ressources usage | ||
docker stats $(docker ps --format={{.Names}}) | ||
|
||
stop: ## Stop the environment | ||
docker-compose stop | ||
|
||
.PHONY: backup build cache composer logs logs-full nginx web db redis rabbit elk ps restore start stats stop | ||
|
||
.DEFAULT_GOAL := help | ||
help: | ||
@grep -E '(^[a-zA-Z_-]+:.*?##.*$$)|(^##)' $(MAKEFILE_LIST) \ | ||
| sed -e 's/^.*Makefile://g' \ | ||
| awk 'BEGIN {FS = ":.*?## "}; {printf "\033[32m%-30s\033[0m %s\n", $$1, $$2}' \ | ||
| sed -e 's/\[32m##/[33m/' | ||
.PHONY: help |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
Real Docker environment for Symfony apps | ||
============== | ||
|
||
This is a complete and hightly flexible stack for running Symfony 4 (latest version: Flex) into Docker containers using docker-compose tool. | ||
|
||
## Features | ||
* Flexible and easily configurable. | ||
* (Almost) production-ready. | ||
* Uses it's own makefile to manage the environment. | ||
|
||
## Installation | ||
|
||
* Clone the repository into `docker` folder (or wherever you wish). | ||
* Make sure you have `make` installed on your host machine. | ||
* Copy `.env.dist` into `.env` and configure to your liking. | ||
* Use `make start` to build & start the env. | ||
|
||
|
||
## Services | ||
* `nginx`: [nginx:1.15-alpine](nginx/Dockerfile) custom NGINX image. | ||
* `php-fpm`: [php:7.2-fpm-alpine](php/Dockerfile) custom image with additional extensions and Composer. | ||
* `redis`: [redis:5.0-alpine](https://hub.docker.com/_/mysql/) official Redis image. | ||
* `elk`: [willdurand/elk](https://hub.docker.com/r/willdurand/elk) complete ELK stack. | ||
* `rabbitmq`: [rabbitmq:3.7-management-alpine](https://hub.docker.com/_/rabbitmq/) RabbitMQ image with admin UI. | ||
|
||
## Logs | ||
|
||
You can access Nginx and your application logs in the following directories on your host machine: | ||
|
||
* `logs/nginx` | ||
* `logs/app` | ||
|
||
## Documentation | ||
|
||
> In order to make things more readable, and maintainable, the documentation has been migrated to | ||
the [repository Wiki](https://github.com/okwinza/docker-symfony/wiki). Where you will find all details about the | ||
installation process along the available instructions for the day-to-day work. | ||
|
||
## Code license | ||
|
||
You are free to use the code in this repository under the terms of the 0-clause BSD license. LICENSE contains a copy of this license. | ||
|
||
## Useful links | ||
|
||
This docker setup is based on following works: | ||
* [ajardin/docker-symfony](https://github.com/ajardin/docker-symfony) | ||
* [eko/docker-symfony](https://github.com/eko/docker-symfony) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
version: '3.7' | ||
services: | ||
db: | ||
image: mysql | ||
build: ./mysql | ||
restart: on-failure | ||
command: ["--default-authentication-plugin=mysql_native_password"] | ||
ports: | ||
- "${DB_PORT}:3306" | ||
volumes: | ||
- db:/var/lib/mysql | ||
environment: | ||
TZ: ${TIMEZONE} | ||
MYSQL_ROOT_PASSWORD: ${DB_ROOT_PASSWORD} | ||
MYSQL_USER: ${DB_USER} | ||
MYSQL_PASSWORD: ${DB_PASSWORD} | ||
tty: true | ||
|
||
app: | ||
image: app | ||
build: ./php-fpm | ||
restart: on-failure | ||
ports: | ||
- "${APP_PHPFPM_PORT}:9000" | ||
volumes: | ||
- ${APP_PROJECT_ROOT}:/var/www/app:cached | ||
- ${LOGS_ROOT}/app/symfony:/var/www/app/var/log:cached | ||
- ${LOGS_ROOT}/app/php:/var/log/php:cached | ||
environment: | ||
TZ: ${TIMEZONE} | ||
REDIS_HOST: redis | ||
REDIS_PORT: ${REDIS_PORT} | ||
RABBITMQ_HOST: rabbitmq | ||
RABBITMQ_PORT: ${RABBITMQ_PORT} | ||
RABBITMQ_USER: ${RABBITMQ_USER} | ||
RABBITMQ_PASS: ${RABBITMQ_PASSWORD} | ||
DB_HOST: db | ||
DB_PORT: ${DB_PORT} | ||
DB_USER: ${DB_USER} | ||
DB_PASSWORD: ${DB_PASSWORD} | ||
links: | ||
- db | ||
- redis | ||
- rabbitmq | ||
tty: true | ||
|
||
nginx: | ||
image: nginx | ||
build: ./nginx | ||
restart: on-failure | ||
ports: | ||
- "${NGINX_PORT}:80" | ||
links: | ||
- app | ||
volumes: | ||
- ${LOGS_ROOT}/nginx:/var/log/nginx:cached | ||
- ${APP_PROJECT_ROOT}:/var/www/app:cached | ||
environment: | ||
TZ: ${TIMEZONE} | ||
APP_PHPFPM_PORT: ${APP_PHPFPM_PORT} | ||
APP_NGINX_SERVER_NAME: ${APP_NGINX_SERVER_NAME} | ||
tty: true | ||
|
||
elk: | ||
image: willdurand/elk | ||
restart: on-failure | ||
ports: | ||
- "${ELK_PORT}:80" | ||
volumes: | ||
- ./elk/logstash:/etc/logstash:cached | ||
- ${LOGS_ROOT}/app:/var/www/app/var/log:cached | ||
- ${LOGS_ROOT}/nginx:/var/log/nginx:cached | ||
environment: | ||
TZ: ${TIMEZONE} | ||
tty: true | ||
|
||
redis: | ||
image: redis | ||
build: ./redis | ||
restart: on-failure | ||
ports: | ||
- "${REDIS_PORT}:6379" | ||
volumes: | ||
- redis-data:/data | ||
environment: | ||
TZ: ${TIMEZONE} | ||
tty: true | ||
|
||
rabbitmq: | ||
image: rabbitmq | ||
build: ./rabbitmq | ||
restart: on-failure | ||
ports: | ||
- "${RABBITMQ_PORT}:5672" | ||
- "${RABBITMQ_MANAGEMENT_PORT}:15672" | ||
volumes: | ||
- "./rabbitmq/enabled_plugins:/etc/rabbitmq/enabled_plugins" | ||
environment: | ||
TZ: ${TIMEZONE} | ||
RABBITMQ_ERLANG_COOKIE: ${RABBITMQ_ERLANG_COOKIE} | ||
RABBITMQ_DEFAULT_USER: ${RABBITMQ_USER} | ||
RABBITMQ_DEFAULT_PASS: ${RABBITMQ_PASSWORD} | ||
RABBITMQ_DEFAULT_VHOST: / | ||
tty: true | ||
|
||
volumes: | ||
db: | ||
redis-data: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
input { | ||
file { | ||
type => "nginx_access" | ||
path => "/var/log/nginx/symfony_access.log" | ||
start_position => beginning | ||
} | ||
file { | ||
type => "app_dev" | ||
path => "/var/www/app/var/log/dev.log" | ||
start_position => beginning | ||
} | ||
file { | ||
type => "app_prod" | ||
path => "/var/www/app/var/log/prod.log" | ||
start_position => beginning | ||
} | ||
} | ||
|
||
filter { | ||
if [type] == "nginx_access" { | ||
grok { | ||
patterns_dir => "/etc/logstash/patterns" | ||
match => { "message" => "%{NGINXACCESS}"} | ||
} | ||
} | ||
else if [type] in ["app_dev", "app_prod"] { | ||
grok { | ||
patterns_dir => "/etc/logstash/patterns" | ||
match => { "message" => "%{SYMFONY}"} | ||
} | ||
} | ||
} | ||
|
||
output { | ||
elasticsearch { | ||
host => "localhost" | ||
cluster => "logstash" | ||
} | ||
} |
Oops, something went wrong.