Skip to content

Commit

Permalink
add example for shopware (#645)
Browse files Browse the repository at this point in the history
  • Loading branch information
eeliu authored Jul 11, 2024
1 parent 4216ac5 commit 3356cf7
Show file tree
Hide file tree
Showing 6 changed files with 170 additions and 2 deletions.
2 changes: 1 addition & 1 deletion install_pinpoint_php.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
32 changes: 31 additions & 1 deletion testapps/compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ services:
environment:
MYSQL_ROOT_PASSWORD: 'password'
MYSQL_TCP_PORT: 3306
MYSQL_USER: 'pinpoint'
MYSQL_PASSWORD: 'password'
ports:
- '3306:3306'
volumes:
Expand Down Expand Up @@ -456,4 +458,32 @@ services:
condition: service_healthy
dev-collector:
condition: service_started
restart: on-failure
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
1 change: 1 addition & 0 deletions testapps/db.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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;
9 changes: 9 additions & 0 deletions testapps/shopware/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
## What's shopware?

https://github.com/shopware/shopware

### How to use

```sh
$ cd testapps && docker compose up --build shopware-php
```
116 changes: 116 additions & 0 deletions testapps/shopware/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
<?php

// ref from https://github.com/shopware/shopware/blob/trunk/public/index.php
declare(strict_types=1);

use Shopware\Core\HttpKernel;
use Shopware\Core\Installer\InstallerKernel;
use Symfony\Component\Dotenv\Dotenv;
use Symfony\Component\ErrorHandler\Debug;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;

if (\PHP_VERSION_ID < 70403) {
header('Content-type: text/html; charset=utf-8', true, 503);

echo '<h2>Error</h2>';
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());
}
12 changes: 12 additions & 0 deletions testapps/shopware/shopware.dockerfile
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 3356cf7

Please sign in to comment.