Skip to content
Merged
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
8 changes: 4 additions & 4 deletions build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ func TestBuildEmitsRecipeForOutputDirectory(t *testing.T) {

require.Len(t, plan.GetRecipes(), 1)
recipe := plan.GetRecipes()[0]
require.Equal(t, "builder/Dockerfile", recipe.GetDockerfile())
require.Equal(t, "Dockerfile", recipe.GetDockerfile())
require.Equal(t, ".", recipe.GetContext())
require.Equal(t, []string{"linux/amd64", "linux/arm64"}, recipe.GetPlatforms())
require.NotEmpty(t, recipe.GetImage())
Expand All @@ -144,13 +144,13 @@ func TestBuildEmitsRecipeForOutputDirectory(t *testing.T) {
sources := copySources(string(dockerfile))
require.NotEmpty(t, sources, "expected the Dockerfile to COPY at least one file")
for _, src := range sources {
_, err := os.Stat(filepath.Join(outDir, recipe.GetContext(), src))
_, err := os.Stat(filepath.Join(builder.Location, recipe.GetContext(), src))
require.NoErrorf(t, err, "COPY source %q missing from recipe context", src)
}
}

// TestBuildRecipeDockerfileIsValidDocker runs `docker buildx build --check`
// over the recipe Build emits into an output_directory, from that directory as
// over the recipe Build emits into an output_directory, from the service as
// the context — the frontend validation a consumer without the codefly
// toolchain gets for free before building. VerifyDockerBuildPlan only checks
// the tree against the digest; it does not parse the Dockerfile, so an
Expand Down Expand Up @@ -205,7 +205,7 @@ func TestBuildRecipeDockerfileIsValidDocker(t *testing.T) {
defer cancel()
cmd := exec.CommandContext(checkCtx, "docker", "buildx", "build", "--check",
"-f", filepath.Join(outDir, filepath.FromSlash(recipe.GetDockerfile())),
filepath.Join(outDir, filepath.FromSlash(recipe.GetContext())))
filepath.Join(builder.Location, filepath.FromSlash(recipe.GetContext())))
out, err := cmd.CombinedOutput()
require.NoErrorf(t, err, "docker buildx build --check of the emitted recipe failed:\n%s", out)
}
Expand Down
9 changes: 6 additions & 3 deletions builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"embed"
"fmt"
"path/filepath"

"github.com/codefly-dev/core/agents/communicate"
dockerhelpers "github.com/codefly-dev/core/agents/helpers/docker"
Expand Down Expand Up @@ -366,14 +365,18 @@ func (s *Builder) Build(ctx context.Context, req *builderv0.BuildRequest) (*buil
// pushes a multi-arch manifest list, so the image becomes a reproducible
// artifact a consumer can rebuild without the agent toolchain.
func (s *Builder) buildRecipe(ctx context.Context, out string, image *resources.DockerImage, docker DockerTemplating) (*builderv0.BuildResponse, error) {
err := s.Templates(ctx, docker, services.WithBuilder(builderFS).WithDestination("%s", filepath.Join(out, "builder")))
// COPY paths resolve from the service, while the Dockerfile and inventory
// resolve from out. Stage the bootstrap in both locations when they differ.
err := s.Templates(ctx, docker,
services.WithBuilder(builderFS),
services.WithBuilder(builderFS).WithDestination("%s", out))
if err != nil {
return s.Builder.BuildError(err)
}

recipe := &builderv0.DockerBuildRecipe{
Name: s.Base.Service.Name,
Dockerfile: "builder/Dockerfile",
Dockerfile: "Dockerfile",
Context: ".",
Image: image.FullName(),
Platforms: []string{"linux/amd64", "linux/arm64"},
Expand Down
Loading