We use TeamCity to build our Laravel application. So activating the relevant .env file happens on our build-server. After building the app we use deployer to deploy/upload the app to our production servers.
Somehow it seems that deployer does not copy the newest .env file to the shared
folder before symlinking it.
Is there a way to deactivate the symlinking for the .env file? We also use a Laravel-receipe to handle the Laravel specific tasks:
<?php
namespace Deployer;
require 'recipe/laravel.php';
// Project name
set('application', 'faaren_core');
set('default_stage', 'staging');
set('keep_releases', 10);
// Project repository
//set('repository', '[email protected]:faaren/core-system.git');
// [Optional] Allocate tty for git clone. Default value is false.
//set('git_tty', true);
set('shared_dirs', ['storage']);
//set('shared_files', ['.env']);
set('writable_dirs', [
'bootstrap/cache',
'storage',
'storage/app',
'storage/app/public',
'storage/framework',
'storage/framework/cache',
'storage/framework/sessions',
'storage/framework/views',
'storage/logs',
]);
/**
* Run an artisan command.
*
* Supported options:
* - 'min' => #.#: The minimum Laravel version required (included).
* - 'max' => #.#: The maximum Laravel version required (included).
* - 'skipIfNoEnv': Skip and warn the user if `.env` file is inexistant or empty.
* - 'failIfNoEnv': Fail the command if `.env` file is inexistant or empty.
* - 'runInCurrent': Run the artisan command in the current directory.
* - 'showOutput': Show the output of the command if given.
*
* @param string $command The artisan command (with cli options if any).
* @param array $options The options that define the behaviour of the command.
* @return callable A function that can be used as a task.
*/
function artisan($command, $options = [])
{
return function () use ($command, $options) {
$versionTooEarly = array_key_exists('min', $options)
&& laravel_version_compare($options['min'], '<');
$versionTooLate = array_key_exists('max', $options)
&& laravel_version_compare($options['max'], '>');
if ($versionTooEarly || $versionTooLate) {
return;
}
if (in_array('failIfNoEnv', $options) && !test('[ -s {{release_path}}/.env ]')) {
throw new Exception('Your .env file is empty! Cannot proceed.');
}
if (in_array('skipIfNoEnv', $options) && !test('[ -s {{release_path}}/.env ]')) {
warning("Your .env file is empty! Skipping...</>");
return;
}
$artisan = in_array('runInCurrent', $options)
? '{{current_path}}/artisan'
: '{{release_path}}/artisan';
$output = run("{{bin/php}} $artisan $command");
if (in_array('showOutput', $options)) {
writeln("<info>$output</info>");
}
};
}
/*
set('log_files', 'storage/logs/*.log');
set('laravel_version', function () {
$result = run('{{bin/php}} {{release_path}}/artisan --version');
preg_match_all('/(d+.?)+/', $result, $matches);
return $matches[0][0] ?? 5.8;
});*/
host('production')
->hostname('xxx.xxx.xxx.xxx')
->user('forge')
->set('deploy_path', '/home/forge/site.com')
->stage('switzerland');
desc('Execute artisan cache:clear');
task('artisan:cache:clear', artisan('cache:clear'));
desc('Execute artisan config:clear');
task('artisan:config:clear', artisan('config:clear'));
desc('Execute artisan config:cache');
task('artisan:config:cache', artisan('config:cache'));
desc('Execute artisan route:clear');
task('artisan:route:clear', artisan('route:clear'));
desc('Execute artisan view:clear');
task('artisan:view:clear', artisan('view:clear'));
desc('Execute artisan migrate');
task('artisan:migrate', artisan('migrate', ['--force']));
desc('Execute artisan storage:link');
task('artisan:storage:link', artisan('storage:link'));
desc('Reloads php-fpm');
task('reload-fpm', function() {
run("echo 'Restarting FPM...'; sudo -S service php7.4-fpm reload");
});
task('deploy', [
'build',
'release',
'reload-fpm',
'artisan:config:clear',
'artisan:config:cache',
'artisan:cache:clear',
'artisan:route:clear',
'artisan:view:clear',
'artisan:migrate',
'artisan:storage:link',
'cleanup',
'success'
]);
task('build', function(){
write('Current Stage:');
write(input()->getArgument('stage'));
})->local();
task('release', [
'deploy:prepare',
'deploy:release',
'upload',
'deploy:shared',
'deploy:symlink',
]);
task('upload', function () {
upload(__DIR__ . '/', '{{release_path}}');
});