This repository has been archived on 2026-03-27. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
mcdeploy/push.go
Kyle Isom 17c86c4c79 Push versioned tags to registry, not just :latest
Build already creates both :latest and :<version> tags, but push
only pushed :latest. Now push detects the version via git describe
and pushes both tags, giving the registry version history.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-26 12:19:00 -07:00

68 lines
1.5 KiB
Go

package main
import (
"fmt"
"github.com/spf13/cobra"
)
func pushCommand() *cobra.Command {
var imageFlag string
cmd := &cobra.Command{
Use: "push <service>",
Short: "Push container images to the registry",
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 pushed []string
for _, image := range images {
ref := cfg.ImageRef(image)
tagLatest := ref + ":latest"
tagVersion := ref + ":" + version
if err := run("podman", "push", tagLatest); err != nil {
return fmt.Errorf("push %s:latest: %w", image, err)
}
pushed = append(pushed, tagLatest)
if err := run("podman", "push", tagVersion); err != nil {
return fmt.Errorf("push %s:%s: %w", image, version, err)
}
pushed = append(pushed, tagVersion)
}
fmt.Printf("\nPushed %d image(s):\n", len(pushed))
for _, ref := range pushed {
fmt.Printf(" %s\n", ref)
}
return nil
},
}
cmd.Flags().StringVar(&imageFlag, "image", "", "push only this image")
return cmd
}