Fix --project-directory mix with --workdir

Signed-off-by: Ulysses Souza <ulyssessouza@gmail.com>
This commit is contained in:
Ulysses Souza 2021-02-25 17:37:11 -03:00
parent 3420df679b
commit bc234bdcdf
4 changed files with 10 additions and 11 deletions

View File

@ -32,7 +32,7 @@ type projectOptions struct {
ProjectName string
Profiles []string
ConfigPaths []string
WorkingDir string
ProjectDir string
EnvFile string
}
@ -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)")
}
func (o *projectOptions) toProjectName() (string, error) {
@ -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))
}

View File

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

View File

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

View File

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