Skip to content

Commit ed3127e

Browse files
authored
fix(docker): Fix failing end to end tests (#997)
<!-- Provide summary of changes --> With #980, we fixed an issue which occurred when there were multiple dockerfiles present in the build directory. However, this may have broken our end to end tests, because the call to Docker was formatted as the following: ```sh docker build -t <imageTag> path/to -f Dockerfile ``` This should be fine, but the end to end tests began to fail on Monday with the following output: ```bash addons flow when deploying svc svc deploy should succeed /github.com/aws/amazon-ecs-cli-v2/e2e/addons/addons_test.go:145 unable to prepare context: unable to evaluate symlinks in Dockerfile path: lstat /github.com/aws/amazon-ecs-cli-v2/e2e/addons/Dockerfile: no such file or directory Error: build Dockerfile at ./hello/Dockerfile with tag gallopinggurdey: building image: exit status 1 ``` This indicates that although the Dockerfile path was set to `hello/Dockerfile`, Docker was looking for the file somewhere in the root directory of that path (.) and subsequently failing. This fix always sets the dockerfile path to be relative to the *root* of the docker build context, not the *leaf* of the build context. (previously we were parsing paths like `path/to/dockerfile` into `path/to` and `dockerfile`, assuming that the dockerfile would be searched for in `path/to`, not `path`. This was incorrect.) The new behavior is to call: ```sh docker build -t <imageTag> path/to -f path/to/dockerfile ``` <!-- Issue number, if available. E.g. "Fixes #31", "Addresses #42, 77" --> By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.
1 parent 098e612 commit ed3127e

3 files changed

Lines changed: 7 additions & 7 deletions

File tree

e2e/addons/hello/addons/params.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ App:
44
Env:
55
Type: String
66
Description: The environment name your service is being deployed to.
7-
Service:
7+
Name:
88
Type: String
99
Description: The name of the service being deployed.

internal/pkg/docker/docker.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@ func New() Runner {
2929
}
3030
}
3131

32-
// Build will run a `docker build` command with the input uri, tag, and Dockerfile image path.
32+
// Build will run a `docker build` command with the input uri, tag, and Dockerfile path.
3333
func (r Runner) Build(uri, imageTag, path string) error {
3434
imageName := imageName(uri, imageTag)
35-
dfPath, dfName := filepath.Split(path)
35+
dfDir := filepath.Dir(path)
3636

37-
err := r.Run("docker", []string{"build", "-t", imageName, dfPath, "-f", dfName})
37+
err := r.Run("docker", []string{"build", "-t", imageName, dfDir, "-f", path})
3838

3939
if err != nil {
4040
return fmt.Errorf("building image: %w", err)

internal/pkg/docker/docker_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ func TestBuild(t *testing.T) {
1717

1818
mockURI := "mockURI"
1919
mockImageTag := "mockImageTag"
20-
mockPath := "mockPath/mockDockerfile"
20+
mockPath := "mockPath/to/mockDockerfile"
2121

2222
var mockRunner *mocks.Mockrunner
2323

@@ -32,7 +32,7 @@ func TestBuild(t *testing.T) {
3232
setupMocks: func(controller *gomock.Controller) {
3333
mockRunner = mocks.NewMockrunner(controller)
3434

35-
mockRunner.EXPECT().Run("docker", []string{"build", "-t", imageName(mockURI, mockImageTag), "mockPath/", "-f", "mockDockerfile"}).Return(mockError)
35+
mockRunner.EXPECT().Run("docker", []string{"build", "-t", imageName(mockURI, mockImageTag), "mockPath/to", "-f", "mockPath/to/mockDockerfile"}).Return(mockError)
3636
},
3737
want: fmt.Errorf("building image: %w", mockError),
3838
},
@@ -41,7 +41,7 @@ func TestBuild(t *testing.T) {
4141
setupMocks: func(controller *gomock.Controller) {
4242
mockRunner = mocks.NewMockrunner(controller)
4343

44-
mockRunner.EXPECT().Run("docker", []string{"build", "-t", imageName(mockURI, mockImageTag), "mockPath/", "-f", "mockDockerfile"}).Return(nil)
44+
mockRunner.EXPECT().Run("docker", []string{"build", "-t", imageName(mockURI, mockImageTag), "mockPath/to", "-f", "mockPath/to/mockDockerfile"}).Return(nil)
4545
},
4646
},
4747
}

0 commit comments

Comments
 (0)