-
Notifications
You must be signed in to change notification settings - Fork 4k
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
feat(ecr-assets): custom docker files #5652
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
30b75f0
support custom docker files
iliapolo bf319f4
Merge branch 'master' into epolon/custom-docker-files
iliapolo 119458f
revert tsconfig changes
iliapolo d93c246
doc strings modification according to conventions
iliapolo da68fa8
Merge branch 'master' into epolon/custom-docker-files
iliapolo 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
5 changes: 5 additions & 0 deletions
5
packages/@aws-cdk/aws-ecr-assets/test/demo-image-custom-docker-file/Dockerfile.Custom
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,5 @@ | ||
FROM python:3.6 | ||
EXPOSE 8000 | ||
WORKDIR /src | ||
ADD . /src | ||
CMD python3 index.py |
33 changes: 33 additions & 0 deletions
33
packages/@aws-cdk/aws-ecr-assets/test/demo-image-custom-docker-file/index.py
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,33 @@ | ||
#!/usr/bin/python | ||
import sys | ||
import textwrap | ||
import http.server | ||
import socketserver | ||
|
||
PORT = 8000 | ||
|
||
|
||
class Handler(http.server.SimpleHTTPRequestHandler): | ||
def do_GET(self): | ||
self.send_response(200) | ||
self.send_header('Content-Type', 'text/html') | ||
self.end_headers() | ||
self.wfile.write(textwrap.dedent('''\ | ||
<!doctype html> | ||
<html><head><title>It works</title></head> | ||
<body> | ||
<h1>Hello from the integ test container</h1> | ||
<p>This container got built and started as part of the integ test.</p> | ||
<img src="https://media.giphy.com/media/nFjDu1LjEADh6/giphy.gif"> | ||
</body> | ||
''').encode('utf-8')) | ||
|
||
|
||
def main(): | ||
httpd = http.server.HTTPServer(("", PORT), Handler) | ||
print("serving at port", PORT) | ||
httpd.serve_forever() | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
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 | ||||
---|---|---|---|---|---|---|
|
@@ -87,6 +87,23 @@ export = { | |||||
test.done(); | ||||||
}, | ||||||
|
||||||
'with file'(test: Test) { | ||||||
// GIVEN | ||||||
const stack = new Stack(); | ||||||
|
||||||
const directoryPath = path.join(__dirname, 'demo-image-custom-docker-file'); | ||||||
// WHEN | ||||||
new DockerImageAsset(stack, 'Image', { | ||||||
directory: directoryPath, | ||||||
file: 'Dockerfile.Custom' | ||||||
}); | ||||||
|
||||||
// THEN | ||||||
const assetMetadata = stack.node.metadata.find(({ type }) => type === ASSET_METADATA); | ||||||
test.deepEqual(assetMetadata && assetMetadata.data.file, path.join(directoryPath, 'Dockerfile.Custom')); | ||||||
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. This assertion should have just been:
Suggested change
|
||||||
test.done(); | ||||||
}, | ||||||
|
||||||
'asset.repository.grantPull can be used to grant a principal permissions to use the image'(test: Test) { | ||||||
// GIVEN | ||||||
const stack = new Stack(); | ||||||
|
@@ -211,7 +228,21 @@ export = { | |||||
new DockerImageAsset(stack, 'Asset', { | ||||||
directory: __dirname | ||||||
}); | ||||||
}, /No 'Dockerfile' found in/); | ||||||
}, /Cannot find file at/); | ||||||
test.done(); | ||||||
}, | ||||||
|
||||||
'fails if the file does not exist'(test: Test) { | ||||||
// GIVEN | ||||||
const stack = new Stack(); | ||||||
|
||||||
// THEN | ||||||
test.throws(() => { | ||||||
new DockerImageAsset(stack, 'Asset', { | ||||||
directory: __dirname, | ||||||
file: 'doesnt-exist' | ||||||
}); | ||||||
}, /Cannot find file at/); | ||||||
test.done(); | ||||||
}, | ||||||
|
||||||
|
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
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
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.
This needs to be a relative path since the docker directory is copied into cloud assembly ("staging"). Since we resolve
dir
above, it results in an absolute path.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.
I think
props.file
would just work hereThere 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.
This was actually done intentionally. The idea was to do the validation as soon as possible (like the other validations). To validate - I have to
join
the directory and the file. If I were to pass only the relative path here, it means the cli would have tojoin
again - resulting in duplicate logic. I think its also inline with the notion of letting the framework do the work and keeping the cli as simple as possible.I think what I missed though is that the final command would look something like:
docker build --file ${props.directory}/${props.file} /generated/path/to/cloudassemby/....
Which means the command relies on resources outside the cloudassemly. Is this what you meant by:
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.
Ok that the validation is done early, but the value passed to "docker build" needs to be relative to the docker directory.
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.
Actually the value can't be relative because docker will fail - it doesn't assume you pass a relative path to the context when you use
--file
.The path passed to
docker build --file
should be absolute, it just needs to be derived from the asset path inside the cloud assembly. What has to be relative is the property passed to the asset, since otherwise, themanifest
in the cloud-assembly will contain an absolute path of the machine the assembly was created on.