Browse Source

Make service>build>dockerfile a simple filename

- It makes it keep a simple filename instead of an absolute path

Signed-off-by: Ulysses Souza <[email protected]>
Ulysses Souza 4 năm trước cách đây
mục cha
commit
94379769e3

+ 1 - 1
cmd/compose/convert.go

@@ -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
 	}

+ 1 - 1
go.mod

@@ -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

+ 2 - 2
go.sum

@@ -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=

+ 2 - 1
pkg/compose/build.go

@@ -20,6 +20,7 @@ import (
 	"context"
 	"fmt"
 	"os"
+	"path/filepath"
 
 	"github.com/compose-spec/compose-go/types"
 	"github.com/containerd/containerd/platforms"
@@ -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,

+ 0 - 41
pkg/e2e/compose_build_test.go

@@ -17,10 +17,7 @@
 package e2e
 
 import (
-	"io/ioutil"
 	"net/http"
-	"os"
-	"path/filepath"
 	"strings"
 	"testing"
 	"time"
@@ -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 - 0
pkg/e2e/compose_test.go

@@ -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})
+	})
+}

+ 3 - 1
pkg/e2e/fixtures/simple-build-test/compose.yaml

@@ -1,3 +1,5 @@
 services:
   nginx:
-    build: nginx-build
+    build:
+      context: nginx-build
+      dockerfile: Dockerfile