Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change the test image build to use docker buildx #290

Merged
merged 3 commits into from
Jun 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 35 additions & 5 deletions test/localenv/magefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"os/exec"
"path/filepath"
"regexp"
"runtime"
"strings"
"sync"
"time"
Expand All @@ -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())
Expand Down Expand Up @@ -336,7 +339,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
}
Expand Down Expand Up @@ -384,13 +391,16 @@ func (Build) Api() error {
return buildAPI()
}
func buildAPI() error {
return shellcmd.Command("docker compose -f ../../api/docker-compose.yaml build").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 compose -f ../../api/docker-compose-poll-agent.yaml build"),
shellcmd.Command("docker compose -f ../../api/docker-compose-target-agent.yaml build"),
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
}

Expand All @@ -399,7 +409,8 @@ func (Build) K8s() error {
return buildK8s()
}
func buildK8s() error {
return shellcmd.Command("docker compose -f ../../k8s/docker-compose.yaml build").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 ********************/
Expand Down Expand Up @@ -812,3 +823,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
}
Loading