Skip to content
Open
Show file tree
Hide file tree
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
29 changes: 29 additions & 0 deletions pkg/build/buildkit/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,25 @@ func generateContainerfile(w io.Writer, image string, tsuruYamlHooks *build.Tsur
return err
}

func findAndReadTsuruYaml(tmpDir string) (string, error) {
contextDir := filepath.Join(tmpDir, "context")

// Try all possible Tsuru YAML filenames
for _, filename := range build.TsuruYamlNames {
tsuruYamlPath := filepath.Join(contextDir, filename)
if _, err := os.Stat(tsuruYamlPath); err == nil {
tsuruYamlData, err := os.ReadFile(tsuruYamlPath)
if err != nil {
return "", fmt.Errorf("failed to read %s: %w", filename, err)
}
return string(tsuruYamlData), nil
}
}

// No Tsuru YAML file found, return empty string (not an error)
return "", nil
}

func (b *BuildKit) buildFromContainerImage(ctx context.Context, c *client.Client, r *pb.BuildRequest, w console.File) (*pb.TsuruConfig, error) {
if err := ctx.Err(); err != nil {
return nil, err
Expand Down Expand Up @@ -462,6 +481,16 @@ func (b *BuildKit) buildFromContainerFile(ctx context.Context, c *client.Client,
return nil, err
}

if tc.TsuruYaml == "" {
tsuruYamlData, err := findAndReadTsuruYaml(tmpDir)
if err != nil {
return nil, err
}
if tsuruYamlData != "" {
tc.TsuruYaml = tsuruYamlData
}
}
Comment on lines +484 to +492
Copy link

Copilot AI Dec 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test data directory contains a Procfile, but the implementation only extracts tsuru.yaml from the context directory. Consider implementing similar fallback logic for Procfile extraction when it's not present in the container filesystem. The test case "Dockerfile w/ build context (adds tsuru.yaml and Procfile)" (line 649) shows that both files should be handled consistently when they exist in the build context.

Copilot uses AI. Check for mistakes.

tc.ImageConfig = ic

return tc, nil
Expand Down
37 changes: 37 additions & 0 deletions pkg/build/buildkit/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -697,6 +697,43 @@ kubernetes:
}, appFiles)
})

t.Run("Extract tsuru.yaml from context when is not present on container fs", func(t *testing.T) {
destImage := baseRegistry(t, "my-app", "")

dockerfile, err := os.ReadFile("./testdata/tsuru-files-from-context/Dockerfile")
require.NoError(t, err)

req := &pb.BuildRequest{
Kind: pb.BuildKind_BUILD_KIND_APP_BUILD_WITH_CONTAINER_FILE,
App: &pb.TsuruApp{
Name: "my-app",
},
DestinationImages: []string{destImage},
Containerfile: string(dockerfile),
Data: compressGZIP(t, "./testdata/tsuru-files-from-context/"),
PushOptions: &pb.PushOptions{
InsecureRegistry: registryHTTP,
},
}

appFiles, err := NewBuildKit(bc, BuildKitOptions{TempDir: t.TempDir()}).Build(context.TODO(), req, os.Stdout)
require.NoError(t, err)
assert.Equal(t, &pb.TsuruConfig{
Procfile: "",
Copy link

Copilot AI Dec 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test data includes a Procfile but the test expects an empty Procfile field. This is inconsistent with the presence of the Procfile in the testdata directory. Either the Procfile should be removed from the testdata if it's not intended to be extracted, or the expected value should be updated to match the Procfile content and the implementation should be enhanced to extract it from context (similar to how tsuru.yaml is extracted).

Copilot uses AI. Check for mistakes.
TsuruYaml: `healthcheck:
path: /healthz
interval_seconds: 3
timeout_seconds: 1
ports:
- port: 443
`,
ImageConfig: &pb.ContainerImageConfig{
Cmd: []string{"echo", "Hello from Tsuru files from context!"},
WorkingDir: "/tmp",
},
}, appFiles)
})

t.Run("Dockerfile mounting the app's env vars", func(t *testing.T) {
destImage := baseRegistry(t, "my-app", "")

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
FROM busybox:latest

WORKDIR /tmp
CMD ["echo", "Hello from Tsuru files from context!"]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
web: my-server --addr 0.0.0.0:${PORT}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
healthcheck:
path: /healthz
interval_seconds: 3
timeout_seconds: 1
ports:
- port: 443
Loading