0

Problem

Using deployer in a Symfony 6 applaction has required me to change from deployer/deployer to deployer/dist (7.0.0-rc.3), with the downside being that I cannot load enviroment variables from my .env anymore with the way I used to do it.

Situation

With deployer/deployer I had the following example to use the dotenv variables in the deploy script:

<?php

namespace Deployer;

use Symfony\Component\Dotenv\Dotenv;

require 'recipe/common.php';
require 'contrib/discord.php';

$dotenv = new Dotenv();
$dotenv->loadEnv(__DIR__ . '/.env');

set('application', $_ENV['APP_NAME']);
set('discord_channel', $_ENV['DISCORD_DEPLOY_CHANNEL']);
set('discord_token', $_ENV['DISCORD_DEPLOY_TOKEN']);

But with deployer/dist I can no longer do this, giving the error message:

Class "Symfony\Component\Dotenv\Dotenv" not found

Could someone firstly explain why it isn't working anymore? And secondly, what could be a possible solution (or alternative) for loading the environment variables from my .env file?

YTZ
  • 876
  • 11
  • 26

1 Answers1

1

The dist version includes its own dependencies in the phar package (and it does not depend on dotenv), while the deployer version uses your project's own dependencies. Since your project is most likely using the dotenv component, you were able to use it in your deploy script.

But since you are using symfony 6 you cannot install deployer 7 because it depends on symfony 5, causing a conflict with your project.

It's a bit of a hassle, but you could fork the package to add the dotenv dependency and build your own phar with the provided bin/build script, and copy it manually to your project.

msg
  • 7,863
  • 3
  • 14
  • 33
  • I think I understand your explanation, but forking and building my own forces me to keep it up-to-date, which is a lot more trouble than it's worth. Is there no easier way to do it? If not, I'll accept your answer as it answers both of my questions. – YTZ Feb 06 '22 at 14:41
  • @YTZ yes, however, the whole ordeal shouldn't take more than 4 or 5 commands to automate. Other than that, you could submit a feature/pull request and get it accepted upstream. I could see value in it, it's however up to the mantainer to ultimately get it in or not if he wants to keep it lean, but I've seen him open to improvements. – msg Feb 06 '22 at 16:32
  • 1
    @YTZ There is a new 8.x development branch that includes symfony 6 support. It might not be too stable at the moment, but it may be worth checking out. – msg Mar 12 '22 at 10:56