Actualiza toolkit operativo y documentación
This commit is contained in:
@@ -29,7 +29,9 @@ $args = @("-sS", "-i", "-X", $Method.ToUpper(), "-H", "Authorization: Bearer $en
|
||||
if ($PSBoundParameters.ContainsKey("BodyJson")) {
|
||||
try { $null = $BodyJson | ConvertFrom-Json } catch { throw "BodyJson is not valid JSON: $($_.Exception.Message)" }
|
||||
$tmpBody = [System.IO.Path]::GetTempFileName()
|
||||
Set-Content -LiteralPath $tmpBody -Value $BodyJson -NoNewline -Encoding utf8
|
||||
# Set-Content -Encoding utf8 mete BOM en PS 5.1 y GitHub responde
|
||||
# 400 "Problems parsing JSON". WriteAllText con UTF8Encoding($false) no lo hace.
|
||||
[System.IO.File]::WriteAllText($tmpBody, $BodyJson, (New-Object System.Text.UTF8Encoding($false)))
|
||||
$args += @("--data", "@$tmpBody", "-H", "Content-Type: application/json")
|
||||
}
|
||||
|
||||
@@ -44,7 +46,9 @@ try {
|
||||
$bodyBlock = if ($parts.Count -ge 2) { $parts[1] } else { "{}" }
|
||||
|
||||
$statusLine = ($headersBlock -split "`n" | Select-Object -First 1).Trim()
|
||||
if ($statusLine -notmatch " 20[04-9] ") {
|
||||
# 2xx completo: crear un repo responde 201 y la clase anterior ([04-9]) lo
|
||||
# trataba como error pese al éxito.
|
||||
if ($statusLine -notmatch " 20[0-9] ") {
|
||||
$snippet = $bodyBlock.Trim()
|
||||
if ($snippet.Length -gt 400) { $snippet = $snippet.Substring(0, 400) + "..." }
|
||||
throw "GitHub API HTTP error: $statusLine`nBody: $snippet"
|
||||
|
||||
@@ -0,0 +1,110 @@
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Create a Coolify application directly in the database (bypasses the 404 API and the web UI).
|
||||
|
||||
.DESCRIPTION
|
||||
For instances where POST /applications/* returns 404 and no UI credentials are available.
|
||||
Requires SSH access to the Proxmox host and the Coolify DB container.
|
||||
|
||||
Creates:
|
||||
1. applications row (Dockerfile build pack, GitHub source)
|
||||
2. application_settings row (prevents "disable_build_cache on null" crash)
|
||||
Then triggers a deploy via the API.
|
||||
|
||||
See deploy_skill/references/coolify-4.1.2-notes.md §8 for the full backstory.
|
||||
|
||||
.PARAMETER AppName
|
||||
Display name (also used in the generated UUID suffix).
|
||||
|
||||
.PARAMETER GitRepo
|
||||
GitHub repo in owner/repo format (e.g. urieljarethbusiness-cpu/agendamax).
|
||||
|
||||
.PARAMETER Fqdn
|
||||
Full domain (e.g. https://agendamax.urieljareth.org).
|
||||
|
||||
.PARAMETER Port
|
||||
Internal port the app listens on. Default: 3000.
|
||||
|
||||
.PARAMETER EnvironmentId
|
||||
Numeric ID of the Coolify environment. Find with:
|
||||
SELECT id FROM environments WHERE uuid = '<env_uuid>';
|
||||
|
||||
.PARAMETER GithubRepoId
|
||||
Numeric GitHub repo ID. Get from: GET https://api.github.com/repos/<owner>/<repo> → .id
|
||||
|
||||
.EXAMPLE
|
||||
. .\.env.local.ps1
|
||||
.\deploy_skill\scripts\New-CoolifyAppViaDB.ps1 `
|
||||
-AppName agendamax `
|
||||
-GitRepo urieljarethbusiness-cpu/agendamax `
|
||||
-Fqdn https://agendamax.urieljareth.org `
|
||||
-Port 3000 -EnvironmentId 9 -GithubRepoId 1314049704
|
||||
#>
|
||||
param(
|
||||
[Parameter(Mandatory)] [string]$AppName,
|
||||
[Parameter(Mandatory)] [string]$GitRepo,
|
||||
[Parameter(Mandatory)] [string]$Fqdn,
|
||||
[int]$Port = 3000,
|
||||
[Parameter(Mandatory)] [int]$EnvironmentId,
|
||||
[Parameter(Mandatory)] [int64]$GithubRepoId
|
||||
)
|
||||
|
||||
$ErrorActionPreference = "Stop"
|
||||
. "$PSScriptRoot\..\..\scripts\ProxmoxAgent.ps1"
|
||||
|
||||
# Generate a 24-char lowercase UUID (Coolify style)
|
||||
$uuid = -join ((1..24) | ForEach-Object { '{0:x}' -f (Get-Random -Max 16) })
|
||||
Write-Host "Generated UUID: $uuid" -ForegroundColor Cyan
|
||||
|
||||
# Build the SQL (single-line to avoid heredoc issues through SSH)
|
||||
$sql = @"
|
||||
INSERT INTO applications (uuid, name, git_repository, git_branch, git_commit_sha, build_pack, dockerfile_location, ports_exposes, health_check_path, health_check_port, health_check_host, health_check_method, health_check_return_code, health_check_scheme, health_check_interval, health_check_timeout, health_check_retries, health_check_start_period, health_check_enabled, limits_memory, limits_memory_swap, limits_memory_swappiness, limits_memory_reservation, limits_cpus, limits_cpu_shares, status, preview_url_template, fqdn, repository_project_id, source_type, source_id, destination_type, destination_id, environment_id, base_directory, static_image, created_at, updated_at) VALUES ('${uuid}', '${AppName}:main-${uuid}', '${GitRepo}', 'main', 'HEAD', 'dockerfile', '/Dockerfile', '${Port}', '/', '${Port}', 'localhost', 'GET', 200, 'http', 5, 5, 10, 5, false, '0', '0', 60, '0', '0', 1024, 'exited', '{{pr_id}}.{{domain}}', '${Fqdn}', ${GithubRepoId}, 'App\Models\GithubApp', 3, 'App\Models\StandaloneDocker', 0, ${EnvironmentId}, '/', 'nginx:alpine', NOW(), NOW()) RETURNING id;
|
||||
"@
|
||||
|
||||
# Write the SQL to a temp .sh script, scp it, execute it
|
||||
$tmpSh = [IO.Path]::GetTempFileName() + ".sh"
|
||||
@"
|
||||
pct exec 102 -- docker exec coolify-db psql -U coolify -d coolify -t -A -c "$($sql -replace '"', '\"' -replace "'", "'\''")"
|
||||
"@ | Set-Content -Path $tmpSh -Encoding ASCII
|
||||
|
||||
Write-Host "`n>>> Step 1: INSERT application row" -ForegroundColor Magenta
|
||||
$remoteSh = "/tmp/coolify_create_$(Get-Random).sh"
|
||||
scp -o BatchMode=yes -o StrictHostKeyChecking=no -i $env:PROXMOX_SSH_KEY $tmpSh "root@$($env:PROXMOX_HOST):$remoteSh" 2>&1 | Out-Null
|
||||
$appId = Invoke-ProxmoxSshCommand -Command "sh $remoteSh; rm $remoteSh"
|
||||
$appId = $appId.Trim()
|
||||
Remove-Item $tmpSh -ErrorAction SilentlyContinue
|
||||
Write-Host "Application ID: $appId" -ForegroundColor Green
|
||||
|
||||
if (-not $appId -or $appId -notmatch '^\d+$') {
|
||||
throw "INSERT failed or didn't return an ID. Output: $appId"
|
||||
}
|
||||
|
||||
# Step 2: application_settings
|
||||
Write-Host "`n>>> Step 2: INSERT application_settings row" -ForegroundColor Magenta
|
||||
$sqlSettings = @"
|
||||
INSERT INTO application_settings (application_id, is_static, is_git_submodules_enabled, is_git_lfs_enabled, is_auto_deploy_enabled, is_force_https_enabled, is_debug_enabled, is_preview_deployments_enabled, is_log_drain_enabled, is_gpu_enabled, is_swarm_only_worker_nodes, is_raw_compose_deployment_enabled, is_build_server_enabled, is_consistent_container_name_enabled, is_gzip_enabled, is_stripprefix_enabled, is_container_label_escape_enabled, is_container_label_readonly_enabled, disable_build_cache, is_spa, is_git_shallow_clone_enabled, is_pr_deployments_public_enabled, use_build_secrets, inject_build_args_to_dockerfile, docker_images_to_keep, created_at, updated_at) VALUES (${appId}, false, true, true, true, true, false, false, false, false, true, false, false, false, true, true, true, true, false, false, true, false, false, true, 2, NOW(), NOW());
|
||||
"@
|
||||
|
||||
$tmpSh2 = [IO.Path]::GetTempFileName() + ".sh"
|
||||
@"
|
||||
pct exec 102 -- docker exec coolify-db psql -U coolify -d coolify -c "$($sqlSettings -replace '"', '\"' -replace "'", "'\''")"
|
||||
"@ | Set-Content -Path $tmpSh2 -Encoding ASCII
|
||||
$remoteSh2 = "/tmp/coolify_settings_$(Get-Random).sh"
|
||||
scp -o BatchMode=yes -o StrictHostKeyChecking=no -i $env:PROXMOX_SSH_KEY $tmpSh2 "root@$($env:PROXMOX_HOST):$remoteSh2" 2>&1 | Out-Null
|
||||
Invoke-ProxmoxSshCommand -Command "sh $remoteSh2; rm $remoteSh2" | Write-Host
|
||||
Remove-Item $tmpSh2 -ErrorAction SilentlyContinue
|
||||
Write-Host "Settings created for app_id=$appId" -ForegroundColor Green
|
||||
|
||||
# Step 3: Deploy via API
|
||||
Write-Host "`n>>> Step 3: Trigger deploy" -ForegroundColor Magenta
|
||||
$headers = @{ Authorization = "Bearer $($env:COOLIFY_TOKEN)" }
|
||||
$deploy = Invoke-RestMethod "$($env:COOLIFY_API_URL)/deploy?uuid=${uuid}&force=true" -Headers $headers
|
||||
$deployUuid = $deploy.deployments[0].deployment_uuid
|
||||
Write-Host "Deployment queued: $deployUuid" -ForegroundColor Green
|
||||
|
||||
Write-Host "`n=== DONE ===" -ForegroundColor Green
|
||||
Write-Host "App UUID: $uuid"
|
||||
Write-Host "App ID: $appId"
|
||||
Write-Host "FQDN: $Fqdn"
|
||||
Write-Host "Deploy: $deployUuid"
|
||||
Write-Host "Monitor: GET $($env:COOLIFY_API_URL)/deployments/$deployUuid"
|
||||
@@ -213,13 +213,13 @@ Write-Host "Using server: $serverUuid" -ForegroundColor Cyan
|
||||
|
||||
if ($ServiceUuid) {
|
||||
Write-Host "Updating existing service: $ServiceUuid" -ForegroundColor Cyan
|
||||
# PATCH /services/{uuid} rechaza (422 "This field is not allowed")
|
||||
# server_uuid/project_uuid/environment_name — solo se envian name,
|
||||
# docker_compose_raw y urls. Verificado contra la instancia el 2026-09-02.
|
||||
$patch = [ordered]@{
|
||||
name = $AppName
|
||||
docker_compose_raw = $composeRaw
|
||||
urls = $urlsList
|
||||
project_uuid = $proj.uuid
|
||||
environment_name = $env.name
|
||||
server_uuid = $serverUuid
|
||||
name = $AppName
|
||||
docker_compose_raw = [Convert]::ToBase64String([Text.Encoding]::UTF8.GetBytes($composeRaw))
|
||||
urls = $urlsList
|
||||
}
|
||||
if (-not (Confirm-Step "PATCH /services/$ServiceUuid (compose=$($composePath), urls=$($urlsList.Count), fqdn=$Fqdn)")) {
|
||||
throw "Aborted by user."
|
||||
@@ -227,13 +227,18 @@ if ($ServiceUuid) {
|
||||
$result = & $coolifyApi -Method PATCH -Path "/services/$ServiceUuid" -BodyJson ($patch | ConvertTo-Json -Depth 6) -Raw -ErrorAction Stop
|
||||
$svcUuid = $ServiceUuid
|
||||
} else {
|
||||
# Verified against Coolify 4.x on 2026-08-24:
|
||||
# - Do NOT send `type` together with `docker_compose_raw`. The API answers
|
||||
# 422 "You cannot provide both service type and docker_compose_raw."
|
||||
# `type` is only for one-click services from the library.
|
||||
# - `docker_compose_raw` MUST be base64. Sent raw it answers
|
||||
# 422 "The docker_compose_raw should be base64 encoded."
|
||||
$createBody = [ordered]@{
|
||||
type = "one-click-service" # custom service; Coolify accepts any non-empty string here
|
||||
name = $AppName
|
||||
project_uuid = $proj.uuid
|
||||
environment_name = $env.name
|
||||
server_uuid = $serverUuid
|
||||
docker_compose_raw = $composeRaw
|
||||
docker_compose_raw = [Convert]::ToBase64String([Text.Encoding]::UTF8.GetBytes($composeRaw))
|
||||
urls = $urlsList
|
||||
instant_deploy = [bool]$InstantDeploy
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user