dunglas / symfony-docker

A Docker-based installer and runtime for Symfony. Install: download and `docker compose up`.
https://dunglas.dev/2021/12/symfonys-new-native-docker-support-symfony-world/
2.46k stars 729 forks source link

Deploy for production returns errors #479

Closed Rom1906 closed 6 months ago

Rom1906 commented 9 months ago

Hi ! in locally all is all right but when I try to deploy my project on production with this documentation : https://github.com/dunglas/symfony-docker/blob/main/docs/production.md#deploying I get this error :

=> ERROR [php frankenphp_prod 8/8] RUN set -eux;  mkdir -p var/cache var/log;  composer dump-autoload --classmap-authoritative --no-dev;  composer dump-env prod  1.7s

 > [php frankenphp_prod 8/8] RUN set -eux;  mkdir -p var/cache var/log;     composer dump-autoload --classmap-authoritative --no-dev;   composer dump-env prod;composer run-script --no-dev post-install-cmd;   chmod +x bin/console; sync;:
0.215 + mkdir -p var/cache var/log
0.218 + composer dump-autoload --classmap-authoritative --no-dev
0.407 Generating optimized autoload files (authoritative)
1.133 Generated optimized autoload files (authoritative) containing 1158 classes
1.141 + composer dump-env prod
1.338 Successfully dumped .env files in .env.local.php
1.345 + composer run-script --no-dev post-install-cmd
1.561 
1.562 Run composer recipes at any time to see the status of your Symfony recipes.
1.563 
1.568 Executing script cache:clear [KO]
1.629  [KO]
1.629 Script cache:clear returned with error code 255
1.629 !!  PHP Fatal error:  Uncaught Error: Class "Symfony\Bundle\TwigBundle\TwigBundle" not found in /app/vendor/symfony/framework-bundle/Kernel/MicroKernelTrait.php:126
1.630 !!  Stack trace:
1.630 !!  #0 /app/vendor/symfony/http-kernel/Kernel.php(346): App\Kernel->registerBundles()
1.630 !!  #1 /app/vendor/symfony/http-kernel/Kernel.php(756): Symfony\Component\HttpKernel\Kernel->initializeBundles()
1.631 !!  #2 /app/vendor/symfony/http-kernel/Kernel.php(126): Symfony\Component\HttpKernel\Kernel->preBoot()
1.631 !!  #3 /app/vendor/symfony/framework-bundle/Console/Application.php(154): Symfony\Component\HttpKernel\Kernel->boot()
1.631 !!  #4 /app/vendor/symfony/framework-bundle/Console/Application.php(72): Symfony\Bundle\FrameworkBundle\Console\Application->registerCommands()
1.632 !!  #5 /app/vendor/symfony/console/Application.php(174): Symfony\Bundle\FrameworkBundle\Console\Application->doRun()
1.632 !!  #6 /app/vendor/symfony/runtime/Runner/Symfony/ConsoleApplicationRunner.php(54): Symfony\Component\Console\Application->run()
1.632 !!  #7 /app/vendor/autoload_runtime.php(29): Symfony\Component\Runtime\Runner\Symfony\ConsoleApplicationRunner->run()
1.632 !!  #8 /app/bin/console(11): require_once('...')
1.632 !!  #9 {main}
1.633 !!    thrown in /app/vendor/symfony/framework-bundle/Kernel/MicroKernelTrait.php on line 126
1.633 !!  
1.633 Script @auto-scripts was called via post-install-cmd

failed to solve: process "/bin/sh -c set -eux; \tmkdir -p var/cache var/log; \tcomposer dump-autoload --classmap-authoritative --no-dev; \tcomposer dump-env prod; \tcomposer run-script --no-dev post-install-cmd; \tchmod +x bin/console; sync;" did not complete successfully: exit code: 255

My os is ubuntu 22.04 up to date with new installation of docker

dunglas commented 9 months ago

Can you share your composer.json file please? It looks like TwigBundle is not part of the non-dev dependencies while it should.

Rom1906 commented 9 months ago

Yes of course :


{
    "name": "symfony/skeleton",
    "type": "project",
    "license": "MIT",
    "description": "A minimal Symfony project recommended to create bare bones applications",
    "minimum-stability": "stable",
    "prefer-stable": true,
    "require": {
        "php": ">=8.2.10",
        "ext-ctype": "*",
        "ext-iconv": "*",
        "runtime/frankenphp-symfony": "^0.1.1",
        "symfony/console": "6.3.*",
        "symfony/dotenv": "6.3.*",
        "symfony/flex": "^2",
        "symfony/framework-bundle": "6.3.*",
        "symfony/runtime": "6.3.*",
        "symfony/var-dumper": "6.3.*",
        "symfony/yaml": "6.3.*"
    },
    "config": {
        "allow-plugins": {
            "php-http/discovery": true,
            "symfony/flex": true,
            "symfony/runtime": true
        },
        "sort-packages": true
    },
    "autoload": {
        "psr-4": {
            "App\\": "src/"
        }
    },
    "autoload-dev": {
        "psr-4": {
            "App\\Tests\\": "tests/"
        }
    },
    "replace": {
        "symfony/polyfill-ctype": "*",
        "symfony/polyfill-iconv": "*",
        "symfony/polyfill-php72": "*",
        "symfony/polyfill-php73": "*",
        "symfony/polyfill-php74": "*",
        "symfony/polyfill-php80": "*",
        "symfony/polyfill-php81": "*"
    },
    "scripts": {
        "auto-scripts": {
            "cache:clear": "symfony-cmd",
            "assets:install %PUBLIC_DIR%": "symfony-cmd"
        },
        "post-install-cmd": [
            "@auto-scripts"
        ],
        "post-update-cmd": [
            "@auto-scripts"
        ]
    },
    "conflict": {
        "symfony/symfony": "*"
    },
    "extra": {
        "symfony": {
            "allow-contrib": false,
            "require": "6.3.*",
            "docker": true
        }
    },
    "require-dev": {
        "symfony/maker-bundle": "^1.51",
        "symfony/stopwatch": "6.3.*",
        "symfony/web-profiler-bundle": "6.3.*"
    }
}
dunglas commented 9 months ago

The problem is that TwigBundle isn't listed in your require section. Typing composer req twig should fix the issue.

Rom1906 commented 9 months ago

The problem is that TwigBundle isn't listed in your require section. Typing composer req twig should fix the issue.

Yes now no problem for build and up the contenairs (can you list all the dependencies like twig are required for production please ? ) But there is a problem with ssl : ERR_SSL_PROTOCOL_ERROR

Rom1906 commented 9 months ago

The problem is that TwigBundle isn't listed in your require section. Typing composer req twig should fix the issue.

Yes now no problem for build and up the contenairs (can you list all the dependencies like twig are required for production please ? ) But there is a problem with ssl : ERR_SSL_PROTOCOL_ERROR

Some details on this ERR_SSL_PROTOCOL_ERROR problem. I have a feeling these are the instructions before the command docker compose -f docker-compose.yml -f docker-compose.prod.yml up --wait

SERVER_NAME=your-domain-name.example.com \
APP_SECRET=ChangeMe \
CADDY_MERCURE_JWT_SECRET=ChangeThisMercureHubJWTSecretKey \

which are not executed because if I put my domain name, SERVER_NAME, in the Symfony .env then it works. Is a known issue? What is good practice?

dunglas commented 9 months ago

What is your domain name? Do you have something related to SSL in the logs?

dunglas commented 9 months ago

(TwigBundle is a dependency of your application. Symfony doesn't depend on TwigBundle by default, there is nothing we can do about that on our side.)

Rom1906 commented 9 months ago

(TwigBundle is a dependency of your application. Symfony doesn't depend on TwigBundle by default, there is nothing we can do about that on our side.)

Thanks for reply, it's strange beacause locally I have no problems. Maybe it's the profiler who use twig but I'm sure I always used composer require...

Rom1906 commented 9 months ago

What is your domain name? Do you have something related to SSL in the logs?

domain name is vps.opaleweb.com Where can I find the ssl logs or access logs with this config please ?

dunglas commented 9 months ago

You should have logs by running docker compose logs. Are you using the standard port (443)? Non-standard ports aren't supported by Let's Encrypt.

Rom1906 commented 9 months ago

You should have logs by running docker compose logs. Are you using the standard port (443)? Non-standard ports aren't supported by Let's Encrypt.

Sorry but I have no logs no configuration file provided: not found and I use the standard port. If it can help you I can send to you by private message the access to the vps ? this .env works in production with the offical command

###> symfony/framework-bundle ###
APP_ENV=prod
SERVER_NAME=vps.opaleweb.com
CADDY_MERCURE_JWT_SECRET=xxxxxx
APP_SECRET=xxxxxxx
###< symfony/framework-bundle ###

BUT this .env doesn't works with the official command below

###> symfony/framework-bundle ###
APP_ENV=prod
###< symfony/framework-bundle ###

The command

SERVER_NAME=vps.opaleweb.com \
APP_SECRET=xxxxx \
CADDY_MERCURE_JWT_SECRET=xxxxxx \
docker compose -f docker-compose.yml -f docker-compose.prod.yml up -d --wait

It's the only difference

Rom1906 commented 9 months ago

@dunglas have you a clean solution to this issue please ?

beejaz commented 8 months ago

@dunglas have you a clean solution to this issue please ?

Have you tried passing the environment variable with -e ?

docker compose -e SERVER_NAME=vps.opaleweb.com -e APP_SECRET=xxxxx -e CADDY_MERCURE_JWT_SECRET=xxxxxx -f docker-compose.yml -f docker-compose.prod.yml up -d --wait
Rom1906 commented 8 months ago

@dunglas have you a clean solution to this issue please ?

Have you tried passing the environment variable with -e ?

docker compose -e SERVER_NAME=vps.opaleweb.com -e APP_SECRET=xxxxx -e CADDY_MERCURE_JWT_SECRET=xxxxxx -f docker-compose.yml -f docker-compose.prod.yml up -d --wait

Hello when I try it I get : unknown shorthand flag: 'e' in -e

maxhelias commented 7 months ago

Hi @Rom1906

First, the TwigBundle is installed by the symfony/web-profiler-bundle and not present when the composer command use --no-dev during the install. For the SSL, don't run docker compose logs anywhere. Run it in your docker project folder. For the env, I don't understand what the problem is? For the reccord, the flag -e work only on docker run command not on docker compose command.