-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Dockerfile to build context if passed from outside the build cont…
…ext (#542) Breaking Change: If a user provides a Dockerfile, the path specified must be absolute, or relative to the _Pulumi_ context, not the Docker build context. The `dockerfile` field remains optional, and if left blank, we assume traditional location of Dockerfile within the Docker build context. Specifics: - If a user does not specify a Dockerfile the provider defaults to "Dockerfile", relative to Docker build context. The tarball already contains all necessary build files. - If a user declares a Dockerfile, it must be an absolute path or a path relative to the Pulumi.yaml's location in the file system. The provider does its best to detect if a Dockerfile path was declared in error, and sends a helpful error message to the user during `Check()`, i.e. during a `pulumi preview`. - When a Dockerfile is passed from outside the Docker build context, we create a separate Dockerfile context and add it to the build tarball. Note that any COPY statements are now relative to the Docker context, and not the Pulumi program's filesystem location. * Add Dockerfile to build context using the clibuild method Testing this against context: app and dockerfile: Dockerfile, we see error hashing dockerfile "Dockerfile": could not open file Dockerfile: open app/Dockerfile: no such file or directory Unsure if I installed the correct provider version. Retrying. * First attempt at getting a relative Dockerfile so we can hash it properly * Pass relDockerfile to hashContext Currently fails wilt dockerfile frontend error. relDockerfile needs to be passed to the build context tarball. * This now errors with Diagnostics: docker:index:Image (my-image): error: failed to compute cache key: "/app" not found: not found But that just means the Dockerfile is passing the wrong folder - this is an expected error. * Remove debugs and cleanup * fix linter; disable dotnet registry tests * A blank Dockerfile gets tests to pass but reverses the logic for outside-context Dockerfiles again. We need to create different logic for hashing and not use the cli build library. * Use separator as way to determine whether this dockerfile is relative to the build context or not * Use filepath separator detection to determine if a Dockerfile context is needed. * unskip dotnet tests * Refactor relative path getter function for testing purposes * Add unit test for getting the relative path to demonstrate and cement assumptions * lint: handle error * Remove default values for Dockerfile and Context. Refine logic for detecting external Dockerfile. Return dockerfile and context as outputs in schema. Return additional outputs from Create: build context and its relative Dockerfile Pass the replaced Dockerfile to the image build options when necessary Co-authored-by: Aaron Friel <friel@pulumi.com> * Verify existence of Dockerfile in Check function This allows for us to fail early, during preview, and send an error message to a user who is providing an erroneous Dockerfile. Co-authored-by: Aaron Friel <friel@pulumi.com> * Add integration tests for new dockerfile logic Co-authored-by: Aaron Friel <friel@pulumi.com> * Re-generate schema and SDKs * Add a test for a build left blank * Pacify linter --------- Co-authored-by: Aaron Friel <friel@pulumi.com>
- Loading branch information
1 parent
df363db
commit 993e8a3
Showing
32 changed files
with
505 additions
and
137 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
// Copyright 2016-2018, Pulumi Corporation. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
//go:build go || all | ||
// +build go all | ||
|
||
package examples | ||
|
||
import ( | ||
"github.com/pulumi/pulumi/pkg/v3/testing/integration" | ||
"github.com/stretchr/testify/assert" | ||
"os" | ||
"path" | ||
"testing" | ||
) | ||
|
||
func TestDockerfileDefaultYAML(t *testing.T) { | ||
cwd, err := os.Getwd() | ||
if !assert.NoError(t, err) { | ||
t.FailNow() | ||
} | ||
|
||
integration.ProgramTest(t, &integration.ProgramTestOptions{ | ||
Dir: path.Join(cwd, "test-dockerfile", "dockerfile-default"), | ||
Quick: true, | ||
SkipRefresh: true, | ||
}) | ||
} | ||
|
||
func TestDockerfileDefaultContextYAML(t *testing.T) { | ||
cwd, err := os.Getwd() | ||
if !assert.NoError(t, err) { | ||
t.FailNow() | ||
} | ||
|
||
integration.ProgramTest(t, &integration.ProgramTestOptions{ | ||
Dir: path.Join(cwd, "test-dockerfile", "dockerfile-default-context"), | ||
Quick: true, | ||
SkipRefresh: true, | ||
}) | ||
} | ||
|
||
func TestDockerfileExternalYAML(t *testing.T) { | ||
cwd, err := os.Getwd() | ||
if !assert.NoError(t, err) { | ||
t.FailNow() | ||
} | ||
|
||
integration.ProgramTest(t, &integration.ProgramTestOptions{ | ||
Dir: path.Join(cwd, "test-dockerfile", "dockerfile-external"), | ||
Quick: true, | ||
SkipRefresh: true, | ||
}) | ||
} | ||
|
||
func TestDockerfileInContextYAML(t *testing.T) { | ||
cwd, err := os.Getwd() | ||
if !assert.NoError(t, err) { | ||
t.FailNow() | ||
} | ||
|
||
integration.ProgramTest(t, &integration.ProgramTestOptions{ | ||
Dir: path.Join(cwd, "test-dockerfile", "dockerfile-in-context"), | ||
Quick: true, | ||
SkipRefresh: true, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
examples/test-dockerfile/dockerfile-default-context/Dockerfile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
FROM scratch | ||
|
||
COPY . / |
13 changes: 13 additions & 0 deletions
13
examples/test-dockerfile/dockerfile-default-context/Pulumi.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
name: dockerfile-default-context | ||
runtime: yaml | ||
resources: | ||
demo-image: | ||
type: docker:Image | ||
properties: | ||
imageName: pulumibot/test-image:tag | ||
skipPush: true | ||
options: | ||
version: v4.0.0 | ||
outputs: | ||
imageName: ${demo-image.imageName} | ||
out-dockerfile: ${demo-image.dockerfile} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Hi! I am a test file! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
name: dockerfile-default | ||
runtime: yaml | ||
resources: | ||
demo-image: | ||
type: docker:Image | ||
properties: | ||
imageName: pulumibot/test-image:tag2 | ||
skipPush: true | ||
build: | ||
context: ./app | ||
options: | ||
version: v4.0.0 | ||
outputs: | ||
imageName: ${demo-image.imageName} | ||
out-dockerfile: ${demo-image.dockerfile} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
FROM scratch | ||
|
||
COPY . / |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Hi! I am a test file! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
FROM scratch | ||
|
||
COPY .. / |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
name: dockerfile-external | ||
runtime: yaml | ||
resources: | ||
demo-image: | ||
type: docker:Image | ||
properties: | ||
imageName: pulumibot/test-image:tag3 | ||
skipPush: true | ||
build: | ||
context: ./app | ||
dockerfile: ./Dockerfile | ||
options: | ||
version: v4.0.0 | ||
outputs: | ||
imageName: ${demo-image.imageName} | ||
out-dockerfile: ${demo-image.dockerfile} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Hi! I am a test file! |
15 changes: 15 additions & 0 deletions
15
examples/test-dockerfile/dockerfile-in-context/Pulumi.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
name: dockerfile-in-context | ||
runtime: yaml | ||
resources: | ||
demo-image: | ||
type: docker:Image | ||
properties: | ||
imageName: pulumibot/test-image:tag1 | ||
skipPush: true | ||
build: | ||
context: ./app | ||
dockerfile: ./app/Dockerfile | ||
options: | ||
version: v4.0.0 | ||
outputs: | ||
imageName: ${demo-image.imageName} |
3 changes: 3 additions & 0 deletions
3
examples/test-dockerfile/dockerfile-in-context/app/Dockerfile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
FROM scratch | ||
|
||
COPY . / |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Hi! I am a test file! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.