Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[1.x] Add Docker Compose Tests #721

Merged
merged 11 commits into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 82 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
name: Docker Compose Test

on:
push:
branches:
- master
- '*.x'
pull_request:

permissions:
contents: read

jobs:
tests:
runs-on: ubuntu-latest

strategy:
fail-fast: true
matrix:
include:
- php: '8.0'
laravel: 9
- php: '8.1'
laravel: 10
- php: '8.2'
laravel: 11
- php: '8.3'
laravel: 11

name: PHP ${{ matrix.php }} - L${{ matrix.laravel }}

steps:

- name: Checkout code
uses: actions/checkout@v4
with:
path: 'sail'

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: dom, curl, libxml, mbstring, zip, fileinfo
ini-values: error_reporting=E_ALL
tools: composer:v2
coverage: none

- name: Create a new laravel application
run: composer create-project laravel/laravel app "${{ matrix.laravel }}.x" --remove-vcs --no-interaction --prefer-dist

- name: Link Sail Repository
run: |
composer config minimum-stability dev
composer config repositories.sail path ../sail
composer require laravel/sail:* --dev -W
working-directory: app

- name: Install Sail into App
run: |
php artisan sail:install --php=${{ matrix.php }} --no-interaction
php artisan sail:publish --no-interaction
working-directory: app

- name: Remove Sail
run: composer remove laravel/sail --dev --no-interaction -W
working-directory: app

- name: Start Sail Container
run: ../sail/bin/sail up -d --wait
working-directory: app

- name: Run Migrations
run: ../sail/bin/sail artisan migrate --no-interaction
working-directory: app

- name: Run Tests in Sail Container
run: ../sail/bin/sail test
working-directory: app

- name: Stop Sail Container
run: ../sail/bin/sail down
working-directory: app
6 changes: 5 additions & 1 deletion src/Console/Concerns/InteractsWithDockerComposeServices.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,11 @@ protected function buildDockerCompose(array $services)
$compose['services']['selenium']['image'] = 'seleniarm/standalone-chromium';
}

file_put_contents($this->laravel->basePath('docker-compose.yml'), Yaml::dump($compose, Yaml::DUMP_OBJECT_AS_MAP));
$yaml = Yaml::dump($compose, Yaml::DUMP_OBJECT_AS_MAP);

$yaml = str_replace('{{PHP_VERSION}}', $this->option('php'), $yaml);

file_put_contents($this->laravel->basePath('docker-compose.yml'), $yaml);
}

/**
Expand Down
3 changes: 2 additions & 1 deletion src/Console/InstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ class InstallCommand extends Command
*/
protected $signature = 'sail:install
{--with= : The services that should be included in the installation}
{--devcontainer : Create a .devcontainer configuration directory}';
{--devcontainer : Create a .devcontainer configuration directory}
{--php=8.3 : The PHP version that should be used}';

/**
* The console command description.
Expand Down
4 changes: 2 additions & 2 deletions stubs/docker-compose.stub
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
services:
laravel.test:
build:
context: ./vendor/laravel/sail/runtimes/8.3
context: ./vendor/laravel/sail/runtimes/{{PHP_VERSION}}
dockerfile: Dockerfile
args:
WWWGROUP: '${WWWGROUP}'
image: sail-8.3/app
image: sail-{{PHP_VERSION}}/app
extra_hosts:
- 'host.docker.internal:host-gateway'
ports:
Expand Down