Deployer: How to deploy a project in laradock ?

Created on 19 Jun 2018  ·  26Comments  ·  Source: deployphp/deployer

| Q | A
| ----------------- | ---
| Issue Type | Question
| Deployer Version | N/A
| Local Machine OS | mac
| Remote Machine OS | ubuntu (laradock)

Description

I want to deploy a laravel project in laradock. I can update code files to server.But how to run php command in laradock ?Is there a configuration to run php command in laradock ?Thank you!

Most helpful comment

How to use Deployer with Docker containers?

Good question. :) Now not. Will be in v7.

All 26 comments

I never worked with laradock, can't tell.

@antonmedv
Can I run some commands after ssh host?
I need run command "docker-compose exec workspace bash". Then I can run command other tasks in docker container.

I try to add a task:

task('deploy:intodocker', function () {
    run("cd /home/www/laradock && docker-compose exec workspace bash");
})
before('deploy:prepare', 'deploy:intodocker');

But I failed.

You need to connect to laradock by ssh.

@kisexu @antonmedv I have the same problem. I am new to Laradock and Deployer (both look so cool!), and I installed them yesterday, and where I'm stuck is a couple places:

  1. I keep getting this warning To speed up composer installation setup "unzip" command with PHP zip extension https://goo.gl/sxzFcD even though I'm pretty sure I've installed the zip extension in the appropriate containers.
  2. When Deployer reaches the vendors.php script, I get this error:
In Client.php line 99:

  [Deployer\Exception\RuntimeException (1)]
  The command "command -v 'php'" failed.

  Exit Code: 1 (General error)

So then I tried overriding with:

task('deploy:vendors', function () {
    run('cd ~/laradock && docker-compose exec workspace bash');
    if (!commandExist('unzip')) {
        //writeln('<comment>To speed up composer installation setup "unzip" command with PHP zip extension https://goo.gl/sxzFcD</comment>');
    }
    //run('cd {{release_path}} && {{bin/composer}} {{composer_options}}');
    run('cd /var/www/myproject/release && {{bin/composer}} {{composer_options}}');
});

(sort of like @kisexu ) but now I'm stuck with this error:

[Deployer\Exception\RuntimeException (255)]
  The command "cd ~/laradock && docker-compose exec workspace bash" failed.

  Exit Code: 255 (Unknown error)

I'm curious if there is a way to get Deployer working with Docker.

The unzip extension you can add to your PHP worker. As for the other errrors, I would check logs in workspace.

@kisexu Did you ever get Deployer to work with Docker?

I posted a question here: https://stackoverflow.com/questions/51274489/how-to-use-deployer-with-docker-laradock

@jasperf Yes, I think the zip extension is already installed in my php-fpm Docker container, but the problem is that Deployer won't switch into that container (as you can see in my recent StackOverflow question).

I'm super confused about why run('cd /root/laradock && (docker exec -i $(docker-compose ps -q php-fpm) bash;)'); would be completely ignored by Deployer. It's as if nothing happens. I've used Xdebug to step through the code and see that it successfully runs proc_open at https://github.com/symfony/process/blob/v4.1.0/Process.php#L304, but in reality, Deployer stays outside of the Docker container that it would have entered if docker exec -i $(docker-compose ps -q php-fpm) bash actually had been run.

I'd appreciate any ideas, @antonmedv . Your tool is so impressive! I hope I can get it to work for me. This is all I've been working on for almost 3 days now.

More details about what I've tried are at: https://stackoverflow.com/questions/51274489/how-to-use-deployer-with-docker-laradock

Thanks!

@ryancwalsh laradock created only for local development?

@antonmedv I'm almost positive that it doesn't matter how the Docker containers were created (Laradock or otherwise).

(If I had created Docker containers from scratch without Laradock, I'd face the same problem right now.)

So this question could be renamed to "How to use Deployer with Docker containers?"

How to use Deployer with Docker containers?

Good question. :) Now not. Will be in v7.

@antonmedv Thanks for your response! I look forward to v7.

+1

Also waiting for docker support. ASAP :) Cause I've spent 3 days trying to make it work with docker. Nope. And between docker and deployer we have chosen docker.

Please, update your package to make it possible to use it with latest technologies :)

@Denis4yk will do :) Please, tell me more about your setup, and how you use docker.

@antonmedv I'm ready to help))

Here is my mail

riabiy.[email protected]

Please, write your telegram phone number (or suggest any other option)

same problem “How to use Deployer with Docker containers?”
look forward to v7 too.....

I sent the docker setup 1-2 months ago to the maintainer :)

I sent the docker setup 1-2 months ago to the maintainer :)

Would you care to share a repo on this? There is a pull request by @blizzke already by the way.

@jasperf

Of course :)

https://github.com/Denis4yk/laravel-docker-setup

-1. Clone
0. Install Docker
1. From the root run `docker-compose up -d` (tested only on mac)
2. Check in your browser `127.0.0.1`

@Denis4yk Do not see here how deployer is used to deploy the app's code and work within the container to be able to execute PHP...?

@jasperf Looks like you misunderstood me. It is just a setup of a Docker project :D

Cause not every dev knows how to set it up and the maintainer has to have a working docker setup in order to implement docker support.

So I decided to help with that :)

To use laravel deployer you should connect via ssh directly to the workspace container.

You can expose the container's ssh port: https://laradock.io/documentation/#access-workspace-via-ssh

Let's say you've forwarded container ssh port 22 to vm port 2222. In that case you need configure your deployer to use the port 2222.

Also remember to set proper secure SSH keys, not the default ones.

@Yudikubota Forwarding workspace ssh port 22 to VPS port 2222 is an interesting idea. This so port 2222 would give direct access to the workspace via SSH instead of the VM SSH server.

👋 Hello, maybe this can help as a work-around:

➡️ Create on your server a shell script running the command you need, for instance:

#!/bin/bash

DEPLOY_PATH="/var/www/html"

cd ${DEPLOY_PATH}/laradock \
        && docker-compose exec -T  workspace php artisan cache:clear \
        && docker-compose exec -T workspace php artisan config:clear \
        && docker-compose exec -T workspace php artisan config:cache

# the -T flag disables pseudo-tty allocation.

➡️ Then from your deploy file, run something like this :

run("{{deploy_path}}/php-artisan-clear.sh");

🔥 Note that if you use a "deploy" user to run your CD, you need to give him access to docker permission. Here this command add the user to the docker group: usermod -a -G docker $USER
You need to be sure the user is correctly configured and the key access secured as this user can now access to your docker containers.

@kisexu Did you ever get Deployer to work with Docker?

I posted a question here: https://stackoverflow.com/questions/51274489/how-to-use-deployer-with-docker-laradock

@jasperf Yes, I think the zip extension is already installed in my php-fpm Docker container, but the problem is that Deployer won't switch into that container (as you can see in my recent StackOverflow question).

I'm super confused about why run('cd /root/laradock && (docker exec -i $(docker-compose ps -q php-fpm) bash;)'); would be completely ignored by Deployer. It's as if nothing happens. I've used Xdebug to step through the code and see that it successfully runs proc_open at https://github.com/symfony/process/blob/v4.1.0/Process.php#L304, but in reality, Deployer stays outside of the Docker container that it would have entered if docker exec -i $(docker-compose ps -q php-fpm) bash actually had been run.

I'd appreciate any ideas, @antonmedv . Your tool is so impressive! I hope I can get it to work for me. This is all I've been working on for almost 3 days now.

More details about what I've tried are at: https://stackoverflow.com/questions/51274489/how-to-use-deployer-with-docker-laradock

Thanks!

Hi.Have you ever solved this problem?I have the same problem.How to enter the php container in deployer.The command like php or composer it need to run in php container.In the outside of the container i have no install any php or composer,so it absolutly deploy failed.
My English is not good,hope you would understand what i say.Thank you.

Couldn't you use port 2222 for your Workspace or something as suggested here by https://github.com/kOld to use in deploy.php:

host('SERVER-IP')
    ->set('deploy_path', '/path/to/deployer')
    ->set('bin/php', 'cd /path/to/laradock/ && docker-compose exec -T workspace php')
    ->set('bin/composer', 'cd /path/to/laradock/ && docker-compose exec -T workspace composer -d={{release_path}}');

and to reload this:

set('php_fpm_service', 'php7.2-fpm');
set('php_fpm_command', 'echo "" | sudo -S /usr/sbin/service {{php_fpm_service}} reload'); // for setups like laravel forge
set('php_fpm_command', "kill -USR2 "$(ps -ef | grep '[p]hp-fpm: master' | awk '{print $2}')""); // for docker based setups with laradock or similar
task('fpm:reload', function () {
run('{{php_fpm_command}}');
})->desc('Reload the php-fpm service');

Is there a no problem way for deploy using laradock now?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

antonmedv picture antonmedv  ·  5Comments

dima-stefantsov picture dima-stefantsov  ·  5Comments

greatwitenorth picture greatwitenorth  ·  4Comments

exts picture exts  ·  3Comments

ovaiskhan11 picture ovaiskhan11  ·  4Comments