-
Notifications
You must be signed in to change notification settings - Fork 5.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support buildkit build time secrets #7046
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,9 @@ | ||
# syntax=docker/dockerfile:1.0.0-experimental | ||
FROM busybox | ||
|
||
# https://github.com/moby/moby/issues/1996#issuecomment-550020843 | ||
ARG CACHEBUST | ||
|
||
RUN --mount=type=secret,target=/secret,required cp secret out | ||
RUN --mount=type=secret,target=/secret_3,required cat secret_3 >> out | ||
CMD cat out |
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,10 @@ | ||
version: '3.7' | ||
services: | ||
foo: | ||
build: | ||
context: . | ||
secrets: | ||
- | ||
id: secret | ||
src: "${FOO_SECRET:-secret_1}" | ||
- secret_3 |
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 @@ | ||
secret 1 |
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 @@ | ||
secret 2 |
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 @@ | ||
secret 3 |
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 | ||
---|---|---|---|---|
|
@@ -7,6 +7,7 @@ | |||
import tempfile | ||||
from distutils.spawn import find_executable | ||||
from os import path | ||||
from textwrap import dedent | ||||
|
||||
import pytest | ||||
from docker.errors import APIError | ||||
|
@@ -973,12 +974,49 @@ def test_build_cli(self): | |||
self.addCleanup(shutil.rmtree, base_dir) | ||||
|
||||
with open(os.path.join(base_dir, 'Dockerfile'), 'w') as f: | ||||
f.write("FROM busybox\n") | ||||
# f.write("FROM busybox\n") | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove commented code?
Suggested change
|
||||
f.write(dedent("""\ | ||||
# syntax=docker/dockerfile:1.0.0-experimental | ||||
FROM busybox | ||||
RUN --mount=type=secret,target=/secret_1 true | ||||
""")) | ||||
|
||||
service = self.create_service('web', | ||||
build={'context': base_dir}, | ||||
environment={ | ||||
'COMPOSE_DOCKER_CLI_BUILD': '1', | ||||
'DOCKER_BUILDKIT': '1', | ||||
}) | ||||
service.build(cli=True) | ||||
self.addCleanup(self.client.remove_image, service.image_name) | ||||
assert self.client.inspect_image('composetest_web') | ||||
|
||||
def test_build_cli_with_secrets(self): | ||||
base_dir = tempfile.mkdtemp() | ||||
self.addCleanup(shutil.rmtree, base_dir) | ||||
secret_path_1 = os.path.join(base_dir, 'secret_1') | ||||
secret_path_2 = os.path.join(base_dir, 'secret_2') | ||||
|
||||
with open(os.path.join(base_dir, 'Dockerfile'), 'w') as f: | ||||
# f.write("FROM busybox\n") | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove commented code?
Suggested change
|
||||
f.write(dedent("""\ | ||||
# syntax=docker/dockerfile:1.0.0-experimental | ||||
FROM busybox | ||||
RUN --mount=type=secret,target=/secret_1,required cat /secret_1 | ||||
RUN --mount=type=secret,target=/secret_2,required cat /secret_2 | ||||
""")) | ||||
with open(secret_path_1, 'w') as f: | ||||
f.write("secret 1\n") | ||||
with open(secret_path_2, 'w') as f: | ||||
f.write("secret 2\n") | ||||
|
||||
service = self.create_service('web', | ||||
build={ | ||||
'context': base_dir, | ||||
'secrets': [ | ||||
{'id': 'secret_1', 'src': secret_path_1}, | ||||
{'id': 'secret_2', 'src': secret_path_2}] | ||||
}, | ||||
environment={ | ||||
'DOCKER_BUILDKIT': '1', | ||||
}) | ||||
service.build(cli=True) | ||||
|
@@ -992,12 +1030,7 @@ def test_up_build_cli(self): | |||
with open(os.path.join(base_dir, 'Dockerfile'), 'w') as f: | ||||
f.write("FROM busybox\n") | ||||
|
||||
web = self.create_service('web', | ||||
build={'context': base_dir}, | ||||
environment={ | ||||
'COMPOSE_DOCKER_CLI_BUILD': '1', | ||||
'DOCKER_BUILDKIT': '1', | ||||
}) | ||||
web = self.create_service('web', build={'context': base_dir}) | ||||
project = Project('composetest', [web], self.client) | ||||
project.up(do_build=BuildAction.force) | ||||
|
||||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that we can't update the 3.7 schema, as it's already been released, so to add this property to the schema, it probably has to be added to the upcoming 3.9 schema in https://github.com/docker/cli/blob/master/cli/compose/schema/data/config_schema_v3.9.json first