Commit ae0d3573 authored by Mathieu Girard's avatar Mathieu Girard

Docker integration

parent 5d588920
.idea
/app/config/parameters.yml
/app/config/parameters.yml.dist
/build/
......
......@@ -19,7 +19,7 @@ imports:
# http://symfony.com/doc/current/best_practices/configuration.html#application-related-configuration
parameters:
locale: fr
mongodb_server: "mongodb://localhost:27017"
mongodb_server: "mongodb://mongo:27017"
router.request_context.host: '%base_url%'
router.request_context.base_url: '%base_path%'
......
......@@ -6,6 +6,7 @@ parameters:
use_as_saas: false
# URL config
base_protocol: http # my-site.com
base_url: saas.localhost # my-site.com
base_path: ~ # on localhost its probably something like /GoGoCarto/web/app_dev.php
......
This diff is collapsed.
DOCKER_PHP_IMAGE=symfony_php_xdebug
DOCKER_MOUNT_POINT=..
##### BLACKFIRE
BLACKFIRE_PORT=8707
BLACKFIRE_LOG_LEVEL=4
BLACKFIRE_SERVER_ID=
BLACKFIRE_SERVER_TOKEN=
BLACKFIRE_CLIENT_ID=
BLACKFIRE_CLIENT_TOKEN=
##### POSTGRES
POSTGRES_USER=symfony
POSTGRES_PASSWORD=YourPwdShouldBeLongAndSecure!
POSTGRES_DB=docker
/.circleci/ export-ignore
/.github/ export-ignore
/docs/ export-ignore
/.gitattributes export-ignore
/.gitignore export-ignore
/CODE_OF_CONDUCT.md export-ignore
/nginx/conf.d/custom.conf
/.env
# Contributor Covenant Code of Conduct
## Our Pledge
In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation.
## Our Standards
Examples of behavior that contributes to creating a positive environment include:
* Using welcoming and inclusive language
* Being respectful of differing viewpoints and experiences
* Gracefully accepting constructive criticism
* Focusing on what is best for the community
* Showing empathy towards other community members
Examples of unacceptable behavior by participants include:
* The use of sexualized language or imagery and unwelcome sexual attention or advances
* Trolling, insulting/derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or electronic address, without explicit permission
* Other conduct which could reasonably be considered inappropriate in a professional setting
## Our Responsibilities
Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior.
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.
## Scope
This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers.
## Enforcement
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at info@ajardin.fr. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately.
Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership.
## Attribution
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version]
[homepage]: http://contributor-covenant.org
[version]: http://contributor-covenant.org/version/1/4/
# Contributing
We would love to receive your help to make this Docker environment for Symfony better!
Feel free to open an [issue](https://github.com/ajardin/docker-symfony/issues) if you run into any problem, or send
a pull request (see bellow) with your contribution.
## Code of Conduct
The code of conduct is described in [`CODE_OF_CONDUCT.md`](CODE_OF_CONDUCT.md).
## How to contribute
:construction:
MIT License
Copyright (c) 2018 Alexandre Jardin <info@ajardin.fr>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
SELF_DIR := $(dir $(lastword $(MAKEFILE_LIST)))
PHP_SERVICE := docker-compose exec php sh -c
# Define a static project name that will be prepended to each service name
export COMPOSE_PROJECT_NAME := symfony
# This Makefile is designed to be extended by another Makefile located in your project directory.
# ==> https://github.com/ajardin/docker-symfony/wiki/Makefile
# Create configuration files needed by the environment
SETUP_ENV := $(shell (test -f $(SELF_DIR).env || cp $(SELF_DIR).env.dist $(SELF_DIR).env))
SETUP_SERVER := $(shell (test -f $(SELF_DIR)nginx/conf.d/custom.conf || cp $(SELF_DIR)nginx/conf.d/symfony.conf.dist $(SELF_DIR)nginx/conf.d/custom.conf))
# Extract environment variables needed by the environment
export DOCKER_PHP_IMAGE := $(shell grep DOCKER_PHP_IMAGE $(SELF_DIR).env | awk -F '=' '{print $$NF}')
export DOCKER_MOUNT_POINT := $(shell grep DOCKER_MOUNT_POINT $(SELF_DIR).env | awk -F '=' '{print $$NF}')
##
## ----------------------------------------------------------------------------
## Environment
## ----------------------------------------------------------------------------
##
backup: ## Backup the "postgres" volume
docker run --rm \
--volumes-from $$(docker-compose ps -q postgres) \
-v $$(pwd):/backup \
busybox sh -c "tar cvf /backup/backup.tar /var/lib/postgresql/data"
build: ## Build the environment
docker-compose build
cache: ## Flush the Symfony cache
$(PHP_SERVICE) "bin/console cache:clear"
composer: ## Install Composer dependencies from the "php" container
$(PHP_SERVICE) "composer install --optimize-autoloader --prefer-dist --working-dir=$(PROJECT_PATH)"
logs: ## Follow logs generated by all containers
docker-compose logs -f --tail=0
logs-full: ## Follow logs generated by all containers from the containers creation
docker-compose logs -f
nginx: ## Open a terminal in the "nginx" container
docker-compose exec nginx sh
php: ## Open a terminal in the "php" container
docker-compose exec php sh
ps: ## List all containers managed by the environment
docker-compose ps
restore: ## Restore the "postgres" volume
docker run --rm \
--volumes-from $$(docker-compose ps -q postgres) \
-v $$(pwd):/backup \
busybox sh -c "tar xvf /backup/backup.tar /var/lib/postgresql/data"
docker-compose restart postgres
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
yarn: ## Install npm dependencies from the "php" container
$(PHP_SERVICE) "yarn install --cwd=$(PROJECT_PATH)"
.PHONY: backup build cache composer logs logs-full nginx php ps restore start stats stop yarn
.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
# Project specific variables
DOCKER_PATH := ./docker
PROJECT_PATH := /var/www/html
# Retrieve the Makefile used to manage the Docker environment
export COMPOSE_FILE := $(DOCKER_PATH)/docker-compose.yml
include $(DOCKER_PATH)/Makefile
# Docker for Symfony [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
This repository allows the creation of a Docker environment that meets
[Symfony requirements](https://symfony.com/doc/current/reference/requirements.html).
**What you will find here is an environment designed to simplify the development workflow when working with a Symfony
application. Thus, some services or configurations are not suitables for a production usage.**
## Architecture
![Architecture overview](docs/architecture.png "Architecture")
## Services
* `blackfire`: [blackfire/blackfire:latest](https://hub.docker.com/r/blackfire/blackfire/) image (application profiling).
* `maildev`: [djfarrelly/maildev:latest](https://hub.docker.com/r/djfarrelly/maildev/) (emails testing).
* `nginx`: [nginx:1.15-alpine](nginx/Dockerfile) custom image with HTTPS (web server).
* `php`: [php:7.2-fpm-alpine](php/Dockerfile) custom image with additional extensions and Composer.
* `postgres`: [postgres:10-alpine](https://hub.docker.com/_/postgres/) image (database).
And more to come...
## Documentation
> In order to make things more readable, and maintainable, the documentation has been migrated to
the [repository Wiki](https://github.com/ajardin/docker-symfony/wiki). Where you will find all details about the
installation process along the available instructions for the day-to-day work.
{
"name": "ajardin/docker-symfony",
"description": "Docker environment that meets Symfony requirements",
"license": "MIT",
"authors": [
{
"name": "Alexandre Jardin",
"email": "info@ajardin.fr"
}
]
}
version: "3.4"
services:
blackfire:
image: blackfire/blackfire:latest
env_file: .env
depends_on:
- php
maildev:
image: djfarrelly/maildev:latest
env_file: .env
depends_on:
- php
ports:
- 1080:80
nginx:
build: nginx
env_file: .env
ports:
- 443:443
- 80:80
volumes:
- ${DOCKER_MOUNT_POINT}:/var/www/app:rw,delegated
# Custom configuration
- ./nginx/conf.d/custom.conf:/etc/nginx/conf.d/symfony.conf:ro
depends_on:
- php
tty: true
php:
build:
context: ./php
target: ${DOCKER_PHP_IMAGE}
env_file: .env
ports:
- 9000:9000
volumes:
- ${DOCKER_MOUNT_POINT}:/var/www/app:rw,delegated
# Avoid heavy I/O workloads on bind-mounted volumes
# - /var/www/html/var/cache
# - /var/www/html/var/logs
# - /var/www/html/var/sessions
# Custom configuration
- ./php/conf.d/custom.ini:/usr/local/etc/php/conf.d/custom.ini:ro
# SSH keys
- ~/.ssh:/root/.ssh:ro
tty: true
node:
build: node
env_file: .env
working_dir: /var/www/html
volumes:
- ${DOCKER_MOUNT_POINT}:/var/www/html:rw,delegated
- /var/www/html/node_modules
tty: true
mongo:
image: mvertes/alpine-mongo
env_file: .env
ports:
- 27017:27017
volumes:
- mongo:/data/db
tty: true
volumes:
mongo: {}
FROM nginx:alpine
RUN rm -rf /var/cache/apk/* && \
rm -rf /tmp/*
RUN apk update && apk add bash rsync
# Install HTTPS requirements
RUN \
apk add --no-cache --virtual .build-deps \
openssl && \
mkdir -p /etc/nginx/ssl && \
openssl req -subj '/CN=localhost' -days 365 -x509 -newkey rsa:4096 -nodes \
-keyout /etc/nginx/ssl/server.key -out /etc/nginx/ssl/server.crt && \
apk del .build-deps
WORKDIR /var/www/html/
COPY conf.d/* /etc/nginx/conf.d/
# Install custom entrypoint
COPY entrypoint.sh /usr/local/bin/docker-custom-entrypoint
RUN chmod 777 /usr/local/bin/docker-custom-entrypoint
CMD ["nginx", "-g", "daemon off;"]
ENTRYPOINT ["docker-custom-entrypoint"]
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name ~^(.*)\.saas\.localhost;
root /var/www/html/web;
ssl on;
ssl_certificate /etc/nginx/ssl/server.crt;
ssl_certificate_key /etc/nginx/ssl/server.key;
location / {
# try to serve file directly, fallback to app.php
try_files $uri /app.php$is_args$args;
}
location ~ ^/(app_dev|config)\.php(/|$) {
fastcgi_pass php:9000;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
# When you are using symlinks to link the document root to the
# current version of your application, you should pass the real
# application path instead of the path to the symlink to PHP
# FPM.
# Otherwise, PHP's OPcache may not properly detect changes to
# your PHP files (see https://github.com/zendtech/ZendOptimizerPlus/issues/126
# for more information).
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
fastcgi_param DOCUMENT_ROOT $realpath_root;
}
location ~ ^/app\.php(/|$) {
fastcgi_pass php:9000;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
# When you are using symlinks to link the document root to the
# current version of your application, you should pass the real
# application path instead of the path to the symlink to PHP
# FPM.
# Otherwise, PHP's OPcache may not properly detect changes to
# your PHP files (see https://github.com/zendtech/ZendOptimizerPlus/issues/126
# for more information).
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
fastcgi_param DOCUMENT_ROOT $realpath_root;
# Prevents URIs that include the front controller. This will 404:
# http://domain.tld/index.php/some-path
# Remove the internal directive to allow URIs like this
internal;
}
# return 404 for all other php files not matching the front controller
# this prevents access to other php files you don't want to be accessible.
location ~ \.php$ {
return 404;
}
}
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name symfony.localhost;
root /var/www/html/public;
ssl on;
ssl_certificate /etc/nginx/ssl/server.crt;
ssl_certificate_key /etc/nginx/ssl/server.key;
location / {
# try to serve file directly, fallback to index.php
try_files $uri /index.php$is_args$args;
}
location ~ ^/index\.php(/|$) {
fastcgi_pass php:9000;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
# When you are using symlinks to link the document root to the
# current version of your application, you should pass the real
# application path instead of the path to the symlink to PHP
# FPM.
# Otherwise, PHP's OPcache may not properly detect changes to
# your PHP files (see https://github.com/zendtech/ZendOptimizerPlus/issues/126
# for more information).
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
fastcgi_param DOCUMENT_ROOT $realpath_root;
# Prevents URIs that include the front controller. This will 404:
# http://domain.tld/index.php/some-path
# Remove the internal directive to allow URIs like this
internal;
}
# return 404 for all other php files not matching the front controller
# this prevents access to other php files you don't want to be accessible.
location ~ \.php$ {
return 404;
}
}
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name symfony.localhost;
root /var/www/html/public;
ssl on;
ssl_certificate /etc/nginx/ssl/server.crt;
ssl_certificate_key /etc/nginx/ssl/server.key;
location / {
# try to serve file directly, fallback to index.php
try_files $uri /index.php$is_args$args;
}
location ~ ^/index\.php(/|$) {
fastcgi_pass php:9000;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
# When you are using symlinks to link the document root to the
# current version of your application, you should pass the real
# application path instead of the path to the symlink to PHP
# FPM.
# Otherwise, PHP's OPcache may not properly detect changes to
# your PHP files (see https://github.com/zendtech/ZendOptimizerPlus/issues/126
# for more information).
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
fastcgi_param DOCUMENT_ROOT $realpath_root;
# Prevents URIs that include the front controller. This will 404:
# http://domain.tld/index.php/some-path
# Remove the internal directive to allow URIs like this
internal;
}
# return 404 for all other php files not matching the front controller
# this prevents access to other php files you don't want to be accessible.
location ~ \.php$ {
return 404;
}
}
#!/bin/bash
mkdir -p /var/www/html/web && chown -R nginx /var/www/html
watch -n 2 -d 'rsync -avu /var/www/app/web/ /var/www/html/web/' > /dev/null &
exec "$@"
FROM node:alpine
LABEL maintainer="Mathieu Girard <mgirard.dev@gmail.com>"
RUN apk update && apk add --no-cache git shadow
RUN npm install -g gulp node-sass postcss-cli autoprefixer watch --unsafe-perm
COPY package.json /var/www/html/
WORKDIR /var/www/html/
RUN chown -R node:node /var/www/html/
RUN \
npm update && \
npm install gulp && \
npm install
{
"name": "GoGoCarto",
"version": "2.0.0",
"homepage": "https://github.com/pixelhumain/GoGoCarto",
"description": "Collaborative mapping directory",
"keywords": [
"map",
"mapping",
"cartography",
"directory"
],
"license": "GPL-3.0",
"repository": {
"type": "git",
"url": "https://github.com/pixelhumain/GoGoCarto.git"
},
"engines": {
"node": "6.5.0"
},
"dependencies": {
"GoGoCartoJs": "github:pixelhumain/gogocartojs"
},
"devDependencies": {
"del": "^2.2.2",
"gulp": "^3.9.1",
"gulp-concat": "^2.6.1",
"gulp-gzip": "^1.4.0",
"gulp-minify-css": "^1.2.4",
"gulp-notify": "^2.2.0",
"gulp-rename": "^1.2.2",
"gulp-sass": "^3.0.0",
"gulp-uglify": "^2.0.0",
"node-notifier": "^4.6.1",
"watchify": "^3.8.0"
}
}
FROM php:7.1-fpm-alpine as symfony_php
LABEL maintainer="Alexandre Jardin <info@ajardin.fr>"
RUN rm -rf /var/cache/apk/* && \
rm -rf /tmp/*
RUN apk update
RUN apk add bash
# Install Symfony requirements
RUN \
apk add --no-cache --virtual .persistent-deps \
autoconf \
freetype-dev \
gcc \
git \
icu-libs \
libc-dev \
libjpeg-turbo-dev \
libpng-dev \
postgresql-libs \
rsync \
ssmtp \
yarn \
zlib-dev && \
apk add --no-cache --virtual .build-deps \
$PHPIZE_DEPS \
icu-dev \
postgresql-dev && \
docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ && \
docker-php-ext-install \
bcmath \
intl \
gd \
opcache \
pdo_pgsql \
zip && \
yes "" | pecl install lzf mongodb && \
docker-php-ext-enable lzf mongodb && \
perl -pi -e "s/mailhub=mail/mailhub=maildev/" /etc/ssmtp/ssmtp.conf && \
apk del .build-deps
# RUN \
# pecl update-channels && \
# yes "" | pecl install mongodb && \
# docker-php-ext-enable mongodb
# Install Composer globally
ENV COMPOSER_ALLOW_SUPERUSER 1
ENV COMPOSER_MEMORY_LIMIT -1
RUN \
curl -sS https://getcomposer.org/installer | php && \
mv composer.phar /usr/local/bin/composer && \
composer self-update --preview
# Install custom entrypoint
COPY entrypoint.sh /usr/local/bin/docker-custom-entrypoint
RUN chmod 777 /usr/local/bin/docker-custom-entrypoint
CMD ["php-fpm"]
ENTRYPOINT ["docker-custom-entrypoint"]
# ======================================================================================================================
FROM symfony_php as symfony_php_blackfire
RUN \
curl -sS https://packages.blackfire.io/binaries/blackfire-php/1.23.1/blackfire-php-alpine_amd64-php-72.so \
--output $(php -r "echo ini_get('extension_dir');")/blackfire.so && \
docker-php-ext-enable blackfire
# ======================================================================================================================
# ======================================================================================================================
FROM symfony_php as symfony_php_xdebug
RUN \
apk add --no-cache --virtual .build-deps $PHPIZE_DEPS && \
yes "" | pecl install xdebug && \
docker-php-ext-enable xdebug
# ======================================================================================================================