From 3356cf7ac58b4acdffccc333d7145bafcd4708c9 Mon Sep 17 00:00:00 2001 From: eeliu <27064129+eeliu@users.noreply.github.com> Date: Thu, 11 Jul 2024 10:54:13 +0800 Subject: [PATCH] add example for shopware (#645) --- install_pinpoint_php.sh | 2 +- testapps/compose.yaml | 32 ++++++- testapps/db.sql | 1 + testapps/shopware/Readme.md | 9 ++ testapps/shopware/index.php | 116 ++++++++++++++++++++++++++ testapps/shopware/shopware.dockerfile | 12 +++ 6 files changed, 170 insertions(+), 2 deletions(-) create mode 100644 testapps/shopware/Readme.md create mode 100644 testapps/shopware/index.php create mode 100644 testapps/shopware/shopware.dockerfile diff --git a/install_pinpoint_php.sh b/install_pinpoint_php.sh index 4e5c9e292..627720613 100644 --- a/install_pinpoint_php.sh +++ b/install_pinpoint_php.sh @@ -63,7 +63,7 @@ func_show_pinpoint_php(){ } main(){ - for cmd in php phpize gcc make php-config curl; do + for cmd in php phpize gcc make php-config curl autoconf; do func_check_command $cmd done func_download_extension diff --git a/testapps/compose.yaml b/testapps/compose.yaml index 316b69d50..890dada1d 100644 --- a/testapps/compose.yaml +++ b/testapps/compose.yaml @@ -5,6 +5,8 @@ services: environment: MYSQL_ROOT_PASSWORD: 'password' MYSQL_TCP_PORT: 3306 + MYSQL_USER: 'pinpoint' + MYSQL_PASSWORD: 'password' ports: - '3306:3306' volumes: @@ -456,4 +458,32 @@ services: condition: service_healthy dev-collector: condition: service_started - restart: on-failure \ No newline at end of file + restart: on-failure + shopware-php: + build: + dockerfile: testapps/shopware/shopware.dockerfile + context: ../ + environment: + APP_SECRET: 440dec3766de53010c5ccf6231c182acfc90bd25cff82e771245f736fd276518 + INSTANCE_ID: 10612e3916e153dd3447850e944a03fabe89440970295447a30a75b151bd844e + APP_URL: http://localhost:8200 + BLUE_GREEN_DEPLOYMENT: 0 + DATABASE_HOST: dev-mysql + DATABASE_URL: mysql://root:password@dev-mysql:3306/shopware + CACHE_ADAPTER: redis + REDIS_CACHE_HOST: redis + REDIS_CACHE_PORT: 6379 + REDIS_CACHE_DATABASE: 3 + REDIS_SESSION_HOST: redis + REDIS_SESSION_PORT: 6379 + REDIS_SESSION_DATABASE: 3 + APP_ENV: dev + ports: + - 8200:80 + depends_on: + redis: + condition: service_healthy + dev-collector: + condition: service_started + dev-mysql-setup: + condition: service_completed_successfully \ No newline at end of file diff --git a/testapps/db.sql b/testapps/db.sql index 8b6370907..7e553e8b7 100644 --- a/testapps/db.sql +++ b/testapps/db.sql @@ -363,3 +363,4 @@ UNLOCK TABLES; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; -- Dump completed on 2023-11-16 7:35:22 +CREATE DATABASE shopware; \ No newline at end of file diff --git a/testapps/shopware/Readme.md b/testapps/shopware/Readme.md new file mode 100644 index 000000000..889f7f3d2 --- /dev/null +++ b/testapps/shopware/Readme.md @@ -0,0 +1,9 @@ +## What's shopware? + +https://github.com/shopware/shopware + +### How to use + +```sh +$ cd testapps && docker compose up --build shopware-php +``` \ No newline at end of file diff --git a/testapps/shopware/index.php b/testapps/shopware/index.php new file mode 100644 index 000000000..fcfea7106 --- /dev/null +++ b/testapps/shopware/index.php @@ -0,0 +1,116 @@ +Error'; + echo 'Your server is running PHP version ' . \PHP_VERSION . ' but Shopware 6 requires at least PHP 7.4.3'; + exit(1); +} + +$classLoader = require __DIR__ . '/../vendor/autoload.php'; + +class ShopwareRequestPlugin extends Pinpoint\Plugins\DefaultRequestPlugin +{ + public function __construct() + { + $blackUri = ['/favicon.ico']; + // if uri in blackUri, skips it + if (!in_array($_SERVER['REQUEST_URI'], $blackUri)) { + parent::__construct(); + } + } + public function __destruct() + { + // do nothing + } +} +define('APPLICATION_NAME', 'cd.dev.test.php'); // your application name +define('APPLICATION_ID', 'cd.dev.shopware'); // your application id +define('PP_REQ_PLUGINS', ShopwareRequestPlugin::class); +require_once __DIR__ . '/../vendor/pinpoint-apm/pinpoint-php-aop/auto_pinpointed.php'; + +if (!file_exists(dirname(__DIR__) . '/install.lock')) { + $baseURL = str_replace(basename(__FILE__), '', $_SERVER['SCRIPT_NAME']); + $baseURL = rtrim($baseURL, '/'); + /* @deprecated tag:v6.5.0 remove if condition and else block, only the new installer will be supported */ + if (class_exists(InstallerKernel::class)) { + $installerURL = $baseURL . '/installer'; + } else { + $installerURL = $baseURL . '/recovery/install/index.php'; + } + + if (strpos($_SERVER['REQUEST_URI'], '/installer') === false) { + header('Location: ' . $installerURL); + exit; + } +} + +if (is_file(dirname(__DIR__) . '/files/update/update.json') || is_dir(dirname(__DIR__) . '/update-assets')) { + header('Content-type: text/html; charset=utf-8', true, 503); + header('Status: 503 Service Temporarily Unavailable'); + header('Retry-After: 1200'); + if (file_exists(__DIR__ . '/maintenance.html')) { + readfile(__DIR__ . '/maintenance.html'); + } else { + readfile(__DIR__ . '/recovery/update/maintenance.html'); + } + + return; +} + +$projectRoot = dirname(__DIR__); +if (class_exists(Dotenv::class) && (file_exists($projectRoot . '/.env.local.php') || file_exists($projectRoot . '/.env') || file_exists($projectRoot . '/.env.dist'))) { + (new Dotenv())->usePutenv()->setProdEnvs(['prod', 'e2e'])->bootEnv(dirname(__DIR__) . '/.env'); +} + +$appEnv = $_SERVER['APP_ENV'] ?? $_ENV['APP_ENV'] ?? 'dev'; +$debug = (bool) ($_SERVER['APP_DEBUG'] ?? $_ENV['APP_DEBUG'] ?? ($appEnv !== 'prod' && $appEnv !== 'e2e')); + +if ($debug) { + umask(0000); + + Debug::enable(); +} + +$trustedProxies = $_SERVER['TRUSTED_PROXIES'] ?? $_ENV['TRUSTED_PROXIES'] ?? false; +if ($trustedProxies) { + Request::setTrustedProxies(explode(',', $trustedProxies), Request::HEADER_X_FORWARDED_FOR | Request::HEADER_X_FORWARDED_PORT | Request::HEADER_X_FORWARDED_PROTO); +} + +$trustedHosts = $_SERVER['TRUSTED_HOSTS'] ?? $_ENV['TRUSTED_HOSTS'] ?? false; +if ($trustedHosts) { + Request::setTrustedHosts(explode(',', $trustedHosts)); +} + +$request = Request::createFromGlobals(); + +if (file_exists(dirname(__DIR__) . '/install.lock')) { + $kernel = new HttpKernel($appEnv, $debug, $classLoader); + + if ($_SERVER['COMPOSER_PLUGIN_LOADER'] ?? $_SERVER['DISABLE_EXTENSIONS'] ?? false) { + $kernel->setPluginLoader(new \Shopware\Core\Framework\Plugin\KernelPluginLoader\ComposerPluginLoader($classLoader)); + } +} else { + $kernel = new InstallerKernel($appEnv, $debug); +} + +$result = $kernel->handle($request); + +if ($result instanceof Response) { + $result->send(); + $kernel->terminate($request, $result); +} else { + $result->getResponse()->send(); + $kernel->terminate($result->getRequest(), $result->getResponse()); +} diff --git a/testapps/shopware/shopware.dockerfile b/testapps/shopware/shopware.dockerfile new file mode 100644 index 000000000..3fb2c92bf --- /dev/null +++ b/testapps/shopware/shopware.dockerfile @@ -0,0 +1,12 @@ +FROM shyim/shopware:6.4.20-php8.2 + +RUN apk update && apk add --virtual build-dependencies build-base git autoconf + +RUN curl -sL https://github.com/pinpoint-apm/pinpoint-c-agent/releases/download/v0.6.0/install_pinpoint_php.sh | sh + +## install composer +RUN composer self-update 2.4.4 +USER www-data +COPY testapps/shopware/index.php /var/www/html/public/index.php +RUN cd /var/www/html/ && composer require -w pinpoint-apm/pinpoint-php-aop +USER root \ No newline at end of file