diff --git a/.env b/.env index 42c7a42..322045a 100644 --- a/.env +++ b/.env @@ -27,3 +27,13 @@ APP_SECRET=ddaf593d53cd6fca2a95f748ceacdfe2 # IMPORTANT: You MUST configure your server version, either here or in config/packages/doctrine.yaml DATABASE_URL=mysql://db_user:db_password@127.0.0.1:3306/db_name?serverVersion=5.7 ###< doctrine/doctrine-bundle ### + +###> symfony/messenger ### +# Choose one of the transports below +# MESSENGER_TRANSPORT_DSN=amqp://guest:guest@localhost:5672/%2f/messages +# MESSENGER_TRANSPORT_DSN=doctrine://default +# MESSENGER_TRANSPORT_DSN=redis://localhost:6379/messages +###< symfony/messenger ### + +COMPOSER_PATH=composer +BOX_PATH=box diff --git a/assets/sass/style.scss b/assets/sass/style.scss index bd62d4e..a82398d 100755 --- a/assets/sass/style.scss +++ b/assets/sass/style.scss @@ -10,9 +10,9 @@ $footer-height: 60px; html { - font-size: 14px; position: relative; min-height: 100%; + line-height: 1.3; } body { diff --git a/composer.json b/composer.json index b6b98d7..4a2f0b4 100644 --- a/composer.json +++ b/composer.json @@ -6,6 +6,8 @@ "ext-ctype": "*", "ext-iconv": "*", "ext-json": "*", + "ext-curl": "*", + "ext-zip": "*", "kadet/keylighter": "dev-master", "league/commonmark": "^1.3", "sensio/framework-extra-bundle": "^5.5", @@ -14,6 +16,7 @@ "symfony/dotenv": "5.0.*", "symfony/flex": "^1.3.1", "symfony/framework-bundle": "5.0.*", + "symfony/messenger": "5.0.*", "symfony/orm-pack": "^1.0", "symfony/profiler-pack": "^1.0", "symfony/twig-pack": "^1.0", diff --git a/composer.lock b/composer.lock index ac83df9..03128ec 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "e2304bcfe75a51f30dd11d1699bab82a", + "content-hash": "21e44e8aa90d4d7ae44c34fdfdee4f2c", "packages": [ { "name": "doctrine/annotations", @@ -3104,6 +3104,94 @@ ], "time": "2020-03-30T15:04:59+00:00" }, + { + "name": "symfony/messenger", + "version": "v5.0.7", + "source": { + "type": "git", + "url": "https://github.com/symfony/messenger.git", + "reference": "56bec7d319695f6c284af382d803074262a8f074" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/messenger/zipball/56bec7d319695f6c284af382d803074262a8f074", + "reference": "56bec7d319695f6c284af382d803074262a8f074", + "shasum": "" + }, + "require": { + "php": "^7.2.5", + "psr/log": "~1.0" + }, + "conflict": { + "doctrine/persistence": "<1.3", + "symfony/event-dispatcher": "<4.4", + "symfony/framework-bundle": "<4.4", + "symfony/http-kernel": "<4.4" + }, + "require-dev": { + "doctrine/dbal": "^2.6", + "doctrine/persistence": "^1.3", + "psr/cache": "~1.0", + "symfony/console": "^4.4|^5.0", + "symfony/dependency-injection": "^4.4|^5.0", + "symfony/event-dispatcher": "^4.4|^5.0", + "symfony/http-kernel": "^4.4|^5.0", + "symfony/process": "^4.4|^5.0", + "symfony/property-access": "^4.4|^5.0", + "symfony/serializer": "^4.4|^5.0", + "symfony/service-contracts": "^1.1|^2", + "symfony/stopwatch": "^4.4|^5.0", + "symfony/validator": "^4.4|^5.0" + }, + "suggest": { + "enqueue/messenger-adapter": "For using the php-enqueue library as a transport." + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "5.0-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Component\\Messenger\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Samuel Roze", + "email": "samuel.roze@gmail.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony Messenger Component", + "homepage": "https://symfony.com", + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2020-03-27T16:56:45+00:00" + }, { "name": "symfony/mime", "version": "v5.0.7", diff --git a/config/packages/messenger.yaml b/config/packages/messenger.yaml new file mode 100644 index 0000000..677f6c5 --- /dev/null +++ b/config/packages/messenger.yaml @@ -0,0 +1,7 @@ +framework: + messenger: + transports: + async: '%env(MESSENGER_TRANSPORT_DSN)%' + + routing: + 'App\Message\UpdateKeylighterMessage': async diff --git a/config/services.yaml b/config/services.yaml index 802f36b..d9f34b0 100644 --- a/config/services.yaml +++ b/config/services.yaml @@ -1,8 +1,8 @@ # put parameters here that don't need to change on each machine where the app is deployed # https://symfony.com/doc/current/best_practices/configuration.html#application-related-configuration parameters: - keylighter_dir: '%kernel.project_dir%/var/keylighter/' - keylighter_temp_dir: '%kernel.cache_dir%/keylighter/' + keylighter_dir: '%kernel.project_dir%/var/keylighter' + keylighter_temp_dir: '/tmp/keylighter' services: # default configuration for services in *this* file @@ -46,6 +46,12 @@ services: - { name: kernel.event_listener, event: kernel.request } - { name: kernel.event_listener, event: kernel.response } + App\MessageHandler\UpdateKeylighterHandler: + arguments: + $composer: "%env(COMPOSER_PATH)%" + $box: "%env(BOX_PATH)%" + $installed: "%keylighter_dir%/installed.json" + Kadet\Highlighter\KeyLighter: class: Kadet\Highlighter\KeyLighter factory: 'Kadet\Highlighter\KeyLighter::get' diff --git a/docker-compose.yml b/docker-compose.yml index da96df2..7910e68 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -11,8 +11,13 @@ services: php: build: docker/php + environment: + - MESSENGER_TRANSPORT_DSN=redis://redis:6379/messages env_file: - ./docker/php/.env volumes: - ./:/var/www:cached - ./docker/php/log.conf:/usr/local/etc/php-fpm.d/zz-log.conf + + redis: + image: redis:latest diff --git a/docker/php/Dockerfile b/docker/php/Dockerfile index eb9a355..e24fa5e 100644 --- a/docker/php/Dockerfile +++ b/docker/php/Dockerfile @@ -3,22 +3,33 @@ FROM php:7.3-fpm ARG XDEBUG_REMOTE_HOST="172.17.0.1" RUN apt-get update && \ - apt-get install -y --no-install-recommends git zip libzip-dev + apt-get install -y --no-install-recommends git zip libzip-dev wget libcurl4-openssl-dev -RUN docker-php-ext-install zip +RUN docker-php-ext-install zip curl # XDebug RUN pecl install xdebug-2.9.0 && docker-php-ext-enable xdebug RUN echo "xdebug.remote_enable = 1" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini && \ echo "xdebug.remote_host = ${XDEBUG_REMOTE_HOST}" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini; -#Composer +# Redis +RUN pecl install -o -f redis && docker-php-ext-enable redis + +# Cleanup +RUN rm -rf /tmp/pear + +# Composer RUN php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" \ && php composer-setup.php \ && php -r "unlink('composer-setup.php');" \ && mv composer.phar /usr/local/bin/composer \ && chmod +x /usr/local/bin/composer +# Box +RUN wget https://github.com/humbug/box/releases/download/3.8.4/box.phar \ + && mv box.phar /usr/local/bin/box \ + && chmod +x /usr/local/bin/box + # Timezone RUN ln -snf /usr/share/zoneinfo/Europe/Warsaw /etc/localtime RUN echo "date.timezone = Europe/Warsaw" >> /usr/local/etc/php/conf.d/datetime.ini; diff --git a/src/Command/KeyLighterUpdate.php b/src/Command/KeyLighterUpdate.php index 5a5c81c..83dcbf5 100755 --- a/src/Command/KeyLighterUpdate.php +++ b/src/Command/KeyLighterUpdate.php @@ -30,8 +30,10 @@ class KeyLighterUpdate extends Command { } - protected function execute(InputInterface $input, OutputInterface $output) + protected function execute(InputInterface $input, OutputInterface $output): int { $this->versioner->updateAll(); + + return 0; } -} \ No newline at end of file +} diff --git a/src/Consumer/.gitignore b/src/Consumer/.gitignore deleted file mode 100755 index e69de29..0000000 diff --git a/src/Message/UpdateKeylighterMessage.php b/src/Message/UpdateKeylighterMessage.php new file mode 100644 index 0000000..2ee763e --- /dev/null +++ b/src/Message/UpdateKeylighterMessage.php @@ -0,0 +1,25 @@ +revision = $revision; + $this->destination = $destination; + } + + public function getRevision() + { + return $this->revision; + } + + public function getDestination() + { + return $this->destination; + } +} diff --git a/src/Consumer/UpdateKeylighterConsumer.php b/src/MessageHandler/UpdateKeylighterHandler.php similarity index 77% rename from src/Consumer/UpdateKeylighterConsumer.php rename to src/MessageHandler/UpdateKeylighterHandler.php index cc7a1ed..5dac566 100755 --- a/src/Consumer/UpdateKeylighterConsumer.php +++ b/src/MessageHandler/UpdateKeylighterHandler.php @@ -1,47 +1,34 @@ logger = $logger; $this->composer = $composer; $this->box = $box; $this->filesystem = $filesystem; + $this->installed = $installed; } /** @@ -61,32 +48,11 @@ class UpdateKeylighterConsumer implements ConsumerInterface return realpath($path); } - /** - * @param mixed $temp - */ - public function setTemp($temp) + public function __invoke(UpdateKeylighterMessage $message) { - $this->temp = $temp; - $this->filesystem->mkdir($this->temp, 0755); - } + $this->logger->info(sprintf('Downloading KeyLighter revision %s to %s', $message->getRevision()['version'], $message->getDestination())); - public function setInstalledFile(string $path) - { - $this->installed = $path; - } - - /** - * @param AMQPMessage $msg The message - * - * @return mixed false to reject and requeue, any other value to acknowledge - */ - public function execute(AMQPMessage $msg) - { - list($destination, $revision) = unserialize($msg->getBody()); - - $this->logger->info(sprintf('Downloading KeyLighter revision %s to %s', $revision['version'], $destination)); - - return $this->download($revision, $destination); + return $this->download($message->getRevision(), $message->getDestination()); } private function download($revision, $destination) @@ -103,7 +69,7 @@ class UpdateKeylighterConsumer implements ConsumerInterface $cwd = getcwd(); chdir($destination); try { - $this->runCommands([ $this->composer.' install -n --no-ansi --quiet' ]); + $this->runCommands([ $this->composer.' install -n --no-ansi --quiet --no-dev' ]); if (file_exists('./box.json.dist')) { $this->runCommands([ $this->box.' build -n --no-ansi']); @@ -159,6 +125,7 @@ class UpdateKeylighterConsumer implements ConsumerInterface if ($this->filesystem->exists($final)) { $this->filesystem->remove($final); } + $this->filesystem->rename($dir, $final, true); return true; @@ -202,4 +169,12 @@ class UpdateKeylighterConsumer implements ConsumerInterface file_put_contents($this->installed, json_encode($entries, true), LOCK_EX); } -} \ No newline at end of file + + /** + * @inheritDoc + */ + public static function getHandledMessages(): iterable + { + yield UpdateKeylighterMessage::class; + } +} diff --git a/src/Service/KeyLighterVersioner.php b/src/Service/KeyLighterVersioner.php index 6afd4e6..86456b2 100755 --- a/src/Service/KeyLighterVersioner.php +++ b/src/Service/KeyLighterVersioner.php @@ -1,27 +1,27 @@ filesystem = $filesystem; $this->parameters = $parameters; + $this->bus = $bus; } public function getAvailableVersions() @@ -51,7 +51,7 @@ class KeyLighterVersioner continue; } - // fixme: add package to download queue + $this->bus->dispatch(new UpdateKeylighterMessage($revision, $this->getDirectory($version))); } } diff --git a/symfony.lock b/symfony.lock index b725b32..89dd483 100644 --- a/symfony.lock +++ b/symfony.lock @@ -204,6 +204,18 @@ "symfony/http-kernel": { "version": "v5.0.7" }, + "symfony/messenger": { + "version": "4.3", + "recipe": { + "repo": "github.com/symfony/recipes", + "branch": "master", + "version": "4.3", + "ref": "8a2675c061737658bed85102e9241c752620e575" + }, + "files": [ + "config/packages/messenger.yaml" + ] + }, "symfony/mime": { "version": "v5.0.7" },