From fc86fa39d24b515cc45822bab3704880674824b4 Mon Sep 17 00:00:00 2001 From: Jesse Huang Date: Fri, 31 May 2024 16:38:56 +0800 Subject: [PATCH 1/2] change the test image build to use docker buildx --- test/localenv/magefile.go | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/test/localenv/magefile.go b/test/localenv/magefile.go index e3bc1938f..199d8675e 100644 --- a/test/localenv/magefile.go +++ b/test/localenv/magefile.go @@ -336,7 +336,11 @@ func Destroy(flags string) error { func (Build) All() error { defer logTime(time.Now(), "build:all") - err := buildAPI() + err := ensureBuildxBuilder() + if err != nil { + return err + } + err = buildAPI() if err != nil { return err } @@ -384,13 +388,13 @@ func (Build) Api() error { return buildAPI() } func buildAPI() error { - return shellcmd.Command("docker compose -f ../../api/docker-compose.yaml build").Run() //oss + return shellcmd.Command("docker buildx build --platform \"linux/amd64\" -f ../../api/Dockerfile -t \"ghcr.io/eclipse-symphony/symphony-api\" \"../..\" --load").Run() //oss } func buildAgent() error { return shellcmd.RunAll( - shellcmd.Command("docker compose -f ../../api/docker-compose-poll-agent.yaml build"), - shellcmd.Command("docker compose -f ../../api/docker-compose-target-agent.yaml build"), + shellcmd.Command("docker buildx build --platform \"linux/amd64\" -f ../../api/Dockerfile.poll-agent -t \"ghcr.io/eclipse-symphony/symphony-poll-agent\" \"../..\" --load"), + shellcmd.Command("docker buildx build --platform \"linux/amd64\" -f ../../api/Dockerfile.target-agent -t \"ghcr.io/eclipse-symphony/symphony-target-agent\" \"../..\" --load"), ) //oss } @@ -399,7 +403,7 @@ func (Build) K8s() error { return buildK8s() } func buildK8s() error { - return shellcmd.Command("docker compose -f ../../k8s/docker-compose.yaml build").Run() //oss + return shellcmd.Command("docker buildx build --platform \"linux/amd64\" -f ../../k8s/Dockerfile -t \"ghcr.io/eclipse-symphony/symphony-k8s\" \"../..\" --load").Run() //oss } /******************** Minikube ********************/ @@ -812,3 +816,22 @@ func ensureMinikubeContext() error { func logTime(start time.Time, name string) { fmt.Printf("[DONE] (%s) '%s'\n", time.Since(start), name) } + +func ensureBuildxBuilder() error { + checkCmd := exec.Command("docker", "buildx", "ls") + output, err := checkCmd.CombinedOutput() + if err != nil { + return fmt.Errorf("failed to list buildx builders: %v, output: %s", err, output) + } + if !strings.Contains(string(output), "default") { + createCmd := exec.Command("docker", "buildx", "create", "--use", "--name", "default") + createOutput, err := createCmd.CombinedOutput() + if err != nil { + return fmt.Errorf("failed to create buildx builder: %v, output: %s", err, createOutput) + } + fmt.Println("Created buildx builder:", string(createOutput)) + } else { + fmt.Println("Buildx builder 'default' already exists.") + } + return nil +} From 4c17c85b6d39e34583eec0c3ec30c5cffa203f3f Mon Sep 17 00:00:00 2001 From: Jesse Huang Date: Tue, 4 Jun 2024 18:35:06 +0800 Subject: [PATCH 2/2] resolve comments --- test/localenv/magefile.go | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/test/localenv/magefile.go b/test/localenv/magefile.go index 199d8675e..d4aa574ef 100644 --- a/test/localenv/magefile.go +++ b/test/localenv/magefile.go @@ -20,6 +20,7 @@ import ( "os/exec" "path/filepath" "regexp" + "runtime" "strings" "sync" "time" @@ -39,6 +40,8 @@ const ( LOG_ROOT = "/tmp/symphony-integration-test-logs" ) +var platform = fmt.Sprintf("%s/%s", runtime.GOOS, runtime.GOARCH) + // Print parameters for mage local testing func PrintParams() error { fmt.Println("OSS_CONTAINER_REGISTRY: ", getContainerRegistry()) @@ -388,13 +391,16 @@ func (Build) Api() error { return buildAPI() } func buildAPI() error { - return shellcmd.Command("docker buildx build --platform \"linux/amd64\" -f ../../api/Dockerfile -t \"ghcr.io/eclipse-symphony/symphony-api\" \"../..\" --load").Run() //oss + imageName := "ghcr.io/eclipse-symphony/symphony-api" + return shellcmd.Command(fmt.Sprintf("docker buildx build --platform %s -f ../../api/Dockerfile -t %s \"../..\" --load", platform, imageName)).Run() //oss } func buildAgent() error { + pollAgentImageName := "ghcr.io/eclipse-symphony/symphony-poll-agent" + targetAgentImageName := "ghcr.io/eclipse-symphony/symphony-target-agent" return shellcmd.RunAll( - shellcmd.Command("docker buildx build --platform \"linux/amd64\" -f ../../api/Dockerfile.poll-agent -t \"ghcr.io/eclipse-symphony/symphony-poll-agent\" \"../..\" --load"), - shellcmd.Command("docker buildx build --platform \"linux/amd64\" -f ../../api/Dockerfile.target-agent -t \"ghcr.io/eclipse-symphony/symphony-target-agent\" \"../..\" --load"), + shellcmd.Command(fmt.Sprintf("docker buildx build --platform %s -f ../../api/Dockerfile.poll-agent -t %s \"../..\" --load", platform, pollAgentImageName)), + shellcmd.Command(fmt.Sprintf("docker buildx build --platform %s -f ../../api/Dockerfile.target-agent -t %s \"../..\" --load", platform, targetAgentImageName)), ) //oss } @@ -403,7 +409,8 @@ func (Build) K8s() error { return buildK8s() } func buildK8s() error { - return shellcmd.Command("docker buildx build --platform \"linux/amd64\" -f ../../k8s/Dockerfile -t \"ghcr.io/eclipse-symphony/symphony-k8s\" \"../..\" --load").Run() //oss + imageName := "ghcr.io/eclipse-symphony/symphony-k8s" + return shellcmd.Command(fmt.Sprintf("docker buildx build --platform %s -f ../../k8s/Dockerfile -t %s \"../..\" --load", platform, imageName)).Run() //oss } /******************** Minikube ********************/