Skip to content

Commit

Permalink
Use symfony/runtime (#247)
Browse files Browse the repository at this point in the history
Standardize the bootstrapping of the application. Additionally:
* Rename APP_ENVIRONMENT to APP_ENV to comply
with Symfony's standard.
* Enable ACL to remove umask(0000).
* Pull latest image before building production images.
  • Loading branch information
marein authored Oct 21, 2024
1 parent a3f7048 commit 815302e
Show file tree
Hide file tree
Showing 10 changed files with 104 additions and 43 deletions.
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Shared #
############################
# dev|prod
APP_ENVIRONMENT='dev'
APP_ENV='dev'
APP_KERNEL_SECRET='ThisTokenIsNotSoSecretChangeIt'
APP_WAIT_FOR='unix:///var/run/proxysql/proxysql.sock,mysql:3306,redis:6379,rabbitmq:5672,nchan:81'
APP_RUN_MIGRATIONS='1'
Expand Down
26 changes: 5 additions & 21 deletions bin/console
Original file line number Diff line number Diff line change
@@ -1,32 +1,16 @@
#!/usr/bin/env php
<?php

declare(strict_types=1);

namespace {

use Gaming\Kernel;
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Component\Console\Input\ArgvInput;
use Symfony\Component\ErrorHandler\Debug;

umask(0000);

set_time_limit(0);

require_once __DIR__ . '/../vendor/autoload.php';

$input = new ArgvInput();
$environment = $input->getParameterOption(
['--env', '-e'],
$_SERVER['APP_ENVIRONMENT'] ?? $_ENV['APP_ENVIRONMENT'] ?? 'dev'
);
$isDevelopmentEnvironment = $environment !== 'prod';

if ($isDevelopmentEnvironment) {
Debug::enable();
}
require_once __DIR__ . '/../vendor/autoload_runtime.php';

$kernel = new Kernel($environment, $isDevelopmentEnvironment);
$application = new Application($kernel);
$application->run($input);
return static function (array $context): Application {
return new Application(new Kernel($context['APP_ENV'], (bool)$context['APP_DEBUG']));
};
}
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
"symfony/http-kernel": "^7.0",
"symfony/lock": "^7.0",
"symfony/monolog-bundle": "^3.8",
"symfony/runtime": "^7.1",
"symfony/security-bundle": "^7.0",
"symfony/service-contracts": "^3.3",
"symfony/translation-contracts": "^3.5",
Expand Down Expand Up @@ -86,7 +87,8 @@
"sort-packages": true,
"allow-plugins": {
"composer/package-versions-deprecated": true,
"phpstan/extension-installer": true
"phpstan/extension-installer": true,
"symfony/runtime": true
}
}
}
81 changes: 80 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion deploy/load-test/stack/app.env
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
APP_ENVIRONMENT=prod
APP_ENV=prod
APP_KERNEL_SECRET=ThisTokenIsNotSoSecretChangeIt
APP_WAIT_FOR=unix:///var/run/proxysql/proxysql.sock,chat-mysql:3306,connect-four-mysql-1:3306,connect-four-mysql-2:3306,connect-four-mysql-3:3306,connect-four-mysql-4:3306,connect-four-mysql-5:3306,identity-mysql:3306,chat-redis:6379,connect-four-redis:6379,web-interface-redis:6379,rabbitmq:5672,nchan:81
APP_RUN_MIGRATIONS=1
Expand Down
2 changes: 1 addition & 1 deletion deploy/single-server/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ x-php-container:
&php-container
image: marein/php-gaming-website:php-fpm
environment:
APP_ENVIRONMENT: "prod"
APP_ENV: "prod"
APP_KERNEL_SECRET: "ThisTokenIsNotSoSecretChangeIt"
APP_WAIT_FOR: "unix:///var/run/proxysql/proxysql.sock,mysql:3306,redis:6379,rabbitmq:5672,nchan:81"
APP_RUN_MIGRATIONS: "1"
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ x-php-container:
image: marein/php-gaming-website:php-fpm
env_file: ./.env
environment:
APP_ENVIRONMENT: prod
APP_ENV: prod
depends_on:
- mysql
- proxysql
Expand Down
3 changes: 3 additions & 0 deletions docker/warmup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,6 @@ else
bin/console importmap:install --env=prod
bin/console asset-map:compile --env=prod
fi

setfacl -dR -m u:www-data:rwX -m u:$(whoami):rwX var
setfacl -R -m u:www-data:rwX -m u:$(whoami):rwX var
5 changes: 4 additions & 1 deletion project
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,10 @@ acceptance() {
}

buildProductionImages() {
docker build --build-arg environment=production --file docker/Dockerfile --tag marein/php-gaming-website:php-fpm .
docker build --pull \
--build-arg environment=production \
--file docker/Dockerfile \
--tag marein/php-gaming-website:php-fpm .
}

pushProductionImages() {
Expand Down
20 changes: 5 additions & 15 deletions public/index.php
Original file line number Diff line number Diff line change
@@ -1,24 +1,14 @@
<?php

declare(strict_types=1);

namespace {

use Gaming\Kernel;
use Symfony\Component\ErrorHandler\Debug;
use Symfony\Component\HttpFoundation\Request;

require_once __DIR__ . '/../vendor/autoload.php';

$environment = $_SERVER['APP_ENVIRONMENT'] ?? $_ENV['APP_ENVIRONMENT'] ?? 'dev';
$isDevelopmentEnvironment = $environment !== 'prod';

if ($isDevelopmentEnvironment) {
Debug::enable();
}
require_once __DIR__ . '/../vendor/autoload_runtime.php';

$kernel = new Kernel($environment, $isDevelopmentEnvironment);
$request = Request::createFromGlobals();
$response = $kernel->handle($request);
$response->send();
$kernel->terminate($request, $response);
return static function (array $context): Kernel {
return new Kernel($context['APP_ENV'], (bool)$context['APP_DEBUG']);
};
}

0 comments on commit 815302e

Please sign in to comment.