[Symfony] My EasyDeploy configuration

Published on 2019-12-01 • Modified on 2019-12-01

This is my deploy configuration for the EasyDeploy bundle. Well, that wasn't so easy but now it works πŸ™ƒ. I had to do a "small" hack to modify a private property to make it work. Click on the "more on Stackoverflow" to understand why. The deployment takes one minute exactly (That includes installing all the composer dependencies) and "cerise sur le gateau", at the end, I have my Mac saying "Deployment finished!". 😁


<?php declare(strict_types=1);

// config/prod/deploy.php

use EasyCorp\Bundle\EasyDeployBundle\Configuration\DefaultConfiguration;
use EasyCorp\Bundle\EasyDeployBundle\Deployer\DefaultDeployer;

/**
 * @see https://github.com/EasyCorp/easy-deploy-bundle/blob/master/doc/default-deployer.md
 */
return new class extends DefaultDeployer
{
    public function configure(): DefaultConfiguration
    {
        $configuration = $this->getConfigBuilder()
            ->server('deploy-agent@vps.ovh.net:21') // fake server name
            ->useSshAgentForwarding(true)
            ->deployDir('/var/www-deploy/strangebuzz.com')
            ->repositoryUrl('git@github.com:COil/strangebuzz.com.git')
            ->repositoryBranch('master') // πŸ™ƒ
            ->keepReleases(2)
            ->remoteComposerBinaryPath('/usr/bin/composer')
            ->composerInstallFlags('--no-interaction --quiet')
            ->controllersToRemove(['public/index_dev.php'])
            ->sharedFilesAndDirs(['.env', 'public/media'])
            ->writableDirs(['public/media']);

        return $this->forceEnvironmentEnvVarName($configuration);
    }

    /**
     * @see https://stackoverflow.com/q/59111354/633864
     */
    private function forceEnvironmentEnvVarName(DefaultConfiguration $configuration): DefaultConfiguration
    {
        $property = (new ReflectionClass(get_class($configuration)))->getProperty('_symfonyEnvironmentEnvVarName');
        $property->setAccessible(true);
        $property->setValue($configuration, 'FAKE_APP_ENV');
        $property->setAccessible(false);

        return $configuration;
    }

    /**
     * Run some local or remote commands after the deployment is finished.
     */
    public function beforeFinishingDeploy(): void
    {
        $this->runRemote('/usr/bin/make load-fixtures');
        $this->runRemote('/usr/bin/make populate');
        $this->runRemote('touch /var/cache/mod_pagespeed/cache.flush');
        $this->runLocal('say "DΓ©ploiment terminΓ©."');
    }
};

 More on Stackoverflow   Read the doc