Skip to content

Commit 7f3300a

Browse files
author
dmitriy
committed
docker-nginx-php-symfony done
0 parents  commit 7f3300a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

84 files changed

+14642
-0
lines changed

.circleci/config.yml

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
version: 2
2+
jobs:
3+
build:
4+
working_directory: ~/html
5+
machine: true
6+
branches:
7+
ignore:
8+
- develop
9+
steps:
10+
- checkout
11+
12+
- run:
13+
name: Start container and verify it's working
14+
command: |
15+
make start-test
16+
17+
- run:
18+
name: Wait for DB container is running and initialize DB
19+
command: |
20+
make wait-for-db
21+
make drop-migrate
22+
make fixtures
23+
24+
- run:
25+
name: Run unit/functional tests
26+
command: |
27+
make phpunit
28+
29+
- store_artifacts:
30+
path: reports
31+
32+
- store_test_results:
33+
path: reports

.dockerignore

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/.git*
2+
/.idea*
3+
var/mysql-data
4+
vendor/
5+
.dockerignore
6+
.editorconfig
7+
.env.local.php
8+
Dockerfile
9+
docker-compose.yml
10+
docker-compose-test-ci.yml
11+
docker-compose-prod.yml
12+
Makefile

.editorconfig

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
end_of_line = lf
6+
insert_final_newline = true
7+
indent_style = space
8+
indent_size = 4
9+
trim_trailing_whitespace = true
10+
11+
[*.md]
12+
trim_trailing_whitespace = false
13+
14+
[*.yml]
15+
indent_size = 2

.env

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# In all environments, the following files are loaded if they exist,
2+
# the later taking precedence over the former:
3+
#
4+
# * .env contains default values for the environment variables needed by the app
5+
# * .env.local uncommitted file with local overrides
6+
# * .env.$APP_ENV committed environment-specific defaults
7+
# * .env.$APP_ENV.local uncommitted environment-specific overrides
8+
#
9+
# Real environment variables win over .env files.
10+
#
11+
# DO NOT DEFINE PRODUCTION SECRETS IN THIS FILE NOR IN ANY OTHER COMMITTED FILES.
12+
#
13+
# Run "composer dump-env prod" to compile .env files for production use (requires symfony/flex >=1.2).
14+
# https://symfony.com/doc/current/best_practices/configuration.html#infrastructure-related-configuration
15+
16+
###> symfony/framework-bundle ###
17+
APP_ENV=dev
18+
APP_SECRET=42f011ec3a7bde0bec87364b1d967193
19+
#TRUSTED_PROXIES=127.0.0.1,127.0.0.2
20+
#TRUSTED_HOSTS='^localhost|example\.com$'
21+
###< symfony/framework-bundle ###
22+
23+
###> doctrine/doctrine-bundle ###
24+
# Format described at http://docs.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/configuration.html#connecting-using-a-url
25+
# For an SQLite database, use: "sqlite:///%kernel.project_dir%/var/data.db"
26+
# Configure your db driver and server_version in config/packages/doctrine.yaml
27+
DATABASE_URL=mysql://root:secret@mysql:3306/symfony
28+
###< doctrine/doctrine-bundle ###
29+
30+
###> symfony/swiftmailer-bundle ###
31+
# For Gmail as a transport, use: "gmail://username:password@localhost"
32+
# For a generic SMTP server, use: "smtp://localhost:25?encryption=&auth_mode="
33+
# Delivery is disabled by default via "null://localhost"
34+
MAILER_URL=null://localhost
35+
###< symfony/swiftmailer-bundle ###

.env.prod

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# define your env variables for the prod env here
2+
APP_ENV=prod
3+
APP_SECRET=42f011ec3a7bde0bec87364b1d967194
4+
APP_DEBUG=0

.env.test

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# define your env variables for the test env here
2+
APP_ENV=test
3+
KERNEL_CLASS='App\Kernel'
4+
APP_SECRET='s$cretf0rt3st'
5+
APP_DEBUG=0
6+
SYMFONY_DEPRECATIONS_HELPER=999999
7+
DATABASE_URL=mysql://root:secret@mysql:3306/symfony_testing

.gitattributes

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
* text=auto
2+
*.css linguist-vendored
3+
*.scss linguist-vendored
4+
*.js linguist-vendored
5+
CHANGELOG.md export-ignore

.gitignore

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/.idea
2+
reports/*
3+
!reports/.gitkeep
4+
.phpunit.result.cache
5+
6+
###> symfony/framework-bundle ###
7+
/.env.local
8+
/.env.local.php
9+
/.env.*.local
10+
/public/bundles/
11+
/var/
12+
/vendor/
13+
###< symfony/framework-bundle ###
14+
15+
###> symfony/phpunit-bridge ###
16+
.phpunit
17+
/phpunit.xml
18+
###< symfony/phpunit-bridge ###
19+
20+
###> symfony/web-server-bundle ###
21+
/.web-server-pid
22+
###< symfony/web-server-bundle ###

Dockerfile

+87
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
FROM php:7.3-fpm
2+
3+
# set main params
4+
ARG BUILD_ARGUMENT_DEBUG_ENABLED=false
5+
ENV DEBUG_ENABLED=$BUILD_ARGUMENT_DEBUG_ENABLED
6+
ARG BUILD_ARGUMENT_ENV=dev
7+
ENV ENV=$BUILD_ARGUMENT_ENV
8+
ENV APP_HOME /var/www/html
9+
10+
# check environment
11+
RUN if [ "$BUILD_ARGUMENT_ENV" = "default" ]; then echo "Set BUILD_ARGUMENT_ENV in docker build-args like --build-arg BUILD_ARGUMENT_ENV=dev" && exit 2; \
12+
elif [ "$BUILD_ARGUMENT_ENV" = "dev" ]; then echo "Building development environment."; \
13+
elif [ "$BUILD_ARGUMENT_ENV" = "test" ]; then echo "Building test environment."; \
14+
elif [ "$BUILD_ARGUMENT_ENV" = "prod" ]; then echo "Building production environment."; \
15+
else echo "Set correct BUILD_ARGUMENT_ENV in docker build-args like --build-arg BUILD_ARGUMENT_ENV=dev. Available choices are dev,test,prod." && exit 2; \
16+
fi
17+
18+
# install all the dependencies and enable PHP modules
19+
RUN apt-get update && apt-get upgrade -y && apt-get install -y \
20+
procps \
21+
nano \
22+
git \
23+
unzip \
24+
libicu-dev \
25+
zlib1g-dev \
26+
libxml2 \
27+
libxml2-dev \
28+
libreadline-dev \
29+
supervisor \
30+
cron \
31+
libzip-dev \
32+
&& docker-php-ext-configure pdo_mysql --with-pdo-mysql=mysqlnd \
33+
&& docker-php-ext-install \
34+
pdo_mysql \
35+
sockets \
36+
intl \
37+
zip && \
38+
rm -fr /tmp/* && \
39+
rm -rf /var/list/apt/* && \
40+
rm -r /var/lib/apt/lists/* && \
41+
apt-get clean
42+
43+
# create document root
44+
RUN mkdir -p $APP_HOME/public
45+
46+
# change owner
47+
RUN chown -R www-data:www-data $APP_HOME
48+
49+
# put php config for Symfony
50+
COPY ./docker/$BUILD_ARGUMENT_ENV/www.conf /usr/local/etc/php-fpm.d/www.conf
51+
COPY ./docker/$BUILD_ARGUMENT_ENV/php.ini /usr/local/etc/php/php.ini
52+
53+
# install Xdebug in case development environment
54+
COPY ./docker/other/do_we_need_xdebug.sh /tmp/
55+
COPY ./docker/dev/xdebug.ini /tmp/
56+
RUN chmod u+x /tmp/do_we_need_xdebug.sh && /tmp/do_we_need_xdebug.sh
57+
58+
# install composer
59+
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/bin/ --filename=composer
60+
61+
# add supervisor
62+
RUN mkdir -p /var/log/supervisor
63+
COPY --chown=root:root ./docker/other/supervisord.conf /etc/supervisor/conf.d/supervisord.conf
64+
COPY --chown=root:root ./docker/other/cron /var/spool/cron/crontabs/root
65+
RUN chmod 0600 /var/spool/cron/crontabs/root
66+
67+
# set working directory
68+
WORKDIR $APP_HOME
69+
70+
# create composer folder for user www-data
71+
RUN mkdir -p /var/www/.composer && chown -R www-data:www-data /var/www/.composer
72+
73+
USER www-data
74+
75+
# copy source files
76+
COPY --chown=www-data:www-data . $APP_HOME/
77+
78+
# install all PHP dependencies
79+
RUN if [ "$BUILD_ARGUMENT_ENV" = "dev" ] || [ "$BUILD_ARGUMENT_ENV" = "test" ]; then composer install --optimize-autoloader --no-interaction --no-progress; \
80+
else export APP_ENV=$BUILD_ARGUMENT_ENV && composer install --optimize-autoloader --no-interaction --no-progress --no-dev; \
81+
fi
82+
83+
# create cached config file .env.local.php in case prod environment
84+
RUN if [ "$BUILD_ARGUMENT_ENV" = "prod" ]; then composer dump-env $BUILD_ARGUMENT_ENV; \
85+
fi
86+
87+
USER root

Makefile

+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
dir=${CURDIR}
2+
project=-p symfony
3+
service=symfony:latest
4+
5+
start:
6+
@docker-compose -f docker-compose.yml $(project) up -d
7+
8+
start-test:
9+
@docker-compose -f docker-compose-test-ci.yml $(project) up -d
10+
11+
start-prod:
12+
@docker-compose -f docker-compose-prod.yml $(project) up -d
13+
14+
stop:
15+
@docker-compose -f docker-compose.yml $(project) down
16+
17+
stop-test:
18+
@docker-compose -f docker-compose-test-ci.yml $(project) down
19+
20+
stop-prod:
21+
@docker-compose -f docker-compose-prod.yml $(project) down
22+
23+
restart: stop start
24+
restart-test: stop-test start-test
25+
restart-prod: stop-prod start-prod
26+
27+
env-prod:
28+
@make exec cmd="composer dump-env prod"
29+
30+
ssh:
31+
@docker-compose $(project) exec symfony bash
32+
33+
ssh-supervisord:
34+
@docker-compose $(project) exec supervisord bash
35+
36+
exec:
37+
@docker-compose $(project) exec symfony $$cmd
38+
39+
clean:
40+
rm -rf $(dir)/reports/*
41+
42+
prepare:
43+
mkdir -p $(dir)/reports/coverage
44+
45+
wait-for-db:
46+
@make exec cmd="php bin/console db:wait"
47+
48+
composer-install-prod:
49+
@make exec cmd="composer install --optimize-autoloader --no-dev"
50+
51+
composer-install:
52+
@make exec cmd="composer install --optimize-autoloader"
53+
54+
composer-update:
55+
@make exec cmd="composer update"
56+
57+
info:
58+
@make exec cmd="bin/console --version"
59+
@make exec cmd="php --version"
60+
61+
drop-migrate:
62+
@make exec cmd="php bin/console doctrine:schema:drop --full-database --force"
63+
@make exec cmd="php bin/console doctrine:schema:drop --full-database --force --env=test"
64+
@make migrate
65+
66+
migrate-prod:
67+
@make exec cmd="php bin/console doctrine:migrations:migrate --no-interaction"
68+
69+
migrate:
70+
@make exec cmd="php bin/console doctrine:migrations:migrate --no-interaction"
71+
@make exec cmd="php bin/console doctrine:migrations:migrate --no-interaction --env=test"
72+
73+
fixtures:
74+
@make exec cmd="php bin/console doctrine:fixtures:load --append"
75+
76+
phpunit:
77+
@make exec cmd="./vendor/bin/simple-phpunit -c phpunit.xml.dist --log-junit reports/phpunit.xml --coverage-html reports/coverage --coverage-clover reports/coverage.xml"

bin/console

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/usr/bin/env php
2+
<?php
3+
4+
use App\Kernel;
5+
use Symfony\Bundle\FrameworkBundle\Console\Application;
6+
use Symfony\Component\Console\Input\ArgvInput;
7+
use Symfony\Component\Debug\Debug;
8+
9+
set_time_limit(0);
10+
11+
require dirname(__DIR__).'/vendor/autoload.php';
12+
13+
if (!class_exists(Application::class)) {
14+
throw new RuntimeException('You need to add "symfony/framework-bundle" as a Composer dependency.');
15+
}
16+
17+
$input = new ArgvInput();
18+
if (null !== $env = $input->getParameterOption(['--env', '-e'], null, true)) {
19+
putenv('APP_ENV='.$_SERVER['APP_ENV'] = $_ENV['APP_ENV'] = $env);
20+
}
21+
22+
if ($input->hasParameterOption('--no-debug', true)) {
23+
putenv('APP_DEBUG='.$_SERVER['APP_DEBUG'] = $_ENV['APP_DEBUG'] = '0');
24+
}
25+
26+
require dirname(__DIR__).'/config/bootstrap.php';
27+
28+
if ($_SERVER['APP_DEBUG']) {
29+
umask(0000);
30+
31+
if (class_exists(Debug::class)) {
32+
Debug::enable();
33+
}
34+
}
35+
36+
$kernel = new Kernel($_SERVER['APP_ENV'], (bool) $_SERVER['APP_DEBUG']);
37+
$application = new Application($kernel);
38+
$application->run($input);

bin/phpunit

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/usr/bin/env php
2+
<?php
3+
4+
if (!file_exists(dirname(__DIR__).'/vendor/symfony/phpunit-bridge/bin/simple-phpunit')) {
5+
echo "Unable to find the `simple-phpunit` script in `vendor/symfony/phpunit-bridge/bin/`.\n";
6+
exit(1);
7+
}
8+
9+
if (false === getenv('SYMFONY_PHPUNIT_VERSION')) {
10+
putenv('SYMFONY_PHPUNIT_VERSION=6.5');
11+
}
12+
if (false === getenv('SYMFONY_PHPUNIT_REMOVE')) {
13+
putenv('SYMFONY_PHPUNIT_REMOVE=');
14+
}
15+
if (false === getenv('SYMFONY_PHPUNIT_DIR')) {
16+
putenv('SYMFONY_PHPUNIT_DIR='.__DIR__.'/.phpunit');
17+
}
18+
19+
require dirname(__DIR__).'/vendor/symfony/phpunit-bridge/bin/simple-phpunit';

0 commit comments

Comments
 (0)