diff --git a/builder/build.go b/builder/build.go index c9486178..27fb8be9 100644 --- a/builder/build.go +++ b/builder/build.go @@ -80,11 +80,11 @@ func BuildImage(image string, handler string, functionName string, language stri tarPath := path.Join(tempDir, "req.tar") - if err := makeTar(builderConfig{Image: imageName, BuildArgs: buildArgMap}, path.Join("build", functionName), tarPath); err != nil { + if err := makeTar(buildConfig{Image: imageName, BuildArgs: buildArgMap}, path.Join("build", functionName), tarPath); err != nil { return fmt.Errorf("failed to create tar file for %s, error: %w", functionName, err) } - res, err := callBuilder(tarPath, tempPath, remoteBuilder, functionName, payloadSecretPath) + res, err := callBuilder(tarPath, remoteBuilder, functionName, payloadSecretPath) if err != nil { return err } diff --git a/builder/publish.go b/builder/publish.go index 4662037c..6bca112c 100644 --- a/builder/publish.go +++ b/builder/publish.go @@ -26,9 +26,11 @@ import ( hmac "github.com/alexellis/hmac/v2" ) -type builderConfig struct { +type buildConfig struct { Image string `json:"image"` + Frontend string `json:"frontend,omitempty"` BuildArgs map[string]string `json:"buildArgs,omitempty"` + Platforms []string `json:"platforms,omitempty"` } type builderResult struct { @@ -87,11 +89,13 @@ func PublishImage(image string, handler string, functionName string, language st tarPath := path.Join(tempDir, "req.tar") - if err := makeTar(builderConfig{Image: imageName, BuildArgs: buildArgMap}, path.Join("build", functionName), tarPath); err != nil { + builderPlatforms := strings.Split(platforms, ",") + + if err := makeTar(buildConfig{Image: imageName, BuildArgs: buildArgMap, Platforms: builderPlatforms}, path.Join("build", functionName), tarPath); err != nil { return fmt.Errorf("failed to create tar file for %s, error: %w", functionName, err) } - res, err := callBuilder(tarPath, tempPath, remoteBuilder, functionName, payloadSecretPath) + res, err := callBuilder(tarPath, remoteBuilder, functionName, payloadSecretPath) if err != nil { return err } @@ -200,7 +204,7 @@ func applyTag(index int, baseImage, tag string) string { return fmt.Sprintf("%s:%s", baseImage[:index], tag) } -func makeTar(buildConfig builderConfig, base, tarPath string) error { +func makeTar(buildConfig buildConfig, base, tarPath string) error { configBytes, _ := json.Marshal(buildConfig) if err := os.WriteFile(path.Join(base, BuilderConfigFilename), configBytes, 0664); err != nil { return err @@ -251,7 +255,7 @@ func makeTar(buildConfig builderConfig, base, tarPath string) error { return err } -func callBuilder(tarPath, tempPath, builderAddress, functionName, payloadSecretPath string) (*http.Response, error) { +func callBuilder(tarPath, builderAddress, functionName, payloadSecretPath string) (*http.Response, error) { payloadSecret, err := os.ReadFile(payloadSecretPath) if err != nil { @@ -280,7 +284,7 @@ func callBuilder(tarPath, tempPath, builderAddress, functionName, payloadSecretP r.Header.Set("X-Build-Signature", "sha256="+hex.EncodeToString(digest)) r.Header.Set("Content-Type", "application/octet-stream") - log.Printf("%s invoking the API for build at %s ", functionName, builderAddress) + log.Printf("%s invoking the API for build at %s", functionName, builderAddress) res, err := http.DefaultClient.Do(r) if err != nil { return nil, err diff --git a/commands/publish.go b/commands/publish.go index 5d39203e..d5becfd8 100644 --- a/commands/publish.go +++ b/commands/publish.go @@ -171,27 +171,29 @@ func runPublish(cmd *cobra.Command, args []string) error { fmt.Printf("Ran qemu-user-static --reset. OK.\n") } - task := v2execute.ExecTask{ - Command: "docker", - Args: []string{"buildx", - "create", - "--use", - "--name=multiarch", - "--node=multiarch"}, - StreamStdio: false, - Env: []string{"DOCKER_CLI_EXPERIMENTAL=enabled"}, - } + if len(remoteBuilder) == 0 { + task := v2execute.ExecTask{ + Command: "docker", + Args: []string{"buildx", + "create", + "--use", + "--name=multiarch", + "--node=multiarch"}, + StreamStdio: false, + Env: []string{"DOCKER_CLI_EXPERIMENTAL=enabled"}, + } - res, err := task.Execute(cmd.Context()) - if err != nil { - return err - } + res, err := task.Execute(cmd.Context()) + if err != nil { + return err + } - if res.ExitCode != 0 { - return fmt.Errorf("non-zero exit code: %d, stderr: %s", res.ExitCode, res.Stderr) - } + if res.ExitCode != 0 { + return fmt.Errorf("non-zero exit code: %d, stderr: %s", res.ExitCode, res.Stderr) + } - fmt.Printf("Created buildx node: \"multiarch\"\n") + fmt.Printf("Created buildx node: \"multiarch\"\n") + } if len(services.StackConfiguration.TemplateConfigs) != 0 && !disableStackPull { newTemplateInfos, err := filterExistingTemplates(services.StackConfiguration.TemplateConfigs, "./template")