Add constant for platform value and prettify log
This commit is contained in:
parent
de7ec5b8bb
commit
5ab7851649
15
image.go
15
image.go
@ -25,7 +25,7 @@ type ManifestImage struct {
|
||||
buildOpt string
|
||||
}
|
||||
|
||||
func NewManifest(imageName string, imageTag string, buildDir string, platforms []string, buildOpt string) ManifestImage {
|
||||
func NewManifest(imageName string, imageTag string, buildDir string, platforms []Platform, buildOpt string) ManifestImage {
|
||||
return ManifestImage{
|
||||
Image: Image{
|
||||
imageName,
|
||||
@ -56,7 +56,7 @@ func (manifest *ManifestImage) CreateManifest(registry Registry) {
|
||||
}
|
||||
|
||||
if stdout, err := runOciCli("docker", "manifest create", insecureRegistryOpt, registry, manifest.Image, amend...); err != nil {
|
||||
log.Fatal(err)
|
||||
log.Fatalf("manifest creation failed : %v%v", stdout, err)
|
||||
} else {
|
||||
log.Debug(stdout)
|
||||
}
|
||||
@ -68,20 +68,25 @@ func (manifest *ManifestImage) CreateManifest(registry Registry) {
|
||||
|
||||
// $(OCI_CLI) manifest push $(OCI_OPT) $(REGISTRY_IP):5000/$(1)
|
||||
if stdout, err := runOciCli("docker", "manifest push", insecureRegistryOpt, registry, manifest.Image); err != nil {
|
||||
log.Fatal(err)
|
||||
log.Fatalf("manifest push failed : %v%v", stdout, err)
|
||||
} else {
|
||||
log.Debug(stdout)
|
||||
}
|
||||
}
|
||||
|
||||
func (manifest *ManifestImage) annotateManifest(registry Registry, layer Layer) {
|
||||
annotation := fmt.Sprintf("--os %s --arch %s", layer.os, layer.arch)
|
||||
if layer.variant != "" {
|
||||
annotation = fmt.Sprintf("%s --variant %s", annotation, layer.variant)
|
||||
}
|
||||
|
||||
stdout, err := runOciCli("docker", "manifest annotate",
|
||||
fmt.Sprintf("--os %s --arch %s --variant %s", layer.os, layer.arch, layer.variant),
|
||||
annotation,
|
||||
registry, manifest.Image,
|
||||
fmt.Sprintf("%s/%s", registry.String(), layer.Image.String()),
|
||||
)
|
||||
if err != nil {
|
||||
log.Warn("layer %s not annotated", layer.String())
|
||||
log.Warnf("layer %s not annotated", layer.String())
|
||||
} else {
|
||||
log.Debug(stdout)
|
||||
}
|
||||
|
20
layers.go
20
layers.go
@ -19,32 +19,40 @@ func (layer *Layer) String() string {
|
||||
|
||||
func (layer *Layer) CreateLayer(registry Registry, buildDir string, buildOpt string) {
|
||||
if buildOpt != "" {
|
||||
buildOpt = fmt.Sprintf("--platform %s/%s/%s %s -t", layer.os, layer.arch, layer.variant, buildOpt)
|
||||
buildOpt = fmt.Sprintf("--platform %s %s -t", layer.toPlatform(), buildOpt)
|
||||
} else {
|
||||
buildOpt = fmt.Sprintf("--platform %s/%s/%s -t", layer.os, layer.arch, layer.variant)
|
||||
buildOpt = fmt.Sprintf("--platform %s -t", layer.toPlatform())
|
||||
}
|
||||
|
||||
// $(OCI_CLI_BUILD) build --platform $(2) -t $(REGISTRY_IP):5000/$(1):$(3) .
|
||||
if stdout, err := runOciCli("docker", "build", buildOpt, registry, layer.Image, buildDir); err != nil {
|
||||
log.Fatalf("layer build step failed : %v\n", err)
|
||||
log.Fatalf("layer build step failed : %v%v", stdout, err)
|
||||
} else {
|
||||
log.Debug(stdout)
|
||||
}
|
||||
|
||||
// $(OCI_CLI) push $(REGISTRY_IP):5000/$(1):$(3)
|
||||
if stdout, err := runOciCli("docker", "push", "", registry, layer.Image); err != nil {
|
||||
log.Fatalf("layer push step failed : %v\n", err)
|
||||
log.Fatalf("layer build step failed : %v%v", stdout, err)
|
||||
} else {
|
||||
log.Debug(stdout)
|
||||
}
|
||||
}
|
||||
|
||||
func (layer *Layer) toPlatform() Platform {
|
||||
if layer.variant != "" {
|
||||
return Platform(fmt.Sprintf("%s/%s/%s", layer.os, layer.arch, layer.variant))
|
||||
} else {
|
||||
return Platform(fmt.Sprintf("%s/%s", layer.os, layer.arch))
|
||||
}
|
||||
}
|
||||
|
||||
type Layers []Layer
|
||||
|
||||
func NewLayers(imageName string, platforms []string) Layers {
|
||||
func NewLayers(imageName string, platforms []Platform) Layers {
|
||||
var layers Layers
|
||||
for _, platform := range platforms {
|
||||
splitPlatform := strings.Split(platform, "/")
|
||||
splitPlatform := strings.Split(string(platform), "/")
|
||||
|
||||
var layer Layer
|
||||
if len(splitPlatform) < 3 {
|
||||
|
17
main.go
17
main.go
@ -1,12 +1,20 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
log "github.com/sirupsen/logrus"
|
||||
import log "github.com/sirupsen/logrus"
|
||||
|
||||
type Platform string
|
||||
|
||||
const (
|
||||
LinuxArmV7 Platform = "linux/arm/v7"
|
||||
LinuxArmV6 Platform = "linux/arm/v6"
|
||||
LinuxArm64 Platform = "linux/arm64"
|
||||
LinuxAmd64 Platform = "linux/amd64"
|
||||
)
|
||||
|
||||
// init logging parameter
|
||||
func init() {
|
||||
log.SetLevel(log.DebugLevel)
|
||||
log.SetLevel(log.InfoLevel)
|
||||
//log.SetLevel(log.DebugLevel)
|
||||
}
|
||||
|
||||
func main() {
|
||||
@ -20,12 +28,13 @@ func main() {
|
||||
"registry-ui",
|
||||
"latest",
|
||||
"../rasp/registry/ui/",
|
||||
[]string{"linux/arm/v6"},
|
||||
[]Platform{LinuxArmV6},
|
||||
"",
|
||||
),
|
||||
}
|
||||
|
||||
for _, manifest := range manifests {
|
||||
log.Infof("-> Deal with manifest %s folder %s\n", manifest.name, manifest.buildDir)
|
||||
manifest.CreateLayers(myRegistry)
|
||||
manifest.CreateManifest(myRegistry)
|
||||
}
|
||||
|
17
runner.go
17
runner.go
@ -1,6 +1,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"os/exec"
|
||||
@ -28,11 +29,17 @@ func runCli(binary string, verb string, args ...string) (string, error) {
|
||||
args = append(strings.Split(verb, " "), args...)
|
||||
}
|
||||
|
||||
log.Debugf(" $ %s %s\n", binary, strings.Join(args, " "))
|
||||
out, err := exec.Command(binary, args...).Output()
|
||||
log.Infof(" %s %s\n", binary, strings.Join(args, " "))
|
||||
|
||||
cmd := exec.Command(binary, args...)
|
||||
var out bytes.Buffer
|
||||
var stderr bytes.Buffer
|
||||
cmd.Stdout = &out
|
||||
cmd.Stderr = &stderr
|
||||
err := cmd.Run()
|
||||
if err != nil {
|
||||
log.Warnf("Executing binary with argument : `%s %s %s` failed\n", binary, verb, strings.Join(args, " "))
|
||||
return "", err
|
||||
log.Warnf("Executing binary with argument : `%s %s`\n", binary, strings.Join(args, " "))
|
||||
return stderr.String(), err
|
||||
}
|
||||
return string(out), nil
|
||||
return out.String(), nil
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user