Skip to content

Commit

Permalink
Merge pull request #8779 from ulyssessouza/build-dockerfile-relativepath
Browse files Browse the repository at this point in the history
Make service>build>dockerfile a simple filename
  • Loading branch information
ulyssessouza authored Oct 20, 2021
2 parents ea5b094 + 9437976 commit c3a5eb2
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 51 deletions.
2 changes: 1 addition & 1 deletion cmd/compose/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func convertCommand(p *projectOptions, backend api.Service) *cobra.Command {

func runConvert(ctx context.Context, backend api.Service, opts convertOptions, services []string) error {
var json []byte
project, err := opts.toProject(services, cli.WithInterpolation(!opts.noInterpolate), cli.WithResolvedPaths(false))
project, err := opts.toProject(services, cli.WithInterpolation(!opts.noInterpolate), cli.WithResolvedPaths(true))
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require (
github.com/AlecAivazis/survey/v2 v2.2.3
github.com/buger/goterm v1.0.0
github.com/cnabio/cnab-to-oci v0.3.1-beta1
github.com/compose-spec/compose-go v1.0.2
github.com/compose-spec/compose-go v1.0.3
github.com/containerd/console v1.0.2
github.com/containerd/containerd v1.5.5
github.com/distribution/distribution/v3 v3.0.0-20210316161203-a01c71e2477e
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,8 @@ github.com/cncf/udpa/go v0.0.0-20200629203442-efcf912fb354/go.mod h1:WmhPx2Nbnht
github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk=
github.com/cockroachdb/datadriven v0.0.0-20190809214429-80d97fb3cbaa/go.mod h1:zn76sxSg3SzpJ0PPJaLDCu+Bu0Lg3sKTORVIj19EIF8=
github.com/codahale/hdrhistogram v0.0.0-20160425231609-f8ad88b59a58/go.mod h1:sE/e/2PUdi/liOCUjSTXgM1o87ZssimdTWN964YiIeI=
github.com/compose-spec/compose-go v1.0.2 h1:fPBm1irll5NkN4MYWihZSZ6Ter7IMQgKMnN0HqDBaEw=
github.com/compose-spec/compose-go v1.0.2/go.mod h1:gCIA3No0j5nNszz2X0yd/mkigTIWcOgHiPa9guWvoec=
github.com/compose-spec/compose-go v1.0.3 h1:yvut1x9H4TUMptNA4mZ63VGVtDNX1OKy2TZCi6yFw8Q=
github.com/compose-spec/compose-go v1.0.3/go.mod h1:gCIA3No0j5nNszz2X0yd/mkigTIWcOgHiPa9guWvoec=
github.com/compose-spec/godotenv v1.0.0 h1:TV24JYhh5GCC1G14npQVhCtxeoiwd0NcT0VdwcCQyXU=
github.com/compose-spec/godotenv v1.0.0/go.mod h1:zF/3BOa18Z24tts5qnO/E9YURQanJTBUf7nlcCTNsyc=
github.com/containerd/aufs v0.0.0-20200908144142-dab0cbea06f4/go.mod h1:nukgQABAEopAHvB6j7cnP5zJ+/3aVcE7hCYqvIwAHyE=
Expand Down
3 changes: 2 additions & 1 deletion pkg/compose/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"context"
"fmt"
"os"
"path/filepath"

"github.com/compose-spec/compose-go/types"
"github.com/containerd/containerd/platforms"
Expand Down Expand Up @@ -271,7 +272,7 @@ func (s *composeService) toBuildOptions(project *types.Project, service types.Se
return build.Options{
Inputs: build.Inputs{
ContextPath: service.Build.Context,
DockerfilePath: service.Build.Dockerfile,
DockerfilePath: filepath.Join(service.Build.Context, service.Build.Dockerfile),
},
BuildArgs: buildArgs,
Tags: tags,
Expand Down
8 changes: 4 additions & 4 deletions pkg/compose/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,12 @@ func TestBuildContainerMountOptions(t *testing.T) {
mounts, err := buildContainerMountOptions(project, project.Services[0], moby.ImageInspect{}, inherit)
assert.NilError(t, err)
assert.Assert(t, len(mounts) == 2)
assert.Assert(t, mounts[0].Target == "/var/myvolume1")
assert.Assert(t, mounts[1].Target == "/var/myvolume2")
assert.Equal(t, mounts[0].Target, "/var/myvolume1")
assert.Equal(t, mounts[1].Target, "/var/myvolume2")

mounts, err = buildContainerMountOptions(project, project.Services[0], moby.ImageInspect{}, inherit)
assert.NilError(t, err)
assert.Assert(t, len(mounts) == 2)
assert.Assert(t, mounts[0].Target == "/var/myvolume1")
assert.Assert(t, mounts[1].Target == "/var/myvolume2")
assert.Equal(t, mounts[0].Target, "/var/myvolume1")
assert.Equal(t, mounts[1].Target, "/var/myvolume2")
}
41 changes: 0 additions & 41 deletions pkg/e2e/compose_build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@
package e2e

import (
"io/ioutil"
"net/http"
"os"
"path/filepath"
"strings"
"testing"
"time"
Expand Down Expand Up @@ -107,41 +104,3 @@ func TestLocalComposeBuild(t *testing.T) {
c.RunDockerCmd("rmi", "custom-nginx")
})
}

func TestLocalComposeBuildStaticDockerfilePath(t *testing.T) {
c := NewParallelE2eCLI(t, binDir)

t.Run("build ddev-style compose files", func(t *testing.T) {
dir, err := ioutil.TempDir("", "ddev")
assert.NilError(t, err)
defer os.RemoveAll(dir) //nolint:errcheck

assert.NilError(t, ioutil.WriteFile(filepath.Join(dir, "compose.yaml"), []byte(`services:
service1:
build:
context: `+dir+`/service1
dockerfile: Dockerfile
service2:
build:
context: `+dir+`/service2
dockerfile: `+dir+`/service2/Dockerfile
`), 0644))

assert.NilError(t, os.Mkdir(filepath.Join(dir, "service1"), 0700))
assert.NilError(t, ioutil.WriteFile(filepath.Join(dir, "service1", "Dockerfile"), []byte(`FROM alpine
RUN echo "hello"
`), 0644))

assert.NilError(t, os.Mkdir(filepath.Join(dir, "service2"), 0700))
assert.NilError(t, ioutil.WriteFile(filepath.Join(dir, "service2", "Dockerfile"), []byte(`FROM alpine
RUN echo "world"
`), 0644))

res := c.RunDockerCmd("compose", "-f", filepath.Join(dir, "compose.yaml"), "build")

res.Assert(t, icmd.Expected{Out: `RUN echo "hello"`})
res.Assert(t, icmd.Expected{Out: `RUN echo "world"`})

c.RunDockerCmd("compose", "-f", filepath.Join(dir, "compose.yaml"), "down", "--rmi", "all")
})
}
22 changes: 22 additions & 0 deletions pkg/e2e/compose_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,3 +219,25 @@ func TestCompatibility(t *testing.T) {
c.RunDockerCmd("compose", "-p", projectName, "down")
})
}

func TestConvert(t *testing.T) {
const projectName = "compose-e2e-convert"
c := NewParallelE2eCLI(t, binDir)

wd, err := os.Getwd()
assert.NilError(t, err)

t.Run("up", func(t *testing.T) {
res := c.RunDockerCmd("compose", "-f", "./fixtures/simple-build-test/compose.yaml", "-p", projectName, "convert")
res.Assert(t, icmd.Expected{Out: fmt.Sprintf(`services:
nginx:
build:
context: %s
dockerfile: Dockerfile
networks:
default: null
networks:
default:
name: compose-e2e-convert_default`, filepath.Join(wd, "fixtures", "simple-build-test", "nginx-build")), ExitCode: 0})
})
}
4 changes: 3 additions & 1 deletion pkg/e2e/fixtures/simple-build-test/compose.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
services:
nginx:
build: nginx-build
build:
context: nginx-build
dockerfile: Dockerfile

0 comments on commit c3a5eb2

Please sign in to comment.