Skip to content

Commit

Permalink
Use Symfony Local Web Server
Browse files Browse the repository at this point in the history
  • Loading branch information
yguedidi committed Aug 17, 2023
1 parent a465db6 commit acadb9c
Show file tree
Hide file tree
Showing 18 changed files with 187 additions and 152 deletions.
4 changes: 4 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
APP_ENV=dev
APP_SECRET=ch4n63m31fy0uc4n
TRUSTED_PROXIES=127.0.0.1/8,10.0.0.0/8,172.16.0.0/12,172.17.0.0/16,172.18.0.0/15,172.20.0.0/14,172.24.0.0/13,192.168.0.0/16
#TRUSTED_HOSTS='^(localhost|example\\.com)$'
5 changes: 5 additions & 0 deletions .env.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
KERNEL_CLASS='AppKernel'
APP_SECRET='$ecretf0rt3st'
SYMFONY_DEPRECATIONS_HELPER=weak
PANTHER_APP_ENV=panther
PANTHER_ERROR_SCREENSHOT_DIR=./var/error-screenshots
12 changes: 9 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
# From FrameworkBundle recipe
/.env.local
/.env.local.php
/.env.*.local
/config/secrets/prod/prod.decrypt.private.php
/web/bundles/
/var/
/vendor/

# Cache, logs & sessions
/var/*
!/var/cache
Expand All @@ -20,9 +29,6 @@ docker-compose.override.yml
# Parameters
/app/config/parameters.yml

# Managed by Composer
/vendor/

# Assets and user uploads
web/uploads/
/web/bundles/*
Expand Down
1 change: 0 additions & 1 deletion app/AppKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ public function registerBundles()

if ('dev' === $this->getEnvironment()) {
$bundles[] = new Symfony\Bundle\MakerBundle\MakerBundle();
$bundles[] = new Symfony\Bundle\WebServerBundle\WebServerBundle();
}
}

Expand Down
2 changes: 1 addition & 1 deletion app/config/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ framework:
enabled: true
fallback: "%locale%"
default_path: '%kernel.project_dir%/translations'
secret: "%secret%"
secret: "%env(APP_SECRET)%"
router:
resource: "%kernel.project_dir%/app/config/routing.yml"
strict_requirements: ~
Expand Down
3 changes: 0 additions & 3 deletions app/config/parameters.yml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@ parameters:

locale: en

# A secret key that's used to generate certain security-related tokens
secret: CHANGE_ME_TO_SOMETHING_SECRET_AND_RANDOM

# two factor stuff
twofactor_sender: no-reply@wallabag.org

Expand Down
2 changes: 1 addition & 1 deletion app/config/security.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ security:

anonymous: true
remember_me:
secret: "%secret%"
secret: "%env(APP_SECRET)%"
lifetime: 31536000
path: /
domain: ~
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@
"symfony/dependency-injection": "^4.4",
"symfony/doctrine-bridge": "^4.4",
"symfony/dom-crawler": "^4.4",
"symfony/dotenv": "^4.4",
"symfony/error-handler": "^4.4",
"symfony/event-dispatcher": "^4.4",
"symfony/finder": "^4.4",
Expand Down Expand Up @@ -171,8 +172,7 @@
"symfony/maker-bundle": "^1.18",
"symfony/phpunit-bridge": "~6.0",
"symfony/var-dumper": "^4.4",
"symfony/web-profiler-bundle": "^4.4",
"symfony/web-server-bundle": "^4.4"
"symfony/web-profiler-bundle": "^4.4"
},
"suggest": {
"ext-imagick": "To keep GIF animation when downloading image is enabled"
Expand Down
144 changes: 70 additions & 74 deletions composer.lock

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

23 changes: 23 additions & 0 deletions config/bootstrap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

use Symfony\Component\Dotenv\Dotenv;

require dirname(__DIR__) . '/vendor/autoload.php';

if (!class_exists(Dotenv::class)) {
throw new LogicException('Please run "composer require symfony/dotenv" to load the ".env" files configuring the application.');
}

// Load cached env vars if the .env.local.php file exists
// Run "composer dump-env prod" to create it (requires symfony/flex >=1.2)
if (is_array($env = @include dirname(__DIR__) . '/.env.local.php') && (!isset($env['APP_ENV']) || ($_SERVER['APP_ENV'] ?? $_ENV['APP_ENV'] ?? $env['APP_ENV']) === $env['APP_ENV'])) {
(new Dotenv(false))->populate($env);
} else {
// load all the .env files
(new Dotenv(false))->loadEnv(dirname(__DIR__) . '/.env');
}

$_SERVER += $_ENV;
$_SERVER['APP_ENV'] = $_ENV['APP_ENV'] = ($_SERVER['APP_ENV'] ?? $_ENV['APP_ENV'] ?? null) ?: 'dev';
$_SERVER['APP_DEBUG'] = $_SERVER['APP_DEBUG'] ?? $_ENV['APP_DEBUG'] ?? 'prod' !== $_SERVER['APP_ENV'];
$_SERVER['APP_DEBUG'] = $_ENV['APP_DEBUG'] = (int) $_SERVER['APP_DEBUG'] || filter_var($_SERVER['APP_DEBUG'], \FILTER_VALIDATE_BOOLEAN) ? '1' : '0';
17 changes: 12 additions & 5 deletions docker/php/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM php:8.1-fpm AS rootless
FROM php:8.1 AS rootless

ARG DEBIAN_FRONTEND=noninteractive
ARG NODE_VERSION=16
Expand All @@ -15,6 +15,8 @@ RUN apt-get update \
RUN curl 'https://deb.nodesource.com/gpgkey/nodesource.gpg.key' | apt-key add - \
&& echo "deb https://deb.nodesource.com/node_${NODE_VERSION}.x $(lsb_release -cs) main" > /etc/apt/sources.list.d/nodesource.list

RUN curl -1sLf 'https://dl.cloudsmith.io/public/symfony/stable/setup.deb.sh' | bash

RUN apt-get update && apt-get install -y \
libmcrypt-dev \
libicu-dev \
Expand All @@ -34,7 +36,8 @@ RUN apt-get update && apt-get install -y \
git \
build-essential \
nodejs \
npm
npm \
symfony-cli
RUN docker-php-ext-configure gd --with-freetype --with-jpeg --with-webp
RUN docker-php-ext-install -j "$(nproc)" \
bcmath \
Expand Down Expand Up @@ -77,10 +80,13 @@ RUN mkdir -p \
/var/www/html/web/assets \
/var/www/html/data \
/var/www/html/data/db \
/var/www/.cache
/var/www/.cache \
/var/www/.symfony5

WORKDIR /var/www/html

ENTRYPOINT ["/entrypoint.sh"]
CMD ["php", "bin/console", "--env=dev", "server:run", "0.0.0.0:8000"]
CMD ["symfony", "serve"]

FROM rootless AS default

Expand All @@ -94,6 +100,7 @@ RUN groupmod -g 1000 www-data ; \
chown -R www-data: /var/www/html \
/usr/local/etc/php/conf.d/wallabag-php.ini \
/var/www/.cache \
/var/www/.yarnrc
/var/www/.yarnrc \
/var/www/.symfony5

USER www-data
3 changes: 0 additions & 3 deletions docker/php/config/parameters.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ parameters:

locale: ${LOCALE:-en}

# A secret key that's used to generate certain security-related tokens
secret: ${SECRET:-~}

# two factor stuff
twofactor_sender: ${TWOFACTOR_SENDER:-no-reply@wallabag.org}

Expand Down
27 changes: 17 additions & 10 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,27 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>

<!-- https://phpunit.readthedocs.io/en/latest/configuration.html -->
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.8/phpunit.xsd"
xsi:noNamespaceSchemaLocation="bin/.phpunit/phpunit.xsd"
backupGlobals="false"
colors="true"
bootstrap="vendor/autoload.php"
bootstrap="tests/bootstrap.php"
>
<php>
<ini name="display_errors" value="1" />
<ini name="error_reporting" value="-1" />
<server name="APP_ENV" value="test" force="true" />
<server name="SHELL_VERBOSITY" value="-1" />
<server name="SYMFONY_PHPUNIT_REMOVE" value="" />
<server name="SYMFONY_PHPUNIT_VERSION" value="8.5" />
</php>

<testsuites>
<testsuite name="wallabag">
<directory>tests</directory>
</testsuite>
</testsuites>

<php>
<ini name="error_reporting" value="-1" />
<server name="KERNEL_CLASS" value="AppKernel" />
<env name="SYMFONY_DEPRECATIONS_HELPER" value="weak" />
</php>

<filter>
<whitelist>
<directory>src</directory>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">src</directory>
<exclude>
<directory>vendor</directory>
<directory>src/Wallabag/*Bundle/Resources</directory>
Expand All @@ -34,4 +37,8 @@
<extensions>
<extension class="DAMA\DoctrineTestBundle\PHPUnit\PHPUnitExtension" />
</extensions>

<listeners>
<listener class="Symfony\Bridge\PhpUnit\SymfonyTestsListener" />
</listeners>
</phpunit>
7 changes: 7 additions & 0 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

require dirname(__DIR__) . '/config/bootstrap.php';

if ($_SERVER['APP_DEBUG']) {
umask(0000);
}
Loading

0 comments on commit acadb9c

Please sign in to comment.