Initial implementation of mcdeploy deployment tool
Single Go binary with five commands: - build: podman build locally with registry tags + git version - push: podman push to MCR - deploy: SSH pull/stop/rm/run on target node - cert renew: issue TLS cert from Metacrypt via REST API - status: show container status on a node Config-driven via TOML service registry describing images, Dockerfiles, container configs per node. Shells out to podman for container operations and ssh for remote access. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
73
build.go
Normal file
73
build.go
Normal file
@@ -0,0 +1,73 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
func buildCommand() *cobra.Command {
|
||||
var imageFlag string
|
||||
|
||||
cmd := &cobra.Command{
|
||||
Use: "build <service>",
|
||||
Short: "Build container images for a service",
|
||||
Args: cobra.ExactArgs(1),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
cfg, err := loadCfg()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
svc, err := cfg.FindService(args[0])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
svcPath := cfg.ServicePath(svc)
|
||||
|
||||
version, err := runOutput(svcPath, "git", "describe", "--tags", "--always", "--dirty")
|
||||
if err != nil {
|
||||
return fmt.Errorf("git describe in %s: %w", svcPath, err)
|
||||
}
|
||||
fmt.Printf("Version: %s\n", version)
|
||||
|
||||
images := svc.Images
|
||||
if imageFlag != "" {
|
||||
images = []string{imageFlag}
|
||||
}
|
||||
|
||||
var built []string
|
||||
for _, image := range images {
|
||||
dockerfile, ok := svc.Dockerfiles[image]
|
||||
if !ok {
|
||||
dockerfile = "Dockerfile"
|
||||
}
|
||||
|
||||
ref := cfg.ImageRef(image)
|
||||
tagLatest := ref + ":latest"
|
||||
tagVersion := ref + ":" + version
|
||||
|
||||
err := runIn(svcPath, "podman", "build",
|
||||
"-f", dockerfile,
|
||||
"-t", tagLatest,
|
||||
"-t", tagVersion,
|
||||
".",
|
||||
)
|
||||
if err != nil {
|
||||
return fmt.Errorf("build %s: %w", image, err)
|
||||
}
|
||||
built = append(built, tagLatest, tagVersion)
|
||||
}
|
||||
|
||||
fmt.Printf("\nBuilt %d image(s):\n", len(images))
|
||||
for _, tag := range built {
|
||||
fmt.Printf(" %s\n", tag)
|
||||
}
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
cmd.Flags().StringVar(&imageFlag, "image", "", "build only this image")
|
||||
return cmd
|
||||
}
|
||||
Reference in New Issue
Block a user