diff --git a/.env.dist b/.env.dist deleted file mode 100644 index daf74cbb..00000000 --- a/.env.dist +++ /dev/null @@ -1,10 +0,0 @@ -# Application -APP_ENV= -SECRET_KEY= -SHORTENED_URL_SCHEMA= -SHORTENED_URL_HOSTNAME= - -# Database -DB_USER= -DB_PASSWORD= -DB_NAME= diff --git a/.gitattributes b/.gitattributes index df9095a4..80102b6f 100644 --- a/.gitattributes +++ b/.gitattributes @@ -9,7 +9,6 @@ /module/PreviewGenerator/test-db export-ignore /module/Rest/test export-ignore /module/Rest/test-api export-ignore -.env.dist export-ignore .gitattributes export-ignore .gitignore export-ignore .phpstorm.meta.php export-ignore diff --git a/.gitignore b/.gitignore index 7b14364c..ab121a93 100644 --- a/.gitignore +++ b/.gitignore @@ -4,7 +4,6 @@ build composer.lock composer.phar vendor/ -.env data/database.sqlite data/shlink-tests.db data/GeoLite2-City.mmdb diff --git a/CHANGELOG.md b/CHANGELOG.md index 27e08896..66a30779 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,6 +26,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com), and this * [#492](https://github.com/shlinkio/shlink/issues/492) Updated to monolog 2, together with other dependencies, like Symfony 5 and infection-php. * [#527](https://github.com/shlinkio/shlink/issues/527) Increased minimum required mutation score for unit tests to 80%. +* [#557](https://github.com/shlinkio/shlink/issues/557) Added a few php.ini configs for development and production docker images. #### Deprecated diff --git a/Dockerfile b/Dockerfile index eae81a5a..f24dd289 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,7 @@ FROM php:7.3.11-alpine3.10 LABEL maintainer="Alejandro Celaya " -ARG SHLINK_VERSION=1.20.0 +ARG SHLINK_VERSION=1.20.2 ENV SHLINK_VERSION ${SHLINK_VERSION} ENV SWOOLE_VERSION 4.4.12 ENV COMPOSER_VERSION 1.9.1 @@ -52,5 +52,6 @@ VOLUME /etc/shlink/config/params # Copy config specific for the image COPY docker/docker-entrypoint.sh docker-entrypoint.sh COPY docker/config/shlink_in_docker.local.php config/autoload/shlink_in_docker.local.php +COPY docker/config/php.ini ${PHP_INI_DIR}/conf.d/ ENTRYPOINT ["/bin/sh", "./docker-entrypoint.sh"] diff --git a/composer.json b/composer.json index 84290c2a..c1563613 100644 --- a/composer.json +++ b/composer.json @@ -65,7 +65,6 @@ "roave/security-advisories": "dev-master", "shlinkio/php-coding-standard": "~2.0.0", "shlinkio/shlink-test-utils": "^1.2", - "symfony/dotenv": "^5.0", "symfony/var-dumper": "^5.0" }, "autoload": { diff --git a/config/autoload/entity-manager.global.php b/config/autoload/entity-manager.global.php index bd847f5a..561579f1 100644 --- a/config/autoload/entity-manager.global.php +++ b/config/autoload/entity-manager.global.php @@ -11,9 +11,9 @@ return [ 'proxies_dir' => 'data/proxies', ], 'connection' => [ - 'user' => env('DB_USER'), - 'password' => env('DB_PASSWORD'), - 'dbname' => env('DB_NAME', 'shlink'), + 'user' => '', + 'password' => '', + 'dbname' => 'shlink', 'charset' => 'utf8', ], ], diff --git a/config/autoload/entity-manager.local.php.dist b/config/autoload/entity-manager.local.php.dist index cb53a6ae..3c38fb82 100644 --- a/config/autoload/entity-manager.local.php.dist +++ b/config/autoload/entity-manager.local.php.dist @@ -1,8 +1,13 @@ [ 'connection' => [ + 'user' => 'root', + 'password' => 'root', 'driver' => 'pdo_mysql', 'host' => 'shlink_db', 'driverOptions' => [ diff --git a/config/autoload/url-shortener.global.php b/config/autoload/url-shortener.global.php index 7c7e19de..46e12593 100644 --- a/config/autoload/url-shortener.global.php +++ b/config/autoload/url-shortener.global.php @@ -2,14 +2,12 @@ declare(strict_types=1); -use function Shlinkio\Shlink\Common\env; - return [ 'url_shortener' => [ 'domain' => [ - 'schema' => env('SHORTENED_URL_SCHEMA', 'http'), - 'hostname' => env('SHORTENED_URL_HOSTNAME'), + 'schema' => 'https', + 'hostname' => '', ], 'validate_url' => true, ], diff --git a/config/autoload/url-shortener.local.php.dist b/config/autoload/url-shortener.local.php.dist new file mode 100644 index 00000000..c686137f --- /dev/null +++ b/config/autoload/url-shortener.local.php.dist @@ -0,0 +1,14 @@ + [ + 'domain' => [ + 'schema' => 'http', + 'hostname' => 'localhost:8080', + ], + ], + +]; diff --git a/config/container.php b/config/container.php index f2c1d0c7..3df59ed9 100644 --- a/config/container.php +++ b/config/container.php @@ -2,21 +2,12 @@ declare(strict_types=1); -use Symfony\Component\Dotenv\Dotenv; use Zend\ServiceManager\ServiceManager; chdir(dirname(__DIR__)); require 'vendor/autoload.php'; -// If the Dotenv class exists, load env vars and enable errors -if (class_exists(Dotenv::class)) { - error_reporting(E_ALL); - ini_set('display_errors', '1'); - $dotenv = new Dotenv(true); - $dotenv->load(__DIR__ . '/../.env'); -} - // Build container $config = require __DIR__ . '/config.php'; $container = new ServiceManager($config['dependencies']); diff --git a/config/test/bootstrap_api_tests.php b/config/test/bootstrap_api_tests.php index 562986c1..3605427c 100644 --- a/config/test/bootstrap_api_tests.php +++ b/config/test/bootstrap_api_tests.php @@ -7,14 +7,6 @@ namespace Shlinkio\Shlink\TestUtils; use Doctrine\ORM\EntityManager; use Psr\Container\ContainerInterface; -use function file_exists; -use function touch; - -// Create an empty .env file -if (! file_exists('.env')) { - touch('.env'); -} - /** @var ContainerInterface $container */ $container = require __DIR__ . '/../container.php'; $testHelper = $container->get(Helper\TestHelper::class); diff --git a/config/test/bootstrap_db_tests.php b/config/test/bootstrap_db_tests.php index e5e88e20..9f14c38d 100644 --- a/config/test/bootstrap_db_tests.php +++ b/config/test/bootstrap_db_tests.php @@ -6,14 +6,6 @@ namespace Shlinkio\Shlink\TestUtils; use Psr\Container\ContainerInterface; -use function file_exists; -use function touch; - -// Create an empty .env file -if (! file_exists('.env')) { - touch('.env'); -} - /** @var ContainerInterface $container */ $container = require __DIR__ . '/../container.php'; $container->get(Helper\TestHelper::class)->createTestDb(); diff --git a/data/infra/php.ini b/data/infra/php.ini index 9c1e3f01..5ef7b7ea 100644 --- a/data/infra/php.ini +++ b/data/infra/php.ini @@ -1 +1,6 @@ -date.timezone = Europe/Madrid +display_errors=On +error_reporting=-1 +memory_limit=-1 +log_errors_max_len=0 +zend.assertions=1 +assert.exception=1 diff --git a/docker-compose.yml b/docker-compose.yml index 811eec69..99cc93fb 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -3,7 +3,7 @@ version: '3' services: shlink_nginx: container_name: shlink_nginx - image: nginx:1.15.9-alpine + image: nginx:1.17.6-alpine ports: - "8000:80" volumes: @@ -37,6 +37,7 @@ services: - "9001:9001" volumes: - ./:/home/shlink + - ./data/infra/php.ini:/usr/local/etc/php/php.ini links: - shlink_db - shlink_db_postgres diff --git a/docker/config/php.ini b/docker/config/php.ini new file mode 100644 index 00000000..f6c718d0 --- /dev/null +++ b/docker/config/php.ini @@ -0,0 +1,3 @@ +log_errors_max_len=0 +zend.assertions=1 +assert.exception=1 diff --git a/module/Rest/test-api/Action/ListShortUrlsTest.php b/module/Rest/test-api/Action/ListShortUrlsTest.php index eaa13a0a..0952a627 100644 --- a/module/Rest/test-api/Action/ListShortUrlsTest.php +++ b/module/Rest/test-api/Action/ListShortUrlsTest.php @@ -46,7 +46,7 @@ class ListShortUrlsTest extends ApiTestCase 'longUrl' => 'https://blog.alejandrocelaya.com/2017/12/09' . '/acmailer-7-0-the-most-important-release-in-a-long-time/', - 'dateCreated' => '2019-01-01T00:00:00+00:00', + 'dateCreated' => '2019-01-01T00:00:10+00:00', 'visitsCount' => 2, 'tags' => ['bar', 'foo'], 'meta' => [ @@ -62,7 +62,7 @@ class ListShortUrlsTest extends ApiTestCase 'shortCode' => 'custom', 'shortUrl' => 'http://doma.in/custom', 'longUrl' => 'https://shlink.io', - 'dateCreated' => '2019-01-01T00:00:00+00:00', + 'dateCreated' => '2019-01-01T00:00:20+00:00', 'visitsCount' => 0, 'tags' => [], 'meta' => [ @@ -78,7 +78,7 @@ class ListShortUrlsTest extends ApiTestCase 'longUrl' => 'https://blog.alejandrocelaya.com/2019/04/27' . '/considerations-to-properly-use-open-source-software-projects/', - 'dateCreated' => '2019-01-01T00:00:00+00:00', + 'dateCreated' => '2019-01-01T00:00:30+00:00', 'visitsCount' => 0, 'tags' => [], 'meta' => [ diff --git a/module/Rest/test-api/Fixtures/ShortUrlsFixture.php b/module/Rest/test-api/Fixtures/ShortUrlsFixture.php index 62ec00a9..cc359047 100644 --- a/module/Rest/test-api/Fixtures/ShortUrlsFixture.php +++ b/module/Rest/test-api/Fixtures/ShortUrlsFixture.php @@ -22,32 +22,32 @@ class ShortUrlsFixture extends AbstractFixture { $abcShortUrl = $this->setShortUrlDate( new ShortUrl('https://shlink.io', ShortUrlMeta::createFromRawData(['customSlug' => 'abc123'])), - Chronos::parse('2018-05-01') + '2018-05-01' ); $manager->persist($abcShortUrl); $defShortUrl = $this->setShortUrlDate(new ShortUrl( 'https://blog.alejandrocelaya.com/2017/12/09/acmailer-7-0-the-most-important-release-in-a-long-time/', ShortUrlMeta::createFromParams(Chronos::parse('2020-05-01'), null, 'def456') - )); + ), '2019-01-01 00:00:10'); $manager->persist($defShortUrl); $customShortUrl = $this->setShortUrlDate(new ShortUrl( 'https://shlink.io', ShortUrlMeta::createFromParams(null, null, 'custom', 2) - )); + ), '2019-01-01 00:00:20'); $manager->persist($customShortUrl); $withDomainShortUrl = $this->setShortUrlDate(new ShortUrl( 'https://blog.alejandrocelaya.com/2019/04/27/considerations-to-properly-use-open-source-software-projects/', ShortUrlMeta::createFromRawData(['domain' => 'example.com', 'customSlug' => 'ghi789']) - )); + ), '2019-01-01 00:00:30'); $manager->persist($withDomainShortUrl); $withDomainAndSlugShortUrl = $this->setShortUrlDate(new ShortUrl( 'https://google.com', ShortUrlMeta::createFromRawData(['domain' => 'some-domain.com', 'customSlug' => 'custom-with-domain']) - ), Chronos::parse('2018-10-20')); + ), '2018-10-20'); $manager->persist($withDomainAndSlugShortUrl); $manager->flush(); @@ -56,12 +56,12 @@ class ShortUrlsFixture extends AbstractFixture $this->addReference('def456_short_url', $defShortUrl); } - private function setShortUrlDate(ShortUrl $shortUrl, ?Chronos $date = null): ShortUrl + private function setShortUrlDate(ShortUrl $shortUrl, string $date): ShortUrl { $ref = new ReflectionObject($shortUrl); $dateProp = $ref->getProperty('dateCreated'); $dateProp->setAccessible(true); - $dateProp->setValue($shortUrl, $date ?? Chronos::parse('2019-01-01')); + $dateProp->setValue($shortUrl, Chronos::parse($date)); return $shortUrl; }