Skip to content
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
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
/rector.php export-ignore
/webpack.config.js export-ignore
/yarn.lock export-ignore
/demo export-ignore
/doc export-ignore
/tests export-ignore
/tools export-ignore
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ jobs:
- name: Setup castor
uses: castor-php/setup-castor@v0.1.0

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
Expand Down
1 change: 1 addition & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
__FILE__,
])
->notPath([
'demo',
'src/Bridge/EasyAdmin/src/JoliMediaEasyAdminBundle.php',
'src/Bridge/SonataAdmin/src/JoliMediaSonataAdminBundle.php',
'src/JoliMediaBundle.php',
Expand Down
2 changes: 2 additions & 0 deletions castor.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

use function Castor\import;
use function Castor\mount;

import(__DIR__ . '/.castor');
mount(__DIR__ . '/demo', 'demo');
99 changes: 99 additions & 0 deletions demo/.castor/context.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
<?php

namespace demo\docker;

use Castor\Attribute\AsContext;
use Castor\Context;
use Symfony\Component\Process\Process;

use function Castor\log;

#[AsContext(default: true)]
function create_default_context(): Context
{
$data = create_default_variables() + [
'project_name' => 'app',
'root_domain' => 'app.test',
'extra_domains' => [],
'php_version' => '8.4',
'docker_compose_files' => [
'docker-compose.yml',
'docker-compose.dev.yml',
],
'docker_compose_run_environment' => [],
'macos' => false,
'power_shell' => false,
// check if posix_geteuid is available, if not, use getmyuid (windows)
'user_id' => \function_exists('posix_geteuid') ? posix_geteuid() : getmyuid(),
'root_dir' => \dirname(__DIR__),
];

if (file_exists($data['root_dir'] . '/infrastructure/docker/docker-compose.override.yml')) {
$data['docker_compose_files'][] = 'docker-compose.override.yml';
}

$platform = strtolower(php_uname('s'));
if (str_contains($platform, 'darwin')) {
$data['macos'] = true;
} elseif (\in_array($platform, ['win32', 'win64', 'windows nt'])) {
$data['power_shell'] = true;
}

// 2³² - 1
if (false === $data['user_id'] || $data['user_id'] > 4294967295) {
$data['user_id'] = 1000;
}

if (0 === $data['user_id']) {
log('Running as root? Fallback to fake user id.', 'warning');
$data['user_id'] = 1000;
}

return new Context(
$data,
pty: Process::isPtySupported(),
environment: [
'BUILDKIT_PROGRESS' => 'plain',
]
);
}

#[AsContext(name: 'test')]
function create_test_context(): Context
{
$c = create_default_context();

return $c
->withData([
'docker_compose_run_environment' => [
'APP_ENV' => 'test',
],
])
;
}

#[AsContext(name: 'ci')]
function create_ci_context(): Context
{
$c = create_test_context();

return $c
->withData([
// override the default context here
])
->withData(
[
'docker_compose_files' => [
'docker-compose.yml',
// Usually, the following service is not be needed in the CI
'docker-compose.dev.yml',
// 'docker-compose.ci.yml',
],
],
recursive: false
)
->withEnvironment([
'COMPOSE_ANSI' => 'never',
])
;
}
17 changes: 17 additions & 0 deletions demo/.castor/database.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace demo\db;

use Castor\Attribute\AsTask;

use function Castor\context;
use function Castor\io;
use function demo\docker\docker_compose;

#[AsTask(description: 'Connect to the PostgreSQL database', name: 'client', namespace: 'db')]
function postgres_client(): void
{
io()->title('Connecting to the PostgreSQL database');

docker_compose(['exec', 'postgres', 'psql', '-U', 'app', 'app'], context()->toInteractive());
}
Loading