it is the Magento-Cloud Program (magento-cloud CLI)
which is really just a rebranding of Platform.sh
if you want try locally, then install magento-cloud
http://devdocs.magento.com/guides/v2.1/cloud/before/before-workspace-cli.html
If you are able to find the issue is in their code (which I don’t doubt at all) then
the scripts that are responsible for the deploy process i believe are these:
#/var/www/beta.pumpunderwear.com/web/2e/vendor/magento/magento-cloud-configuration/pre-deploy.php
<?php
/**
* This script contains logic to cleanup outdated caches and restore the contents of mounted directories so that
* the main deploy hook is able to start.
*/
// Should be deleted at the end of pre-deploy, so presence of flag later indicate if something failed in the pre-deploy.
echo "Setting the pre-deploy flag." . PHP_EOL;
use Magento\MagentoCloud\Environment;
require_once 'src/Magento/MagentoCloud/Environment.php';
touch(Environment::PRE_DEPLOY_FLAG);
$env = new Environment();
$env->log("Starting pre-deploy.");
// Clear redis and file caches
$relationships = $env->getRelationships();
$var = $env->getVariables();
$useGeneratedCodeSymlink = isset($var["GENERATED_CODE_SYMLINK"]) && $var["GENERATED_CODE_SYMLINK"] == 'disabled' ? false : true;
$useStaticContentSymlink = isset($var["STATIC_CONTENT_SYMLINK"]) && $var["STATIC_CONTENT_SYMLINK"] == 'disabled' ? false : true;
if (isset($relationships['redis']) && count($relationships['redis']) > 0) {
$redisHost = $relationships['redis'][0]['host'];
$redisPort = $relationships['redis'][0]['port'];
$redisCacheDb = '1'; // Matches \Magento\MagentoCloud\Console\Command\Deploy::$redisCacheDb
$env->execute("redis-cli -h $redisHost -p $redisPort -n $redisCacheDb flushdb");
}
$fileCacheDir = Environment::MAGENTO_ROOT . '/var/cache';
if (file_exists($fileCacheDir)) {
$env->execute("rm -rf $fileCacheDir");
}
$mountedDirectories = ['app/etc', 'pub/media'];
/**
* optionally symlink DI assets from build resources directory(var/generation to init/var/generation
* (var/di -> init/var/di, var/generation -> init/var/generation)
**/
$buildDir = realpath(Environment::MAGENTO_ROOT . 'init') . '/';
if ($useGeneratedCodeSymlink) {
$varDir = realpath(Environment::MAGENTO_ROOT . 'var') . '/';
$env->removePathInBackground('var/di');
$env->removePathInBackground('var/generation');
if (symlink($buildDir . 'var/generation', $varDir . 'generation')) {
$env->log('Symlinked var/generation to init/var/generation');
} else {
$env->log('Failed to symlink var/generation to init/var/generation');
}
if (symlink($buildDir . 'var/di', $varDir . 'di')) {
$env->log('Symlinked var/di to init/var/di');
} else {
$env->log('Failed to symlink var/di to init/var/di');
}
} else {
$env->atomicCopyPath('init/var/generation', 'var/generation');
$env->atomicCopyPath('init/var/di', 'var/di');
}
/**
* Handle case where static content is deployed during build hook:
* 1. set a flag to be read by magento-cloud:deploy
* 2. Either copy or symlink files from init/ directory, depending on strategy
*/
if (file_exists(Environment::MAGENTO_ROOT . 'init/' . Environment::STATIC_CONTENT_DEPLOY_FLAG)) {
$env->log("Static content deployment was performed during build hook");
$env->removeStaticContent();
$env->setStaticDeployInBuild(true);
if ($useStaticContentSymlink) {
$env->log("Symlinking static content from pub/static to init/pub/static");
// Symlink pub/static/* to init/pub/static/*
$staticContentLocation = realpath(Environment::MAGENTO_ROOT . 'pub/static') . '/';
if (file_exists($buildDir . 'pub/static')) {
$dir = new \DirectoryIterator($buildDir . 'pub/static');
foreach ($dir as $fileInfo) {
$fileName = $fileInfo->getFilename();
if (!$fileInfo->isDot() && symlink($buildDir . 'pub/static/' . $fileName, $staticContentLocation . '/' . $fileName)) {
$env->log('Symlinked ' . $staticContentLocation . '/' . $fileName . ' to ' . $buildDir . 'pub/static/' . $fileName);
}
}
}
} else {
$env->log("Copying static content from init/pub/static to pub/static");
copyFromBuildDir('pub/static', $env);
}
}
// Restore mounted directories
$env->log("Copying writable directories back.");
foreach ($mountedDirectories as $dir) {
copyFromBuildDir($dir, $env);
}
if (file_exists(Environment::REGENERATE_FLAG)) {
$env->log("Removing var/.regenerate flag");
unlink(Environment::REGENERATE_FLAG);
}
$env->log("Pre-deploy complete.");
unlink(Environment::PRE_DEPLOY_FLAG);
/**
* @param string $dir The directory to copy. Pass in its normal location relative to Magento root with no prepending
* or trailing slashes
* @param Environment $env
*/
function copyFromBuildDir($dir, Environment $env) {
if (!file_exists($dir)) {
mkdir($dir);
$env->log(sprintf('Created directory: %s', $dir));
}
$env->execute(sprintf('/bin/bash -c "shopt -s dotglob; cp -R ./init/%s/* %s/ || true"', $dir, $dir));
$env->log(sprintf('Copied directory: %s', $dir));
}
#/var/www/beta.pumpunderwear.com/web/2e/vendor/magento/magento-cloud-configuration/patch.php
<?php
use Magento\MagentoCloud\Environment;
require_once 'src/Magento/MagentoCloud/Environment.php';
$env = new Environment();
$env->log("Copying static.php to front-static.php");
copy(Environment::MAGENTO_ROOT . 'pub/static.php', Environment::MAGENTO_ROOT . 'pub/front-static.php');
$dirName = __DIR__ . '/patches';
$files = glob($dirName . '/*');
sort($files);
foreach ($files as $file) {
$cmd = 'git apply ' . $file;
$env->execute($cmd);
}
copy(Environment::MAGENTO_ROOT . 'app/etc/di.xml', Environment::MAGENTO_ROOT . 'app/di.xml');
$enterpriseFolder = Environment::MAGENTO_ROOT . 'app/enterprise';
if(!file_exists($enterpriseFolder)){
mkdir($enterpriseFolder, 0777, true);
}
copy(Environment::MAGENTO_ROOT . 'app/etc/enterprise/di.xml', Environment::MAGENTO_ROOT . 'app/enterprise/di.xml');
$sampleDataDir = Environment::MAGENTO_ROOT . 'vendor/magento/sample-data-media';
if (file_exists($sampleDataDir)) {
$env->log("Sample data media found. Marshalling to pub/media.");
$destination = Environment::MAGENTO_ROOT . '/pub/media';
foreach (
$iterator = new \RecursiveIteratorIterator(
new \RecursiveDirectoryIterator($sampleDataDir, \RecursiveDirectoryIterator::SKIP_DOTS),
\RecursiveIteratorIterator::SELF_FIRST) as $item
) {
if ($item->isDir()) {
if (!file_exists($destination . DIRECTORY_SEPARATOR . $iterator->getSubPathName())) {
mkdir($destination . DIRECTORY_SEPARATOR . $iterator->getSubPathName());
}
} else {
copy($item, $destination . DIRECTORY_SEPARATOR . $iterator->getSubPathName());
}
}
}
#/var/www/beta.pumpunderwear.com/web/2e/vendor/magento/magento-cloud-configuration/src/Magento/MagentoCloud/Environment.php
<?php
/**
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\MagentoCloud;
/**
* Contains logic for interacting with the server environment
*/
class Environment
{
const MAGENTO_ROOT = __DIR__ . '/../../../../../../';
const STATIC_CONTENT_DEPLOY_FLAG = 'var/.static_content_deploy';
const PRE_DEPLOY_FLAG = self::MAGENTO_ROOT . 'var/.predeploy_in_progress';
const REGENERATE_FLAG = self::MAGENTO_ROOT . 'var/.regenerate';
public $writableDirs = ['var/di', 'var/generation', 'app/etc', 'pub/media'];
/**
* Get routes information from MagentoCloud environment variable.
*
* @return mixed
*/
public function getRoutes()
{
return json_decode(base64_decode($_ENV["MAGENTO_CLOUD_ROUTES"]), true);
}
/**
* Get relationships information from MagentoCloud environment variable.
*
* @return mixed
*/
public function getRelationships()
{
return json_decode(base64_decode($_ENV["MAGENTO_CLOUD_RELATIONSHIPS"]), true);
}
/**
* Get custom variables from MagentoCloud environment variable.
*
* @return mixed
*/
public function getVariables()
{
return json_decode(base64_decode($_ENV["MAGENTO_CLOUD_VARIABLES"]), true);
}
public function log($message)
{
echo sprintf('[%s] %s', date("Y-m-d H:i:s"), $message) . PHP_EOL;
}
public function execute($command)
{
$this->log('Command:'.$command);
exec(
$command,
$output,
$status
);
$this->log('Status:'.var_export($status, true));
$this->log('Output:'.var_export($output, true));
if ($status != 0) {
throw new \RuntimeException("Command $command returned code $status", $status);
}
return $output;
}
public function backgroundExecute($command)
{
$command = "nohup {$command} 1>/dev/null 2>&1 &";
$this->log("Execute command in background: $command");
shell_exec($command);
}
public function setStaticDeployInBuild($flag)
{
if ($flag) {
$this->log('Setting flag file ' . Environment::STATIC_CONTENT_DEPLOY_FLAG);
touch(Environment::MAGENTO_ROOT . Environment::STATIC_CONTENT_DEPLOY_FLAG);
} else {
if ($this->isStaticDeployInBuild()) {
$this->log('Removing flag file ' . Environment::STATIC_CONTENT_DEPLOY_FLAG);
unlink(Environment::MAGENTO_ROOT . Environment::STATIC_CONTENT_DEPLOY_FLAG);
}
}
}
public function isStaticDeployInBuild()
{
return file_exists(Environment::MAGENTO_ROOT . Environment::STATIC_CONTENT_DEPLOY_FLAG);
}
public function removeStaticContent()
{
// atomic move within pub/static directory
$staticContentLocation = realpath(Environment::MAGENTO_ROOT . 'pub/static/') . '/';
$timestamp = time();
$oldStaticContentLocation = $staticContentLocation . 'old_static_content_' . $timestamp;
$this->log("Moving out old static content into $oldStaticContentLocation");
if (!file_exists($oldStaticContentLocation)) {
mkdir($oldStaticContentLocation);
}
$dir = new \DirectoryIterator($staticContentLocation);
foreach ($dir as $fileInfo) {
$fileName = $fileInfo->getFilename();
if (!$fileInfo->isDot() && strpos($fileName, 'old_static_content_') !== 0) {
$this->log("Rename " . $staticContentLocation . '/' . $fileName . " to " . $oldStaticContentLocation . '/' . $fileName);
rename($staticContentLocation . '/' . $fileName, $oldStaticContentLocation . '/' . $fileName);
}
}
$this->log("Removing $oldStaticContentLocation in the background");
$this->backgroundExecute("rm -rf $oldStaticContentLocation");
$preprocessedLocation = realpath(Environment::MAGENTO_ROOT . 'var') . '/view_preprocessed';
if (file_exists($preprocessedLocation)) {
$oldPreprocessedLocation = $preprocessedLocation . '_old_' . $timestamp;
$this->log("Rename $preprocessedLocation to $oldPreprocessedLocation");
rename($preprocessedLocation, $oldPreprocessedLocation);
$this->log("Removing $oldPreprocessedLocation in the background");
$this->backgroundExecute("rm -rf $oldPreprocessedLocation");
}
}
public function removePathInBackground($relativePath)
{
$fullPath = rtrim(realpath(Environment::MAGENTO_ROOT) . '/' . $relativePath, '/');
$timestamp = time();
if (file_exists($fullPath)) {
$backgroundLocation = $fullPath . '_old_' . $timestamp;
$this->log("Rename $fullPath to $backgroundLocation");
rename($fullPath, $backgroundLocation);
$this->log("Removing $backgroundLocation in the background");
$this->backgroundExecute("rm -rf $backgroundLocation");
}
}
public function atomicCopyPath($relativeSourcePath, $relativeDestinationPath) {
$fullDestinationPath = rtrim(realpath(Environment::MAGENTO_ROOT) . '/' . $relativeDestinationPath, '/');
$fullSourcePath = rtrim(realpath(Environment::MAGENTO_ROOT) . '/' . $relativeSourcePath, '/');
$timestamp = time();
if (file_exists($fullSourcePath)) {
$tmpLocation = $fullDestinationPath . '_tmp_' . $timestamp;
$this->log("Copy $fullSourcePath to $tmpLocation");
$this->execute(sprintf('bash -c "shopt -s dotglob; cp -R %s/ %s/ || true"', $fullSourcePath, $tmpLocation));
$this->removePathInBackground($relativeDestinationPath);
$this->log("Rename $tmpLocation to $fullDestinationPath");
rename($tmpLocation, $fullDestinationPath);
}
}
}