Merge pull request #1013 from coollabsio/ijpatricio-wip-4
Prepare GH Action and Pest
This commit is contained in:
commit
e129e8b347
@ -8,6 +8,7 @@ GROUPID=
|
|||||||
############################################################################################################
|
############################################################################################################
|
||||||
|
|
||||||
APP_NAME=Laravel
|
APP_NAME=Laravel
|
||||||
|
APP_SERVICE=php
|
||||||
APP_ENV=local
|
APP_ENV=local
|
||||||
APP_KEY=
|
APP_KEY=
|
||||||
APP_DEBUG=true
|
APP_DEBUG=true
|
||||||
|
45
.github/workflows/docker-image.yml
vendored
45
.github/workflows/docker-image.yml
vendored
@ -7,23 +7,34 @@ on:
|
|||||||
branches: [ "*" ]
|
branches: [ "*" ]
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
|
|
||||||
build:
|
build:
|
||||||
|
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
- name: Build the Docker image
|
- name: Cache Docker layers
|
||||||
run: |
|
uses: actions/cache@v2
|
||||||
docker run --rm -u "$(id -u):$(id -g)" \
|
with:
|
||||||
-v "$(pwd):/app" \
|
path: |
|
||||||
-w /app composer:2 \
|
/usr/local/share/ca-certificates
|
||||||
composer install --ignore-platform-reqs
|
/var/cache/apt/archives
|
||||||
TAG=$(date +%s) ./vendor/bin/sail build
|
/var/lib/apt/lists
|
||||||
TAG=$(date +%s) ./vendor/bin/sail up -d
|
~/.cache
|
||||||
sleep 1
|
key: ${{ runner.os }}-docker-${{ hashFiles('**/Dockerfile') }}
|
||||||
./vendor/bin/sail ps
|
restore-keys: |
|
||||||
# Now to create .env
|
${{ runner.os }}-docker-
|
||||||
# Await database is created
|
- name: Build the Docker image
|
||||||
# pest
|
run: |
|
||||||
|
cp .env.example .env
|
||||||
|
docker run --rm -u "$(id -u):$(id -g)" \
|
||||||
|
-v "$(pwd):/app" \
|
||||||
|
-w /app composer:2 \
|
||||||
|
composer install --ignore-platform-reqs
|
||||||
|
./vendor/bin/sail build
|
||||||
|
- name: Start the stack
|
||||||
|
run: |
|
||||||
|
./vendor/bin/sail up -d
|
||||||
|
./vendor/bin/sail artisan key:generate
|
||||||
|
./vendor/bin/sail artisan migrate:fresh --seed
|
||||||
|
- name: Test (missing E2E tests)
|
||||||
|
run: |
|
||||||
|
./vendor/bin/sail artisan test
|
||||||
|
@ -51,17 +51,21 @@ class User extends Authenticatable
|
|||||||
$model->uuid = (string) new Cuid2(7);
|
$model->uuid = (string) new Cuid2(7);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public function teams()
|
public function teams()
|
||||||
{
|
{
|
||||||
return $this->belongsToMany(Team::class);
|
return $this->belongsToMany(Team::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function currentTeam()
|
public function currentTeam()
|
||||||
{
|
{
|
||||||
return $this->belongsTo(Team::class);
|
return $this->belongsTo(Team::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function otherTeams()
|
public function otherTeams()
|
||||||
{
|
{
|
||||||
$team_id = session('currentTeam')->id;
|
$team_id = data_get(session('currentTeam'), 'id');
|
||||||
|
|
||||||
return auth()->user()->teams->filter(function ($team) use ($team_id) {
|
return auth()->user()->teams->filter(function ($team) use ($team_id) {
|
||||||
return $team->id != $team_id;
|
return $team->id != $team_id;
|
||||||
});
|
});
|
||||||
|
@ -19,6 +19,7 @@ class UserFactory extends Factory
|
|||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'name' => fake()->name(),
|
'name' => fake()->name(),
|
||||||
|
'uuid' => Str::uuid(),
|
||||||
'email' => fake()->unique()->safeEmail(),
|
'email' => fake()->unique()->safeEmail(),
|
||||||
'email_verified_at' => now(),
|
'email_verified_at' => now(),
|
||||||
'password' => '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', // password
|
'password' => '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', // password
|
||||||
|
@ -10,13 +10,11 @@ class UserSeeder extends Seeder
|
|||||||
public function run(): void
|
public function run(): void
|
||||||
{
|
{
|
||||||
User::factory()->create([
|
User::factory()->create([
|
||||||
'id' => 1,
|
|
||||||
'name' => 'Root User',
|
'name' => 'Root User',
|
||||||
'email' => 'test@example.com',
|
'email' => 'test@example.com',
|
||||||
'is_root_user' => true,
|
'is_root_user' => true,
|
||||||
]);
|
]);
|
||||||
User::factory()->create([
|
User::factory()->create([
|
||||||
'id' => 2,
|
|
||||||
'name' => 'Normal User',
|
'name' => 'Normal User',
|
||||||
'email' => 'test2@example.com',
|
'email' => 'test2@example.com',
|
||||||
]);
|
]);
|
||||||
|
@ -1,4 +1,16 @@
|
|||||||
version: '3.8'
|
version: '3.8'
|
||||||
|
|
||||||
|
x-testing-host: &testing-host-base
|
||||||
|
image: coolify-testing-host
|
||||||
|
build:
|
||||||
|
dockerfile: Dockerfile
|
||||||
|
context: ./docker/testing-host
|
||||||
|
volumes:
|
||||||
|
- /var/run/docker.sock:/var/run/docker.sock
|
||||||
|
- ./docker/testing-host/supervisord.conf:/etc/supervisor/conf.d/supervisord.conf
|
||||||
|
networks:
|
||||||
|
- coolify
|
||||||
|
|
||||||
services:
|
services:
|
||||||
php:
|
php:
|
||||||
image: "coolify:${TAG:-4}"
|
image: "coolify:${TAG:-4}"
|
||||||
@ -19,6 +31,9 @@ services:
|
|||||||
- .:/var/www/html
|
- .:/var/www/html
|
||||||
networks:
|
networks:
|
||||||
- coolify
|
- coolify
|
||||||
|
depends_on:
|
||||||
|
postgres:
|
||||||
|
condition: service_healthy
|
||||||
postgres:
|
postgres:
|
||||||
image: postgres:15-alpine
|
image: postgres:15-alpine
|
||||||
ports:
|
ports:
|
||||||
@ -36,34 +51,18 @@ services:
|
|||||||
test:
|
test:
|
||||||
[
|
[
|
||||||
"CMD-SHELL",
|
"CMD-SHELL",
|
||||||
"pg_isready -U $$DB_USERNAME",
|
"pg_isready -U coolify",
|
||||||
"-d",
|
"-d",
|
||||||
"db_prod"
|
"coolify"
|
||||||
]
|
]
|
||||||
retries: 3
|
retries: 5
|
||||||
timeout: 5s
|
timeout: 10s
|
||||||
testing-host:
|
testing-host:
|
||||||
|
<<: *testing-host-base
|
||||||
container_name: coolify-testing-host
|
container_name: coolify-testing-host
|
||||||
image: coolify-testing-host
|
|
||||||
build:
|
|
||||||
dockerfile: Dockerfile
|
|
||||||
context: ./docker/testing-host
|
|
||||||
volumes:
|
|
||||||
- /var/run/docker.sock:/var/run/docker.sock
|
|
||||||
- ./docker/testing-host/supervisord.conf:/etc/supervisor/conf.d/supervisord.conf
|
|
||||||
networks:
|
|
||||||
- coolify
|
|
||||||
testing-host2:
|
testing-host2:
|
||||||
|
<<: *testing-host-base
|
||||||
container_name: coolify-testing-host-2
|
container_name: coolify-testing-host-2
|
||||||
image: coolify-testing-host
|
|
||||||
build:
|
|
||||||
dockerfile: Dockerfile
|
|
||||||
context: ./docker/testing-host
|
|
||||||
volumes:
|
|
||||||
- /var/run/docker.sock:/var/run/docker.sock
|
|
||||||
- ./docker/testing-host/supervisord.conf:/etc/supervisor/conf.d/supervisord.conf
|
|
||||||
networks:
|
|
||||||
- coolify
|
|
||||||
|
|
||||||
volumes:
|
volumes:
|
||||||
db-coolify:
|
db-coolify:
|
||||||
|
@ -13,18 +13,20 @@ stdout_logfile_maxbytes=0
|
|||||||
stderr_logfile=/dev/stderr
|
stderr_logfile=/dev/stderr
|
||||||
stderr_logfile_maxbytes=0
|
stderr_logfile_maxbytes=0
|
||||||
|
|
||||||
[program:laravel-worker]
|
# Run workers by running manually `sail artisan queue:listen`
|
||||||
process_name=%(program_name)s_%(process_num)02d
|
#
|
||||||
command=/usr/bin/php -d variables_order=EGPCS /var/www/html/artisan queue:listen
|
#[program:laravel-worker]
|
||||||
user=sail
|
#process_name=%(program_name)s_%(process_num)02d
|
||||||
autostart=true
|
#command=/usr/bin/php -d variables_order=EGPCS /var/www/html/artisan queue:listen
|
||||||
autorestart=true
|
#user=sail
|
||||||
stopasgroup=true
|
#autostart=true
|
||||||
killasgroup=true
|
#autorestart=true
|
||||||
numprocs=8
|
#stopasgroup=true
|
||||||
redirect_stderr=true
|
#killasgroup=true
|
||||||
stdout_logfile=/var/www/html/storage/logs/worker.log
|
#numprocs=8
|
||||||
stopwaitsecs=3600
|
#redirect_stderr=true
|
||||||
|
#stdout_logfile=/var/www/html/storage/logs/worker.log
|
||||||
|
#stopwaitsecs=3600
|
||||||
|
|
||||||
[program:laravel-schedule]
|
[program:laravel-schedule]
|
||||||
process_name=%(program_name)s_%(process_num)02d
|
process_name=%(program_name)s_%(process_num)02d
|
||||||
|
51
run
Executable file
51
run
Executable file
@ -0,0 +1,51 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
# Inspired on https://github.com/adriancooney/Taskfile
|
||||||
|
#
|
||||||
|
# Install an alias, to be able to simply execute `run`
|
||||||
|
# echo 'alias run=./run' >> ~/.aliases
|
||||||
|
#
|
||||||
|
|
||||||
|
# Define Docker Compose command prefix...
|
||||||
|
set -e
|
||||||
|
|
||||||
|
docker compose &> /dev/null
|
||||||
|
if [ $? == 0 ]; then
|
||||||
|
DOCKER_COMPOSE="docker compose"
|
||||||
|
else
|
||||||
|
DOCKER_COMPOSE="docker-compose"
|
||||||
|
fi
|
||||||
|
|
||||||
|
SAIL=./vendor/bin/sail
|
||||||
|
export WWWUSER=${WWWUSER:-$UID}
|
||||||
|
export WWWGROUP=${WWWGROUP:-$(id -g)}
|
||||||
|
|
||||||
|
function help {
|
||||||
|
echo "$0 <task> <args>"
|
||||||
|
echo "Tasks:"
|
||||||
|
compgen -A function | cat -n
|
||||||
|
}
|
||||||
|
|
||||||
|
function default {
|
||||||
|
help
|
||||||
|
}
|
||||||
|
|
||||||
|
function wait_db {
|
||||||
|
TRIES=0
|
||||||
|
MAX_TRIES=15
|
||||||
|
WAIT=4
|
||||||
|
|
||||||
|
until $DOCKER_COMPOSE exec postgres bash -c "psql -U coolify -d coolify -t -q -c \"SELECT datname FROM pg_database;\" " | grep coolify
|
||||||
|
do
|
||||||
|
((TRIES++))
|
||||||
|
if [ $TRIES -gt $MAX_TRIES ]; then
|
||||||
|
echo "Database is not ready after $MAX_TRIES tries. Exiting."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
echo "Database is not ready yet. Attempt $TRIES/$MAX_TRIES. Waiting $WAIT seconds before next try..."
|
||||||
|
sleep $WAIT
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
TIMEFORMAT="Task completed in %3lR"
|
||||||
|
time "${@:-default}"
|
@ -1,11 +1,29 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use App\Models\User;
|
||||||
use App\Models\Server;
|
use App\Models\Server;
|
||||||
|
use Database\Seeders\DatabaseSeeder;
|
||||||
use Tests\Support\Output;
|
use Tests\Support\Output;
|
||||||
|
use Illuminate\Foundation\Testing\DatabaseMigrations;
|
||||||
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||||
|
|
||||||
|
uses(RefreshDatabase::class);
|
||||||
|
uses(DatabaseMigrations::class);
|
||||||
|
|
||||||
|
beforeEach(function () {
|
||||||
|
$this->seed(DatabaseSeeder::class);
|
||||||
|
});
|
||||||
|
|
||||||
it('starts a docker container correctly', function () {
|
it('starts a docker container correctly', function () {
|
||||||
|
|
||||||
|
test()->actingAs(User::factory([
|
||||||
|
'uuid' => Str::uuid(),
|
||||||
|
'email' => Str::uuid().'@example.com',
|
||||||
|
])->create());
|
||||||
|
|
||||||
$coolifyNamePrefix = 'coolify_test_';
|
$coolifyNamePrefix = 'coolify_test_';
|
||||||
|
|
||||||
|
|
||||||
$format = '{"ID":"{{ .ID }}", "Image": "{{ .Image }}", "Names":"{{ .Names }}"}';
|
$format = '{"ID":"{{ .ID }}", "Image": "{{ .Image }}", "Names":"{{ .Names }}"}';
|
||||||
$areThereCoolifyTestContainers = "docker ps --filter=\"name={$coolifyNamePrefix}*\" --format '{$format}' ";
|
$areThereCoolifyTestContainers = "docker ps --filter=\"name={$coolifyNamePrefix}*\" --format '{$format}' ";
|
||||||
|
|
||||||
@ -13,6 +31,19 @@ it('starts a docker container correctly', function () {
|
|||||||
$containerName = 'coolify_test_' . now()->format('Ymd_his');
|
$containerName = 'coolify_test_' . now()->format('Ymd_his');
|
||||||
$host = Server::where('name', 'testing-local-docker-container')->first();
|
$host = Server::where('name', 'testing-local-docker-container')->first();
|
||||||
|
|
||||||
|
// Stop testing containers
|
||||||
|
$activity = remoteProcess([
|
||||||
|
"docker stop $(docker ps --filter='name={$coolifyNamePrefix}*' -aq)",
|
||||||
|
"docker rm $(docker ps --filter='name={$coolifyNamePrefix}*' -aq)",
|
||||||
|
], $host);
|
||||||
|
|
||||||
|
throw_if(
|
||||||
|
$activity->getExtraProperty('exitCode') !== 0,
|
||||||
|
new RuntimeException($activity->description),
|
||||||
|
);
|
||||||
|
|
||||||
|
expect($activity->getExtraProperty('exitCode'))->toBe(0);
|
||||||
|
|
||||||
// Assert there's no containers start with coolify_test_*
|
// Assert there's no containers start with coolify_test_*
|
||||||
$activity = remoteProcess([$areThereCoolifyTestContainers], $host);
|
$activity = remoteProcess([$areThereCoolifyTestContainers], $host);
|
||||||
$containers = formatDockerCmdOutputToJson($activity->getExtraProperty('stdout'));
|
$containers = formatDockerCmdOutputToJson($activity->getExtraProperty('stdout'));
|
||||||
@ -28,6 +59,9 @@ it('starts a docker container correctly', function () {
|
|||||||
expect($containers->where('Names', $containerName)->count())->toBe(1);
|
expect($containers->where('Names', $containerName)->count())->toBe(1);
|
||||||
|
|
||||||
// Stop testing containers
|
// Stop testing containers
|
||||||
$activity = remoteProcess(["docker stop $(docker ps --filter='name={$coolifyNamePrefix}*' -q)"], $host);
|
$activity = remoteProcess([
|
||||||
|
"docker stop $(docker ps --filter='name={$coolifyNamePrefix}*' -aq)",
|
||||||
|
"docker rm $(docker ps --filter='name={$coolifyNamePrefix}*' -aq)",
|
||||||
|
], $host);
|
||||||
expect($activity->getExtraProperty('exitCode'))->toBe(0);
|
expect($activity->getExtraProperty('exitCode'))->toBe(0);
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user