From b6f0b5ae1eddf45f97eac688f9853635e89162c9 Mon Sep 17 00:00:00 2001 From: gaiterjones Date: Mon, 4 Jul 2022 09:07:00 +0000 Subject: [PATCH] Magento 2.4.4, PHP 8.1, Ubuntu 22.04 --- README.md | 9 +- magento2/elasticsearch/Dockerfile | 2 +- .../Scale/Varnish/Admin/ServerAddress.php | 55 +++ .../Docker/Scale/Varnish/Admin/Socket.php | 85 ++++ .../Scale/Varnish/Admin/VarnishAdmin.php | 80 ++++ .../Varnish/Admin/VarnishAdminSocket.php | 434 ++++++++++++++++++ .../Scale/Varnish/Admin/commands/Commands.php | 72 +++ .../Admin/commands/CommandsVersion3.php | 22 + .../Admin/commands/CommandsVersion4.php | 22 + .../Admin/commands/CommandsVersion5.php | 22 + .../PAJ/Library/Docker/Scale/Varnish/VCL.php | 49 +- .../Scale/Varnish/VarnishAdminSocket.php | 45 +- magento2/manager/magento2/Dockerfile | 19 +- magento2/ubuntu/Dockerfile | 8 +- .../magento233-build/bin/install-magento | 12 - magento2/ubuntu/magento235-build/Dockerfile | 134 ------ magento2/ubuntu/magento235-build/auth.json | 8 - .../magento235-build/bin/install-sampledata | 10 - .../ubuntu/magento235-build/healthcheck.php | 17 - .../Dockerfile | 70 +-- .../auth.json | 0 .../bin/install-magento | 2 +- .../bin/install-sampledata | 0 .../healthcheck.php | 0 .../Dockerfile | 40 +- .../apache2-foreground | 0 .../apache2.conf | 0 .../docker-php-ext-configure | 0 .../docker-php-ext-enable | 0 .../docker-php-ext-install | 0 .../Dockerfile | 34 +- .../apache2-foreground | 0 .../apache2.conf | 0 .../docker-php-ext-configure | 0 .../docker-php-ext-enable | 0 .../docker-php-ext-install | 0 magento2/varnish/varnish7.vcl | 291 ++++++++++++ magento2/varnish/varnish7/Dockerfile | 44 ++ magento2/varnish/varnish7/start.sh | 35 ++ 39 files changed, 1336 insertions(+), 285 deletions(-) create mode 100644 magento2/manager/dev/PAJ/Library/Docker/Scale/Varnish/Admin/ServerAddress.php create mode 100644 magento2/manager/dev/PAJ/Library/Docker/Scale/Varnish/Admin/Socket.php create mode 100644 magento2/manager/dev/PAJ/Library/Docker/Scale/Varnish/Admin/VarnishAdmin.php create mode 100644 magento2/manager/dev/PAJ/Library/Docker/Scale/Varnish/Admin/VarnishAdminSocket.php create mode 100644 magento2/manager/dev/PAJ/Library/Docker/Scale/Varnish/Admin/commands/Commands.php create mode 100644 magento2/manager/dev/PAJ/Library/Docker/Scale/Varnish/Admin/commands/CommandsVersion3.php create mode 100644 magento2/manager/dev/PAJ/Library/Docker/Scale/Varnish/Admin/commands/CommandsVersion4.php create mode 100644 magento2/manager/dev/PAJ/Library/Docker/Scale/Varnish/Admin/commands/CommandsVersion5.php delete mode 100644 magento2/ubuntu/magento233-build/bin/install-magento delete mode 100644 magento2/ubuntu/magento235-build/Dockerfile delete mode 100644 magento2/ubuntu/magento235-build/auth.json delete mode 100644 magento2/ubuntu/magento235-build/bin/install-sampledata delete mode 100644 magento2/ubuntu/magento235-build/healthcheck.php rename magento2/ubuntu/{magento233-build => magento244-build}/Dockerfile (60%) rename magento2/ubuntu/{magento233-build => magento244-build}/auth.json (100%) rename magento2/ubuntu/{magento235-build => magento244-build}/bin/install-magento (88%) rename magento2/ubuntu/{magento233-build => magento244-build}/bin/install-sampledata (100%) rename magento2/ubuntu/{magento233-build => magento244-build}/healthcheck.php (100%) rename magento2/ubuntu/{phusion1100-apache2-php7-3-build => phusion2204-apache2-php7-4-build}/Dockerfile (76%) rename magento2/ubuntu/{phusion1100-apache2-php7-2-25-build => phusion2204-apache2-php7-4-build}/apache2-foreground (100%) rename magento2/ubuntu/{phusion1100-apache2-php7-2-25-build => phusion2204-apache2-php7-4-build}/apache2.conf (100%) rename magento2/ubuntu/{phusion1100-apache2-php7-2-25-build => phusion2204-apache2-php7-4-build}/docker-php-ext-configure (100%) rename magento2/ubuntu/{phusion1100-apache2-php7-2-25-build => phusion2204-apache2-php7-4-build}/docker-php-ext-enable (100%) rename magento2/ubuntu/{phusion1100-apache2-php7-2-25-build => phusion2204-apache2-php7-4-build}/docker-php-ext-install (100%) rename magento2/ubuntu/{phusion1100-apache2-php7-2-25-build => phusion2204-apache2-php8-1-build}/Dockerfile (82%) rename magento2/ubuntu/{phusion1100-apache2-php7-3-build => phusion2204-apache2-php8-1-build}/apache2-foreground (100%) rename magento2/ubuntu/{phusion1100-apache2-php7-3-build => phusion2204-apache2-php8-1-build}/apache2.conf (100%) rename magento2/ubuntu/{phusion1100-apache2-php7-3-build => phusion2204-apache2-php8-1-build}/docker-php-ext-configure (100%) rename magento2/ubuntu/{phusion1100-apache2-php7-3-build => phusion2204-apache2-php8-1-build}/docker-php-ext-enable (100%) rename magento2/ubuntu/{phusion1100-apache2-php7-3-build => phusion2204-apache2-php8-1-build}/docker-php-ext-install (100%) create mode 100644 magento2/varnish/varnish7.vcl create mode 100644 magento2/varnish/varnish7/Dockerfile create mode 100644 magento2/varnish/varnish7/start.sh diff --git a/README.md b/README.md index c7d4401..d8f0e6d 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,14 @@ -# Docker Magento 2.4.X Open Source (CE) 01-2022 +# Docker Magento 2.4.X Open Source (CE) 07-2022 Docker containers for Magento 2.4.x development including : - - PHP 7.4 + - Ubuntu 22.04 + - PHP 8.1 - Apache 2.4 - MYSQL 8 - - Varnish 6 FPC - - RabbitMQ + - Varnish 7 FPC + - RabbitMQ 3.x - PhpMyAdmin - memcached - ELASTIC search 7.x diff --git a/magento2/elasticsearch/Dockerfile b/magento2/elasticsearch/Dockerfile index ad8ad90..212b43f 100644 --- a/magento2/elasticsearch/Dockerfile +++ b/magento2/elasticsearch/Dockerfile @@ -1,4 +1,4 @@ -FROM elasticsearch:7.9.3 +FROM elasticsearch:7.16.1 LABEL maintainer="GAITERJONES" # Magento 2 required plugins # https://github.com/elastic/elasticsearch-analysis-icu diff --git a/magento2/manager/dev/PAJ/Library/Docker/Scale/Varnish/Admin/ServerAddress.php b/magento2/manager/dev/PAJ/Library/Docker/Scale/Varnish/Admin/ServerAddress.php new file mode 100644 index 0000000..ee5f651 --- /dev/null +++ b/magento2/manager/dev/PAJ/Library/Docker/Scale/Varnish/Admin/ServerAddress.php @@ -0,0 +1,55 @@ +host = $host; + if (empty($this->host)) { + $this->host = self::DEFAULT_HOST; + } + $this->port = $port; + if (empty($this->port)) { + $this->port = self::DEFAULT_PORT; + } + } + + /** + * @return string + */ + public function getHost() + { + return $this->host; + } + + /** + * @return int + */ + public function getPort() + { + return $this->port; + } +} diff --git a/magento2/manager/dev/PAJ/Library/Docker/Scale/Varnish/Admin/Socket.php b/magento2/manager/dev/PAJ/Library/Docker/Scale/Varnish/Admin/Socket.php new file mode 100644 index 0000000..a05e4a2 --- /dev/null +++ b/magento2/manager/dev/PAJ/Library/Docker/Scale/Varnish/Admin/Socket.php @@ -0,0 +1,85 @@ +host = $host; + $this->port = $port; + $errno = null; + $errstr = null; + + $this->fp = fsockopen($this->host, $this->port, $errno, $errstr, $timeout); + if (!is_resource($this->fp)) { + // error would have been raised already by fsockopen + throw new Exception(sprintf( + 'Failed to connect to varnishadm on %s:%s; "%s"', + $this->host, + $this->port, + $errstr + )); + } + // set socket options + stream_set_blocking($this->fp, 1); + stream_set_timeout($this->fp, $timeout); + } + + public function read(&$code) + { + $code = null; + $len = null; + // get bytes until we have either a response code and message length or an end of file + // code should be on first line, so we should get it in one chunk + while (!feof($this->fp)) { + $response = fgets($this->fp, 1024); + if (!$response) { + $meta = stream_get_meta_data($this->fp); + if ($meta['timed_out']) { + throw new Exception(sprintf('Timed out reading from socket %s:%s', $this->host, $this->port)); + } + } + if (preg_match('/^(\d{3}) (\d+)/', $response, $r)) { + $code = (int)$r[1]; + $len = (int)$r[2]; + break; + } + } + if (is_null($code)) { + throw new Exception('Failed to get numeric code in response'); + } + $response = ''; + while (!feof($this->fp) && strlen($response) < $len) { + $response .= fgets($this->fp, 1024); + } + + return $response; + } + + + public function write($data) + { + $bytes = fputs($this->fp, $data); + if ($bytes !== strlen($data)) { + throw new Exception(sprintf('Failed to write to varnishadm on %s:%s', $this->host, $this->port)); + } + + return true; + } + + public function close() + { + is_resource($this->fp) && fclose($this->fp); + $this->fp = null; + } +} diff --git a/magento2/manager/dev/PAJ/Library/Docker/Scale/Varnish/Admin/VarnishAdmin.php b/magento2/manager/dev/PAJ/Library/Docker/Scale/Varnish/Admin/VarnishAdmin.php new file mode 100644 index 0000000..8da6922 --- /dev/null +++ b/magento2/manager/dev/PAJ/Library/Docker/Scale/Varnish/Admin/VarnishAdmin.php @@ -0,0 +1,80 @@ + [&& ]..." + * + * @return string + */ + public function purge($expr); + + /** + * Shortcut to purge.url function. + * + * @see https://www.varnish-cache.org/docs/4.0/users-guide/purging.html + * + * @param string $url is a url to purge + * + * @return string + */ + public function purgeUrl($url); + + /** + * Graceful close, sends quit command. + */ + public function quit(); + + /** + * @return bool + */ + public function start(); + + /** + * Test varnish child status. + * + * @return bool whether child is alive + */ + public function status(); + + /** + * Set authentication secret. + * Warning: may require a trailing newline if passed to varnishadm from a text file. + * + * @param string + */ + public function setSecret($secret); + + /** + * @return bool + */ + public function stop(); +} diff --git a/magento2/manager/dev/PAJ/Library/Docker/Scale/Varnish/Admin/VarnishAdminSocket.php b/magento2/manager/dev/PAJ/Library/Docker/Scale/Varnish/Admin/VarnishAdminSocket.php new file mode 100644 index 0000000..d0d6c48 --- /dev/null +++ b/magento2/manager/dev/PAJ/Library/Docker/Scale/Varnish/Admin/VarnishAdminSocket.php @@ -0,0 +1,434 @@ +calculateVersion($version); + $this->setDefaultCommands(); + $this->serverAddress = new ServerAddress($host, $port); + $this->socket = new Socket(); + } + + /** + * @param $version + * @throws Exception + */ + private function calculateVersion($version) + { + $this->setVersion($version); + $this->checkSupportedVersion(); + } + + private function setVersion($version) + { + if (empty($version)) { + $version = Commands::DEFAULT_VERSION; + } + $versionSplit = explode('.', $version, Commands::DEFAULT_VERSION); + $this->version = isset($versionSplit[0]) ? (int)$versionSplit[0] : Commands::DEFAULT_VERSION; + } + + private function checkSupportedVersion() + { + $isUnsupportedVersion = !$this->isFourthVersion() && !$this->isThirdVersion() && !$this->isFifthVersion(); + if ($isUnsupportedVersion) { + throw new \Exception('Only versions 3, 4 and 5 of Varnish are supported'); + } + } + + /** + * @return bool + */ + private function isFifthVersion() + { + return $this->version == CommandsVersion5::NUMBER; + } + + /** + * @return bool + */ + private function isFourthVersion() + { + return $this->version == CommandsVersion4::NUMBER; + } + + private function isThirdVersion() + { + return $this->version == CommandsVersion3::NUMBER; + } + + private function setDefaultCommands() + { + if ($this->isFourthVersion()) { + $this->commands = new CommandsVersion4(); + } + + if ($this->isThirdVersion()) { + $this->commands = new CommandsVersion3(); + } + + if ($this->isFifthVersion()) { + $this->commands = new CommandsVersion5(); + } + } + + /** + * Connect to admin socket. + * + * @param int $timeout in seconds, defaults to 5; used for connect and reads + * @return string the banner, in case you're interested + * @throws Exception + */ + public function connect($timeout = null) + { + if (empty($timeout)) { + $timeout = self::DEFAULT_TIMEOUT; + } + + $this->socket->openSocket($this->getServerAddress()->getHost(), $this->getServerAddress()->getPort(), $timeout); + + $banner = $this->socket->read($code); + + if ($this->needAuthenticate($code)) { + $this->checkSecretIsSet(); + try { + $authenticationData = $this->commands->getAuth() . ' ' . $this->obtainAuthenticationKey($banner); + $banner = $this->command($authenticationData, $code, self::SUCCESS_STATUS); + } catch (Exception $ex) { + throw new Exception('Authentication failed '. $ex->getMessage()); + } + } + $this->checkResponse($code); + + return $banner; + } + + /** + * @return ServerAddress + */ + public function getServerAddress() + { + return $this->serverAddress; + } + + /** + * @param $code + * @return bool + */ + private function needAuthenticate($code) + { + return $code === 107; + } + + private function checkSecretIsSet() + { + if (empty($this->secret)) { + throw new \Exception('Authentication required; see VarnishAdminSocket::setSecret'); + } + } + + /** + * @param $banner + * @return string + */ + private function obtainAuthenticationKey($banner) + { + $challenge = substr($banner, 0, 32); + $auth_string = $challenge . self::NEW_LINE . $this->secret . $challenge . self::NEW_LINE; + $response = hash('sha256', $auth_string); + return $response; + } + + + /** + * Write a command to the socket with a trailing line break and get response straight away. + * + * @param string $cmd + * @param $code + * @param int $ok + * @return string + * @throws Exception + * @internal param $string + */ + public function exec($cmd, &$code = '', $ok = 200) + { + if (!$this->serverAddress->getHost()) { + return null; + } + if (!empty($cmd)) { + $this->socket->write($cmd); + } + $this->socket->write(self::NEW_LINE); + $response = $this->socket->read($code); + if ($code !== $ok) { + $responseParsed = $this->parseResponse($response); + throw new Exception(sprintf("%s command responded %d:\n > %s", $cmd, $code, $responseParsed), $code); + } + return array( + 'code' => $code, + 'text' => $response + ); + } + + /** + * Write a command to the socket with a trailing line break and get response straight away. + * + * @param string $cmd + * @param $code + * @param int $ok + * @return string + * @throws Exception + * @internal param $string + */ + protected function command($cmd, &$code = '', $ok = 200) + { + if (!$this->serverAddress->getHost()) { + return null; + } + if (!empty($cmd)) { + $this->socket->write($cmd); + } + $this->socket->write(self::NEW_LINE); + $response = $this->socket->read($code); + if ($code !== $ok) { + $responseParsed = $this->parseResponse($response); + throw new Exception(sprintf("%s command responded %d:\n > %s", $cmd, $code, $responseParsed), $code); + } + return $response; + } + + /** + * @param $response + * @return string + */ + protected function parseResponse($response) + { + $response = implode(self::NEW_LINE . " > ", explode(self::NEW_LINE, trim($response))); + return $response; + } + + /** + * @param $code + * @throws Exception + */ + private function checkResponse($code) + { + if ($this->isBad($code)) { + throw new \Exception(sprintf( + 'Bad response from varnishadm on %s:%s', + $this->serverAddress->getHost(), + $this->serverAddress->getPort() + )); + } + } + + /** + * @param $code + * @return bool + */ + private function isBad($code) + { + return $code !== self::SUCCESS_STATUS; + } + + /** + * Shortcut to purge function. + * + * @see https://www.varnish-cache.org/docs/4.0/users-guide/purging.html + * + * @param string $expr is a purge expression in form " [&& ]..." + * + * @return string + */ + public function purge($expr) + { + return $this->command($this->commands->getPurgeCommand() . ' ' . $expr); + } + + /** + * Shortcut to purge.url function. + * + * @see https://www.varnish-cache.org/docs/4.0/users-guide/purging.html + * + * @param string $url is a url to purge + * + * @return string + */ + public function purgeUrl($url) + { + return $this->command($this->commands->getPurgeUrlCommand() . ' ' . $url); + } + + /** + * Graceful close, sends quit command. + */ + public function quit() + { + try { + $this->command($this->commands->getQuit(), $code, 500); + } catch (Exception $Ex) { + // silent fail - force close of socket + } + $this->close(); + } + + /** + * Brutal close, doesn't send quit command to varnishadm. + */ + public function close() + { + $this->socket->close(); + $this->socket = null; + } + + /** + * @return bool + */ + public function start() + { + if ($this->status()) { + $this->generateErrorMessage(sprintf( + 'varnish host already started on %s:%s', + $this->serverAddress->getHost(), + $this->serverAddress->getPort() + )); + + return true; + } + $this->command($this->commands->getStart()); + + return true; + } + + public function status() + { + try { + $response = $this->command($this->commands->getStatus()); + + return $this->isRunning($response); + } catch (\Exception $Ex) { + return false; + } + } + + protected function isRunning($response) + { + if (!preg_match('/Child in state (\w+)/', $response, $result)) { + return false; + } + + return $result[1] === 'running' ? true : false; + } + + private function generateErrorMessage($msg) + { + trigger_error($msg, E_USER_NOTICE); + } + + /** + * Set authentication secret. + * Warning: may require a trailing newline if passed to varnishadm from a text file. + * + * @param string + */ + public function setSecret($secret) + { + // Secret requires a new line at the end, so if its not there, lets add it. + + //$this->secret = (strpos($secret, self::NEW_LINE) === (strlen($secret) - 1)) ? $secret : $secret.self::NEW_LINE; + + $this->secret = $secret; + + } + + /** + * @return bool + */ + public function stop() + { + if (!$this->status()) { + $this->generateErrorMessage(sprintf( + 'varnish host already stopped on %s:%s', + $this->serverAddress->getHost(), + $this->serverAddress->getPort() + )); + + return true; + } + + $this->command($this->commands->getStop()); + + return true; + } + + /** + * @return Socket + */ + public function getSocket() + { + return $this->socket; + } + + /** + * @param Socket $socket + */ + public function setSocket($socket) + { + $this->socket = $socket; + } +} diff --git a/magento2/manager/dev/PAJ/Library/Docker/Scale/Varnish/Admin/commands/Commands.php b/magento2/manager/dev/PAJ/Library/Docker/Scale/Varnish/Admin/commands/Commands.php new file mode 100644 index 0000000..a618673 --- /dev/null +++ b/magento2/manager/dev/PAJ/Library/Docker/Scale/Varnish/Admin/commands/Commands.php @@ -0,0 +1,72 @@ +__varnish = new VarnishAdminSocket(array( - 'host' => $_host, - 'auth_secret' => file_get_contents("/etc/varnish/secret"), - 'version' => '4.1' - )); + $this->__varnish = new VarnishAdminSocket($_host); + $this->__varnish->setSecret(file_get_contents("/etc/varnish/secret")); + $this->__varnish->connect(); + + //$this->__varnish = new VarnishAdminSocket(array( + // 'host' => $_host, + // 'auth_secret' => file_get_contents("/etc/varnish/secret"), + // 'version' => '4' + //)); } public function updateVCL($_config) @@ -44,15 +48,15 @@ public function updateVCL($_config) // $_vclName = 'scalemanager_' . time(); - $this->__varnish->vcl_inline($_vclName, trim($_newVCL)); + $this->__varnish->exec('vcl.inline '. $_vclName. ' << EOF'.PHP_EOL. trim($_newVCL).PHP_EOL.'EOF'); sleep(1); - $this->__varnish->vcl_use($_vclName); + $this->__varnish->exec('vcl.use '. $_vclName); // remove all VCL except the last one // - $_vcls = $this->__varnish->vcl_list(); + $_vcls = $this->__varnish->exec('vcl.list'); if ($_vcls["code"] == VarnishAdminSocket::CODE_OK) { @@ -64,7 +68,7 @@ public function updateVCL($_config) $_vcl_to_remove = explode(" ", $_vcl_to_remove); $_vcl_to_remove = $_vcl_to_remove[sizeof($_vcl_to_remove) - 1]; - $this->__varnish->vcl_discard($_vcl_to_remove); + $this->__varnish->exec('vcl.discard '. $_vcl_to_remove); } @@ -76,8 +80,7 @@ public function updateVCL($_config) public function getVCL() { - - $_vcl = $this->__varnish->vcl_list(); + $_vcl = $this->__varnish->exec('vcl.list'); if ($_vcl["code"] != VarnishAdminSocket::CODE_OK) throw new \Exception("Unable to read VCLs from Varnish"); @@ -85,7 +88,7 @@ public function getVCL() $_vcl = explode(" ", $_vcl); $_vcl = $_vcl[sizeof($_vcl) - 1]; - $_vcl = $this->__varnish->vcl_show($_vcl); + $_vcl = $this->__varnish->exec('vcl.show '.$_vcl); if ($_vcl["code"] != VarnishAdminSocket::CODE_OK) throw new \Exception("Unable to read latest VCL from Varnish"); @@ -97,7 +100,19 @@ public function getVCL() public function getParam() { - $_return = $this->__varnish->param_show(); + $_return = $this->__varnish->exec('param.show'); + + if ($_return["code"] != VarnishAdminSocket::CODE_OK) throw new \Exception("Unable to read VCLs from Varnish"); + + $_return = $_return["text"]; + + return $_return; + } + + public function getHelp() + { + + $_return = $this->__varnish->exec('help'); if ($_return["code"] != VarnishAdminSocket::CODE_OK) throw new \Exception("Unable to read VCLs from Varnish"); @@ -109,7 +124,7 @@ public function getParam() public function getBanner() { - $_return = $this->__varnish->banner(); + $_return = $this->__varnish->exec('banner'); if ($_return["code"] != VarnishAdminSocket::CODE_OK) throw new \Exception("Unable to read VCLs from Varnish"); @@ -121,7 +136,7 @@ public function getBanner() public function getBackendList() { - $_return = $this->__varnish->backend_list(); + $_return = $this->__varnish->exec('backend.list'); if ($_return["code"] != VarnishAdminSocket::CODE_OK) throw new \Exception("Unable to read VCLs from Varnish"); diff --git a/magento2/manager/dev/PAJ/Library/Docker/Scale/Varnish/VarnishAdminSocket.php b/magento2/manager/dev/PAJ/Library/Docker/Scale/Varnish/VarnishAdminSocket.php index a3b23ae..8f12c64 100644 --- a/magento2/manager/dev/PAJ/Library/Docker/Scale/Varnish/VarnishAdminSocket.php +++ b/magento2/manager/dev/PAJ/Library/Docker/Scale/Varnish/VarnishAdminSocket.php @@ -88,7 +88,7 @@ class VarnishAdminSocket { protected $_port = 6082; protected $_private = null; protected $_authSecret = null; - protected $_timeout = 30; // timeout + protected $_timeout = 5; protected $_version = null; //auto-detect public function __construct(array $options = array()) { @@ -313,9 +313,8 @@ protected function _connect() { stream_set_blocking($this->_varnishConn, 1); stream_set_timeout($this->_varnishConn, $this->_timeout); - //varnish 2.0 doesn't spit out a banner on connection, this will need - //to be changed if 2.0 support is ever added $banner = $this->_read(); + if ($banner['code'] === self::CODE_AUTH) { $challenge = substr($banner['text'], 0, 32); $response = hash('sha256', sprintf("%s\n%s%s\n", $challenge, @@ -348,7 +347,7 @@ protected function _determineVersion($bannerText) { // Varnish before 3.0.4 does not spit out a version number $resp = $this->_write('help')->_read(); if (strpos($resp['text'], 'ban.url') !== false) { - // Varnish versions 3.0 through 3.0.3 do not return a version banner. + // Varnish versions 3.0 through 3.0.3 do not return a version banner. // To differentiate between 2.1 and 3.0, we check the existence of the ban.url command. return '3.0'; } @@ -384,9 +383,12 @@ protected function _write($data) { $this->_connect(); } $data = rtrim($data).PHP_EOL; + $dataLength = strlen($data); + if ($dataLength >= self::CLI_CMD_LENGTH_LIMIT) { $cliBufferResponse = $this->param_show('cli_buffer'); + $regexp = '~^cli_buffer\s+(\d+)\s+\[bytes\]~'; if ($this->getVersion() === '4.0' || $this->getVersion() === '4.1') { // Varnish4 supports "16k" style notation @@ -407,13 +409,32 @@ protected function _write($data) { $dataLength - $realLimit )); } } - if (($byteCount = fwrite($this->_varnishConn, $data)) !== $dataLength) { - throw new \Exception(sprintf('Varnish socket write error: %d != %d', - $byteCount, $dataLength)); + + //if ($this->strposa($data, array('auth','vcl.inline'))) + if (false) + { + fwrite($this->_varnishConn, str_replace('"','',$data)); + + } else { + if (($byteCount = fwrite($this->_varnishConn, $data)) !== $dataLength) { + throw new \Exception(sprintf('Varnish socket write error: %d != %d : %s', + $byteCount, $dataLength, $data)); + } } + return $this; } + protected function strposa($haystack, $needles=array(), $offset=0) { + $chr = array(); + foreach($needles as $needle) { + $res = strpos($haystack, $needle, $offset); + if ($res !== false) $chr[$needle] = $res; + } + if(empty($chr)) return false; + return min($chr); + } + /** * Read a response from Varnish instance * @@ -464,20 +485,20 @@ protected function _command($verb, $okCode = 200) { //remove $okCode (if it exists) array_shift($params); $cleanedParams = array(); - + foreach ($params as $param) { $cp = addcslashes($param, "\"\\"); $cp = trim(preg_replace('/\s\s+/', PHP_EOL, $cp)); $cp = str_replace(PHP_EOL, '\n', $cp); $cleanedParams[] = sprintf('"%s"', $cp); } - + $data = implode(' ', array_merge( array(sprintf('"%s"', $verb)), $cleanedParams )); - + $response = $this->_write($data)->_read(); - + if ($response['code'] !== $okCode && ! is_null($okCode)) { throw new \Exception(sprintf( "ERROR : Got unexpected response code from Varnish: %d\n%s\nCommand : %s\n", @@ -511,4 +532,4 @@ protected function _translateCommandMethod($verb) { } return $command; } -} \ No newline at end of file +} diff --git a/magento2/manager/magento2/Dockerfile b/magento2/manager/magento2/Dockerfile index 6c48091..104e8f4 100644 --- a/magento2/manager/magento2/Dockerfile +++ b/magento2/manager/magento2/Dockerfile @@ -1,8 +1,8 @@ -FROM gaiterjones/phusion1100-apache2-php7-4:27 +FROM gaiterjones/phusion2204-apache2-php8-1:5 LABEL maintainer="paj@gaiterjones.com" LABEL service "Magento 2 MANAGER Production Service" -ENV CREATION_DATE 22122021 +ENV CREATION_DATE 01072022 # dependencies RUN requirements="libsodium-dev libonig-dev libzip-dev libpng-dev libcurl3-dev zlib1g-dev libpng-dev libjpeg-turbo8 libjpeg-turbo8-dev libfreetype6 libfreetype6-dev libicu-dev libxslt1-dev msmtp nano git" \ @@ -34,20 +34,20 @@ RUN apt-get update && apt-get -yq install \ pngcrush \ && apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* -# Install memcache extension +# Install memcache extension for PHP8 # RUN set -x \ && apt-get update && apt-get install -y --no-install-recommends unzip libssl-dev libpcre3 libpcre3-dev \ && cd /tmp \ - && curl -sSL -o php7.zip https://github.com/websupport-sk/pecl-memcache/archive/4.0.5.2.zip \ - && unzip php7 \ - && cd pecl-memcache-4.0.5.2 \ + && curl -sSL -o php8.zip https://github.com/websupport-sk/pecl-memcache/archive/refs/tags/8.0-fixed.zip \ + && unzip php8.zip \ + && cd pecl-memcache-8.0-fixed \ && /usr/local/bin/phpize \ && ./configure --with-php-config=/usr/local/bin/php-config \ && make \ && make install \ && echo "extension=memcache.so" > /usr/local/etc/php/conf.d/ext-memcache.ini \ - && rm -rf /tmp/pecl-memcache-php7 php7.zip + && rm -rf /tmp/pecl-memcache-8.0-fixed php8.zip # prepare user/s # @@ -99,19 +99,20 @@ RUN a2enmod rewrite \ # >>> DOCKER IN DOCKER RUN set -x \ && cd /tmp \ + && groupmod -g 997 runit-log \ && curl -L -o docker-latest.tgz https://get.docker.com/builds/Linux/x86_64/docker-latest.tgz \ && gzip -d docker-latest.tgz \ && tar -xvf docker-latest.tar \ && mv /tmp/docker/docker /usr/local/bin \ && rm -rf /tmp/docker docker-latest.tar \ - && addgroup --gid 998 docker \ + && addgroup --gid 999 docker \ && usermod -aG docker www-data \ && usermod -aG docker magento # Uncomment for Magepack #RUN set -x \ # && cd /tmp \ -# && curl -sL https://deb.nodesource.com/setup_10.x | bash - \ +# && curl -sL https://deb.nodesource.com/setup_16.x | bash - \ # && apt-get install -y nodejs gconf-service libasound2 libatk1.0-0 libatk-bridge2.0-0 libc6 libcairo2 libcups2 libdbus-1-3 libexpat1 libfontconfig1 libgcc1 libgconf-2-4 libgdk-pixbuf2.0-0 libglib2.0-0 libgtk-3-0 libnspr4 libpango-1.0-0 libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1 libxcomposite1 libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 libxss1 libxtst6 ca-certificates fonts-liberation libappindicator1 libnss3 lsb-release xdg-utils wget \ # && npm install -g magepack --unsafe-perm=true --allow-root \ # && apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* diff --git a/magento2/ubuntu/Dockerfile b/magento2/ubuntu/Dockerfile index bb79107..2ac82f5 100644 --- a/magento2/ubuntu/Dockerfile +++ b/magento2/ubuntu/Dockerfile @@ -1,4 +1,4 @@ -FROM gaiterjones/magento2:2.4.3 +FROM gaiterjones/magento2:2.4.4 LABEL maintainer "paj@gaiterjones.com" LABEL service "Magento 2 PHP-APACHE Service" # ------------------------------------------------------------------ @@ -44,9 +44,9 @@ RUN export PATH=$PATH:/var/www/dev/magento2/bin # DISABLE XDEBUG # https://stackoverflow.com/questions/8754826/how-to-disable-xdebug -RUN cd /usr/local/etc/php/conf.d \ - && mkdir disabled \ - && mv docker-php-ext-xdebug.ini disabled +#RUN cd /usr/local/etc/php/conf.d \ +# && mkdir disabled \ +# && mv docker-php-ext-xdebug.ini disabled # cron job # diff --git a/magento2/ubuntu/magento233-build/bin/install-magento b/magento2/ubuntu/magento233-build/bin/install-magento deleted file mode 100644 index 0dc718d..0000000 --- a/magento2/ubuntu/magento233-build/bin/install-magento +++ /dev/null @@ -1,12 +0,0 @@ -#!/usr/bin/env bash -if [ -f /var/www/dev/magento2/var/composer_home/auth.json ]; then - rm /var/www/dev/magento2/var/composer_home/auth.json - ln -s /var/www/.composer/auth.json /var/www/dev/magento2/var/composer_home/ -fi -if [ ! -f /var/www/dev/magento2/var/composer_home/auth.json ]; then - ln -s /var/www/.composer/auth.json /var/www/dev/magento2/var/composer_home/ -fi -/var/www/dev/magento2/bin/magento setup:install --base-url=$MAGENTO_URL --backend-frontname=admin --language=$MAGENTO_LANGUAGE --timezone=$MAGENTO_TIMEZONE --currency=$MAGENTO_DEFAULT_CURRENCY --db-host=$MYSQL_HOST --db-name=$MYSQL_DATABASE --db-user=$MYSQL_USER --db-password=$MYSQL_PASSWORD --use-secure=0 --base-url-secure=0 --use-secure-admin=0 --admin-firstname=$MAGENTO_ADMIN_FIRSTNAME --admin-lastname=$MAGENTO_ADMIN_LASTNAME --admin-email=$MAGENTO_ADMIN_EMAIL --admin-user=$MAGENTO_ADMIN_USERNAME --admin-password=$MAGENTO_ADMIN_PASSWORD -/var/www/dev/magento2/bin/magento setup:config:set --http-cache-hosts=varnish:80 -/var/www/dev/magento2/bin/magento deploy:mode:set developer -/var/www/dev/magento2/bin/magento c:enable diff --git a/magento2/ubuntu/magento235-build/Dockerfile b/magento2/ubuntu/magento235-build/Dockerfile deleted file mode 100644 index 968d8b4..0000000 --- a/magento2/ubuntu/magento235-build/Dockerfile +++ /dev/null @@ -1,134 +0,0 @@ -FROM gaiterjones/phusion1100-apache2-php7-3:17 -LABEL maintainer="paj@gaiterjones.com" -LABEL description="Magento 2 PHP-APACHE Service" - -ENV MAGENTO_VERSION 2.3.5-p1 -# sha256sum Magento-Open-Source-2.3.5-p1.tar.gz -ENV MAGENTO_SHA256 c808d163ecf1a1648038988a62f21f77ff277f6f7f143adf0baa016509520353 - -# dependencies -# remove mcrpyt for > php 7.2 ? -RUN requirements="libzip-dev libpng-dev libmcrypt-dev libmcrypt4 libcurl3-dev libfreetype6 libjpeg-turbo8 libjpeg-turbo8-dev libfreetype6-dev libicu-dev libxslt1-dev msmtp nano git" \ - && apt-get update && apt-get install -y $requirements && rm -rf /var/lib/apt/lists/* \ - && docker-php-ext-install pdo_mysql \ - && docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \ - && docker-php-ext-install gd \ - && pecl install mcrypt-1.0.2 \ - && docker-php-ext-enable mcrypt \ - && docker-php-ext-install bcmath \ - && docker-php-ext-install mbstring \ - && docker-php-ext-install zip \ - && docker-php-ext-install intl \ - && docker-php-ext-install xsl \ - && docker-php-ext-install soap \ - && docker-php-ext-install opcache \ - && docker-php-ext-install sockets \ - && requirementsToRemove="libpng-dev libmcrypt-dev libcurl3-dev libpng12-dev libfreetype6-dev libjpeg-turbo8-dev" \ - && apt-get purge --auto-remove -y $requirementsToRemove - -# Install XDEBUG extension -# Xdebug replaces PHP's var_dump() function for displaying variables. -# https://xdebug.org/download.php -# confirm => php -m | grep -i xdebug -RUN set -x \ - && pecl install xdebug-2.9.5 \ - && docker-php-ext-enable xdebug - -# Install memcache extension -# -RUN set -x \ - && apt-get update && apt-get install -y --no-install-recommends unzip libssl-dev libpcre3 libpcre3-dev \ - && cd /tmp \ - && curl -sSL -o php7.zip https://github.com/websupport-sk/pecl-memcache/archive/4.0.5.2.zip \ - && unzip php7 \ - && cd pecl-memcache-4.0.5.2 \ - && /usr/local/bin/phpize \ - && ./configure --with-php-config=/usr/local/bin/php-config \ - && make \ - && make install \ - && echo "extension=memcache.so" > /usr/local/etc/php/conf.d/ext-memcache.ini \ - && rm -rf /tmp/pecl-memcache-php7 php7.zip - -# get magento 2 and extract -# -RUN set -x \ - && mkdir /var/www/dev \ - && rm -rf /var/www/html/* \ - && mkdir /tmp/magento2 \ - && cd /tmp/magento2 \ - && curl https://pe.terjon.es/dropbox/Magento-Open-Source-$MAGENTO_VERSION.tar.gz -o $MAGENTO_VERSION.tar.gz \ - && echo "$MAGENTO_SHA256 $MAGENTO_VERSION.tar.gz" | sha256sum -c - \ - && tar xvf $MAGENTO_VERSION.tar.gz \ - && cd .. \ - && mv magento2 /var/www/dev/ \ - && mkdir /var/www/dev/magento2/composer_home - -# install composer -# -RUN set -x \ - && curl -sS https://getcomposer.org/installer | php \ - && mv composer.phar /usr/local/bin/composer - -# install magerun 2 -# -RUN set -x \ - && cd /tmp \ - && curl -s -o n98-magerun2.phar https://files.magerun.net/n98-magerun2.phar \ - && chmod +x ./n98-magerun2.phar \ - && mv ./n98-magerun2.phar /usr/local/bin/ - -# prepare Mage source -# -# add Magento 2 file owner -# -# ensure www-data is group 33 -# add new file owner group 1000 -# file owner member of www-data -# -COPY ./healthcheck.php /var/www/dev/magento2/ -COPY ./auth.json /var/www/.composer/ -ENV COMPOSER_HOME=/var/www/.composer -RUN set -x \ - && usermod -u 33 www-data \ - && adduser --disabled-password --gecos '' magento \ - && usermod -u 1000 magento \ - && usermod -a -G www-data magento \ - && chown -R magento:www-data /var/www - -# composer -RUN chsh -s /bin/bash magento \ - && su magento -c "cd /var/www/dev/magento2 && composer install" - -# php RedisAdmin -# https://github.com/erikdubbelboer/phpRedisAdmin -# -RUN su magento -c "cd /var/www/dev && composer create-project -s dev erik-dubbelboer/php-redis-admin /var/www/dev/phpRedisAdmin" - -# Magento DEVELOPMENT permissions (this may take a while...) -# -RUN set -x \ - && cd /var/www/dev/magento2 \ - && rm -rf ./generated/metadata/* ./generated/code/* ./pub/static/* ./var/cache/* ./var/page_cache/* ./var/view_preprocessed/* ./var/log/* \ - && find var generated vendor pub/static pub/media app/etc -type f -exec chmod g+w {} \; && find var generated vendor pub/static pub/media app/etc -type d -exec chmod g+ws {} \; && chmod u+x bin/magento - -# scripts -# -COPY ./bin/install-magento /usr/local/bin/install-magento -RUN chmod +x /usr/local/bin/install-magento -COPY ./bin/install-sampledata /usr/local/bin/install-sampledata -RUN chmod +x /usr/local/bin/install-sampledata - -# configure apache env -# -ENV APACHE_RUN_USER www-data -ENV APACHE_RUN_GROUP www-data -ENV APACHE_LOG_DIR /var/log/apache2 -ENV APACHE_PID_FILE /var/run/apache2.pid -ENV APACHE_RUN_DIR /var/run/apache2 -ENV APACHE_LOCK_DIR /var/lock/apache2 - -# cleanup -# -RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* - -WORKDIR /var/www/dev/magento2 diff --git a/magento2/ubuntu/magento235-build/auth.json b/magento2/ubuntu/magento235-build/auth.json deleted file mode 100644 index 9dc9ddd..0000000 --- a/magento2/ubuntu/magento235-build/auth.json +++ /dev/null @@ -1,8 +0,0 @@ - { - "http-basic": { - "repo.magento.com": { - "username": "XUSERNAMEX", - "password": "XPASSWORDX" - } - } -} \ No newline at end of file diff --git a/magento2/ubuntu/magento235-build/bin/install-sampledata b/magento2/ubuntu/magento235-build/bin/install-sampledata deleted file mode 100644 index 868338a..0000000 --- a/magento2/ubuntu/magento235-build/bin/install-sampledata +++ /dev/null @@ -1,10 +0,0 @@ -#!/usr/bin/env bash -if [ -f /var/www/dev/magento2/var/composer_home/auth.json ]; then - rm /var/www/dev/magento2/var/composer_home/auth.json - ln -s /var/www/.composer/auth.json /var/www/dev/magento2/var/composer_home/ -fi -if [ ! -f /var/www/dev/magento2/var/composer_home/auth.json ]; then - ln -s /var/www/.composer/auth.json /var/www/dev/magento2/var/composer_home/ -fi -/var/www/dev/magento2/bin/magento sampledata:deploy -/var/www/dev/magento2/bin/magento setup:upgrade diff --git a/magento2/ubuntu/magento235-build/healthcheck.php b/magento2/ubuntu/magento235-build/healthcheck.php deleted file mode 100644 index 3f5b005..0000000 --- a/magento2/ubuntu/magento235-build/healthcheck.php +++ /dev/null @@ -1,17 +0,0 @@ - diff --git a/magento2/ubuntu/magento233-build/Dockerfile b/magento2/ubuntu/magento244-build/Dockerfile similarity index 60% rename from magento2/ubuntu/magento233-build/Dockerfile rename to magento2/ubuntu/magento244-build/Dockerfile index e0370dc..38bf821 100644 --- a/magento2/ubuntu/magento233-build/Dockerfile +++ b/magento2/ubuntu/magento244-build/Dockerfile @@ -1,28 +1,30 @@ -FROM gaiterjones/phusion1100-apache2-php7-2:25 +FROM gaiterjones/phusion2204-apache2-php8-1:5 LABEL maintainer="paj@gaiterjones.com" LABEL description="Magento 2 PHP-APACHE Service" -ENV MAGENTO_VERSION 2.3.3 -# sha256sum Magento-Open-Source-2.3.3.tar.gz -ENV MAGENTO_SHA256 6ac13592c7a90502643ddfd2edf8b21ba88a6a5e11a0d1b8179ef915584518a9 +ENV MAGENTO_VERSION 2.4.4 +# sha256sum Magento-Open-Source-2.4.4.tar.gz +ENV MAGENTO_SHA256 4a420b91510c327e0f22af1701a7033bfab4843b16b67479df09b998b16165cd # dependencies -# remove mcrpyt for > php 7.2 ? -RUN requirements="libpng-dev libmcrypt-dev libmcrypt4 libcurl3-dev libfreetype6 libjpeg-turbo8 libjpeg-turbo8-dev libfreetype6-dev libicu-dev libxslt1-dev msmtp nano git" \ +RUN requirements="libsodium-dev libonig-dev libzip-dev libpng-dev libcurl3-dev zlib1g-dev libpng-dev libjpeg-turbo8 libjpeg-turbo8-dev libfreetype6 libfreetype6-dev libicu-dev libxslt1-dev msmtp nano git" \ && apt-get update && apt-get install -y $requirements && rm -rf /var/lib/apt/lists/* \ - && docker-php-ext-install pdo_mysql \ - && docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \ - && docker-php-ext-install gd \ - && pecl install mcrypt-1.0.2 \ - && docker-php-ext-enable mcrypt \ - && docker-php-ext-install bcmath \ - && docker-php-ext-install mbstring \ - && docker-php-ext-install zip \ - && docker-php-ext-install intl \ - && docker-php-ext-install xsl \ - && docker-php-ext-install soap \ - && docker-php-ext-install opcache \ - && requirementsToRemove="libpng-dev libmcrypt-dev libcurl3-dev libpng12-dev libfreetype6-dev libjpeg-turbo8-dev" \ + && docker-php-ext-configure gd \ + --enable-gd \ + --with-jpeg \ + --with-freetype \ + && docker-php-ext-install -j$(nproc) gd \ + && docker-php-ext-install -j$(nproc) pdo_mysql \ + && docker-php-ext-install -j$(nproc) bcmath \ + && docker-php-ext-install -j$(nproc) mbstring \ + && docker-php-ext-install -j$(nproc) zip \ + && docker-php-ext-install -j$(nproc) intl \ + && docker-php-ext-install -j$(nproc) xsl \ + && docker-php-ext-install -j$(nproc) soap \ + && docker-php-ext-install -j$(nproc) opcache \ + && docker-php-ext-install -j$(nproc) sockets \ + && docker-php-ext-install -j$(nproc) sodium \ + && requirementsToRemove="libcurl3-dev libfreetype6-dev libpng-dev libjpeg-turbo8-dev" \ && apt-get purge --auto-remove -y $requirementsToRemove # Install XDEBUG extension @@ -30,23 +32,23 @@ RUN requirements="libpng-dev libmcrypt-dev libmcrypt4 libcurl3-dev libfreetype6 # https://xdebug.org/download.php # confirm => php -m | grep -i xdebug RUN set -x \ - && pecl install xdebug-2.6.0beta1 \ - && docker-php-ext-enable xdebug + && pecl install xdebug \ + && docker-php-ext-enable xdebug -# Install memcache extension +# Install memcache extension for PHP8 # RUN set -x \ && apt-get update && apt-get install -y --no-install-recommends unzip libssl-dev libpcre3 libpcre3-dev \ && cd /tmp \ - && curl -sSL -o php7.zip https://github.com/websupport-sk/pecl-memcache/archive/php7.zip \ - && unzip php7 \ - && cd pecl-memcache-php7 \ + && curl -sSL -o php8.zip https://github.com/websupport-sk/pecl-memcache/archive/refs/tags/8.0-fixed.zip \ + && unzip php8.zip \ + && cd pecl-memcache-8.0-fixed \ && /usr/local/bin/phpize \ && ./configure --with-php-config=/usr/local/bin/php-config \ && make \ && make install \ && echo "extension=memcache.so" > /usr/local/etc/php/conf.d/ext-memcache.ini \ - && rm -rf /tmp/pecl-memcache-php7 php7.zip + && rm -rf /tmp/pecl-memcache-8.0-fixed php8.zip # get magento 2 and extract # @@ -62,11 +64,10 @@ RUN set -x \ && mv magento2 /var/www/dev/ \ && mkdir /var/www/dev/magento2/composer_home -# install composer +# install composer v2.3.7 # RUN set -x \ - && curl -sS https://getcomposer.org/installer | php \ - && mv composer.phar /usr/local/bin/composer + && curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer --version=2.3.7 # install magerun 2 # @@ -86,6 +87,14 @@ RUN set -x \ # COPY ./healthcheck.php /var/www/dev/magento2/ COPY ./auth.json /var/www/.composer/ +# Magento repo auth config +# +ARG MAGENTO_REPO_USERNAME +ARG MAGENTO_REPO_PASSWORD +RUN set -x \ + && sed -i "s/XUSERNAMEX/$MAGENTO_REPO_USERNAME/g" /var/www/.composer/auth.json \ + && sed -i "s/XPASSWORDX/$MAGENTO_REPO_PASSWORD/g" /var/www/.composer/auth.json \ + && cat /var/www/.composer/auth.json ENV COMPOSER_HOME=/var/www/.composer RUN set -x \ && usermod -u 33 www-data \ @@ -96,7 +105,7 @@ RUN set -x \ # composer RUN chsh -s /bin/bash magento \ - && su magento -c "cd /var/www/dev/magento2 && composer install" + && su magento -c "cd /var/www/dev/magento2 && composer install --ignore-platform-reqs" # php RedisAdmin # https://github.com/erikdubbelboer/phpRedisAdmin @@ -129,5 +138,6 @@ ENV APACHE_LOCK_DIR /var/lock/apache2 # cleanup # RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* +COPY ./auth.json /var/www/.composer/ WORKDIR /var/www/dev/magento2 diff --git a/magento2/ubuntu/magento233-build/auth.json b/magento2/ubuntu/magento244-build/auth.json similarity index 100% rename from magento2/ubuntu/magento233-build/auth.json rename to magento2/ubuntu/magento244-build/auth.json diff --git a/magento2/ubuntu/magento235-build/bin/install-magento b/magento2/ubuntu/magento244-build/bin/install-magento similarity index 88% rename from magento2/ubuntu/magento235-build/bin/install-magento rename to magento2/ubuntu/magento244-build/bin/install-magento index 0dc718d..c1bd3ed 100644 --- a/magento2/ubuntu/magento235-build/bin/install-magento +++ b/magento2/ubuntu/magento244-build/bin/install-magento @@ -6,7 +6,7 @@ fi if [ ! -f /var/www/dev/magento2/var/composer_home/auth.json ]; then ln -s /var/www/.composer/auth.json /var/www/dev/magento2/var/composer_home/ fi -/var/www/dev/magento2/bin/magento setup:install --base-url=$MAGENTO_URL --backend-frontname=admin --language=$MAGENTO_LANGUAGE --timezone=$MAGENTO_TIMEZONE --currency=$MAGENTO_DEFAULT_CURRENCY --db-host=$MYSQL_HOST --db-name=$MYSQL_DATABASE --db-user=$MYSQL_USER --db-password=$MYSQL_PASSWORD --use-secure=0 --base-url-secure=0 --use-secure-admin=0 --admin-firstname=$MAGENTO_ADMIN_FIRSTNAME --admin-lastname=$MAGENTO_ADMIN_LASTNAME --admin-email=$MAGENTO_ADMIN_EMAIL --admin-user=$MAGENTO_ADMIN_USERNAME --admin-password=$MAGENTO_ADMIN_PASSWORD +/var/www/dev/magento2/bin/magento setup:install --base-url=$MAGENTO_URL --backend-frontname=admin --language=$MAGENTO_LANGUAGE --timezone=$MAGENTO_TIMEZONE --currency=$MAGENTO_DEFAULT_CURRENCY --db-host=$MYSQL_HOST --db-name=$MYSQL_DATABASE --db-user=$MYSQL_USER --db-password=$MYSQL_PASSWORD --use-secure=0 --base-url-secure=0 --use-secure-admin=0 --admin-firstname=$MAGENTO_ADMIN_FIRSTNAME --admin-lastname=$MAGENTO_ADMIN_LASTNAME --admin-email=$MAGENTO_ADMIN_EMAIL --admin-user=$MAGENTO_ADMIN_USERNAME --admin-password=$MAGENTO_ADMIN_PASSWORD --search-engine=elasticsearch7 --elasticsearch-host=elasticsearch --elasticsearch-index-prefix=magento2 /var/www/dev/magento2/bin/magento setup:config:set --http-cache-hosts=varnish:80 /var/www/dev/magento2/bin/magento deploy:mode:set developer /var/www/dev/magento2/bin/magento c:enable diff --git a/magento2/ubuntu/magento233-build/bin/install-sampledata b/magento2/ubuntu/magento244-build/bin/install-sampledata similarity index 100% rename from magento2/ubuntu/magento233-build/bin/install-sampledata rename to magento2/ubuntu/magento244-build/bin/install-sampledata diff --git a/magento2/ubuntu/magento233-build/healthcheck.php b/magento2/ubuntu/magento244-build/healthcheck.php similarity index 100% rename from magento2/ubuntu/magento233-build/healthcheck.php rename to magento2/ubuntu/magento244-build/healthcheck.php diff --git a/magento2/ubuntu/phusion1100-apache2-php7-3-build/Dockerfile b/magento2/ubuntu/phusion2204-apache2-php7-4-build/Dockerfile similarity index 76% rename from magento2/ubuntu/phusion1100-apache2-php7-3-build/Dockerfile rename to magento2/ubuntu/phusion2204-apache2-php7-4-build/Dockerfile index 5b3d7d6..27a9e9f 100644 --- a/magento2/ubuntu/phusion1100-apache2-php7-3-build/Dockerfile +++ b/magento2/ubuntu/phusion2204-apache2-php7-4-build/Dockerfile @@ -1,8 +1,8 @@ -FROM phusion/baseimage:0.11 +FROM phusion/baseimage:jammy-1.0.0 # https://github.com/phusion/baseimage-docker/releases -# build for gaiterjones/phusion1100-apache2-php7-2:latest -# BIONIX BABY -# UBUNTU 18.04 +# build for gaiterjones/phusion1100-apache2-php7-4:latest +# VERY JAMMY DUDE +# UBUNTU 22.04 # phpize deps RUN apt-get update && apt-get install -y \ @@ -14,6 +14,7 @@ RUN apt-get update && apt-get install -y \ make \ pkg-config \ re2c \ + zlib1g-dev \ --no-install-recommends && rm -r /var/lib/apt/lists/* # persistent / runtime deps @@ -28,7 +29,6 @@ RUN apt-get update && apt-get install -y \ ENV PHP_INI_DIR /usr/local/etc/php RUN mkdir -p $PHP_INI_DIR/conf.d -#### RUN apt-get update && apt-get install -y apache2 apache2-utils --no-install-recommends && rm -rf /var/lib/apt/lists/* RUN rm -rf /var/www/html && mkdir -p /var/lock/apache2 /var/run/apache2 /var/log/apache2 /var/www/html && chown -R www-data:www-data /var/lock/apache2 /var/run/apache2 /var/log/apache2 /var/www/html @@ -42,14 +42,27 @@ COPY apache2.conf /etc/apache2/apache2.conf ENV PHP_EXTRA_BUILD_DEPS apache2-dev ENV PHP_EXTRA_CONFIGURE_ARGS --with-apxs2 -#### -ENV GPG_KEYS CBAF69F173A0FEA4B537F470D66C9593118BCCB6 F38252826ACD957EF380D39F2F7956BC5DA04B5D +# https://www.openssl.org/source +# Compile OpenSSL 1.1.1 for PHP 7.4.X +# +ENV OPENSSL_VERSION openssl-1.1.1p +RUN set -xe \ + && curl -fSL "https://www.openssl.org/source/$OPENSSL_VERSION.tar.gz" -o "$OPENSSL_VERSION.tar.gz" \ + && ls -al \ + && tar xzf $OPENSSL_VERSION.tar.gz \ + && cd $OPENSSL_VERSION \ + && ./Configure --prefix=/opt/$OPENSSL_VERSION/bin -fPIC -shared linux-x86_64 \ + && make -j 8 \ + && make install \ + && export PKG_CONFIG_PATH=/opt/$OPENSSL_VERSION/bin/lib/pkgconfig + +ENV GPG_KEYS 5A52880781F755608BF815FC910DEB46F53EA312 42670A7FE4D0441C8E4632349E4FDC074A4EF02D # http://php.net/releases/ -ENV PHP_VERSION 7.3.17 -ENV PHP_FILENAME php-7.3.17.tar.xz -ENV PHP_SHA256 6a30304c27f7e7a94538f5ffec599f600ee93aedbbecad8aa4f8bec539b10ad8 +ENV PHP_VERSION 7.4.30 +ENV PHP_FILENAME php-7.4.30.tar.xz +ENV PHP_SHA256 ea72a34f32c67e79ac2da7dfe96177f3c451c3eefae5810ba13312ed398ba70d RUN set -xe \ && buildDeps=" \ @@ -59,6 +72,8 @@ RUN set -xe \ libsqlite3-dev \ libssl-dev \ libxml2-dev \ + libonig-dev \ + libsodium-dev \ xz-utils \ " \ && apt-get update && apt-get install -y $buildDeps --no-install-recommends && rm -rf /var/lib/apt/lists/* \ @@ -67,7 +82,7 @@ RUN set -xe \ && curl -fSL "http://php.net/get/$PHP_FILENAME.asc/from/this/mirror" -o "$PHP_FILENAME.asc" \ && export GNUPGHOME="$(mktemp -d)" \ && for key in $GPG_KEYS; do \ - gpg --keyserver ha.pool.sks-keyservers.net --recv-keys "$key"; \ + gpg --keyserver hkp://keyserver.ubuntu.com --recv-keys "$key"; \ done \ && gpg --batch --verify "$PHP_FILENAME.asc" "$PHP_FILENAME" \ && rm -r "$GNUPGHOME" "$PHP_FILENAME.asc" \ @@ -85,9 +100,12 @@ RUN set -xe \ # --enable-mbstring is included here because otherwise there's no way to get pecl to use it properly (see https://github.com/docker-library/php/issues/195) --enable-mbstring \ --with-curl \ + --with-webp \ --with-libedit \ --with-openssl \ --with-zlib \ + --with-pear \ + PKG_CONFIG_PATH=/opt/$OPENSSL_VERSION/bin/lib/pkgconfig \ && make -j"$(nproc)" \ && make install \ && { find /usr/local/bin /usr/local/sbin -type f -executable -exec strip --strip-all '{}' + || true; } \ diff --git a/magento2/ubuntu/phusion1100-apache2-php7-2-25-build/apache2-foreground b/magento2/ubuntu/phusion2204-apache2-php7-4-build/apache2-foreground similarity index 100% rename from magento2/ubuntu/phusion1100-apache2-php7-2-25-build/apache2-foreground rename to magento2/ubuntu/phusion2204-apache2-php7-4-build/apache2-foreground diff --git a/magento2/ubuntu/phusion1100-apache2-php7-2-25-build/apache2.conf b/magento2/ubuntu/phusion2204-apache2-php7-4-build/apache2.conf similarity index 100% rename from magento2/ubuntu/phusion1100-apache2-php7-2-25-build/apache2.conf rename to magento2/ubuntu/phusion2204-apache2-php7-4-build/apache2.conf diff --git a/magento2/ubuntu/phusion1100-apache2-php7-2-25-build/docker-php-ext-configure b/magento2/ubuntu/phusion2204-apache2-php7-4-build/docker-php-ext-configure similarity index 100% rename from magento2/ubuntu/phusion1100-apache2-php7-2-25-build/docker-php-ext-configure rename to magento2/ubuntu/phusion2204-apache2-php7-4-build/docker-php-ext-configure diff --git a/magento2/ubuntu/phusion1100-apache2-php7-2-25-build/docker-php-ext-enable b/magento2/ubuntu/phusion2204-apache2-php7-4-build/docker-php-ext-enable similarity index 100% rename from magento2/ubuntu/phusion1100-apache2-php7-2-25-build/docker-php-ext-enable rename to magento2/ubuntu/phusion2204-apache2-php7-4-build/docker-php-ext-enable diff --git a/magento2/ubuntu/phusion1100-apache2-php7-2-25-build/docker-php-ext-install b/magento2/ubuntu/phusion2204-apache2-php7-4-build/docker-php-ext-install similarity index 100% rename from magento2/ubuntu/phusion1100-apache2-php7-2-25-build/docker-php-ext-install rename to magento2/ubuntu/phusion2204-apache2-php7-4-build/docker-php-ext-install diff --git a/magento2/ubuntu/phusion1100-apache2-php7-2-25-build/Dockerfile b/magento2/ubuntu/phusion2204-apache2-php8-1-build/Dockerfile similarity index 82% rename from magento2/ubuntu/phusion1100-apache2-php7-2-25-build/Dockerfile rename to magento2/ubuntu/phusion2204-apache2-php8-1-build/Dockerfile index 971e471..6a278e7 100644 --- a/magento2/ubuntu/phusion1100-apache2-php7-2-25-build/Dockerfile +++ b/magento2/ubuntu/phusion2204-apache2-php8-1-build/Dockerfile @@ -1,8 +1,8 @@ -FROM phusion/baseimage:0.11 +FROM phusion/baseimage:jammy-1.0.0 # https://github.com/phusion/baseimage-docker/releases -# build for gaiterjones/phusion1100-apache2-php7-2:latest -# BIONIX BABY -# UBUNTU 18.04 +# build for gaiterjones/phusion2204-apache2-php7-4:latest +# VERY JAMMY DUDE +# UBUNTU 22.04 # phpize deps RUN apt-get update && apt-get install -y \ @@ -14,6 +14,7 @@ RUN apt-get update && apt-get install -y \ make \ pkg-config \ re2c \ + zlib1g-dev \ --no-install-recommends && rm -r /var/lib/apt/lists/* # persistent / runtime deps @@ -40,34 +41,35 @@ RUN mv /etc/apache2/apache2.conf /etc/apache2/apache2.conf.dist && rm /etc/apach COPY apache2.conf /etc/apache2/apache2.conf # it'd be nice if we could not COPY apache2.conf until the end of the Dockerfile, but its contents are checked by PHP during compilation -ENV PHP_EXTRA_BUILD_DEPS apache2-dev -ENV PHP_EXTRA_CONFIGURE_ARGS --with-apxs2 #### -ENV GPG_KEYS 1729F83938DA44E27BA0F4D3DBDB397470D12172 528995BFEDFBA7191D46839EF9BA0ADA31CBD89E A917B1ECDA84AEC2B568FED6F50ABC807BD5DCD0 +ENV GPG_KEYS 5A52880781F755608BF815FC910DEB46F53EA312 42670A7FE4D0441C8E4632349E4FDC074A4EF02D 528995BFEDFBA7191D46839EF9BA0ADA31CBD89E 39B641343D8C104B2B146DC3F9C39DC0B9698544 F1F692238FBC1666E5A5CCD4199F9DFEF6FFBAFD # http://php.net/releases/ -ENV PHP_VERSION 7.2.25 -ENV PHP_FILENAME php-7.2.25.tar.xz -ENV PHP_SHA256 746efeedc38e6ff7b1ec1432440f5fa801537adf6cd21e4afb3f040e5b0760a9 +ENV PHP_VERSION 8.1.5 +ENV PHP_FILENAME php-8.1.5.tar.xz +ENV PHP_SHA256 7647734b4dcecd56b7e4bd0bc55e54322fa3518299abcdc68eb557a7464a2e8a RUN set -xe \ && buildDeps=" \ - $PHP_EXTRA_BUILD_DEPS \ + apache2-dev \ libcurl4-openssl-dev \ libedit-dev \ libsqlite3-dev \ libssl-dev \ libxml2-dev \ + libonig-dev \ xz-utils \ " \ - && apt-get update && apt-get install -y $buildDeps --no-install-recommends && rm -rf /var/lib/apt/lists/* \ + && apt-get update && apt-get install -y $buildDeps --no-install-recommends && rm -rf /var/lib/apt/lists/* + +RUN set -xe \ && curl -fSL "http://php.net/get/$PHP_FILENAME/from/this/mirror" -o "$PHP_FILENAME" \ && echo "$PHP_SHA256 *$PHP_FILENAME" | sha256sum -c - \ && curl -fSL "http://php.net/get/$PHP_FILENAME.asc/from/this/mirror" -o "$PHP_FILENAME.asc" \ && export GNUPGHOME="$(mktemp -d)" \ && for key in $GPG_KEYS; do \ - gpg --keyserver ha.pool.sks-keyservers.net --recv-keys "$key"; \ + gpg --keyserver hkp://keyserver.ubuntu.com --recv-keys "$key"; \ done \ && gpg --batch --verify "$PHP_FILENAME.asc" "$PHP_FILENAME" \ && rm -r "$GNUPGHOME" "$PHP_FILENAME.asc" \ @@ -78,16 +80,18 @@ RUN set -xe \ && ./configure \ --with-config-file-path="$PHP_INI_DIR" \ --with-config-file-scan-dir="$PHP_INI_DIR/conf.d" \ - $PHP_EXTRA_CONFIGURE_ARGS \ + --with-apxs2 \ --disable-cgi \ + --disable-shared \ + --with-openssl \ # --enable-mysqlnd is included here because it's harder to compile after the fact than extensions are (since it's a plugin for several extensions, not an extension in itself) --enable-mysqlnd \ # --enable-mbstring is included here because otherwise there's no way to get pecl to use it properly (see https://github.com/docker-library/php/issues/195) --enable-mbstring \ --with-curl \ --with-libedit \ - --with-openssl \ --with-zlib \ + --with-pear \ && make -j"$(nproc)" \ && make install \ && { find /usr/local/bin /usr/local/sbin -type f -executable -exec strip --strip-all '{}' + || true; } \ diff --git a/magento2/ubuntu/phusion1100-apache2-php7-3-build/apache2-foreground b/magento2/ubuntu/phusion2204-apache2-php8-1-build/apache2-foreground similarity index 100% rename from magento2/ubuntu/phusion1100-apache2-php7-3-build/apache2-foreground rename to magento2/ubuntu/phusion2204-apache2-php8-1-build/apache2-foreground diff --git a/magento2/ubuntu/phusion1100-apache2-php7-3-build/apache2.conf b/magento2/ubuntu/phusion2204-apache2-php8-1-build/apache2.conf similarity index 100% rename from magento2/ubuntu/phusion1100-apache2-php7-3-build/apache2.conf rename to magento2/ubuntu/phusion2204-apache2-php8-1-build/apache2.conf diff --git a/magento2/ubuntu/phusion1100-apache2-php7-3-build/docker-php-ext-configure b/magento2/ubuntu/phusion2204-apache2-php8-1-build/docker-php-ext-configure similarity index 100% rename from magento2/ubuntu/phusion1100-apache2-php7-3-build/docker-php-ext-configure rename to magento2/ubuntu/phusion2204-apache2-php8-1-build/docker-php-ext-configure diff --git a/magento2/ubuntu/phusion1100-apache2-php7-3-build/docker-php-ext-enable b/magento2/ubuntu/phusion2204-apache2-php8-1-build/docker-php-ext-enable similarity index 100% rename from magento2/ubuntu/phusion1100-apache2-php7-3-build/docker-php-ext-enable rename to magento2/ubuntu/phusion2204-apache2-php8-1-build/docker-php-ext-enable diff --git a/magento2/ubuntu/phusion1100-apache2-php7-3-build/docker-php-ext-install b/magento2/ubuntu/phusion2204-apache2-php8-1-build/docker-php-ext-install similarity index 100% rename from magento2/ubuntu/phusion1100-apache2-php7-3-build/docker-php-ext-install rename to magento2/ubuntu/phusion2204-apache2-php8-1-build/docker-php-ext-install diff --git a/magento2/varnish/varnish7.vcl b/magento2/varnish/varnish7.vcl new file mode 100644 index 0000000..047ea28 --- /dev/null +++ b/magento2/varnish/varnish7.vcl @@ -0,0 +1,291 @@ +# VCL version 5.0 is not supported so it should be 4.0 even though actually used Varnish version is 6 +# vcl Magento 2.4.4 +vcl 4.0; + +import std; +import directors; +# The minimal Varnish version is 6.0 +# For SSL offloading, pass the following header in your proxy server or load balancer: 'X-Forwarded-Proto: https' + +#AUTOGENERATED_START +backend apache_1 { + .host = "shop01_magento2_php-apache_1"; + .port = "80"; + .first_byte_timeout = 180s; + .probe = { + .request = "GET /health_check.php HTTP/1.1" + "Host: magento2.dev.com" + "Connection: close" + "Accept: text/html" ; + .timeout = 60s; + .interval = 120s; + .window = 10; + .threshold = 8; + } + +} + +sub vcl_init { + new cluster1 = directors.round_robin(); + cluster1.add_backend(apache_1); +} + +sub vcl_recv { + set req.backend_hint = cluster1.backend(); +} +#AUTOGENERATED_END + +# purge set to docker nets +# 172.0.0.0/12 192.168.0.0/16 +acl purge { + "172.16.0.0"/12; + "192.168.0.0"/16; +} + +sub vcl_recv { + +#CUSTOM VCL START + +# https://github.com/magento/magento2/issues/24353 +# https://github.com/magento/magento2/issues/3897 +if (req.restarts > 0) { set req.hash_always_miss = true; } + +# Bypass scale manager page +if (req.url ~ "/scale-manager") { + return (pass); +} + +#CUSTOM VCL END + + if (req.method == "PURGE") { + if (client.ip !~ purge) { + return (synth(405, "Method not allowed")); + } + # To use the X-Pool header for purging varnish during automated deployments, make sure the X-Pool header + # has been added to the response in your backend server config. This is used, for example, by the + # capistrano-magento2 gem for purging old content from varnish during it's deploy routine. + if (!req.http.X-Magento-Tags-Pattern && !req.http.X-Pool) { + return (synth(400, "X-Magento-Tags-Pattern or X-Pool header required")); + } + if (req.http.X-Magento-Tags-Pattern) { + ban("obj.http.X-Magento-Tags ~ " + req.http.X-Magento-Tags-Pattern); + } + if (req.http.X-Pool) { + ban("obj.http.X-Pool ~ " + req.http.X-Pool); + } + return (synth(200, "Purged")); + } + + if (req.method != "GET" && + req.method != "HEAD" && + req.method != "PUT" && + req.method != "POST" && + req.method != "TRACE" && + req.method != "OPTIONS" && + req.method != "DELETE") { + /* Non-RFC2616 or CONNECT which is weird. */ + return (pipe); + } + + # We only deal with GET and HEAD by default + if (req.method != "GET" && req.method != "HEAD") { + return (pass); + } + + # Bypass customer, shopping cart, checkout + if (req.url ~ "/customer" || req.url ~ "/checkout") { + return (pass); + } + + # Bypass health check requests + if (req.url ~ "^/(pub/)?(health_check.php)$") { + return (pass); + } + + # Set initial grace period usage status + set req.http.grace = "none"; + + # normalize url in case of leading HTTP scheme and domain + set req.url = regsub(req.url, "^http[s]?://", ""); + + # collect all cookies + std.collect(req.http.Cookie); + + # Compression filter. See https://www.varnish-cache.org/trac/wiki/FAQ/Compression + if (req.http.Accept-Encoding) { + if (req.url ~ "\.(jpg|jpeg|png|gif|gz|tgz|bz2|tbz|mp3|ogg|swf|flv)$") { + # No point in compressing these + unset req.http.Accept-Encoding; + } elsif (req.http.Accept-Encoding ~ "gzip") { + set req.http.Accept-Encoding = "gzip"; + } elsif (req.http.Accept-Encoding ~ "deflate" && req.http.user-agent !~ "MSIE") { + set req.http.Accept-Encoding = "deflate"; + } else { + # unknown algorithm + unset req.http.Accept-Encoding; + } + } + + # Remove all marketing get parameters to minimize the cache objects + if (req.url ~ "(\?|&)(gclid|cx|ie|cof|siteurl|zanpid|origin|fbclid|mc_[a-z]+|utm_[a-z]+|_bta_[a-z]+)=") { + set req.url = regsuball(req.url, "(gclid|cx|ie|cof|siteurl|zanpid|origin|fbclid|mc_[a-z]+|utm_[a-z]+|_bta_[a-z]+)=[-_A-z0-9+()%.]+&?", ""); + set req.url = regsub(req.url, "[?|&]+$", ""); + } + + # Static files caching + if (req.url ~ "^/(pub/)?(media|static)/") { + # Static files should not be cached by default + return (pass); + + # But if you use a few locales and don't use CDN you can enable caching static files by commenting previous line (#return (pass);) and uncommenting next 3 lines + #unset req.http.Https; + #unset req.http.X-Forwarded-Proto; + #unset req.http.Cookie; + } + + # Bypass authenticated GraphQL requests without a X-Magento-Cache-Id + if (req.url ~ "/graphql" && !req.http.X-Magento-Cache-Id && req.http.Authorization ~ "^Bearer") { + return (pass); + } + + return (hash); +} + +sub vcl_hash { + if ((req.url !~ "/graphql" || !req.http.X-Magento-Cache-Id) && req.http.cookie ~ "X-Magento-Vary=") { + hash_data(regsub(req.http.cookie, "^.*?X-Magento-Vary=([^;]+);*.*$", "\1")); + } + + # For multi site configurations to not cache each other's content + if (req.http.host) { + hash_data(req.http.host); + } else { + hash_data(server.ip); + } + + # To make sure http users don't see ssl warning + if (req.http.X-Forwarded-Proto) { + hash_data(req.http.X-Forwarded-Proto); + } + + if (req.url ~ "/graphql") { + call process_graphql_headers; + } +} + +sub process_graphql_headers { + if (req.http.X-Magento-Cache-Id) { + hash_data(req.http.X-Magento-Cache-Id); + + # When the frontend stops sending the auth token, make sure users stop getting results cached for logged-in users + if (req.http.Authorization ~ "^Bearer") { + hash_data("Authorized"); + } + } + + if (req.http.Store) { + hash_data(req.http.Store); + } + + if (req.http.Content-Currency) { + hash_data(req.http.Content-Currency); + } +} + +sub vcl_backend_response { + + set beresp.grace = 3d; + + if (beresp.http.content-type ~ "text") { + set beresp.do_esi = true; + } + + if (bereq.url ~ "\.js$" || beresp.http.content-type ~ "text") { + set beresp.do_gzip = true; + } + + if (beresp.http.X-Magento-Debug) { + set beresp.http.X-Magento-Cache-Control = beresp.http.Cache-Control; + } + + # cache only successfully responses and 404s that are not marked as private + if (beresp.status != 200 && + beresp.status != 404 && + beresp.http.Cache-Control ~ "private") { + set beresp.uncacheable = true; + set beresp.ttl = 86400s; + return (deliver); + } + + # validate if we need to cache it and prevent from setting cookie + if (beresp.ttl > 0s && (bereq.method == "GET" || bereq.method == "HEAD")) { + unset beresp.http.set-cookie; + } + + # If page is not cacheable then bypass varnish for 2 minutes as Hit-For-Pass + if (beresp.ttl <= 0s || + beresp.http.Surrogate-control ~ "no-store" || + (!beresp.http.Surrogate-Control && + beresp.http.Cache-Control ~ "no-cache|no-store") || + beresp.http.Vary == "*") { + # Mark as Hit-For-Pass for the next 2 minutes + set beresp.ttl = 120s; + set beresp.uncacheable = true; + } + + # If the cache key in the Magento response doesn't match the one that was sent in the request, don't cache under the request's key + if (bereq.url ~ "/graphql" && bereq.http.X-Magento-Cache-Id && bereq.http.X-Magento-Cache-Id != beresp.http.X-Magento-Cache-Id) { + set beresp.ttl = 0s; + set beresp.uncacheable = true; + } + + return (deliver); +} + +sub vcl_deliver { + if (resp.http.x-varnish ~ " ") { + set resp.http.X-Magento-Cache-Debug = "HIT"; + set resp.http.Grace = req.http.grace; + } else { + set resp.http.X-Magento-Cache-Debug = "MISS"; + } + + # Not letting browser to cache non-static files. + if (resp.http.Cache-Control !~ "private" && req.url !~ "^/(pub/)?(media|static)/") { + set resp.http.Pragma = "no-cache"; + set resp.http.Expires = "-1"; + set resp.http.Cache-Control = "no-store, no-cache, must-revalidate, max-age=0"; + } + + if (!resp.http.X-Magento-Debug) { + unset resp.http.Age; + } + unset resp.http.X-Magento-Debug; + unset resp.http.X-Magento-Tags; + unset resp.http.X-Powered-By; + unset resp.http.Server; + unset resp.http.X-Varnish; + unset resp.http.Via; + unset resp.http.Link; +} + +sub vcl_hit { + if (obj.ttl >= 0s) { + # Hit within TTL period + return (deliver); + } + if (std.healthy(req.backend_hint)) { + if (obj.ttl + 300s > 0s) { + # Hit after TTL expiration, but within grace period + set req.http.grace = "normal (healthy server)"; + return (deliver); + } else { + # Hit after TTL and grace expiration + return (restart); + } + } else { + # server is not healthy, retrieve from cache + set req.http.grace = "unlimited (unhealthy server)"; + return (deliver); + } +} diff --git a/magento2/varnish/varnish7/Dockerfile b/magento2/varnish/varnish7/Dockerfile new file mode 100644 index 0000000..4884fc8 --- /dev/null +++ b/magento2/varnish/varnish7/Dockerfile @@ -0,0 +1,44 @@ +FROM varnish:7.0.2 +# https://hub.docker.com/_/varnish +LABEL maintainer="paj@gaiterjones.com" +LABEL service="varnish" +LABEL version="7.0.2" + +ARG ENV_TYPE +ENV ENV_TYPE ${ENV_TYPE:-development} + +ARG VARNISH_STORAGE +ENV VARNISH_STORAGE ${VARNISH_STORAGE:-malloc,1G} + +ARG VARNISH_TTL +ENV VARNISH_TTL ${VARNISH_TTL:-120} + +ARG VARNISH_VCL_CONF +ENV VARNISH_VCL_CONF ${VARNISH_VCL_CONF:-/etc/varnish/default.vcl} + +ARG VARNISH_LISTEN_ADDRESS +ENV VARNISH_LISTEN_ADDRESS ${VARNISH_LISTEN_ADDRESS:-0.0.0.0} + +ARG VARNISH_LISTEN_PORT +ENV VARNISH_LISTEN_PORT ${VARNISH_LISTEN_PORT:-80} + +ARG VARNISH_ADMIN_LISTEN_ADDRESS +ENV VARNISH_ADMIN_LISTEN_ADDRESS ${VARNISH_ADMIN_LISTEN_ADDRESS:-0.0.0.0} + +ARG VARNISH_ADMIN_LISTEN_PORT +ENV VARNISH_ADMIN_LISTEN_PORT ${VARNISH_ADMIN_LISTEN_PORT:-6082} + +# https://community.magento.com/t5/Magento-2-x-Programming/how-to-fix-Error-503-Backend-fetch-failed/td-p/84061 +ARG VARNISH_DAEMON_OPTIONS +ENV VARNISH_DAEMON_OPTIONS ${VARNISH_DAEMON_OPTIONS:-"-p connect_timeout=300 -p thread_pool_min=5 -p thread_pool_max=2000 -p thread_pool_add_delay=4 -p thread_pools=4 -p pcre2_depth_limit=500 -p pcre2_match_limit=2500 -p thread_pool_stack=72k -p http_resp_size=98304 -p http_resp_hdr_len=65536 -p workspace_backend=131072 -S /etc/varnish/secret"} + +ARG VARNISH_CONTAINER_LOG_TYPE +ENV VARNISH_CONTAINER_LOG_TYPE ${VARNISH_LOG_TYPE:-"varnishncsa"} + +WORKDIR /etc/varnish + +EXPOSE 80 +#ENTRYPOINT ["docker-varnish-entrypoint"] +COPY ./start.sh /usr/bin/varnish-start.sh +RUN chmod +x /usr/bin/varnish-start.sh +ENTRYPOINT "/usr/bin/varnish-start.sh" diff --git a/magento2/varnish/varnish7/start.sh b/magento2/varnish/varnish7/start.sh new file mode 100644 index 0000000..c9fec01 --- /dev/null +++ b/magento2/varnish/varnish7/start.sh @@ -0,0 +1,35 @@ +#!/bin/bash +set -e + +startVarnish() { + /usr/sbin/varnishd \ + -F \ + -f $VARNISH_VCL_CONF \ + -a ${VARNISH_LISTEN_ADDRESS}:${VARNISH_LISTEN_PORT} \ + -T ${VARNISH_ADMIN_LISTEN_ADDRESS}:${VARNISH_ADMIN_LISTEN_PORT} \ + -t $VARNISH_TTL \ + -p feature=+http2 \ + -s $VARNISH_STORAGE \ + $VARNISH_DAEMON_OPTIONS +} + +startVarnishWithLogging() { + /usr/sbin/varnishd \ + -f $VARNISH_VCL_CONF \ + -a ${VARNISH_LISTEN_ADDRESS}:${VARNISH_LISTEN_PORT} \ + -T ${VARNISH_ADMIN_LISTEN_ADDRESS}:${VARNISH_ADMIN_LISTEN_PORT} \ + -t $VARNISH_TTL \ + -p feature=+http2 \ + -s $VARNISH_STORAGE \ + $VARNISH_DAEMON_OPTIONS + + /usr/bin/$VARNISH_CONTAINER_LOG_TYPE -F "%t - %{%Y-%m-%d}t - %{%H:%M:%S}t - %{X-Forwarded-For}i - %h - %r - %s - %b - %T - %D - %{Varnish:time_firstbyte}x - %{Varnish:handling}x - %{Referer}i - %{User-agent}i" +} + +if [ "$VARNISH_LOGGING_ENABLED" = true ]; then + echo "Starting varnish with logging..." + startVarnishWithLogging +else + echo "Starting varnish without logging..." + startVarnish +fi