Deploy Shopware to the Cloud
About me
Benjamin Cremer
~5 years at shopware AG
PHP UG Münster (phpug.ms)
Tweet me @benjamincremer
Questions?
Feel free to ask at any time
Deploy Shopware to the Cloud
What is the Cloud anyway?
It's probably not that easy
IaaS
IaaS is the hardware and software that powers it all – servers, storage, networks, operating systems
Virtualization of someone else’s hardware managed via an API
Containers as a Service (CaaS)
The Way to Hassle Free Docker PHP Web Stack Deployments
Sandro Keil (18:00)
PaaS
-
PaaS is the set of tools and services designed to make coding and deploying those applications quick and efficient
- Concentrate on your Application, not on the infrastructure
PaaS is the set of tools and services designed to make coding and deploying those applications quick and efficient
Saas
SaaS applications are designed for end-users, delivered over the web
What is managed by you?
What is managed by the vendor?
What is controlled by you?
What is controlled by the vendor?
Is your software ready for the cloud?
Config
- Store config in the environment
- Strict separation of config from code
Could your codebase be made open source at any moment, without compromising any credentials?
vlucas/dotenv
- github.com/vlucas/phpdotenv
- Loads environment variables from .env to getenv(), $_ENV and $_SERVER automagically
- .env in .gitingore, provide .env.example
vlucas/dotenv
# file: .env
S3_BUCKET="devbucket"
SECRET_KEY="abc123"
// autoload/bootstrap.php
if (file_exists(__DIR__ . '/.env')) {
$dotenv = new Dotenv(__DIR__);
$dotenv->load();
}
getenv('S3_BUCKET');
# some/shellscript.sh
if [ -f .env ]; then
source .env
fi
echo $S3_BUCKET
Stateless AppServer
- Ephemeral filesystem
- Cache/Session/State/Lock-Files
- Disposability
- Processes are stateless and share-nothing
- Any data that needs to persist must be stored in a stateful backing service, typically a database
- scale out horizontally
league/flysystem
// Create the adapter
$localAdapter = new League\Flysystem\Adapter\Local('/path/to/root');
// And use that to create the file system
$filesystem = new League\Flysystem\Filesystem($adapter);
// Write or Update Files
$filesystem->put('path/to/file.txt', 'contents');
// Read Files
$contents = $filesystem->read('path/to/file.txt');
// Check if a file exists
$exists = $filesystem->has('path/to/file.txt');
// Delete file
$filesystem->delete('path/to/file.txt');
// Rename Files
$filesystem->rename('filename.txt', 'newname.txt');
Shopware
- https://github.com/shopware/shopware
- "classic" installation approach (ftp anyone?)
- Shopware is using composer for it's dependencies
- No clean separation of project files and Shopware files
Full-Stack
- Big standard library
- Zend_Barcode
- Zend_Captcha
- Zend_Ldap
- …
- Shopware is Using composer for it's dependencies
- Components instead full stack
- vendor/ is bundled in tar.gz
Problems for Plugin developers
- No full stack -> Less components to choose from
- composer.json belongs to Shopware and not to the project
- Plugins have no supported way of using composer
- Separate compposer.json in Plugin
- Duplication and version conflicts
Shopware as a dependency
composer.json
{
"name": "myvendor/myproject",
"autoload": {
"psr-4": { "myvendor": "src/" },
},
"require": {
"shopware/shopware": "5.3.1",
"shopwarelabs/swag-media-s3": "~2.0",
"myvendor/mypluginA": "~2.0",
"myvendor/mypluginB": "~2.0"
},
}
Shopware as a dependency
- Shopware is a dependency
- Version your shopware project with git
- The project directory belongs to the vendor
- Plugins can be installed via composer
- Plugins can use composer to define own dependencies
- Deploy using git push
Composer create-project
composer create-project bcremer/shopware-composer-project
Demo
Configure project locally (.env)
Demo
Git init (it's your project!)
Demo
Deploy to PaaS
- Create Hekorku Project
- Configure Environment
- JawsDB MySQL Addon