Last active
September 16, 2020 10:36
-
-
Save devicezero/998ed475a41a236347334b27812ced47 to your computer and use it in GitHub Desktop.
0001-add-platorm.sh-config.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/.platform.app.yaml b/.platform.app.yaml | |
new file mode 100644 | |
index 0000000..66322f9 | |
--- /dev/null | |
+++ b/.platform.app.yaml | |
@@ -0,0 +1,166 @@ | |
+# This file describes an application. You can have multiple applications | |
+# in the same project. | |
+ | |
+# The name of this app. Must be unique within a project. | |
+name: app | |
+ | |
+# The type of the application to build. | |
+type: php:7.4 | |
+build: | |
+ flavor: composer | |
+ | |
+variables: | |
+ env: | |
+ # Tell Shopware to always install in production-mode. | |
+ SHOPWARE_ENV: 'prod' | |
+ # Instance ID is empty by default, change to something unique in your project | |
+ INSTANCE_ID: '' | |
+ php: | |
+ upload_max_filesize: 6M | |
+ | |
+# Specify additional PHP extensions that should be loaded. | |
+runtime: | |
+ extensions: | |
+ - ctype | |
+ - dom | |
+ - iconv | |
+ - mbstring | |
+ - fileinfo | |
+ - intl | |
+ | |
+# The hooks that will be performed when the package is deployed. | |
+hooks: | |
+ build: | | |
+ set -e | |
+ | |
+ # install nvm | |
+ unset NPM_CONFIG_PREFIX | |
+ curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.35.3/install.sh | dash | |
+ export NVM_DIR="$PLATFORM_APP_DIR/.nvm" | |
+ [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" | |
+ nvm current | |
+ nvm install 12 | |
+ | |
+ # Add the Redis extension. | |
+ bash install-redis.sh 5.1.1 | |
+ | |
+ # Disable UI installer | |
+ touch install.lock | |
+ | |
+ deploy: | | |
+ set -e | |
+ | |
+ # This is necessary for nvm to work. | |
+ unset NPM_CONFIG_PREFIX | |
+ # Disable npm update notifier; being a read only system it will probably annoy you. | |
+ export NO_UPDATE_NOTIFIER=1 | |
+ # This loads nvm for general usage. | |
+ export NVM_DIR="$PLATFORM_APP_DIR/.nvm" | |
+ [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" | |
+ | |
+ if [ "$PLATFORM_BRANCH" != "master" ]; then | |
+ export FRONTEND_URL=`echo $PLATFORM_ROUTES | base64 --decode | jq -r 'to_entries[] | select(.value.id=="shopware") | .key'` | |
+ bin/console sales-channel:update-domain "$FRONTEND_URL" | |
+ fi | |
+ | |
+ # Initialize the Shopware site's data set if it's not already installed. | |
+ if [ ! -f $PLATFORM_APP_DIR/installer/installed ]; then | |
+ # setup the environment | |
+ | |
+ # create database with a basic setup (admin user and storefront sales channel) | |
+ echo "Running system:install" | |
+ bin/console system:install --create-database --basic-setup --force | |
+ | |
+ # generate JWT | |
+ echo "Running system:generate-jwt-secret" | |
+ bin/console system:generate-jwt-secret | |
+ | |
+ # refresh plugins and enable PaaS Plugin | |
+ bin/console plugin:refresh | |
+ bin/console plugin:install --activate SwagPaas | |
+ | |
+ # mark system as installed | |
+ touch $PLATFORM_APP_DIR/installer/installed | |
+ fi; | |
+ | |
+ # optional: run migration automatically with deploy | |
+ # bin/console database:migrate --all | |
+ bin/console cache:clear | |
+ | |
+# The relationships of the application with services or other applications. | |
+# The left-hand side is the name of the relationship as it will be exposed | |
+# to the application in the PLATFORM_RELATIONSHIPS variable. The right-hand | |
+# side is in the form `<service name>:<endpoint name>`. | |
+relationships: | |
+ database: "db:mysql" | |
+ rediscache: "cacheredis:redis" | |
+ | |
+# The size of the persistent disk of the application (in MB). | |
+disk: 2048 | |
+ | |
+# The mounts that will be performed when the package is deployed. | |
+mounts: | |
+ "/files": | |
+ source: local | |
+ source_path: "files" | |
+ "/app": | |
+ source: local | |
+ source_path: "app" | |
+ "/config/secrets": | |
+ source: local | |
+ source_path: "config/secrets" | |
+ "/custom/plugins": | |
+ source: local | |
+ source_path: "custom/plugins" | |
+ "/var/cache": | |
+ source: local | |
+ source_path: "var/cache" | |
+ "/var/queue": | |
+ source: local | |
+ source_path: "var/queue" | |
+ "/var/log": | |
+ source: local | |
+ source_path: "var/log" | |
+ "/public/css": | |
+ source: local | |
+ source_path: "public/css" | |
+ "/public/fonts": | |
+ source: local | |
+ source_path: "public/fonts" | |
+ "/public/js": | |
+ source: local | |
+ source_path: "public/js" | |
+ "/public/media": | |
+ source: local | |
+ source_path: "public/media" | |
+ "/public/thumbnail": | |
+ source: local | |
+ source_path: "public/thumbnail" | |
+ "/public/theme": | |
+ source: local | |
+ source_path: "public/theme" | |
+ "/public/bundles": | |
+ source: local | |
+ source_path: "public/bundles" | |
+ "/config/jwt": | |
+ source: local | |
+ source_path: "config/jwt" | |
+ "/installer": | |
+ source: local | |
+ source_path: "installer" | |
+ | |
+# The configuration of app when it is exposed to the web. | |
+web: | |
+ locations: | |
+ "/": | |
+ # The public directory of the app, relative to its root. | |
+ root: "public" | |
+ # The front-controller script to send non-static requests to. | |
+ passthru: "/index.php" | |
+ | |
+workers: | |
+ queue: | |
+ disk: 128 | |
+ commands: | |
+ start: | | |
+ bin/console messenger:consume-messages default --time-limit=30 | |
diff --git a/.platform/routes.yaml b/.platform/routes.yaml | |
new file mode 100644 | |
index 0000000..74caade | |
--- /dev/null | |
+++ b/.platform/routes.yaml | |
@@ -0,0 +1,9 @@ | |
+# The routes of the project. | |
+# | |
+# Each route describes how an incoming URL is going | |
+# to be processed by Platform.sh. | |
+ | |
+"https://{default}/": | |
+ type: upstream | |
+ id: shopware | |
+ upstream: "app:http" | |
diff --git a/.platform/services.yaml b/.platform/services.yaml | |
new file mode 100644 | |
index 0000000..2662a69 | |
--- /dev/null | |
+++ b/.platform/services.yaml | |
@@ -0,0 +1,6 @@ | |
+db: | |
+ type: mariadb:10.4 | |
+ disk: 2048 | |
+ | |
+cacheredis: | |
+ type: redis:6.0 | |
diff --git a/composer.json b/composer.json | |
index 8b22277..ee8f6e2 100644 | |
--- a/composer.json | |
+++ b/composer.json | |
@@ -31,7 +31,10 @@ | |
"autoload": { | |
"psr-4": { | |
"Shopware\\Production\\": "src\/" | |
- } | |
+ }, | |
+ "files": [ | |
+ "platformsh-env.php" | |
+ ] | |
}, | |
"repositories": [ | |
{ | |
@@ -49,7 +52,9 @@ | |
"shopware\/administration": "~v6.3.0", | |
"shopware\/storefront": "~v6.3.0", | |
"shopware\/elasticsearch": "~v6.3.0", | |
- "shopware\/recovery": "~v6.3.0" | |
+ "shopware\/recovery": "~v6.3.0", | |
+ "platformsh/symfonyflex-bridge": "^2.2", | |
+ "shopware/paas": "dev-master" | |
}, | |
"require-dev": { | |
"ext-tokenizer": "*", | |
diff --git a/config/packages/framework.yaml b/config/packages/framework.yaml | |
new file mode 100644 | |
index 0000000..157194c | |
--- /dev/null | |
+++ b/config/packages/framework.yaml | |
@@ -0,0 +1,6 @@ | |
+framework: | |
+ session: | |
+ handler_id: Symfony\Component\HttpFoundation\Session\Storage\Handler\RedisSessionHandler | |
+ cache: | |
+ app: cache.adapter.redis | |
+ default_redis_provider: '%env(string:REDIS_URL)%' | |
diff --git a/config/packages/shopware.yaml b/config/packages/shopware.yaml | |
new file mode 100644 | |
index 0000000..6e83f19 | |
--- /dev/null | |
+++ b/config/packages/shopware.yaml | |
@@ -0,0 +1,3 @@ | |
+shopware: | |
+ admin_worker: | |
+ enable_admin_worker: false | |
diff --git a/install-redis.sh b/install-redis.sh | |
new file mode 100644 | |
index 0000000..186b9be | |
--- /dev/null | |
+++ b/install-redis.sh | |
@@ -0,0 +1,68 @@ | |
+run() { | |
+ # Run the compilation process. | |
+ cd $PLATFORM_CACHE_DIR || exit 1; | |
+ | |
+ if [ ! -f "${PLATFORM_CACHE_DIR}/phpredis/modules/redis.so" ]; then | |
+ ensure_source | |
+ checkout_version "$1" | |
+ compile_source | |
+ fi | |
+ | |
+ copy_lib | |
+ enable_lib | |
+} | |
+ | |
+enable_lib() { | |
+ # Tell PHP to enable the extension. | |
+ echo "Enabling PhpRedis extension." | |
+ echo "extension=${PLATFORM_APP_DIR}/redis.so" >> $PLATFORM_APP_DIR/php.ini | |
+} | |
+ | |
+copy_lib() { | |
+ # Copy the compiled library to the application directory. | |
+ echo "Installing PhpRedis extension." | |
+ cp $PLATFORM_CACHE_DIR/phpredis/modules/redis.so $PLATFORM_APP_DIR | |
+} | |
+ | |
+checkout_version () { | |
+ # Check out the specific Git tag that we want to build. | |
+ git checkout "$1" | |
+} | |
+ | |
+ensure_source() { | |
+ # Ensure that the extension source code is available and up to date. | |
+ if [ -d "phpredis" ]; then | |
+ cd phpredis || exit 1; | |
+ git fetch --all --prune | |
+ else | |
+ git clone https://github.com/phpredis/phpredis.git | |
+ cd phpredis || exit 1; | |
+ fi | |
+} | |
+ | |
+compile_source() { | |
+ # Compile the extension. | |
+ phpize | |
+ ./configure | |
+ make | |
+} | |
+ | |
+ensure_environment() { | |
+ # If not running in a Platform.sh build environment, do nothing. | |
+ if [[ -z "${PLATFORM_CACHE_DIR}" ]]; then | |
+ echo "Not running in a Platform.sh build environment. Aborting Redis installation." | |
+ exit 0; | |
+ fi | |
+} | |
+ | |
+ensure_arguments() { | |
+ # If no version was specified, don't try to guess. | |
+ if [ -z $1 ]; then | |
+ echo "No version of the PhpRedis extension specified. You must specify a tagged version on the command line." | |
+ exit 1; | |
+ fi | |
+} | |
+ | |
+ensure_environment | |
+ensure_arguments "$1" | |
+run "$1" | |
diff --git a/platformsh-env.php b/platformsh-env.php | |
new file mode 100644 | |
index 0000000..265f1a9 | |
--- /dev/null | |
+++ b/platformsh-env.php | |
@@ -0,0 +1,82 @@ | |
+<?php | |
+ | |
+declare(strict_types=1); | |
+ | |
+namespace Platformsh\ShopwareBridge; | |
+ | |
+use Platformsh\ConfigReader\Config; | |
+ | |
+mapPlatformShEnvironment(); | |
+ | |
+/** | |
+ * Map Platform.Sh environment variables to the values Shopware expects expects. | |
+ * | |
+ * This is wrapped up into a function to avoid executing code in the global | |
+ * namespace. | |
+ * | |
+ * Note: Most values are already handled by the Symfony Flex bridge. This file is just | |
+ * for the additional variables required by Shopware. | |
+ */ | |
+function mapPlatformShEnvironment() : void | |
+{ | |
+ $config = new Config(); | |
+ | |
+ if (!$config->inRuntime()) { | |
+ return; | |
+ } | |
+ | |
+ $config->registerFormatter('redis', __NAMESPACE__ . '\redisFormatter'); | |
+ | |
+ // Set the URL based on the route. This is a required route ID. | |
+ setEnvVar('APP_URL', $config->getRoute('shopware')['url']); | |
+ | |
+ // Map services as feasible. | |
+ mapPlatformShRedis('rediscache', $config); | |
+} | |
+ | |
+/** | |
+ * Sets an environment variable in all the myriad places PHP can store it. | |
+ * | |
+ * @param string $name | |
+ * The name of the variable to set. | |
+ * @param null|string $value | |
+ * The value to set. Null to unset it. | |
+ */ | |
+function setEnvVar(string $name, ?string $value) : void | |
+{ | |
+ if (!putenv("$name=$value")) { | |
+ throw new \RuntimeException('Failed to create environment variable: ' . $name); | |
+ } | |
+ $order = ini_get('variables_order'); | |
+ if (stripos($order, 'e') !== false) { | |
+ $_ENV[$name] = $value; | |
+ } | |
+ if (stripos($order, 's') !== false) { | |
+ if (strpos($name, 'HTTP_') !== false) { | |
+ throw new \RuntimeException('Refusing to add ambiguous environment variable ' . $name . ' to $_SERVER'); | |
+ } | |
+ $_SERVER[$name] = $value; | |
+ } | |
+} | |
+ | |
+/** | |
+ * Maps the specified relationship to the REDIS_URL environment variable, if available. | |
+ * | |
+ * @param string $relationshipName | |
+ * The database relationship name. | |
+ * @param Config $config | |
+ * The config object. | |
+ */ | |
+function mapPlatformShRedis(string $relationshipName, Config $config) : void | |
+{ | |
+ if (!$config->hasRelationship($relationshipName)) { | |
+ return; | |
+ } | |
+ | |
+ setEnvVar('REDIS_URL', $config->formattedCredentials($relationshipName, 'redis')); | |
+} | |
+ | |
+function redisFormatter(array $credentials): string | |
+{ | |
+ return "redis://{$credentials['host']}:{$credentials['port']}"; | |
+} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment