bashy
bashy
1 year ago (1,001,970 XP)

@Mythos33 What does it say for the composer install command process or does it not show?

Mistral
Mistral
1 year ago (15,950 XP)

@Mythos33 I have got the same error. Maybe you have resolved this problem?

gwawr

This is because the ./vendor folder created during the before_script phase isn't carried through into the testing builds. I've yet to reach a satisfactory answer for this - but its currently looking like you need to do a composer install for each of the different build instances.

https://gitlab.com/gitlab-org/gitlab-ci-multi-runner/issues/336

gwawr

It's actually something else... the [[ ! -e /.dockerenv ]] && [[ ! -e /.dockerinit ]] && exit 0 line is causing the script to drop out early

gwawr

Issue is that /.dockerinit was removed in v1.11 so it always fails the test

http://stackoverflow.com/questions/23513045/how-to-check-if-a-process-is-running-inside-docker-container

https://github.com/docker/docker/pull/19490

Replacing that line with

[[ ! -e /.dockerenv ]] && exit 0

works just fine. Running php composer.phar install --no-plugins --no-scripts --dev then runs properly in the before_script section for every test build.

Mythos33

I'm sorry, but I totally forgot about this thread due to missing email notifications. ;-)

@gwawr 's solution works for me, thanks!

gandra404

I have just tried @Refringe setup and Gitlab build fails with similar error as @Mythos33. I have copied files from https://github.com/didikz/laravel-gitlab-ci into my project and push it into GitLab and build fails with error:

Running with gitlab-ci-multi-runner 1.9.0 (82714ae)
Using Docker executor with image php:5.6 ...
Pulling docker image mysql:5.6 ...
Starting service mysql:5.6 ...
Waiting for services to be up and running...
Pulling docker image php:5.6 ...
Running on runner-e11ae361-project-2277718-concurrent-0 via runner-e11ae361-machine-1483904340-0654037a-digital-ocean-4gb...
Cloning repository...
Cloning into '/builds/gandra404/ticketbeast'...
Checking out bacd084d as master...
$ bash .gitlab-ci.sh
$ php vendor/bin/phpunit --colors
Could not open input file: vendor/bin/phpunit
ERROR: Build failed: exit code 1

Here is repo url of the failing project: https://gitlab.com/gandra404/ticketbeast

and here are failiong builds: https://gitlab.com/gandra404/ticketbeast/pipelines/5717598

In case I made some new changes this is relevant commit: https://gitlab.com/gandra404/ticketbeast/commit/bacd084defd3a718b185c8de89ba7f9cabc1fa9b

@Mythos33, can you post your solution? I didn't get what have to change in order to work.

gandra404

Finally I manage to run sucesfully tests on GitLab. Here is the project: https://gitlab.com/gandra404/ticketbeast

This article helped me a lot: https://woohuiren.me/blog/how-to-laravel-testing-on-gitlab-ci-with-docker/

I have code on GitLab. Runner installed on my host(probably would work only with shared runner?) with docker as executor.

I have copied this files in my root: https://github.com/GIANTCRAB/gitlabby-dockerish-laravel

The only error I had at first try was "Unable to prepare route [api/user] for serialization. Uses Closure."(https://gitlab.com/gandra404/ticketbeast/builds/8359637) but seems that is known error: https://laracasts.com/discuss/channels/laravel/why-unable-to-prepare-route-for-serialization-uses-closure

So, at the moment I have commented line php artisan route:cache andbuild paased ok!

scuttlebyte

These scripts are wonderful, thank you all for sharing your knowledge.

I have everything up and running but being new to the CI and docker/container worlds, I feel compelled to ask if theres any way to expedite the build process by pre-compiling php and extensions and creating a container--something along those lines.

Or is there a benefit to using the official images I'm missing out on?

If it helps, I used forge to provision my production server, so if there's a forge-flavored container I'd be safe running my ci-against that would be swell.

bashy
bashy
1 year ago (1,001,970 XP)

@scuttlebyte This may help: https://github.com/WithSocial/docker-build If you look at the Dockerfile, it's pre-compiled like you wanted.

Giolf
Giolf
1 year ago (6,655 XP)

Hi all,

While i was reading this topic

i was thinking if it's possibile to have this kind of test functionality into the docker container:

 public function testBasicExample()
    {
        $this->visit('/')
             ->see('Laravel 5')
             ->dontSee('Rails');
    }

If not what i would need ? maybe a webserver that runs into the docker container ?

thank you

nanosolutions

@Mythos33 had same issue but it was random, endedup deviding the stages into build (composer) and then tests and that seem to work for me.

https://gist.github.com/cerw/d46c33297f1fc0f4f778b4e9d2ec4329

sshamsudheen

Hi,

I am following the same, however ended up with the permision denied error

$ ./vendor/bin/phpunit /bin/sh: eval: line 64: ./vendor/bin/phpunit: Permission denied ERROR: Job failed: exit code 2

I am using the image, image: zaherg/php-7.1-xdebug-alpine:latest

Also i am unable to run the command as sudo as well.

Can someone help on this.. thanks

davidnn

change

vendor/bin/phpunit to 

to

php ./vendor/phpunit/phpunit/phpunit

molerat

Cool. Thanks for all this great work. I am stuck in the database connection establishment.

What credentials should I actually put in? I mean, at that point, it doesn't even know my live servers IP, I don't feel comfortable putting the live credentials there and it will probably not have access anyway.

This is the error message:

Generating optimized autoload files
> Illuminate\Foundation\ComposerScripts::postAutoloadDump
> @php artisan package:discover

   Illuminate\Database\QueryException  : SQLSTATE[HY000] [2002] Connection refused (SQL: select * from information_schema.tables where table_schema = forge and table_name = settings)

  at /builds/securitas-fra/qs-tool/vendor/laravel/framework/src/Illuminate/Database/Connection.php: 664
  660:         // If an exception occurs when attempting to run a query, we'll format the error
  661:         // message to include the bindings with SQL, which will make this exception a
  662:         // lot more helpful to the developer instead of just the database's errors.
  663:         catch (Exception $e) {
  664:             throw new QueryException(
  665:                 $query, $this->prepareBindings($bindings), $e
  666:             );
  667:         }
  668: 
  669:         return $result;

  Exception trace:

  1   Illuminate\Foundation\Application::Illuminate\Foundation\{closure}(Object(App\Providers\SettingsServiceProvider))
      [internal] : 0

  2   PDOException::("SQLSTATE[HY000] [2002] Connection refused")
      /builds/securitas-fra/qs-tool/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php : 68

  Please use the argument -v to see more details.

I am new to this whole topic with CI / CD and docker so forgive me :)

Please sign in or create an account to participate in this conversation.