DEV Community

Pradeep Kumar
Pradeep Kumar

Posted on

 

Run Laravel Dusk Tests via Gitlab (Self-hosted) CI/CD using DigitalOcean Docker

Step 1: Create DigitalOcean (DO) Droplet

This is a fairly simple step.
From DO dashboard > Click on Create > Droplets > Marketplace > Choose Docker.

Step 2: Install Gitlab Runner

  • Login to Droplet via SSH
  • Run the following to install gitlab runner
curl -L https://packages.gitlab.com/install/repositories/runner/gitlab-runner/script.deb.sh | sudo bash
Enter fullscreen mode Exit fullscreen mode
sudo apt-get install gitlab-runner
Enter fullscreen mode Exit fullscreen mode

Step 3: Register gitlab-runner

  • Login to your self-hosted Gitlab
  • Navigate to <gitlab-url>/admin/runners
  • Copy URL and Registration Token
  • Login to Docker install via ssh
  • Run the following command to register
sudo gitlab-runner register
Enter fullscreen mode Exit fullscreen mode

It will ask you the following questions:

Enter the GitLab instance URL (for example, https://gitlab.com/):
Enter the url you received from gitlab runner page
Enter fullscreen mode Exit fullscreen mode
Enter the registration token:
Enter the TOKEN you received from gitlab runner page
Enter fullscreen mode Exit fullscreen mode
Enter a description for the runner:
Enter anything to identify the runner
Enter fullscreen mode Exit fullscreen mode
Enter tags for the runner (comma-separated):
docker
Enter fullscreen mode Exit fullscreen mode

You can anything and this will be used later in gitlab-ci.yml file

Enter an executor:
docker
Enter fullscreen mode Exit fullscreen mode

Here you have to enter docker

Step 4: Configure gitlab-ci.yml

  • Create a gitlab-ci.yml file in the root folder of your repository.
  • Feel free to custom the content of gitlab-ci.yml, following file is for laravel dusk tests:
stages:
    - test
test:
  stage: test
  image: chilio/laravel-dusk-ci:php-7.3

  variables:
    MYSQL_ROOT_PASSWORD: root
    MYSQL_DATABASE: laravel
    DB_HOST: mysql
    DB_CONNECTION: mysql
    DB_DATABASE: laravel
    DB_USERNAME: root
    DB_PASSWORD: root

  services:
    - name: mysql:5.7

  script:
    - cp .env.example .env
    - composer install
    - configure-laravel
    - start-nginx-ci-project
    - php artisan key:generate
    - php artisan dusk

  artifacts:
    paths:
      - storage/logs
      - tests/Browser/screenshots
    expire_in: 7 days
    when: always

  tags:
    - docker
Enter fullscreen mode Exit fullscreen mode
  • Pay attention to tags, you must apply the tag that you have entered while registering the gitlab-runner.

Top comments (0)