X Tutup
The Wayback Machine - https://web.archive.org/web/20201011083613/https://github.com/api-platform/api-platform/issues/1656
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Still waiting for db to be ready... Or maybe the db is not reachable." #1656

Open
xavierdemoor opened this issue Sep 23, 2020 · 14 comments
Open

Comments

@xavierdemoor
Copy link

@xavierdemoor xavierdemoor commented Sep 23, 2020

API Platform version(s) affected: 2.5.7

Description
On a fresh install of API Platform package (.tar.gz), after running docker-compose up, the PHP container is trying to run the command bin/console doctrine:query:sql "SELECT 1" to see if the DB container is up and running.

The problem is that bin/console file doesn't have the executable flag in the container, so PHP container can't see it's connected to DB and exited with an error.

How to reproduce

  • Download the last version in .tar.gz
  • Uncompress the directory to a location
  • Configure the DB password in docker-compose.yaml (or not, but I did it)
  • Start docker-compose (pull > up)
  • Look at the logs to see the message Still waiting for db to be ready... Or maybe the db is not reachable. x attempts left

Possible Solution
Applying +x flag to bin/console

@dunglas
Copy link
Member

@dunglas dunglas commented Sep 30, 2020

How did you installed API Platform? As documented in the "getting started guide", using the Zip file is known to cause issues. Be sure to use the .tar.gz. Unfortunately we cannot tell GitHub to not provide the Zip.

@xavierdemoor
Copy link
Author

@xavierdemoor xavierdemoor commented Sep 30, 2020

I used the .tar.x file and untar under wsl2.

@dunglas
Copy link
Member

@dunglas dunglas commented Sep 30, 2020

Thanks for the feedback! I don't own a Windows computer so I cannot debug this. It would be awesome if someone using Windows can help to track this down (and to fix the bug).

@xavierdemoor
Copy link
Author

@xavierdemoor xavierdemoor commented Oct 1, 2020

Thanks for the feedback! I don't own a Windows computer so I cannot debug this. It would be awesome if someone using Windows can help to track this down (and to fix the bug).

It seems untaring into a wsl2 folder from Windows doesn't keep some linux permissions, even with a .tar.gz archive.

Maybe just adding a chmod +x bin/console before the first composer install, in the Dockerfile, can solve this problem for wsl2 devs ?
It's a lot easier to untar files from Windows to a wsl2 folder than doing all the command lines directly into wsl2. ;)

@dunglas
Copy link
Member

@dunglas dunglas commented Oct 2, 2020

If this works, let's do this, even if I'm not a found of such hacks.

@xavierdemoor
Copy link
Author

@xavierdemoor xavierdemoor commented Oct 2, 2020

You already use it in your Dockerfile, but after the first composer install. I don't like doing that on my dockerfiles too but sometimes...

Now we can dev on wsl2, this kind of problem (files permissions) will be more and more frequent. I switched from dual boot Windows/Linux to Windows with wsl2 2 weeks ago and I'm facing this problem frequently now. (Yeah, I'm thinking switch back to dual boot lol).

@Wacuta
Copy link

@Wacuta Wacuta commented Oct 2, 2020

Hi,
I have also this problem. For a week now, I don't now why it's work on my local (Windows) but not in my server (VPS at OVH)

Process

  • Start with a fresh project with git clone or package from the repository
  • Build with docker-compose up --build.

Results
Local: 200 /ping
Server: Still waiting for db to be ready... Or maybe the db is not reachable.

I juste solve my problem with chmod +x api/bin/console 🤯

@dunglas
Copy link
Member

@dunglas dunglas commented Oct 2, 2020

Maybe should we use php bin/console everywhere instead of bin/console?

@xavierdemoor
Copy link
Author

@xavierdemoor xavierdemoor commented Oct 2, 2020

Maybe should we use php bin/console everywhere instead of bin/console?

I checked permissions for bin/console on the repo. It's 0755, so it's not a repo or archive problem.
It's not the most elegant way to solve, once for all, this problem but chmod +x is the most efficient way.

You're already did it in line https://github.com/api-platform/api-platform/blob/master/api/Dockerfile#L105 but it's after the first composer install command in line https://github.com/api-platform/api-platform/blob/master/api/Dockerfile#L86

Composer do a bin/console cache:clear after an install or update, so it needs to have bin/console to be executable.
composer.json:

    "scripts": {
        "auto-scripts": {
            "cache:clear": "symfony-cmd",
            "assets:install %PUBLIC_DIR%": "symfony-cmd"
        },
        "post-install-cmd": [
            "@auto-scripts"
        ],
        "post-update-cmd": [
            "@auto-scripts"
        ]
    },

I know you don't like this, but... Moving the chmod +x bin/console is the best way to solve this.
A fresh Symfony have bin/console executable.

@dunglas
Copy link
Member

@dunglas dunglas commented Oct 2, 2020

Let's do this! Do you want to work on a PR?

@xavierdemoor
Copy link
Author

@xavierdemoor xavierdemoor commented Oct 2, 2020

Let's do this! Do you want to work on a PR?

I started to but...

I mixed up two bugs reports for the same kind of problem. The other one was not related to api-platform but involved bin/console too.

So, here the problem is for the "Still waiting" because bin/console is not executable in some situations. It's not because of a composer doing a cache:clear... I mixed up.

Back to this problem:

I tried different ways to install and run api-platform.

  1. Under WSL2: git clone and run => No problem on bin/console
  2. Under WSL 2: dl .tar.gz, untar, run => No problem
  3. Under Windows: dl .tar.gz on Windows, move the archive in a WSL2 dir, untar with WSL2, run => No problem
  4. Under Windows: dl .tar.gz, untar it under Windows into a WSL2 dir, run => bin/console is not executable and got the "Still waiting for db..."

I did chmod +x on bin/console under WSL2, ran docker-compose up again and the problem was solved.

So, it can't be fixed in the Dockerfile. It's a Windows and/or WSL2 problem only.

  • Wacuta may have done unzip/untar with Windows, lost flags, uploaded files on his VPS
  • Me, I untar the files under Windows into WSL2 dir. I don't know how Windows do this, but it seems he doesn't keep flags even if we untar files directly to a WSL2 dir.

The problem is because of Windows. Even with the .tar.gz file :/

@Wacuta
Copy link

@Wacuta Wacuta commented Oct 2, 2020

Some of my tests, I worked direct under my VPS (git clone, build...) because I thought the problem was my server (Linux) :/

@xavierdemoor
Copy link
Author

@xavierdemoor xavierdemoor commented Oct 2, 2020

Some of my tests, I worked direct under my VPS (git clone, build...) because I thought the problem was my server (Linux) :/

Did you mount a host folder to a container ?

@Wacuta
Copy link

@Wacuta Wacuta commented Oct 2, 2020

Did you mount a host folder to a container ?

No or not from myself ! I just clone from my server and I build with docker-compose up

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.
X Tutup