mirror of
https://github.com/Dvorinka/Containr.git
synced 2026-10-28 07:41:27 +00:00
POST /projects/:id/import-compose deploys a compose file straight into a project — no template row required. Well-known DB images become managed databases attached to the project network under their service name as DNS alias; other services deploy in dependency order via deployTemplateGraph. - api: extract composeToSpecs converter (shared by the template import-compose preview and the new project endpoint); fix dropped env warnings (pointer receiver); replace insertion sort with sort.Strings - cascade: database_services.project_id links graph-provisioned DBs to their project so project delete tears down runtime + row (previously leaked container + network) - cli: new `containr import` group, `import compose <project> <file|->` - mcp: containr_projects_import_compose tool - openapi + regenerated frontend types; docs snapshot + CLI.md - frontend: compose import modal on the project workspace toolbar - tests: composeToSpecs conversion, ordering, db-image map, warnings
58 lines
1.2 KiB
Go
58 lines
1.2 KiB
Go
package commands
|
|
|
|
import (
|
|
"fmt"
|
|
"io"
|
|
"os"
|
|
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
var importVars []string
|
|
|
|
var ImportCmd = &cobra.Command{
|
|
Use: "import",
|
|
Short: "Import external definitions into Containr",
|
|
}
|
|
|
|
var importComposeCmd = &cobra.Command{
|
|
Use: "compose <project-id> <compose.yml|->",
|
|
Short: "Deploy a docker-compose file straight into a project (no template)",
|
|
Args: cobra.ExactArgs(2),
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
var raw []byte
|
|
var err error
|
|
if args[1] == "-" {
|
|
raw, err = io.ReadAll(os.Stdin)
|
|
} else {
|
|
raw, err = os.ReadFile(args[1])
|
|
}
|
|
if err != nil {
|
|
return fmt.Errorf("cannot read compose file: %w", err)
|
|
}
|
|
vars, err := parseKVFlags(importVars)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
c, err := client()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
body := map[string]interface{}{"compose_yaml": string(raw)}
|
|
if len(vars) > 0 {
|
|
body["variables"] = vars
|
|
}
|
|
data, err := c.Do("POST", "/projects/"+args[0]+"/import-compose", body)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
PrintRaw(data)
|
|
return nil
|
|
},
|
|
}
|
|
|
|
func init() {
|
|
importComposeCmd.Flags().StringArrayVar(&importVars, "var", nil, "Variable override (KEY=VALUE, repeatable)")
|
|
ImportCmd.AddCommand(importComposeCmd)
|
|
}
|