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
|
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{
|
return ManifestImage{
|
||||||
Image: Image{
|
Image: Image{
|
||||||
imageName,
|
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 {
|
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 {
|
} else {
|
||||||
log.Debug(stdout)
|
log.Debug(stdout)
|
||||||
}
|
}
|
||||||
@ -68,20 +68,25 @@ func (manifest *ManifestImage) CreateManifest(registry Registry) {
|
|||||||
|
|
||||||
// $(OCI_CLI) manifest push $(OCI_OPT) $(REGISTRY_IP):5000/$(1)
|
// $(OCI_CLI) manifest push $(OCI_OPT) $(REGISTRY_IP):5000/$(1)
|
||||||
if stdout, err := runOciCli("docker", "manifest push", insecureRegistryOpt, registry, manifest.Image); err != nil {
|
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 {
|
} else {
|
||||||
log.Debug(stdout)
|
log.Debug(stdout)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (manifest *ManifestImage) annotateManifest(registry Registry, layer Layer) {
|
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",
|
stdout, err := runOciCli("docker", "manifest annotate",
|
||||||
fmt.Sprintf("--os %s --arch %s --variant %s", layer.os, layer.arch, layer.variant),
|
annotation,
|
||||||
registry, manifest.Image,
|
registry, manifest.Image,
|
||||||
fmt.Sprintf("%s/%s", registry.String(), layer.Image.String()),
|
fmt.Sprintf("%s/%s", registry.String(), layer.Image.String()),
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warn("layer %s not annotated", layer.String())
|
log.Warnf("layer %s not annotated", layer.String())
|
||||||
} else {
|
} else {
|
||||||
log.Debug(stdout)
|
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) {
|
func (layer *Layer) CreateLayer(registry Registry, buildDir string, buildOpt string) {
|
||||||
if buildOpt != "" {
|
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 {
|
} 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) .
|
// $(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 {
|
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 {
|
} else {
|
||||||
log.Debug(stdout)
|
log.Debug(stdout)
|
||||||
}
|
}
|
||||||
|
|
||||||
// $(OCI_CLI) push $(REGISTRY_IP):5000/$(1):$(3)
|
// $(OCI_CLI) push $(REGISTRY_IP):5000/$(1):$(3)
|
||||||
if stdout, err := runOciCli("docker", "push", "", registry, layer.Image); err != nil {
|
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 {
|
} else {
|
||||||
log.Debug(stdout)
|
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
|
type Layers []Layer
|
||||||
|
|
||||||
func NewLayers(imageName string, platforms []string) Layers {
|
func NewLayers(imageName string, platforms []Platform) Layers {
|
||||||
var layers Layers
|
var layers Layers
|
||||||
for _, platform := range platforms {
|
for _, platform := range platforms {
|
||||||
splitPlatform := strings.Split(platform, "/")
|
splitPlatform := strings.Split(string(platform), "/")
|
||||||
|
|
||||||
var layer Layer
|
var layer Layer
|
||||||
if len(splitPlatform) < 3 {
|
if len(splitPlatform) < 3 {
|
||||||
|
17
main.go
17
main.go
@ -1,12 +1,20 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import log "github.com/sirupsen/logrus"
|
||||||
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
|
// init logging parameter
|
||||||
func init() {
|
func init() {
|
||||||
log.SetLevel(log.DebugLevel)
|
log.SetLevel(log.InfoLevel)
|
||||||
|
//log.SetLevel(log.DebugLevel)
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
@ -20,12 +28,13 @@ func main() {
|
|||||||
"registry-ui",
|
"registry-ui",
|
||||||
"latest",
|
"latest",
|
||||||
"../rasp/registry/ui/",
|
"../rasp/registry/ui/",
|
||||||
[]string{"linux/arm/v6"},
|
[]Platform{LinuxArmV6},
|
||||||
"",
|
"",
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, manifest := range manifests {
|
for _, manifest := range manifests {
|
||||||
|
log.Infof("-> Deal with manifest %s folder %s\n", manifest.name, manifest.buildDir)
|
||||||
manifest.CreateLayers(myRegistry)
|
manifest.CreateLayers(myRegistry)
|
||||||
manifest.CreateManifest(myRegistry)
|
manifest.CreateManifest(myRegistry)
|
||||||
}
|
}
|
||||||
|
17
runner.go
17
runner.go
@ -1,6 +1,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
@ -28,11 +29,17 @@ func runCli(binary string, verb string, args ...string) (string, error) {
|
|||||||
args = append(strings.Split(verb, " "), args...)
|
args = append(strings.Split(verb, " "), args...)
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Debugf(" $ %s %s\n", binary, strings.Join(args, " "))
|
log.Infof(" %s %s\n", binary, strings.Join(args, " "))
|
||||||
out, err := exec.Command(binary, args...).Output()
|
|
||||||
|
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 {
|
if err != nil {
|
||||||
log.Warnf("Executing binary with argument : `%s %s %s` failed\n", binary, verb, strings.Join(args, " "))
|
log.Warnf("Executing binary with argument : `%s %s`\n", binary, strings.Join(args, " "))
|
||||||
return "", err
|
return stderr.String(), err
|
||||||
}
|
}
|
||||||
return string(out), nil
|
return out.String(), nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user