Skip to content

Commit 7b3d381

Browse files
authored
feat(core): support ssh build arg in DockerImageAsset (#26356)
Adds support for the docker build --ssh flag for specifying ssh agent socket or ssh keys for ecr DockerImageAsset ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 4bf0762 commit 7b3d381

File tree

22 files changed

+296
-40
lines changed

22 files changed

+296
-40
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
FROM public.ecr.aws/lambda/python:3.6
2+
RUN yum makecache fast
3+
RUN yum install -y openssh-clients
4+
RUN ssh-keygen -t rsa -b 2048 -f /root/.ssh/id_rsa -q -N ""
5+
RUN ssh-keygen -y -f /root/.ssh/id_rsa > /root/.ssh/id_rsa.pub
6+
RUN cat /root/.ssh/id_rsa.pub >> out.pub
7+
WORKDIR /app
8+
EXPOSE 8000
9+
ADD . /app
10+
CMD python3 index.py
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/usr/bin/python
2+
import os
3+
import sys
4+
import textwrap
5+
import http.server
6+
import socketserver
7+
8+
PORT = 8000
9+
10+
class Handler(http.server.SimpleHTTPRequestHandler):
11+
def do_GET(self):
12+
with open('/root/.ssh/id_rsa.pub', 'r') as file:
13+
data = file.read()
14+
15+
self.send_response(200)
16+
self.send_header('Content-Type', 'text/html')
17+
self.end_headers()
18+
self.wfile.write(textwrap.dedent(f'''\
19+
<!doctype html>
20+
<html><head><title>It works</title></head>
21+
<body>
22+
<h1>Hello from the integ test container</h1>
23+
<p>This container got built and started as part of the integ test.</p>
24+
<p>Public key: {data}</p>
25+
<img src="https://media.giphy.com/media/nFjDu1LjEADh6/giphy.gif">
26+
</body>
27+
''').encode('utf-8'))
28+
29+
def main():
30+
httpd = http.server.HTTPServer(("", PORT), Handler)
31+
print("serving at port", PORT)
32+
httpd.serve_forever()
33+
34+
if __name__ == '__main__':
35+
main()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
FROM public.ecr.aws/lambda/python:3.6
2+
RUN yum makecache fast
3+
RUN yum install -y openssh-clients
4+
RUN ssh-keygen -t rsa -b 2048 -f /root/.ssh/id_rsa -q -N ""
5+
RUN ssh-keygen -y -f /root/.ssh/id_rsa > /root/.ssh/id_rsa.pub
6+
WORKDIR /app
7+
CMD python3 index.py
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/usr/bin/python
2+
import os
3+
import sys
4+
import textwrap
5+
import http.server
6+
import socketserver
7+
8+
PORT = 8000
9+
10+
class Handler(http.server.SimpleHTTPRequestHandler):
11+
def do_GET(self):
12+
with open('/root/.ssh/id_rsa.pub', 'r') as file:
13+
data = file.read()
14+
15+
self.send_response(200)
16+
self.send_header('Content-Type', 'text/html')
17+
self.end_headers()
18+
self.wfile.write(textwrap.dedent(f'''\
19+
<!doctype html>
20+
<html><head><title>It works</title></head>
21+
<body>
22+
<h1>Hello from the integ test container</h1>
23+
<p>This container got built and started as part of the integ test.</p>
24+
<p>Public key: {data}</p>
25+
<img src="https://media.giphy.com/media/nFjDu1LjEADh6/giphy.gif">
26+
</body>
27+
''').encode('utf-8'))
28+
29+
def main():
30+
httpd = http.server.HTTPServer(("", PORT), Handler)
31+
print("serving at port", PORT)
32+
httpd.serve_forever()
33+
34+
if __name__ == '__main__':
35+
main()
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"version":"29.0.0"}
1+
{"version":"33.0.0"}

packages/@aws-cdk-testing/framework-integ/test/aws-ecr-assets/test/integ.assets-docker.js.snapshot/integ-assets-docker.assets.json

+15-3
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
{
2-
"version": "29.0.0",
2+
"version": "33.0.0",
33
"files": {
4-
"b1025f887a56783d23c02c714067f4e119f3a3393c9db47c7ce05076e52e58bd": {
4+
"edc1ba041db81671404e8a861496095ba07bd672d374473e59818e6cb877af42": {
55
"source": {
66
"path": "integ-assets-docker.template.json",
77
"packaging": "file"
88
},
99
"destinations": {
1010
"current_account-current_region": {
1111
"bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}",
12-
"objectKey": "b1025f887a56783d23c02c714067f4e119f3a3393c9db47c7ce05076e52e58bd.json",
12+
"objectKey": "edc1ba041db81671404e8a861496095ba07bd672d374473e59818e6cb877af42.json",
1313
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}"
1414
}
1515
}
@@ -70,6 +70,18 @@
7070
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-image-publishing-role-${AWS::AccountId}-${AWS::Region}"
7171
}
7272
}
73+
},
74+
"6308cecadfac022764e8f3e3272baeab95b48a260cae3978b7ef93bd3ff2be17": {
75+
"source": {
76+
"directory": "asset.6308cecadfac022764e8f3e3272baeab95b48a260cae3978b7ef93bd3ff2be17"
77+
},
78+
"destinations": {
79+
"current_account-current_region": {
80+
"repositoryName": "cdk-hnb659fds-container-assets-${AWS::AccountId}-${AWS::Region}",
81+
"imageTag": "6308cecadfac022764e8f3e3272baeab95b48a260cae3978b7ef93bd3ff2be17",
82+
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-image-publishing-role-${AWS::AccountId}-${AWS::Region}"
83+
}
84+
}
7385
}
7486
}
7587
}

packages/@aws-cdk-testing/framework-integ/test/aws-ecr-assets/test/integ.assets-docker.js.snapshot/integ-assets-docker.template.json

+5
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,11 @@
8686
"Value": {
8787
"Fn::Sub": "${AWS::AccountId}.dkr.ecr.${AWS::Region}.${AWS::URLSuffix}/cdk-hnb659fds-container-assets-${AWS::AccountId}-${AWS::Region}:0a3355be12051c9984bf2b0b2bba4e6ea535968e5b6e7396449701732fe5ed14"
8888
}
89+
},
90+
"ImageUri7": {
91+
"Value": {
92+
"Fn::Sub": "${AWS::AccountId}.dkr.ecr.${AWS::Region}.${AWS::URLSuffix}/cdk-hnb659fds-container-assets-${AWS::AccountId}-${AWS::Region}:6308cecadfac022764e8f3e3272baeab95b48a260cae3978b7ef93bd3ff2be17"
93+
}
8994
}
9095
},
9196
"Parameters": {

packages/@aws-cdk-testing/framework-integ/test/aws-ecr-assets/test/integ.assets-docker.js.snapshot/integ.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version": "29.0.0",
2+
"version": "33.0.0",
33
"testCases": {
44
"integ.assets-docker": {
55
"stacks": [

packages/@aws-cdk-testing/framework-integ/test/aws-ecr-assets/test/integ.assets-docker.js.snapshot/manifest.json

+14-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version": "29.0.0",
2+
"version": "33.0.0",
33
"artifacts": {
44
"integ-assets-docker.assets": {
55
"type": "cdk:asset-manifest",
@@ -17,7 +17,7 @@
1717
"validateOnSynth": false,
1818
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-${AWS::Region}",
1919
"cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-cfn-exec-role-${AWS::AccountId}-${AWS::Region}",
20-
"stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/b1025f887a56783d23c02c714067f4e119f3a3393c9db47c7ce05076e52e58bd.json",
20+
"stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/edc1ba041db81671404e8a861496095ba07bd672d374473e59818e6cb877af42.json",
2121
"requiresBootstrapStackVersion": 6,
2222
"bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version",
2323
"additionalDependencies": [
@@ -75,6 +75,18 @@
7575
"data": "ImageUri5"
7676
}
7777
],
78+
"/integ-assets-docker/ImageUri6": [
79+
{
80+
"type": "aws:cdk:logicalId",
81+
"data": "ImageUri6"
82+
}
83+
],
84+
"/integ-assets-docker/ImageUri7": [
85+
{
86+
"type": "aws:cdk:logicalId",
87+
"data": "ImageUri7"
88+
}
89+
],
7890
"/integ-assets-docker/BootstrapVersion": [
7991
{
8092
"type": "aws:cdk:logicalId",

0 commit comments

Comments
 (0)