-
-
Save JavierCane/42abec574871dedf20a410f94d873fea to your computer and use it in GitHub Desktop.
Dockerizing default Symfony project
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
###> Docker Compose - DB ### | |
MYSQL_DATABASE=symfony | |
MYSQL_USER=codely | |
MYSQL_PASSWORD=c0d3ly | |
###< Docker Compose - DB ### | |
# In all environments, the following files are loaded if they exist, | |
# the later taking precedence over the former: | |
# | |
# * .env contains default values for the environment variables needed by the app | |
# * .env.local uncommitted file with local overrides | |
# * .env.$APP_ENV committed environment-specific defaults | |
# * .env.$APP_ENV.local uncommitted environment-specific overrides | |
# | |
# Real environment variables win over .env files. | |
# | |
# DO NOT DEFINE PRODUCTION SECRETS IN THIS FILE NOR IN ANY OTHER COMMITTED FILES. | |
# | |
# Run "composer dump-env prod" to compile .env files for production use (requires symfony/flex >=1.2). | |
# https://symfony.com/doc/current/best_practices/configuration.html#infrastructure-related-configuration | |
###> symfony/framework-bundle ### | |
APP_ENV=dev | |
APP_SECRET=292097bda570e4e4c2ff6766f272e442 | |
#TRUSTED_PROXIES=127.0.0.1,127.0.0.2 | |
#TRUSTED_HOSTS='^localhost|example\.com$' | |
###< symfony/framework-bundle ### | |
###> doctrine/doctrine-bundle ### | |
# Format described at http://docs.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/configuration.html#connecting-using-a-url | |
# Configure your db driver and server_version in config/packages/doctrine.yaml | |
DATABASE_URL=mysql://codely:[email protected]:3306/symfony | |
###< doctrine/doctrine-bundle ### | |
###> symfony/swiftmailer-bundle ### | |
# For Gmail as a transport, use: "gmail://username:password@localhost" | |
# For a generic SMTP server, use: "smtp://localhost:25?encryption=&auth_mode=" | |
# Delivery is disabled by default via "null://localhost" | |
MAILER_URL=null://localhost | |
###< symfony/swiftmailer-bundle ### |
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
parameters: | |
# Adds a fallback DATABASE_URL if the env var is not set. | |
# This allows you to run cache:warmup even if your | |
# environment variables are not available yet. | |
# You should not need to change this value. | |
env(DATABASE_URL): '' | |
doctrine: | |
dbal: | |
# configure these for your database server | |
driver: 'pdo_mysql' | |
server_version: 'mariadb-10.4.2' | |
charset: utf8mb4 | |
default_table_options: | |
charset: utf8mb4 | |
collate: utf8mb4_unicode_ci | |
url: '%env(resolve:DATABASE_URL)%' | |
orm: | |
auto_generate_proxy_classes: true | |
naming_strategy: doctrine.orm.naming_strategy.underscore | |
auto_mapping: true | |
mappings: | |
App: | |
is_bundle: false | |
type: annotation | |
dir: '%kernel.project_dir%/src/Entity' | |
prefix: 'App\Entity' | |
alias: App |
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
index: | |
path: / | |
controller: App\Controller\HelloWorldController::index |
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
<?php | |
declare(strict_types = 1); | |
namespace App\Controller; | |
use Symfony\Component\HttpFoundation\Response; | |
final class HelloWorldController | |
{ | |
public function index(): Response | |
{ | |
return new Response("Hello World!"); | |
} | |
} |
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
version: '3' | |
services: | |
nginx: | |
container_name: codelytv-symfony-nginx | |
restart: unless-stopped | |
image: nginx:1.15-alpine | |
ports: | |
- "8090:80" | |
volumes: | |
- .:/app:delegated | |
- ./etc/infrastructure/nginx/default.conf:/etc/nginx/conf.d/default.conf:ro | |
depends_on: | |
- php | |
php: | |
container_name: codelytv-symfony-php | |
restart: unless-stopped | |
build: | |
context: . | |
dockerfile: Dockerfile | |
ports: | |
- "9090:9001" | |
volumes: | |
- .:/app:delegated | |
env_file: | |
- .env | |
depends_on: | |
- mysql | |
mysql: | |
container_name: codelytv-symfony-mysql | |
restart: unless-stopped | |
# Modify Doctrine server_version config parameter while updating MariaDB version | |
image: mariadb:10.4.2 | |
ports: | |
- "3390:3306" | |
env_file: | |
- .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
FROM php:7.3-fpm-alpine | |
WORKDIR /app | |
COPY etc/infrastructure/php/ /usr/local/etc/php/ | |
RUN apk --update upgrade \ | |
&& apk add autoconf automake make gcc g++ rabbitmq-c rabbitmq-c-dev \ | |
&& pecl install amqp-1.9.4 \ | |
&& pecl install apcu-5.1.17 \ | |
&& pecl install xdebug-2.7.0RC2 \ | |
&& docker-php-ext-enable amqp apcu xdebug \ | |
&& docker-php-ext-install pdo pdo_mysql |
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
server { | |
listen 80; | |
server_name localhost symfony.codelytv.dev; | |
root /app/public; | |
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; | |
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name; | |
fastcgi_param DOCUMENT_ROOT $realpath_root; | |
send_timeout 1800; | |
fastcgi_read_timeout 1800; | |
# 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; | |
} | |
error_log stderr; | |
access_log stdout; | |
} |
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
date.timezone = "UTC" | |
html_errors = "On" | |
display_errors = "On" | |
error_reporting = E_ALL |
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
zend_extension=xdebug.so | |
;Debugging | |
xdebug.remote_enable = 1; | |
xdebug.remote_connect_back = 1; | |
xdebug.remote_autostart = 1; | |
xdebug.remote_port = 9001; | |
;Profiling | |
xdebug.profiler_enable = 0; | |
xdebug.profiler_enable_trigger = 1; | |
xdebug.profiler_output_dir = "/tmp/xdebug"; | |
xdebug.max_nesting_level = 500; |
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
.PHONY: all deps build test run-tests | |
deps: | |
@docker run --rm --interactive --tty --volume $(shell pwd):/app --user $(id -u):$(id -g) \ | |
gsingh1/prestissimo install \ | |
--ignore-platform-reqs \ | |
--no-ansi \ | |
--no-interaction | |
build: deps start | |
test: | |
@docker exec -it codelytv-symfony-php make run-tests | |
run-tests: | |
mkdir -p var/phpunit | |
./bin/phpunit --exclude-group='disabled --log-junit var/phpunit/junit.xml tests' | |
./vendor/bin/behat | |
start: | |
@docker-compose up -d | |
stop: | |
@docker-compose stop | |
destroy: | |
@docker-compose down |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment