mirror of
https://github.com/Dvorinka/Containr.git
synced 2026-10-28 07:41:27 +00:00
* feat(templates): git compose import, six stack seeds, empty-default vars
- POST /templates/import/git fetches a compose file from any git remote
(clone URL, ssh, owner/repo via connected providers — private repos
included), ref selects branch or commit. Path defaults through
compose.yaml/yml then docker-compose.yml/yaml. Reuses the build-on-node
checkout machinery; repo-relative paths are containment-checked.
- CLI `templates import-git <repo> [path] [--ref]`, MCP
containr_templates_import_git, OpenAPI entry, and a paste/git toggle
in the template import dialog.
- {{VAR:-}} with an empty default now resolves instead of reporting the
var missing — matches shell :- semantics.
- SeedTemplates gains six official graph stacks — n8n (pg+redis+worker),
Gitea, Nextcloud, Vaultwarden, Umami, Immich — wired with
{{service.*}} refs and {{secret}} credentials; no hardcoded passwords.
- TestSeedTemplatesResolveCleanly parses, topo-sorts, validates, and
resolves every seeded graph — catalog drift can't merge silently.
- templates/n8n.md compose block had invalid YAML (mixed depends_on
list/map) — fixed so the documented stack actually parses.
Verified live: import/git on a dumb-HTTP repo returns the converted
graph (db image → managed postgresql), path/ref/traversal/unauth edges
return clean errors, tpl-n8n plan resolves with zero unresolved vars.
Generated with [Devin](https://devin.ai)
Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
* ci: pre-pull compose-smoke images via gcr mirror
Anonymous Docker Hub pulls rate-limit shared CI egress IPs — the compose
boot smoke flaked on traefik:pull. postgres/traefik are library/* images
served by mirror.gcr.io without auth; compose reuses the retagged local
images, falling back to a normal pull when the mirror misses.
Generated with [Devin](https://devin.ai)
Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
* ci: route docker.io through gcr mirror for compose smoke
Pull-time pre-pulls don't cover BuildKit's base-image metadata lookups
(node:22-alpine, nginx:alpine, golang:1.26-alpine all 429). Daemon-level
registry-mirrors covers pulls and resolution in one move.
Generated with [Devin](https://devin.ai)
Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
* ci: mirror docker.io in buildx for image publish job
Generated with [Devin](https://devin.ai)
Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
* ci: route smoke pulls/builds through mirror.gcr.io via compose overlay
daemon.json registry-mirrors isn't honored by the runner's containerd
image store. Qualify refs directly: ARG-parameterized Dockerfile FROMs
(defaults unchanged) plus a CI-only compose overlay that points image
pulls and build args at mirror.gcr.io.
Generated with [Devin](https://devin.ai)
Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
---------
Co-authored-by: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
106 lines
2.9 KiB
Go
106 lines
2.9 KiB
Go
package api
|
|
|
|
import (
|
|
"encoding/json"
|
|
"testing"
|
|
)
|
|
|
|
func TestNormalizeTemplateServiceType(t *testing.T) {
|
|
valid := []string{"web", "worker", "database", "cron"}
|
|
for _, value := range valid {
|
|
got, err := normalizeTemplateServiceType(value)
|
|
if err != nil {
|
|
t.Fatalf("normalizeTemplateServiceType(%q) returned error: %v", value, err)
|
|
}
|
|
if got != value {
|
|
t.Fatalf("normalizeTemplateServiceType(%q) = %q, want %q", value, got, value)
|
|
}
|
|
}
|
|
|
|
_, err := normalizeTemplateServiceType("unsupported")
|
|
if err == nil {
|
|
t.Fatalf("expected unsupported template type to return error")
|
|
}
|
|
}
|
|
|
|
func TestMergeTemplateVariables(t *testing.T) {
|
|
env, secretKeys, missing := mergeTemplateVariables(
|
|
map[string]string{
|
|
"DEFAULT_ONE": "a",
|
|
"DEFAULT_TWO": "b",
|
|
},
|
|
[]TemplateVariable{
|
|
{
|
|
Key: "REQ",
|
|
Default: "",
|
|
Required: true,
|
|
Secret: true,
|
|
},
|
|
{
|
|
Key: "OPTIONAL",
|
|
Default: "fallback",
|
|
Required: false,
|
|
Secret: false,
|
|
},
|
|
},
|
|
map[string]string{
|
|
"REQ": "provided",
|
|
"EXTRA_KEY": "custom",
|
|
},
|
|
)
|
|
|
|
if len(missing) != 0 {
|
|
t.Fatalf("expected no missing required vars, got %v", missing)
|
|
}
|
|
if env["REQ"] != "provided" {
|
|
t.Fatalf("expected REQ=provided, got %q", env["REQ"])
|
|
}
|
|
if env["OPTIONAL"] != "fallback" {
|
|
t.Fatalf("expected OPTIONAL=fallback, got %q", env["OPTIONAL"])
|
|
}
|
|
if env["EXTRA_KEY"] != "custom" {
|
|
t.Fatalf("expected EXTRA_KEY=custom, got %q", env["EXTRA_KEY"])
|
|
}
|
|
if !secretKeys["REQ"] {
|
|
t.Fatalf("expected REQ to be marked secret")
|
|
}
|
|
}
|
|
|
|
func TestResolveTemplateRuntimeImage(t *testing.T) {
|
|
if got := resolveTemplateRuntimeImage("dragonfly"); got == "dragonfly" || got == "" {
|
|
t.Fatalf("expected dragonfly runtime to map to a concrete image, got %q", got)
|
|
}
|
|
if got := resolveTemplateRuntimeImage("custom-runtime"); got != "custom-runtime" {
|
|
t.Fatalf("expected unknown runtime passthrough, got %q", got)
|
|
}
|
|
}
|
|
|
|
func TestSeedTemplatesResolveCleanly(t *testing.T) {
|
|
for _, tpl := range SeedTemplates() {
|
|
var config TemplateConfig
|
|
if err := json.Unmarshal([]byte(tpl.Config), &config); err != nil {
|
|
t.Fatalf("%s: invalid config JSON: %v", tpl.ID, err)
|
|
}
|
|
var variables []TemplateVariable
|
|
if err := json.Unmarshal([]byte(tpl.Variables), &variables); err != nil {
|
|
t.Fatalf("%s: invalid variables JSON: %v", tpl.ID, err)
|
|
}
|
|
if len(config.Services) == 0 {
|
|
continue // legacy single-service template
|
|
}
|
|
sorted, err := topoSortServices(config.Services)
|
|
if err != nil {
|
|
t.Fatalf("%s: topo sort: %v", tpl.ID, err)
|
|
}
|
|
if err := validateTemplateGraph(sorted); err != nil {
|
|
t.Fatalf("%s: graph validation: %v", tpl.ID, err)
|
|
}
|
|
// User vars left empty — every expression must still resolve via
|
|
// defaults, secrets, or service refs.
|
|
graph := resolveTemplateGraph(sorted, map[string]string{})
|
|
if len(graph.unresolved) > 0 {
|
|
t.Fatalf("%s: unresolved expressions: %v", tpl.ID, graph.unresolved)
|
|
}
|
|
}
|
|
}
|