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.59k stars 771 forks source link

Symfony CLI? #654

Closed GalacticSun closed 2 months ago

GalacticSun commented 2 months ago

Hi there, I've tried to add the following code to the Dockerfile in order to get Symfony CLI installed:

RUN curl -sS https://get.symfony.com/cli/installer | bash RUN mv /root/.symfony5/bin/symfony /usr/local/bin/symfony

But it keeps giving me this error: WARN[0000] current commit information was not captured by the build error="failed to read current commit information with git rev-parse --is-inside-work-tree"

What am I doing wrong? Is there a better way of doing this?

7-zete-7 commented 2 months ago

Hello @GalacticSun!

I ran these commands on the image dunglas/frankenphp:latest. Everything worked fine.

$ docker run -it --rm dunglas/frankenphp bash
Digest: sha256:0273cbeaa0d64cfe208cddfa6df4a40e4a460a1b5a97057b9e412d177723f673

root@9187ac7cbb8d:/app# curl -sS https://get.symfony.com/cli/installer | bash
Symfony CLI installer

Environment check
  [*] cURL is installed
  [*] Tar is installed
  [ ] Warning: Git will be needed.
  [*] Your architecture (amd64) is supported

Download
  Downloading https://github.com/symfony-cli/symfony-cli/releases/latest/download/symfony-cli_linux_amd64.tar.gz...
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
100 5609k  100 5609k    0     0  1594k      0  0:00:03  0:00:03 --:--:-- 2360k
  Uncompress binary...
  Installing the binary into your home directory...
  The binary was saved to: /root/.symfony5/bin/symfony

The Symfony CLI was installed successfully!

Use it as a local file:
  /root/.symfony5/bin/symfony

Or add the following line to your shell configuration file:
  export PATH="$HOME/.symfony5/bin:$PATH"

Or install it globally on your system:
  mv /root/.symfony5/bin/symfony /usr/local/bin/symfony

Then start a new shell and run 'symfony'

root@9187ac7cbb8d:/app# mv /root/.symfony5/bin/symfony /usr/local/bin/symfony

root@9187ac7cbb8d:/app# symfony version
Symfony CLI version 5.10.2 (c) 2021-2024 Fabien Potencier (2024-07-19T11:09:07Z - stable)

Is the issue still relevant?

Can you show your Dockerfile?

maxhelias commented 2 months ago

Hi! The project is not designed to use the Symfony CLI. The warning indicates that you don't have the git information that is excluded during the build here : https://github.com/dunglas/symfony-docker/blob/main/.dockerignore#L10C4-L10C9

GalacticSun commented 2 months ago

@7-zete-7 Thanks, I was able to run this, as well. However, I'd like to get it installed automatically and not have to install this each time I launch the container.

@maxhelias Any particular reason this project isn't designed to use Symfony CLI? I'm new to Symfony and trying to learn it, and it is suggested to install and use the CLI in the book (https://symfony.com/doc/6.4/the-fast-track/en/1-tools.html and https://symfony.com/doc/current/the-fast-track/en/6-controller.html, etc) as well as in the Getting Started docs (https://symfony.com/doc/current/setup.html). It seems pretty handy.

If not, were I to remove line 10 from the .dockerignore file, would it break anything else?

maxhelias commented 2 months ago

Why do you want the CLI with this project? Both do the same thing but in different ways

GalacticSun commented 2 months ago

Why do I want it? Why wouldn't I want it? Since I'm new to Symfony I'd like to follow both the Getting Started tutorial and the Symfony book, as I explained in my previous post, and I'd like to follow their recommendations to learn and to use the CLI as an extra tool for development and management.

If you want to get very specific, I went to create a controller (by reading this page: https://symfony.com/doc/current/page_creation.html) and the instructions simply say "create a 'Controller' class and a 'controller' method inside of it". Well, that page doesn't say where to actually put the controller file I've just created. It assumes I know this. Being new to Symfony, I don't know this, which is why I'm reading that page... So I proceeded to search around online as to where to put this new Controller file in the Symfony filesystem and found references to the Symfony CLI. And the CLI says, in the Symfony book (https://symfony.com/doc/current/the-fast-track/en/6-controller.html) that the CLI takes care of the file creation and puts the newly created controller file into the /src/Controller directory. So now I know where to put the Controller file, but I also see other useful commands that the CLI can do, as well, that would be useful for a beginner like me. Why would you be against putting this into the project? It doesn't make any sense to me to omit it. (Or at least provide a simple option for those who might want it?) Thanks.

Both do the same thing but in different ways

Both? What are you referring to? The CLI and ...?

maxhelias commented 2 months ago

You're confusing a lot of things because you don't read the entire documentation page.

All file locations are explained here: Capture d’écran 2024-08-20 à 09 22 31

If you follow the “Getting Started" or the "Symfony book" none of them says you are forced to use this project. If you want to learn Symfony, just follow the book from the beginning, it's a good guide to get you started.

To explain both (the CLI and this project):

For your information, it's not the CLI that create any Symfony file but the maker-bundle : https://symfony.com/bundles/SymfonyMakerBundle/current/index.html

GalacticSun commented 2 months ago

You're kidding, right?

You're confusing a lot of things because you don't read the entire documentation page.

Uh, no, sorry, that's not true. That page simply doesn't describe where to put the Controller file, anywhere. The fact you highlighted src/Controller/LuckController.php doesn't describe clearly that that is where to put it, because it looked like a reference or an include to me as a beginner and I wasn't sure. Or, are you saying that's my fault for being so stupid? (Did I mention I'm a beginner?...) That page is unclear, bottom line. It says "create a Controller" but then fails to describe how to do this or where to put it.

And the setup page you refer to in your screenshot (https://symfony.com/doc/current/setup.html) not only doesn't describe where to put the controller file, either, but it actually recommends making use of the Symfony CLI, with examples, around a dozen times! It is recommended to use the CLI right there in the setup page that you referenced! It is mind boggling that you are being so rude and evasive about this, especially to a beginner.

Look, forget it...

Here's a better question: How can I get the Symfony CLI working in your project? Is this possible?

(I removed line 10, **/.git/, from .dockerignore and tried a build using docker compose build --no-cache but I got the same error.)

dunglas commented 2 months ago

Symfony Docker provides the features of Symfony CLI. If you use Symfony Docker, you don't need Symfony CLI (and if you use Symfony CLI, you likely don't need/want Symfony Docker).

For the examples in the book, replace symfony console [...] with docker compose exec php bin/console [...] and everything should work the same (symfony console is just a wrapper around bin/console).

GalacticSun commented 2 months ago

Symfony Docker provides the features of Symfony CLI. If you use Symfony Docker, you don't need Symfony CLI (and if you use Symfony CLI, you likely don't need/want Symfony Docker).

For the examples in the book, replace symfony console [...] with docker compose exec php bin/console [...] and everything should work the same (symfony console is just a wrapper around bin/console).

Thank you, Kévin, that explains it. I appreciate your clarity. I will give that a try.

GalacticSun commented 2 months ago

Actually, I just found Latte (https://latte.nette.org/en/) / Nette (https://nette.org/en/), I think I'll use that.