69 lines
1.8 KiB
Go
69 lines
1.8 KiB
Go
package cmd
|
|
|
|
import (
|
|
. "antoine-roux.tk/docker-multi-arch-builder/internal"
|
|
"fmt"
|
|
log "github.com/sirupsen/logrus"
|
|
"github.com/spf13/cobra"
|
|
"strings"
|
|
)
|
|
|
|
type BuildParam struct {
|
|
name string
|
|
registry string
|
|
port int
|
|
tag string
|
|
folder string
|
|
platforms Platforms
|
|
}
|
|
|
|
var (
|
|
buildParam = BuildParam{}
|
|
|
|
buildCmd = &cobra.Command{
|
|
Use: "build",
|
|
Short: "Build all multi arch manifest",
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
myRegistry := Registry{
|
|
Hostname: buildParam.registry,
|
|
Port: buildParam.port,
|
|
}
|
|
|
|
manifest := NewManifest(
|
|
buildParam.name,
|
|
buildParam.tag,
|
|
buildParam.folder,
|
|
buildParam.platforms,
|
|
strings.Join(args, " "),
|
|
)
|
|
|
|
log.Infof("-> Deal with manifest %s folder %s\n", manifest.Name, manifest.BuildDir)
|
|
manifest.CreateLayers(myRegistry)
|
|
manifest.CreateManifest(myRegistry)
|
|
},
|
|
}
|
|
)
|
|
|
|
func init() {
|
|
buildCmd.PersistentFlags().StringVarP(&buildParam.registry, "registry", "r", "docker.registry", "oci registry address")
|
|
buildCmd.PersistentFlags().IntVarP(&buildParam.port, "port", "p", 5000, "oci registry port")
|
|
|
|
buildCmd.PersistentFlags().StringVarP(&buildParam.name, "name", "n", "", "oci target image name")
|
|
buildCmd.PersistentFlags().StringVarP(&buildParam.tag, "tag", "t", "latest", "oci target image tag")
|
|
|
|
buildCmd.PersistentFlags().StringVarP(&buildParam.folder, "folder", "f", ".", "build folder")
|
|
buildCmd.PersistentFlags().Var(
|
|
newPlatformSliceValue(AllPlatforms, &buildParam.platforms),
|
|
"platforms",
|
|
fmt.Sprintf("oci target image platforms (default all : %s)", AllPlatforms.Join(", ")),
|
|
)
|
|
buildCmd.MarkPersistentFlagRequired("name")
|
|
}
|
|
|
|
func newPlatformSliceValue(val Platforms, p *Platforms) *PlatformsValue {
|
|
ssv := new(PlatformsValue)
|
|
ssv.Platforms = p
|
|
*ssv.Platforms = val
|
|
return ssv
|
|
}
|