Did anyone get to make Laravel Dusk to work on GitLab CI?
I'm using this docker image, which is amazing, but I simply can't execute ./vendor/laravel/dusk/bin/chromedriver-linux, it says:
/bin/bash: line 102: ./vendor/laravel/dusk/bin/chromedriver-linux: No such file or directory
When I enter at ./vendor/laravel/dusk/bin I can see that chromedriver-linux is there and it's executable, but can't make it run.
By now, the script lines that compose this phase are:
- mv .env.testing .env
- php artisan key:generate
- ./vendor/bin/phpunit --colors=never
- php artisan dusk:install
- chmod -R 0755 vendor/laravel/dusk/bin
- ./vendor/laravel/dusk/bin/chromedriver-linux
- php artisan dusk
I've also tried the approaches on documentation, even though they're not for GitLab CI, but none of them worked.
Update:
Running ls -l ./vendor/laravel/dusk/bin returns:
total 33560
-rwxr-xr-x 1 root root 10885776 Jun 26 13:10 chromedriver-linux
-rwxr-xr-x 1 root root 14994520 Jun 26 13:10 chromedriver-mac
-rwxr-xr-x 1 root root 8393728 Jun 26 13:10 chromedriver-win.exe
-rwxr-xr-x 1 root root 69309 Jun 25 22:59 jquery.js
I've tried to copy the file to the machine's current PATH but didn't work either:
Testing the $PATH variable
$ echo $PATH
./vendor/bin:/composer/vendor/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
Copying the binary to /usr/local/bin
$ CHROME_DRIVER_PATH_BIN=./vendor/laravel/dusk/bin/chromedriver-linux
$ cp $CHROME_DRIVER_PATH_BIN /usr/local/bin
Testing if the file is really there
$ ls -lha /usr/local/bin
total 56564
drwxr-xr-x 1 root root 4.0K Jun 26 17:33 .
drwxr-xr-x 1 root root 4.0K Feb 21 23:08 ..
-rwxr-xr-x 1 root root 10.4M Jun 26 17:33 chromedriver-linux
-rwxr-xr-x 1 root root 1.8M Feb 22 06:40 composer
-rwxrwxr-x 1 root root 118 Feb 21 23:02 docker-php-entrypoint
-rwxrwxr-x 1 root root 1.4K Feb 21 23:02 docker-php-ext-configure
-rwxrwxr-x 1 root root 2.4K Feb 21 23:02 docker-php-ext-enable
-rwxrwxr-x 1 root root 2.3K Feb 21 23:02 docker-php-ext-install
-rwxrwxr-x 1 root root 587 Feb 9 01:57 docker-php-source
lrwxrwxrwx 1 root root 32 Jun 26 17:33 heroku -> /usr/local/lib/heroku/bin/heroku
-rwxr-xr-x 1 root root 817 Feb 21 23:08 pear
-rwxr-xr-x 1 root root 838 Feb 21 23:08 peardev
-rwxr-xr-x 1 root root 751 Feb 21 23:08 pecl
lrwxrwxrwx 1 root root 9 Feb 21 23:08 phar -> phar.phar
-rwxr-xr-x 1 root root 14.5K Feb 21 23:08 phar.phar
-rwxr-xr-x 1 root root 14.3M Feb 21 23:08 php
-rwxr-xr-x 1 root root 14.2M Feb 21 23:08 php-cgi
-rwxr-xr-x 1 root root 2.6K Feb 21 23:08 php-config
-rwxr-xr-x 1 root root 14.4M Feb 21 23:08 phpdbg
-rwxr-xr-x 1 root root 4.5K Feb 21 23:08 phpize
Either way, running chromedriver-linux does not work, I got the error
nohup: can't execute 'chromedriver-linux': No such file or directory
I've tested the same concept on my macOS: created an executable, put it into a folder which is on my PATH variable using a symlink and it works perfectly.
I could solve that installing chromium and chromium-chromedriver packages since they are available on Alpine Linux.
Below is the relevant part of my .gitlab-ci.yml file:
image: lorisleiva/laravel-docker
before_script:
- apk add chromium-chromedriver -y
- apk add chromium -y
phptest:
stage: test
script:
- mv .env.testing .env
- php artisan key:generate
- ./vendor/bin/phpunit --colors=never
- chromedriver 2>&1 &
- sleep 5
- nohup php artisan serve &
- php artisan dusk
Also, a really important part is to add --no-sandbox argument when creating the RemoteWebDriver. This can be done changing the function driver on tests/DuskTestCase.php file:
<?php
// tests/DuskTestCase.php
protected function driver()
{
$options = (new ChromeOptions)->addArguments([
'--disable-gpu',
'--headless',
'--no-sandbox', // # Add this # //
'--window-size=1920,1080',
]);
return RemoteWebDriver::create(
'http://localhost:9515',
DesiredCapabilities::chrome()->setCapability(
ChromeOptions::CAPABILITY,
$options
)
);
}
Just this solved my problem and now I can test with Dusk on GitLab CI using lorisleiva/laravel-docker Docker image.
The Dockerfile for that lorisleiva/laravel-docker image does:
ENV PATH ./vendor/bin:/composer/vendor/bin:$PATH
...
WORKDIR /var/www
So when your script does execute, the '.' in './vendor' might not reference the current working directory you expect.
Since PATH is set, it would be best if chromedriver-linux was in ./vendor/bin instead.
That way, your script can simply call chromedriver-linux (no leading path)
Related
When I use the following command:
~/Downloads cp -r phpMyAdmin /Library/WebServer/Documents/
I get this error:
cp: /Library/WebServer/Documents/phpMyAdmin/sql/upgrade_tables_4_7_0+.sql: No such file or directory
for all the files
.
How should I fix this in OSX?
I have
ls -l /Library/WebServer/Documents/ 1 ✘ at 01:38:03 AM
total 80
-rwxr-xr-x 1 root wheel 3726 Aug 29 2019 PoweredByMacOSX.gif
-rwxr-xr-x 1 root wheel 31958 Aug 29 2019 PoweredByMacOSXLarge.gif
-rwxr-xr-x 1 root wheel 45 Aug 29 2019 index.html.en
and also 755 on phpMyAdmin folder in Downloads folder.
Try to copy it with sudo, as the owner seems to be root:wheel:
sudo cp -r ./phpMyAdmin /Library/WebServer/phpMyAdmin
I'm using bitbucket to host my git repository, the repo holds a test website at the moment, I have created a bitbucket webhook, so when I push to the bitbucket repo, the changes show up as live on the digitalOcean VPS, in other words.. when bitbucket receives a push, it calls the webhook php file, and that php file has a shell script that pulls from github..
the hook file
Hook path : /var/www/html/hook.php
the site folder
Site path : /var/www/html/webhooks/
the hook.php file looks like so
<?php
echo "________PHP_AUTO_PULL________";
$output = shell_exec('git -C ./webhooks/ pull https://userName:password#bitbucket.org/userName/repo.git master');
echo "<pre>$output</pre>";
?>
when I do this in terminal
php hook.php
it does the job normally, and it pulls..
but the problem is, webhooks only shows this reply
________PHP_AUTO_PULL________
indicating that it does no pull, yes I have checked, no pull occured, how to make the hook execute the file normally?
permissions and owners are provided in these listings
listing for /var/www/html/
drwxrwxr-x 3 www-data www-data 4096 Mar 28 09:21 ./
drwxrwxr-x 3 www-data www-data 4096 Mar 3 16:49 ../
-rwxrwxrwx 1 www-data root 200 Mar 28 09:05 hook.php*
-rw-rw-r-- 1 www-data www-data 20 Mar 3 16:49 info.php
drwxr-xr-x 3 root root 4096 Mar 28 09:03 webhooks/
listing for /var/www/html/webhooks/
drwxr-xr-x 3 root root 4096 Mar 28 09:03 ./
drwxrwxr-x 3 www-data www-data 4096 Mar 28 09:21 ../
-rw-r--r-- 1 root root 295 Mar 27 15:13 content.html
drwxr-xr-x 8 root root 4096 Mar 28 09:03 .git/
-rw-r--r-- 1 root root 444 Mar 27 15:13 index.html
-rw-r--r-- 1 root root 963 Mar 27 15:13 menu_1.html
-rw-r--r-- 1 root root 13 Mar 28 09:03 number.txt
my webserver is nginx
any idea why it works from terminal, but bitbucket can't have it to work?
I have managed to solve it, using :
echo shell_exec("/usr/bin/git pull https://userName:password#bitbucket.org/userName/repo.git master 2>&1");
the 2>&1 part was helping me to see errors about permissions of folders, I used
chown -R www-data .git/
and it's working fine.
I am running a Symfony3 application inside a Docker container. I have created a CommonBundle with all the resources (js, css, images). This resources are symlinked to another path as shown below:
$ docker exec -u www-data -it dockeramp_php_1 ls -la oneview_symfony/src/CommonBundle/Resources/public
total 8
drwxrwsr-x 2 www-data www-data 4096 Feb 23 21:09 .
drwxr-sr-x 5 www-data www-data 4096 Feb 23 20:54 ..
lrwxrwxrwx 1 root www-data 32 Feb 23 21:09 css -> /var/www/html/public_html/styles
lrwxrwxrwx 1 root www-data 32 Feb 23 21:09 images -> /var/www/html/public_html/images
lrwxrwxrwx 1 root www-data 28 Feb 23 21:08 js -> /var/www/html/public_html/js
The directory oneview_symfony/web does exists and it's writable by www-data as shown below:
$ docker exec -u www-data -it dockeramp_php_1 ls -la oneview_symfony/web
total 64
drwxrwsr-x 3 www-data www-data 4096 Feb 23 20:50 .
drwxrwsr-x 9 www-data www-data 4096 Feb 23 21:16 ..
-rwxrwxr-x 1 www-data www-data 3319 Feb 23 16:45 .htaccess
-rwxrwxr-x 1 www-data www-data 631 Feb 23 16:45 app.php
-rwxrwxr-x 1 www-data www-data 843 Feb 23 16:45 app_dev.php
-rwxrwxr-x 1 www-data www-data 2092 Feb 23 16:45 apple-touch-icon.png
drwxr-sr-x 2 www-data www-data 4096 Feb 23 20:50 bundles
-rw-rw-rw- 1 www-data www-data 21486 Feb 23 20:50 config.php
-rwxrwxr-x 1 www-data www-data 6518 Feb 23 16:45 favicon.ico
-rwxrwxr-x 1 www-data www-data 116 Feb 23 16:45 robots.tx
I am trying to install the assets relative or symlink switching values on the composer.json file:
{
...
"extra": {
...
"symfony-web-dir": "web",
"symfony-assets-install": "relative",
}
}
I am trying to publish the assets running the following command and ending up with the error below:
$ docker exec -u www-data -it dockeramp_php_1 php oneview_symfony/bin/console assets:install
[InvalidArgumentException]
The target directory "web" does not exist.
What I am missing here?
There is a similar issue here but without answer so far.
Can you try this command instead:
$ docker exec -u www-data -it dockeramp_php_1 php oneview_symfony/bin/console assets:install web
If that doesn't work, try the full path to the web directory.
Let us know if that works. Not sure if that will fix the problem, but please try it.
Configure variable for assets command.
Add public-dir to composer.json
"extra": {
"symfony-web-dir": "web",
"public-dir": "web",
...
},
Because assets command relies on it (view code on github)
Look:
$defaultPublicDir = 'public';
// ...
if (isset($composerConfig['extra']['public-dir'])) {
return $composerConfig['extra']['public-dir'];
}
return $defaultPublicDir;
For anyone trying to install assets in Symfony 4 with the old Symfony3 directory structure getting:
Error thrown while running command "assets:install". Message: "The target directory "public" does not exist."
The same fix Alvin Bunk provided works:
$ bin/console assets:install web
Just manually provide the old target path
You need to run the exact line
app/console assets:install or bin/console assets:install
(depends on your version) since it takes the path of the command as reference.
Is there any good way (faster) to launch phpunit on docker? Here what I used to do :
docker-compose build
docker-compose up
docker ps
docker exec <container_id> phpunit --configuration /myproject/src/Tests/phpunit.xml --testsuite testAllSuites
Note: I don't want to use Volume to sync files, so right now everytime I have to rebuild the project .. and I am trying to figure out how to launch test on a specific container without specifing the containe_id .. is it possible to launch it using the build name instead ?
No need to do a complicated lookup of the container id, here's an example of how you can do it within docker-compose:
$ cat docker-compose.yml
version: '2'
volumes:
testvol:
driver: local
services:
testapp:
image: busybox
entrypoint: "top"
volumes:
- testvol:/data
testapp2:
image: busybox
entrypoint: "top"
volumes:
- testvol:/data
$ ../bin/docker-compose up -d
Creating test_testapp_1
Creating test_testapp2_1
$ ../bin/docker-compose ps
Name Command State Ports
-----------------------------------------
test_testapp2_1 top Up
test_testapp_1 top Up
$ ../bin/docker-compose exec testapp ls -l
total 40
drwxr-xr-x 2 root root 12288 Mar 18 16:39 bin
drwxr-xr-x 2 root root 4096 Jun 11 11:07 data
drwxr-xr-x 5 root root 360 Jun 13 11:50 dev
drwxr-xr-x 2 root root 4096 Jun 13 11:50 etc
drwxr-xr-x 2 nobody nogroup 4096 Mar 18 16:38 home
dr-xr-xr-x 224 root root 0 Jun 13 11:50 proc
drwxr-xr-x 2 root root 4096 Mar 18 16:38 root
dr-xr-xr-x 13 root root 0 Jun 13 11:50 sys
drwxrwxrwt 2 root root 4096 Mar 18 16:38 tmp
drwxr-xr-x 3 root root 4096 Mar 18 16:39 usr
drwxr-xr-x 4 root root 4096 Mar 18 16:39 var
You can also take advantage of the consistent container naming by docker-compose (it prepends the directory name and appends a number for scaling) to run the exec on the individual containers with docker exec:
$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
069d40e3b6c7 busybox "top" 2 minutes ago Up 2 minutes test_testapp2_1
60e6d34d3b5a busybox "top" 2 minutes ago Up 2 minutes test_testapp_1
$ docker exec test_testapp_1 ls -l
total 40
drwxr-xr-x 2 root root 12288 Mar 18 16:39 bin
drwxr-xr-x 2 root root 4096 Jun 11 11:07 data
drwxr-xr-x 5 root root 360 Jun 13 11:50 dev
drwxr-xr-x 2 root root 4096 Jun 13 11:50 etc
drwxr-xr-x 2 nobody nogroup 4096 Mar 18 16:38 home
dr-xr-xr-x 226 root root 0 Jun 13 11:50 proc
drwxr-xr-x 2 root root 4096 Mar 18 16:38 root
dr-xr-xr-x 13 root root 0 Jun 13 11:50 sys
drwxrwxrwt 2 root root 4096 Mar 18 16:38 tmp
drwxr-xr-x 3 root root 4096 Mar 18 16:39 usr
drwxr-xr-x 4 root root 4096 Mar 18 16:39 var
I just figure out an easiest way to launch phpunit tests on my php-fpm container, here the command :
docker exec -it $(docker ps -n=-1 -q --filter name=my_php_container_name --format="{{.ID}}") phpunit --configuration /myproject/src/Tests/phpunit.xml --testsuite testAllSuites
so now whenever I change anything on my code here what I do :
docker-compose build
docker-compose up
docker exec -it $(docker ps -n=-1 -q --filter name=my_php_container_name --format="{{.ID}}") phpunit --configuration /myproject/src/Tests/phpunit.xml --testsuite testAllSuites
So this means I don't have to display all docker containers (docker ps) to get the id and update the command manually to launch phpunit on the new container id.
Runing this command wil return only the container_id :
docker ps -n=-1 -q --filter name=my_php_container_name --format="{{.ID}}"
here some explanations :
-n=-1 : show n last ceated containers
-q : only display numeric IDs
for more details about options here the docker documentation
Note: Just for instance, if we move phpunit.xml file just under /myproject/ root the phpunit command can be even smaller and if we run phpunit it will automatically load phpunit.xml and run all tests under your /Tests/... folder and the command will be :
docker exec -it $(docker ps -n=-1 -q --filter name=my_php_container_name --format="{{.ID}}") phpunit
Hope this can help someone ...
I'm trying to install a PHP-based software package in a Red Hat 7 Amazon EC2 instance (ami-8cff51fb) that has had Apache 2.4.6 and PHP 5.4.16 installed on it using yum. The installation fails because it says a particular directory needs to be writable by the webserver with 0755 or 0775 permissions.
The directory in question has 0775 permissions with root:apache ownership. I have verified that the httpd process is being run by the apache user and that the apache user is a member of the apache group.
If I edit /etc/passwd to temporarily give the apache user a login shell and then su to that account, I am able to manually create files as the apache user within the directory using the touch command.
I took a look at the source code of the installer script and identified that it's failing because PHP's is_writable() function is returning false for the directory in question. I created a separate test PHP script to isolate and verify the behaviour I'm seeing:
<?php
$dir = '/var/www/html/limesurvey/tmp';
if (is_writable($dir)) {
echo $dir, ' is writable';
} else {
echo $dir, ' is NOT writable';
}
?>
This outputs the NOT writable message. If I change $dir above to be /tmp then it correctly outputs that /tmp is writable.
If I change the directory permissions to 0777 and/or change the ownership to apache:apache then PHP still reports that the directory isn't writable. I even tried creating a /test directory set up with the same permissions and ownership and my test script still reports it as not writable.
I'm really at a loss as to explain this behaviour, so any ideas would be welcome!
Thanks in advance.
The directory listing for /var/www/html/limesurvey is given below. The tmp and upload directories have 0775 permissions as per Lime Survey's installation instructions. test.php is my test script mentioned above.
[ec2-user#ip-xx-x-x-xxx limesurvey]$ pwd
/var/www/html/limesurvey
[ec2-user#ip-xx-x-x-xxx limesurvey]$ ls -al
total 80
drwxr-xr-x. 20 root apache 4096 Mar 30 11:25 .
drwxr-xr-x. 3 root root 23 Mar 25 14:41 ..
drwxr-xr-x. 2 root apache 38 Mar 10 12:56 admin
drwxr-xr-x. 16 root apache 4096 Mar 10 12:56 application
drwxr-xr-x. 3 root apache 4096 Mar 10 12:56 docs
drwxr-xr-x. 2 root apache 4096 Mar 10 12:56 fonts
drwxr-xr-x. 19 root apache 4096 Mar 10 12:56 framework
-rw-r--r--. 1 root apache 429 Mar 10 12:56 .gitattributes
-rw-r--r--. 1 root apache 399 Mar 10 12:56 .gitignore
-rw-r--r--. 1 root apache 296 Mar 10 12:56 .htaccess
drwxr-xr-x. 4 root apache 4096 Mar 10 12:56 images
-rw-r--r--. 1 root apache 6652 Mar 10 12:56 index.php
drwxr-xr-x. 5 root apache 39 Mar 10 12:56 installer
drwxr-xr-x. 89 root apache 4096 Mar 10 12:56 locale
drwxrwxr-x. 2 root apache 39 Mar 25 14:41 logs
drwxr-xr-x. 4 root apache 49 Mar 10 12:56 plugins
-rw-r--r--. 1 root apache 61 Mar 10 12:56 README
drwxr-xr-x. 4 root apache 4096 Mar 10 12:56 scripts
-rw-r--r--. 1 root apache 380 Mar 10 12:56 .scrutinizer.yml
drwxr-xr-x. 5 root apache 4096 Mar 10 12:56 styles
drwxr-xr-x. 5 root apache 4096 Mar 10 12:56 styles-public
drwxr-xr-x. 12 root apache 4096 Mar 10 12:56 templates
-rw-r--r--. 1 root apache 159 Mar 30 11:11 test.php
drwxr-xr-x. 3 root apache 20 Mar 10 12:56 themes
drwxr-xr-x. 26 root apache 4096 Mar 10 12:56 third_party
drwxrwxr-x. 5 root apache 80 Mar 26 13:45 tmp
drwxrwxr-x. 6 root apache 79 Mar 10 12:57 upload
Running namei -l /var/www/html/limesurvey/tmp gives:
[ec2-user#ip-x-x-x-xxx ~]$ namei -l /var/www/html/limesurvey/tmp
f: /var/www/html/limesurvey/tmp
drwxr-xr-x root root /
drwxr-xr-x root root var
drwxr-xr-x root root www
drwxr-xr-x root root html
drwxr-xr-x root apache limesurvey
drwxrwxr-x root apache tmp
After much head-scratching, it transpired that SELinux was preventing the directory from being written to. I found a good tutorial that explains what's going on. I was able to fix it by running this command:
sudo chcon -R -t httpd_sys_rw_content_t tmp
in CentOS 6 above should be SELinux enable enforcing
setenforce Permissive
check the status
sestatus
refer to https://wiki.centos.org/HowTos/SELinux
to write to a directory you also need execute permissions to the dirs above.
namei -l /var/www/html/limesurvey/tmp
should show which step you do not have the correct permissions for.
HTTPDUSER=`ps aux | grep -E '[a]pache|[h]ttpd|[_]www|[w]ww-data|[n]ginx' | grep -v root | head -1 | cut -d\ -f1`
sudo setfacl -R -m u:"$HTTPDUSER":rwX -m u:`whoami`:rwX tmp
sudo setfacl -dR -m u:"$HTTPDUSER":rwX -m u:`whoami`:rwX tmp
Taken directly from the Symfony2 installation guide, this solves the problem with cache write access sharing between Apache and CLI tools. This might work for your tmp directory as well.
is_writable by default only checks on the user, not the group.
So even if you group is matching and has permissions is_writable will return false.
To relax this check you will need to set
safe_mode_gid = On
in the PHP config or change the user accordingly.