Skip to content

Build and test the K-Box with Gitlab CI, GitHub Actions or other CI platform

License

Notifications You must be signed in to change notification settings

k-box/k-box-ci-pipeline-php

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

74 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Docker Image

Build and test K-Box with Gitlab CI (or any other CI platform)

PHP Docker images with the necessary dependencies to execute K-Box development and testing.

Docker images are inspired or based on edbizarro/gitlab-ci-pipeline-php images.

All versions comes with:

Available PHP versions

PHP version < 8.1 are not actively updated, old Docker tags still works.

Usage

k-box-ci-pipeline-php can be used on different continuous integration platforms that make use of docker images and also as build step for a multi-step docker image. You can also use it locally to work on the K-Box code without having php installed.

as your development environment

# use it to host your development environment
docker run -t --rm -v $(pwd):/var/www/html -p 8000:8000 klinktechnology/k-box-ci-pipeline-php:8.1 bash
# then execute the K-Box developer installation and run php artisan serve
# to keep this example short additional services, like MariaDB/MySQL, are not linked

on Gitlab CI

# reference it as the source of a Gitlab CI job
image: "klinktechnology/k-box-ci-pipeline-php:8.1"

on GitHub actions

# reference it as the container for a GitHub Action job
container:
  image: klinktechnology/k-box-ci-pipeline-php:8.1
  options: --user root 

Examples

Gitlab pipeline example

This simple example shows how we run the unit test of the K-Box on Gitlab CI.

# Variables
variables:
  MYSQL_ROOT_PASSWORD: root
  MYSQL_USER: dms
  MYSQL_PASSWORD: dms
  MYSQL_DATABASE: dms
  DB_HOST: mariadb

test:
  stage: test
  services:
    - mariadb:10.3
  image: klinktechnology/k-box-ci-pipeline-php:8.1
  script:
    - cp env.ci .env
    - mkdir ./storage/documents
    - composer install --prefer-dist
    - composer run install-video-cli
    - composer run install-content-cli
    - composer run install-language-cli
    - composer run install-streaming-client
    - php artisan view:clear
    - php artisan config:clear
    - php artisan route:clear
    - php artisan migrate --env=testing --force
    - php artisan db:seed --env=testing --force
    - yarn install --pure-lockfile
    - yarn run production
    - vendor/bin/phpunit

GitHub Actions workflow example

This simple example shows how to execute unit tests for a PHP project with a MariaDB linked database using GitHub Actions.

name: CI

on: 
  push:
    branches: 
      - "master"
  pull_request:
    types: [opened, synchronize, reopened]

jobs:
  phpunit:
    name: Tests PHP 8.1
    runs-on: ubuntu-latest
    container: 
      image: klinktechnology/k-box-ci-pipeline-php:8.1
      options: --user root 

    services:
      mariadb:
        image: mariadb:10
        env:
          MYSQL_DATABASE: example
          MYSQL_USER: example
          MYSQL_ROOT_PASSWORD: "example"
          MYSQL_PASSWORD: "example"
          MYSQL_INITDB_SKIP_TZINFO: 1
        ports:
          - 3306
        options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3

    steps:
    - uses: actions/checkout@v2
      with:
        fetch-depth: 1
    
    - name: Cache dependencies
      uses: actions/cache@v1
      with:
        path: ~/.composer/cache/files
        key: dependencies-php-8.1-composer-${{ hashFiles('composer.json') }}
      
    - name: Install dependencies
      run: |
        composer install --prefer-dist
        
    - name: Run Testsuite
      run: |
        vendor/bin/phpunit

For a more complex example see the CI workflow in the K-Box repository

Test

Docker images are tested on every build using Goss.

To run the test suite you need to build the Docker image first and then execute the goss command.

docker build -t k-box-pipeline:8.1 ./php/8.1/
docker run --rm -v $(pwd):/var/www/html k-box-pipeline:8.1 goss -g goss.yml v

License

Licensed under MIT.


Special thanks to Eduardo Bizarro and his gitlab-ci-pipeline-php images.