Skip to content
This repository has been archived by the owner on Nov 27, 2023. It is now read-only.

Fix --project-directory mix with --workdir #1353

Merged
merged 2 commits into from
Mar 1, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
7 changes: 3 additions & 4 deletions cli/cmd/compose/compose.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ type projectOptions struct {
ProjectName string
Profiles []string
ConfigPaths []string
WorkingDir string
ProjectDir string
EnvFile string
}

Expand All @@ -41,8 +41,7 @@ func (o *projectOptions) addProjectFlags(f *pflag.FlagSet) {
f.StringVarP(&o.ProjectName, "project-name", "p", "", "Project name")
f.StringArrayVarP(&o.ConfigPaths, "file", "f", []string{}, "Compose configuration files")
f.StringVar(&o.EnvFile, "env-file", "", "Specify an alternate environment file.")
f.StringVar(&o.WorkingDir, "workdir", "", "Specify an alternate working directory")
// TODO make --project-directory an alias
f.StringVar(&o.ProjectDir, "project-directory", "", "Specify an alternate working directory\n(default: the path of the Compose file)")
Copy link
Contributor

Choose a reason for hiding this comment

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

unfortunately we can't just break existing usage on ACI/ECS like this I think, we'll need to keep workdir an alias of this flag (confusing with the exec one I agree, but... we can put project-directory in front more visible of course, just support running with the --workdir alias)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I understand it's a breaking change, but that's actually a bug fix.
The problem is that in the case of exec and run we can use both at the same time. So in this case it's broken.

}

func (o *projectOptions) toProjectName() (string, error) {
Expand Down Expand Up @@ -87,7 +86,7 @@ func (o *projectOptions) toProjectOptions() (*cli.ProjectOptions, error) {
cli.WithEnvFile(o.EnvFile),
cli.WithDotEnv,
cli.WithOsEnv,
cli.WithWorkingDirectory(o.WorkingDir),
cli.WithWorkingDirectory(o.ProjectDir),
cli.WithName(o.ProjectName))
}

Expand Down
10 changes: 5 additions & 5 deletions local/e2e/compose/compose_build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func TestLocalComposeBuild(t *testing.T) {
c.RunDockerOrExitError("rmi", "build-test_nginx")
c.RunDockerOrExitError("rmi", "custom-nginx")

res := c.RunDockerCmd("compose", "--workdir", "fixtures/build-test", "build")
res := c.RunDockerCmd("compose", "--project-directory", "fixtures/build-test", "build")

res.Assert(t, icmd.Expected{Out: "COPY static /usr/share/nginx/html"})
c.RunDockerCmd("image", "inspect", "build-test_nginx")
Expand All @@ -47,9 +47,9 @@ func TestLocalComposeBuild(t *testing.T) {
c.RunDockerOrExitError("rmi", "build-test_nginx")
c.RunDockerOrExitError("rmi", "custom-nginx")

res := c.RunDockerCmd("compose", "--workdir", "fixtures/build-test", "up", "-d")
res := c.RunDockerCmd("compose", "--project-directory", "fixtures/build-test", "up", "-d")
t.Cleanup(func() {
c.RunDockerCmd("compose", "--workdir", "fixtures/build-test", "down")
c.RunDockerCmd("compose", "--project-directory", "fixtures/build-test", "down")
})

res.Assert(t, icmd.Expected{Out: "COPY static /usr/share/nginx/html"})
Expand All @@ -62,13 +62,13 @@ func TestLocalComposeBuild(t *testing.T) {
})

t.Run("no rebuild when up again", func(t *testing.T) {
res := c.RunDockerCmd("compose", "--workdir", "fixtures/build-test", "up", "-d")
res := c.RunDockerCmd("compose", "--project-directory", "fixtures/build-test", "up", "-d")

assert.Assert(t, !strings.Contains(res.Stdout(), "COPY static /usr/share/nginx/html"), res.Stdout())
})

t.Run("cleanup build project", func(t *testing.T) {
c.RunDockerCmd("compose", "--workdir", "fixtures/build-test", "down")
c.RunDockerCmd("compose", "--project-directory", "fixtures/build-test", "down")
c.RunDockerCmd("rmi", "build-test_nginx")
c.RunDockerCmd("rmi", "custom-nginx")
})
Expand Down
2 changes: 1 addition & 1 deletion local/e2e/compose/compose_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func TestLocalComposeUp(t *testing.T) {
func TestComposePull(t *testing.T) {
c := NewParallelE2eCLI(t, binDir)

res := c.RunDockerOrExitError("compose", "--workdir", "fixtures/simple-composefile", "pull")
res := c.RunDockerOrExitError("compose", "--project-directory", "fixtures/simple-composefile", "pull")
output := res.Combined()

assert.Assert(t, strings.Contains(output, "simple Pulled"))
Expand Down
2 changes: 1 addition & 1 deletion local/e2e/compose/volumes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func TestLocalComposeVolume(t *testing.T) {
c.RunDockerOrExitError("rmi", "compose-e2e-volume_nginx")
c.RunDockerOrExitError("volume", "rm", projectName+"_staticVol")
c.RunDockerOrExitError("volume", "rm", "myvolume")
c.RunDockerCmd("compose", "--workdir", "fixtures/volume-test", "--project-name", projectName, "up", "-d")
c.RunDockerCmd("compose", "--project-directory", "fixtures/volume-test", "--project-name", projectName, "up", "-d")
})

t.Run("access bind mount data", func(t *testing.T) {
Expand Down