deployphp / deployer

The PHP deployment tool with support for popular frameworks out of the box
https://deployer.org
MIT License
10.56k stars 1.48k forks source link

How can I enter the container and execute a composer install if the host does not have Composer and PHP #3751

Closed SemiThin closed 9 months ago

SemiThin commented 9 months ago

Discussed in https://github.com/deployphp/deployer/discussions/3750

Originally posted by **SemiThin** December 14, 2023 How can I enter the container and execute a composer install if the host does not have Composer and PHP I don't want to install PHP and Composer on the server So, should I SSH this container instead of SSH the server? ![bug](https://github.com/deployphp/deployer/assets/12593507/a2dd365c-7ecf-411f-8a1b-0944e16eaf98)
Schrank commented 9 months ago

Good morning! Yes, if you want to install on docker, you either ssh into the container, but imho do you not want to expose ssh to the interwebz. So better prefix all commands with docker exec and then again you might get problems with session and cd.

I have no clue how this works in detail, but I think the best would be to ssh jump host via the host.

hope that helps, good luck!

SemiThin commented 9 months ago

Good morning! Yes, if you want to install on docker, you either ssh into the container, but imho do you not want to expose ssh to the interwebz. So better prefix all commands with docker exec and then again you might get problems with session and cd.

I have no clue how this works in detail, but I think the best would be to ssh jump host via the host.

hope that helps, good luck!

I have a PHP nginx mysql container, and Composer is installed inside the PHP container. If I directly ssh the PHP container, but next time I recreate this container, I will have to redeploy ssh, which is not a good choice

SemiThin commented 9 months ago

I have already resolved it run('docker-compose exec -w /www/project_path/release php composer install');

Schrank commented 9 months ago

🥰😍

SemiThin commented 9 months ago

🥰😍

But there's one thing I didn't understand, the directory should be current. Why doesn't it work when it's current

SemiThin commented 9 months ago

it's work: run('docker-compose exec -w /www/project_path/release php composer install');

it doesn't work: run('docker-compose exec -w /www/project_path/current php composer install');

Schrank commented 9 months ago

Because renaming release to current is the last step. We don’t want to interrupt the web app, so until deployment is finished, we run the old version.

So:

Schrank commented 9 months ago

Ah to be explicit: in your script, current is doo early in time, it shows the old release, and after rename you end up with a version without composer install, because it ran in the wrong directory

SemiThin commented 9 months ago

Because renaming release to current is the last step. We don’t want to interrupt the web app, so until deployment is finished, we run the old version.

So:

  • new release is created in releases
  • release is a symlink into the new release
  • Current shows on the old release
  • Deployment runs, composer install, nom install, building, crrating thumbnsils, whatever 🙃
  • „Last“ step: mv release current (atomic command, so at everytime there is a current symlink which either shows on old or new release)
  • Cleanup (e.g. old releases)

get,thinks