3
3
#
4
4
5
5
import json
6
+ import logging
7
+ import platform
6
8
import uuid
7
- from typing import Callable , Dict , List , Optional , Union
9
+ from typing import Any , Callable , Coroutine , Dict , List , Optional , Union
8
10
9
11
from dagger import Client , Container , File , Service
10
12
from dagger import Secret as DaggerSecret
@@ -56,13 +58,17 @@ def get_base_dockerd_container(dagger_client: Client) -> Container:
56
58
)
57
59
)
58
60
# Expose the docker host port.
61
+ .with_exec (["adduser" , "-u" , "1000" , "-S" , "-H" , "airbyte" ])
59
62
.with_exposed_port (DOCKER_HOST_PORT )
60
63
# We cache /tmp for file sharing between client and daemon.
61
- .with_mounted_cache ("/tmp" , dagger_client .cache_volume (DOCKER_TMP_VOLUME_NAME ))
64
+ .with_mounted_cache ("/tmp" , dagger_client .cache_volume (DOCKER_TMP_VOLUME_NAME ), owner = "airbyte" )
65
+ .with_exec (["chmod" , "777" , "/tmp" ])
62
66
)
63
67
64
68
# We cache /var/lib/docker to avoid downloading images and layers multiple times.
65
- base_container = base_container .with_mounted_cache ("/var/lib/docker" , dagger_client .cache_volume (DOCKER_VAR_LIB_VOLUME_NAME ))
69
+ base_container = base_container .with_mounted_cache (
70
+ "/var/lib/docker" , dagger_client .cache_volume (DOCKER_VAR_LIB_VOLUME_NAME ), owner = "airbyte"
71
+ )
66
72
return base_container
67
73
68
74
@@ -75,8 +81,10 @@ def get_daemon_config_json(registry_mirror_url: Optional[str] = None) -> str:
75
81
Returns:
76
82
str: The json representation of the docker daemon config.
77
83
"""
84
+ storage_driver = "vfs" if platform .system () == "Darwin" else STORAGE_DRIVER
85
+ logging .info (f"Using storage driver: { storage_driver } " )
78
86
daemon_config : Dict [str , Union [List [str ], str ]] = {
79
- "storage-driver" : STORAGE_DRIVER ,
87
+ "storage-driver" : storage_driver ,
80
88
}
81
89
if registry_mirror_url :
82
90
daemon_config ["registry-mirrors" ] = ["http://" + registry_mirror_url ]
@@ -152,7 +160,7 @@ def with_global_dockerd_service(
152
160
).as_service ()
153
161
154
162
155
- def with_bound_docker_host (
163
+ async def with_bound_docker_host (
156
164
context : ConnectorContext ,
157
165
container : Container ,
158
166
) -> Container :
@@ -165,21 +173,22 @@ def with_bound_docker_host(
165
173
Container: The container bound to the docker host.
166
174
"""
167
175
assert context .dockerd_service is not None
176
+ current_user = (await container .with_exec (["whoami" ]).stdout ()).strip ()
168
177
return (
169
178
container .with_env_variable ("DOCKER_HOST" , f"tcp://{ DOCKER_HOST_NAME } :{ DOCKER_HOST_PORT } " )
170
179
.with_service_binding (DOCKER_HOST_NAME , context .dockerd_service )
171
- .with_mounted_cache ("/tmp" , context .dagger_client .cache_volume (DOCKER_TMP_VOLUME_NAME ))
180
+ .with_mounted_cache ("/tmp" , context .dagger_client .cache_volume (DOCKER_TMP_VOLUME_NAME ), owner = current_user )
172
181
)
173
182
174
183
175
- def bound_docker_host (context : ConnectorContext ) -> Callable [[Container ], Container ]:
176
- def bound_docker_host_inner (container : Container ) -> Container :
177
- return with_bound_docker_host (context , container )
184
+ def bound_docker_host (context : ConnectorContext ) -> Callable [[Container ], Coroutine [ Any , Any , Container ] ]:
185
+ async def bound_docker_host_inner (container : Container ) -> Container :
186
+ return await with_bound_docker_host (context , container )
178
187
179
188
return bound_docker_host_inner
180
189
181
190
182
- def with_docker_cli (context : ConnectorContext ) -> Container :
191
+ async def with_docker_cli (context : ConnectorContext ) -> Container :
183
192
"""Create a container with the docker CLI installed and bound to a persistent docker host.
184
193
185
194
Args:
@@ -189,7 +198,7 @@ def with_docker_cli(context: ConnectorContext) -> Container:
189
198
Container: A docker cli container bound to a docker host.
190
199
"""
191
200
docker_cli = context .dagger_client .container ().from_ (consts .DOCKER_CLI_IMAGE )
192
- return with_bound_docker_host (context , docker_cli )
201
+ return await with_bound_docker_host (context , docker_cli )
193
202
194
203
195
204
async def load_image_to_docker_host (context : ConnectorContext , tar_file : File , image_tag : str ) -> str :
@@ -202,7 +211,7 @@ async def load_image_to_docker_host(context: ConnectorContext, tar_file: File, i
202
211
"""
203
212
# Hacky way to make sure the image is always loaded
204
213
tar_name = f"{ str (uuid .uuid4 ())} .tar"
205
- docker_cli = with_docker_cli (context ).with_mounted_file (tar_name , tar_file )
214
+ docker_cli = ( await with_docker_cli (context ) ).with_mounted_file (tar_name , tar_file )
206
215
207
216
image_load_output = await docker_cli .with_exec (["docker" , "load" , "--input" , tar_name ], use_entrypoint = True ).stdout ()
208
217
# Not tagged images only have a sha256 id the load output shares.
0 commit comments