chilio / laravel-dusk-ci

Docker Test suite for Laravel Dusk in gitlab CI
MIT License
159 stars 51 forks source link

Folders permissions ? #25

Closed quienti closed 6 years ago

quienti commented 6 years ago

Hi,

Since few days, I have a problem with folders permissions...

failure-modules_activitylog_tests_resources_views_admin_deletepagetest_testdeletelinkwithpermission-0

I tried every command, permissions, I despair and I hope you can help me ! Even with the command "chmod -R 777" on folder storage not working...

Thank you

My gitlab-ci.yml :

  - build
  - test

variables:
  MYSQL_DATABASE: project_name
  MYSQL_ROOT_PASSWORD: secret

build:
  stage: build
  services:
    - mysql:5.7

  image: chilio/laravel-dusk-ci:stable
  script:
    # Install composer
    - composer install --prefer-dist --no-ansi --no-interaction --no-progress --no-scripts

    # Install Node dependencies.
    - npm install

    # Run npm build
    - npm run dev

  cache:
    key: ${CI_BUILD_REF_NAME}
    paths:
      - vendor
      - node_modules
      - public

test:
  stage: test
  cache:
    key: ${CI_BUILD_REF_NAME}
    paths:
      - vendor
      - node_modules
      - public
    policy: pull

  services:
    - mysql:5.7

  image: chilio/laravel-dusk-ci:stable
  script:
  # Remove php-xdebug
  - apt-get purge php-xdebug -y

  # Install jshint
  - npm install -g jshint

  # Update composer
  - composer update --no-scripts  

  # Copy over testing configuration.
  - cp .env.ci.testing .env

  # Folders permission
  - cd ${CI_PROJECT_DIR}
  - chmod -R 775 storage
  - chmod 775 bootstrap/cache
  - chown -R www-data ./

  # Generate an application key.
  - php artisan config:cache
  - php artisan key:generate

  # Run database migrations.
  - php artisan module:migrate

  # Run database seed
  - php artisan module:seed

  # Command to check chrome lib
  - chrome-system-check
  - sleep 10s

  # Command to start nginx
  - start-nginx-ci-project

  # run laravel tests
  - php vendor/bin/phpunit --no-coverage --colors=never --printer=Codedungeon\\PHPUnitPrettyResultPrinter\\Printer

  # run frontend tests
  - npm test

  # run phpcs
  - ./vendor/bin/phpcs -p --error-severity=1 --warning-severity=8 --extensions=php

  # run jshint
  - jshint --show-non-errors public/js/modules/.

  artifacts:
    paths:
      - ./storage/logs # for debugging
      - ./tests/Browser/console # for debugging
      - ./tests/Browser/screenshots # for debugging
    expire_in: 7 days
    when: always
chilio commented 6 years ago

Did you try php artisan cache:clear?

quienti commented 6 years ago

Yes, I tried too, same result.

Here my last try:

stages:
  - build
  - test

variables:
  MYSQL_DATABASE: project_name
  MYSQL_ROOT_PASSWORD: secret

build:
  stage: build
  services:
    - mysql:5.7

  image: chilio/laravel-dusk-ci:stable
  script:
    # Install composer
    - composer install --prefer-dist --no-ansi --no-interaction --no-progress --no-scripts

    # Install Node dependencies.
    - npm install

    # Run npm build
    - npm run dev

  cache:
    key: ${CI_BUILD_REF_NAME}
    paths:
      - vendor
      - node_modules
      - public

test:
  stage: test
  cache:
    key: ${CI_BUILD_REF_NAME}
    paths:
      - vendor
      - node_modules
      - public
    policy: pull

  services:
    - mysql:5.7

  image: chilio/laravel-dusk-ci:stable
  script:
  # Remove php-xdebug
  - apt-get purge php-xdebug -y

  # Install jshint
  - npm install -g jshint

  # Update composer
  - composer update --no-scripts  

  # Copy over testing configuration.
  - cp .env.ci.testing .env

  # Folders permission
  - cd ${CI_PROJECT_DIR}
  - chmod -R 775 storage
  - chmod 775 bootstrap/cache
  - chown -R www-data ./

  # Generate an application key.
  - php artisan cache:clear
  - php artisan config:cache
  - php artisan key:generate

  # Run database migrations.
  - php artisan module:migrate

  # Run database seed
  - php artisan module:seed

  # Command to check chrome lib
  - chrome-system-check
  - sleep 10s

  # Command to start nginx
  - start-nginx-ci-project

  # run laravel tests
  - php vendor/bin/phpunit --no-coverage --colors=never --printer=Codedungeon\\PHPUnitPrettyResultPrinter\\Printer

  # run frontend tests
  - npm test

  # run phpcs
  - ./vendor/bin/phpcs -p --error-severity=1 --warning-severity=8 --extensions=php

  # run jshint
  - jshint --show-non-errors public/js/modules/.

  artifacts:
    paths:
      - ./storage/logs # for debugging
      - ./tests/Browser/console # for debugging
      - ./tests/Browser/screenshots # for debugging
    expire_in: 7 days
    when: always
chilio commented 6 years ago

Did you try different configs with artifacts or cache paths in .gitlab-ci.yml earlier ? If so try to delete them.

At which point the error pops out ? Laravel trying to build cached views ?

You say since few days, so I assume it was working earlier. What has been changed from that moment?

Are you sure you have not included storage view files to your git? What is the result of `dir storage -l'?

quienti commented 6 years ago

Here my DuskTestCase:


namespace Tests;

use Closure;
use Facebook\WebDriver\Chrome\ChromeOptions;
use Facebook\WebDriver\Remote\DesiredCapabilities;
use Facebook\WebDriver\Remote\RemoteWebDriver;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\Cache;
use Laravel\Dusk\Browser;
use Laravel\Dusk\TestCase as BaseTestCase;
use Throwable;

abstract class DuskTestCase extends BaseTestCase
{
    use CreatesApplication;

    /**
     * Prepare for Dusk test execution.
     *
     * @beforeClass
     * @return void
     */
    public static function prepare()
    {
        static::startChromeDriver();
    }

    /**
     * Create the RemoteWebDriver instance.
     *
     * @return RemoteWebDriver
     */
    protected function driver()
    {
        $options = (new ChromeOptions)->addArguments([
            '--disable-gpu',
            '--headless',
            '--no-sandbox'
        ]);

        return RemoteWebDriver::create(
            'http://localhost:9515',
            DesiredCapabilities::chrome()->setCapability(ChromeOptions::CAPABILITY, $options)
        );
    }

    /**
     * Create a new browser instance.
     *
     * @param  Closure $callback
     * @return Browser|void
     * @throws Throwable
     */
    public function browse(Closure $callback)
    {
        parent::browse($callback);
        foreach (static::$browsers as $browser) {
            $browser->driver->manage()->deleteAllCookies();
        }

        sleep(2);
    }
}

And here, one of mine test :


namespace Modules\Player\Tests\Resources\Views\Frontend;

use Laravel\Dusk\Browser;
use Modules\Planet\Contracts\PlanetContract;
use Modules\Planet\Entities\Planet;
use Modules\Player\Tests\Api\MakeBan;
use Modules\Player\Tests\Api\MakePlayer;
use Tests\DuskTestCase;
use Throwable;

class LoginPageTest extends DuskTestCase
{
    use MakePlayer, MakeBan;

    /**
     * @var Planet
     */
    protected $planet;

    /**
     * Setup the test environment.
     *
     * @return void
     */
    public function setUp()
    {
        parent::setUp();
        $this->planet = app(PlanetContract::class);
    }

    /**
     * Clean up the testing environment before the next test.
     *
     * @return void
     */
    public function tearDown()
    {
        unset($this->planet);

        parent::tearDown();
    }

    /**
     * @test login link
     * @throws Throwable
     */
    public function testLoginLink()
    {
        $this->browse(function ($browser) {
            /** @var Browser $browser */
            $browser->visit('/')
                ->clickLink(__('page::frontend.login'))
                ->assertPathIs('/login')
                ->visit('/register')
                ->clickLink(__('player::frontend.auth.title'))
                ->assertPathIs('/login')
                ->visit('/forgot-password')
                ->clickLink(__('player::frontend.auth.title'))
                ->assertPathIs('/login');
        });
    }

    /**
     * @test login page
     * @throws Throwable
     */
    public function testLoginPage()
    {
        $this->browse(function ($browser) {
            /** @var Browser $browser */
            $browser->visit('/login')
                ->assertSee(strtoupper(__('player::frontend.auth.submit')))
                ->assertSee(__('player::frontend.home'))
                ->assertSee(__('player::frontend.register.title'))
                ->assertSee(__('player::frontend.auth.login'))
                ->assertSee(__('player::frontend.auth.password'))
                ->assertSee(__('player::frontend.forgot-password.title'))
                ->assertSee(__('player::frontend.auth.remember_me'));
        });
    }

    /**
     * @test login form
     * @throws Throwable
     */
    public function testLoginForm()
    {
        $player = $this->makePlayer(['password' => 'secret', 'is_active' => true, 'language' => 'en-US']);
        /** @var Planet $planet */
        $planet = $this->planet->inRandomOrder()->first();
        $player->attachPlanet($planet);

        $this->browse(function ($browser) use ($player) {
            /** @var Browser $browser */
            $browser->visit('/login')
                ->type('login', $player->login)
                ->type('password', 'secret')
                ->press('send')
                ->assertPathIs('/dashboard')
                ->assertAuthenticatedAs($player);
        });
    }

    /**
     * @test login form with player not activated
     * @throws Throwable
     */
    public function testLoginFormWithPlayerNotActivated()
    {
        $player = $this->makePlayer(['password' => 'secret']);

        $this->browse(function ($browser) use ($player) {
            /** @var Browser $browser */
            $browser->visit('/login')
                ->type('login', $player->login)
                ->type('password', 'secret')
                ->press('send')
                ->assertPathIs('/login')
                ->assertSourceHas(__(
                    'player::frontend.activation.error',
                    ['link' => $player->generateNewActivationLink($player->id, $player->email)]
                ));
        });
    }

    /**
     * @test login form with invalid data
     * @throws Throwable
     */
    public function testLoginFormWithInvalidData()
    {
        $this->browse(function ($browser) {
            /** @var Browser $browser */
            $browser->visit('/login')
                ->type('login', 'UnknownPlayerName')
                ->type('password', 'secret')
                ->press('send')
                ->assertPathIs('/login')
                ->assertSee(__('player::frontend.auth.login_fail'));
        });
    }

    /**
     * @test login form with player banned
     * @throws Throwable
     */
    public function testLoginFormWithPlayerBanned()
    {
        $player = $this->makePlayer(['password' => 'secret', 'is_active' => true]);
        $ban = $this->makeBan($player->id);

        $this->browse(function ($browser) use ($player, $ban) {
            /** @var Browser $browser */
            $browser->visit('/login')
                ->type('login', $player->login)
                ->type('password', 'secret')
                ->press('send')
                ->assertPathIs('/')
                ->assertSourceHas(
                    __('player::frontend.auth.ban', ['reason' => $ban->reason, 'expire_on' => $ban->expire_on])
                );
        });
    }

    /**
     * @test login form with player without planet
     * @throws Throwable
     */
    public function testLoginFormWithPlayerWithoutPlanet()
    {
        $player = $this->makePlayer(['password' => 'secret', 'is_active' => true, 'language' => 'en-US']);

        $this->browse(function ($browser) use ($player) {
            /** @var Browser $browser */
            $browser->visit('/login')
                ->type('login', $player->login)
                ->type('password', 'secret')
                ->press('send')
                ->assertPathIs('/galaxy/select');
        });
    }
}
chilio commented 6 years ago

You can try clear runner caches in gitlab ui, but since you said it never worked I doubt it helps. But always better give it a try :) So I suggest let's rework your .gitlab-ci.yml into one stage for the beginning, remove this line: - php artisan config:cache and remove all caching routines. My experience is that all caching mechanisms might become really tricky, especially when you are using multiple runners in multiple environments/hosts. So to eliminate potential problems let's do that.

I assume your project is running fine locally and your dusk tests locally are going green?

Could you create a clean Laravel 5.6 project and run dusk against it to make sure your gitlab infrastructure is working properly?

quienti commented 6 years ago

All right, I'll do this tomorrow, and I'll come back to you as soon as I finish the tests.

And yes, actually, locally (phpstorm / windows 10), everything works perfectly

chilio commented 6 years ago

👍 BTW I use the same dev platform, so we should sort things out finally...

quienti commented 6 years ago

Hello !

Your idea to rework my gitlab-ci.yml was a good idea ! Now, I do not have this error !

I post here my new gitlab-ci.yml for can help anyone else with similar problem !

Thank you for your help !

My gitlab-ci.yml today:


services:
  - mysql:5.7

variables:
  MYSQL_DATABASE: project_name
  MYSQL_ROOT_PASSWORD: secret

cache:
  paths:
    - vendor
    - node_modules
    - public

before_script:
  # Install composer
  - composer install --prefer-dist --no-ansi --no-interaction --no-progress --no-scripts

  # Update composer
  - composer update --no-scripts  

  # Install Node dependencies.
  - npm install

  # Run npm build
  - npm run dev

  # Remove php-xdebug
  - apt-get purge php-xdebug -y

  # Install jshint
  - npm install -g jshint

  # Copy over testing configuration.
  - cp .env.ci.testing .env

  # Folders permission
  - cd ${CI_PROJECT_DIR}
  - chmod -R 775 storage
  - chmod 775 bootstrap/cache
  - chown -R www-data ./

  # Generate an application key.
  - php artisan key:generate

  # Run database migrations.
  - php artisan module:migrate

  # Run database seed
  - php artisan module:seed

  # Command to check chrome lib
  - chrome-system-check
  - sleep 10s

  # Command to start nginx
  - start-nginx-ci-project

test:
  script:
  # run laravel tests
  - php vendor/bin/phpunit --no-coverage --colors=never --printer=Codedungeon\\PHPUnitPrettyResultPrinter\\Printer

  # run frontend tests
  - npm test

  # run phpcs
  - ./vendor/bin/phpcs -p --error-severity=1 --warning-severity=8 --extensions=php

  # run jshint
  - jshint --show-non-errors public/js/modules/.

  artifacts:
    paths:
      - ./storage/logs # for debugging
      - ./tests/Browser/console # for debugging
      - ./tests/Browser/screenshots # for debugging
    expire_in: 7 days
    when: always
chilio commented 6 years ago

I'm happy to hear that 👍