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 .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ composer.lock
# This ensures users get working assets on composer install without needing Node.js.
# The compile-assets workflow auto-commits changes on every push to keep them in sync.
.env
.claude/
20 changes: 15 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Then provision your infrastructure:
php artisan coolify:provision
```

Creates app + PostgreSQL + Dragonfly on Coolify and deploys. One command.
This creates app + PostgreSQL + Dragonfly on Coolify and deploys. The provision command automatically adds `COOLIFY_PROJECT_UUID` to your `.env` file, enabling all other commands to work without manual configuration.

## Documentation

Expand Down Expand Up @@ -146,17 +146,27 @@ Coolify::services()->all();

## Configuration

After running `coolify:provision`, your `.env` will contain:

```env
COOLIFY_URL=https://your-coolify.com
COOLIFY_TOKEN=your-api-token
COOLIFY_PROJECT_UUID=your-project-uuid # Added automatically by provision
```

The package automatically finds your application by matching your local git repository with applications in Coolify. No need to manually configure application UUIDs.

```php
// config/coolify.php
return [
'url' => env('COOLIFY_URL'),
'token' => env('COOLIFY_TOKEN'),
'path' => env('COOLIFY_PATH', 'coolify'), // Dashboard URL path
'project_uuid' => env('COOLIFY_PROJECT_UUID'), // Set by coolify:provision
'path' => env('COOLIFY_PATH', 'coolify'),

'docker' => [
'php_version' => '8.3',
'node_version' => '20',
'extensions' => ['pdo_pgsql', 'redis', 'pcntl', 'bcmath'],
'php_version' => '8.4',
'use_base_image' => true, // Fast builds with pre-built images
],
];
```
Expand Down
14 changes: 14 additions & 0 deletions config/coolify.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,20 @@

'github_app_uuid' => env('COOLIFY_GITHUB_APP_UUID'),

/*
|--------------------------------------------------------------------------
| Project UUID
|--------------------------------------------------------------------------
|
| The UUID of the Coolify project this application belongs to. This is
| set automatically by `coolify:provision`. All other resource UUIDs
| (applications, databases, etc.) are fetched from Coolify using this
| project as the scope.
|
*/

'project_uuid' => env('COOLIFY_PROJECT_UUID'),

/*
|--------------------------------------------------------------------------
| Dashboard Path
Expand Down

This file was deleted.

This file was deleted.

28 changes: 9 additions & 19 deletions docs/src/content/docs/commands/provision.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,25 +51,15 @@ php artisan coolify:provision \
5. Dragonfly cache (with `--with-dragonfly` or `--all`)
6. Environment variables linking all services

## Database Storage

Resource UUIDs are stored in the `coolify_resources` table:

| Column | Value |
|--------|-------|
| `name` | Application name |
| `server_uuid` | Selected server |
| `project_uuid` | Project UUID |
| `environment` | Environment name |
| `application_uuid` | Created application |
| `database_uuid` | PostgreSQL UUID |
| `redis_uuid` | Dragonfly/Redis UUID |
| `deploy_key_uuid` | SSH key UUID |
| `repository` | GitHub repository |
| `branch` | Git branch |
| `is_default` | true |

This record is marked as the default, so subsequent commands (`coolify:deploy`, `coolify:status`, etc.) use it automatically.
## Configuration Storage

After provisioning, `COOLIFY_PROJECT_UUID` is automatically added to your local `.env` file:

```bash
COOLIFY_PROJECT_UUID=abc123-def456-...
```

All other commands (`coolify:deploy`, `coolify:status`, etc.) automatically find your application by matching your local git repository with applications in Coolify. No manual UUID configuration is required.

## Generated Files

Expand Down
17 changes: 15 additions & 2 deletions docs/src/content/docs/getting-started/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ COOLIFY_URL=https://your-coolify.com # Coolify instance URL
COOLIFY_TOKEN=your-api-token # API token
```

After running `coolify:provision`, this is added automatically:

```bash
COOLIFY_PROJECT_UUID=your-project-uuid # Set by coolify:provision
```

Optional:

```bash
Expand All @@ -31,9 +37,16 @@ COOLIFY_NGINX_MAX_BODY_SIZE=35M
COOLIFY_PHP_MEMORY_LIMIT=256M
```

## Database Storage
## How Application Lookup Works

The package automatically finds your application by matching your local git repository URL with applications in Coolify. When you run commands like `coolify:deploy` or `coolify:status`:

1. It reads `COOLIFY_PROJECT_UUID` from your `.env`
2. Fetches all applications from Coolify
3. Matches your local `git remote get-url origin` with application git repositories
4. Uses the matching application for all operations

Resource configuration (UUIDs for applications, databases, etc.) is stored in the `coolify_resources` database table. This is created automatically when you run `php artisan coolify:install`.
This means no manual UUID configuration is needed after provisioning.

## Dashboard Authentication

Expand Down
40 changes: 15 additions & 25 deletions docs/src/content/docs/reference/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,15 @@ return [
// Log channel for Coolify events
'log_channel' => env('COOLIFY_LOG_CHANNEL', 'stack'),

// Project UUID (set by coolify:provision)
'project_uuid' => env('COOLIFY_PROJECT_UUID'),

// Docker configuration
'docker' => [
'php_version' => env('COOLIFY_PHP_VERSION', '8.4'),
'use_base_image' => env('COOLIFY_USE_BASE_IMAGE', true),
'auto_migrate' => env('COOLIFY_AUTO_MIGRATE', true),
'db_wait_timeout' => env('COOLIFY_DB_WAIT_TIMEOUT', 30),
'health_check_path' => env('COOLIFY_HEALTH_CHECK_PATH', '/up'),
'nginx' => [
'client_max_body_size' => env('COOLIFY_NGINX_MAX_BODY_SIZE', '35M'),
Expand All @@ -64,31 +70,15 @@ return [
];
```

## Resource Configuration
## How Application Lookup Works

Resource UUIDs (application, database, redis, etc.) are stored in the `coolify_resources` database table, not in config. Run the migration after installing:
Only `COOLIFY_PROJECT_UUID` is stored in your `.env` file. All other resource UUIDs are fetched from the Coolify API automatically.

```bash
php artisan migrate
```
When you run commands like `coolify:deploy` or `coolify:status`:

1. The package reads `COOLIFY_PROJECT_UUID` from your config
2. Fetches all applications from Coolify
3. Matches your local `git remote get-url origin` with application git repositories
4. Uses the matching application for operations

See [Database Schema](#database-schema) for the table structure.

## Database Schema

The `coolify_resources` table stores provisioned resource information:

| Column | Type | Description |
|--------|------|-------------|
| `name` | string | Unique resource name |
| `server_uuid` | string | Coolify server |
| `project_uuid` | string | Coolify project |
| `environment` | string | Environment (production, staging) |
| `deploy_key_uuid` | string | SSH key for git access |
| `repository` | string | GitHub repository (owner/repo) |
| `branch` | string | Git branch |
| `application_uuid` | string | Coolify application |
| `database_uuid` | string | PostgreSQL instance |
| `redis_uuid` | string | Dragonfly/Redis instance |
| `is_default` | boolean | Default resource for commands |
| `metadata` | json | Additional data |
This means no manual UUID configuration is needed after provisioning.
12 changes: 9 additions & 3 deletions docs/src/content/docs/reference/env-vars.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ description: All supported environment variables
| `COOLIFY_URL` | Coolify instance URL |
| `COOLIFY_TOKEN` | API authentication token |

## Auto-Generated

| Variable | Description |
|----------|-------------|
| `COOLIFY_PROJECT_UUID` | Set automatically by `coolify:provision` |

## Optional

| Variable | Default | Description |
Expand Down Expand Up @@ -51,8 +57,8 @@ When `COOLIFY_USE_BASE_IMAGE=false`:
- Build time: ~12 minutes
- Use this if you need custom PHP extensions

## Resource Configuration
## How Application Lookup Works

Resource UUIDs (application, database, server, etc.) are stored in the database, not environment variables. Run `coolify:provision` to create resources and store their UUIDs automatically.
Only `COOLIFY_PROJECT_UUID` is stored in your `.env`. All other resource UUIDs (applications, databases, etc.) are fetched from the Coolify API.

See [Configuration Reference](/laravel-coolify/reference/config/#database-schema) for the database schema.
When you run commands like `coolify:deploy`, the package automatically finds your application by matching your local git repository URL with applications in Coolify.
4 changes: 2 additions & 2 deletions src/Console/DeployCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
use Stumason\Coolify\Console\Concerns\StreamsDeploymentLogs;
use Stumason\Coolify\Contracts\ApplicationRepository;
use Stumason\Coolify\Contracts\DeploymentRepository;
use Stumason\Coolify\Coolify;
use Stumason\Coolify\CoolifyClient;
use Stumason\Coolify\Exceptions\CoolifyApiException;
use Stumason\Coolify\Models\CoolifyResource;
use Symfony\Component\Console\Attribute\AsCommand;

use function Laravel\Prompts\confirm;
Expand Down Expand Up @@ -52,7 +52,7 @@ public function handle(
return self::FAILURE;
}

$uuid = $this->option('uuid') ?? CoolifyResource::getDefault()?->application_uuid;
$uuid = $this->option('uuid') ?? Coolify::getApplicationUuid();

if (! $uuid) {
$this->components->error('No application configured. Run coolify:provision first or use --uuid option.');
Expand Down
4 changes: 2 additions & 2 deletions src/Console/LogsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
use Illuminate\Console\Command;
use Stumason\Coolify\Contracts\ApplicationRepository;
use Stumason\Coolify\Contracts\DeploymentRepository;
use Stumason\Coolify\Coolify;
use Stumason\Coolify\CoolifyClient;
use Stumason\Coolify\Exceptions\CoolifyApiException;
use Stumason\Coolify\Models\CoolifyResource;
use Symfony\Component\Console\Attribute\AsCommand;

#[AsCommand(name: 'coolify:logs')]
Expand Down Expand Up @@ -60,7 +60,7 @@ public function handle(
*/
protected function showApplicationLogs(ApplicationRepository $applications): int
{
$uuid = $this->option('uuid') ?? CoolifyResource::getDefault()?->application_uuid;
$uuid = $this->option('uuid') ?? Coolify::getApplicationUuid();

if (! $uuid) {
$this->components->error('No application configured. Run coolify:provision first or use --uuid option.');
Expand Down
55 changes: 36 additions & 19 deletions src/Console/ProvisionCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
use Stumason\Coolify\Contracts\ServerRepository;
use Stumason\Coolify\CoolifyClient;
use Stumason\Coolify\Exceptions\CoolifyApiException;
use Stumason\Coolify\Models\CoolifyResource;
use Symfony\Component\Console\Attribute\AsCommand;

use function Laravel\Prompts\confirm;
Expand Down Expand Up @@ -357,26 +356,11 @@ public function handle(
$this->components->twoColumnDetail(' '.$cacheType, $redisUuid);
}

// Save resource configuration to database
$resource = CoolifyResource::updateOrCreate(
['name' => $appName],
[
'server_uuid' => $serverUuid,
'project_uuid' => $projectUuid,
'environment' => $environment,
'deploy_key_uuid' => $deployKey['uuid'],
'repository' => $repoInfo['full_name'],
'branch' => $branch,
'application_uuid' => $appUuid,
'database_uuid' => $dbUuid,
'redis_uuid' => $redisUuid,
'webhook_secret' => $this->webhookSecret,
]
);
$resource->setAsDefault();
// Save project UUID to local .env
$this->updateEnvFile('COOLIFY_PROJECT_UUID', $projectUuid);

$this->newLine();
$this->line(' <fg=gray>Resource configuration saved to database</>');
$this->line(' <fg=gray>COOLIFY_PROJECT_UUID saved to .env</>');
$this->line(' <fg=gray>Database credentials set on Coolify application</>');

// ─────────────────────────────────────────────────────────────────
Expand Down Expand Up @@ -1571,4 +1555,37 @@ protected function checkDockerfile(): bool

return true;
}

/**
* Update or add an environment variable in the .env file.
*/
protected function updateEnvFile(string $key, string $value): void
{
$envPath = base_path('.env');

if (! File::exists($envPath)) {
File::put($envPath, "{$key}={$value}\n");

return;
}

$content = File::get($envPath);

// Escape key for regex pattern
$escapedKey = preg_quote($key, '/');

// Check if the key already exists (only uncommented lines)
if (preg_match("/^{$escapedKey}=.*/m", $content)) {
// Update existing key
$content = preg_replace("/^{$escapedKey}=.*/m", "{$key}={$value}", $content);
} else {
// Add new key at the end
$content = rtrim($content, "\n")."\n{$key}={$value}\n";
}

// Atomic write using temp file
$tempPath = $envPath.'.tmp';
File::put($tempPath, $content);
File::move($tempPath, $envPath);
}
}
Loading