18
18
import json
19
19
import os
20
20
import shutil
21
- import tarfile
22
21
import tempfile
23
22
import time
24
23
from typing import (
@@ -140,8 +139,13 @@ def create_deployment(
140
139
raise
141
140
142
141
143
- DOCKER_IMAGE_NAME = "datacloud-custom-code"
144
- DEPENDENCIES_ARCHIVE_NAME = "dependencies.tar.gz"
142
+ PLATFORM_ENV_VAR = "DOCKER_DEFAULT_PLATFORM=linux/amd64"
143
+ DOCKER_IMAGE_NAME = "datacloud-custom-code-dependency-builder"
144
+ DEPENDENCIES_ARCHIVE_NAME = "native_dependencies"
145
+ DEPENDENCIES_ARCHIVE_FULL_NAME = f"{ DEPENDENCIES_ARCHIVE_NAME } .tar.gz"
146
+ DEPENDENCIES_ARCHIVE_PATH = os .path .join (
147
+ "payload" , "archives" , DEPENDENCIES_ARCHIVE_FULL_NAME
148
+ )
145
149
ZIP_FILE_NAME = "deployment.zip"
146
150
147
151
@@ -150,31 +154,28 @@ def prepare_dependency_archive(directory: str) -> None:
150
154
image_exists = cmd_output (cmd )
151
155
152
156
if not image_exists :
153
- logger .debug ("Building docker image..." )
154
- cmd = f"docker build -t { DOCKER_IMAGE_NAME } ."
157
+ logger .info ("Building docker image..." )
158
+ cmd = (
159
+ f"{ PLATFORM_ENV_VAR } docker build -t { DOCKER_IMAGE_NAME } "
160
+ f"-f Dockerfile.dependencies ."
161
+ )
155
162
cmd_output (cmd )
156
163
157
164
with tempfile .TemporaryDirectory () as temp_dir :
165
+ logger .info ("Building dependencies archive" )
158
166
shutil .copy ("requirements.txt" , temp_dir )
167
+ shutil .copy ("build_native_dependencies.sh" , temp_dir )
159
168
cmd = (
160
- f"docker run --rm "
161
- f"-v { temp_dir } :/dependencies "
162
- f"{ DOCKER_IMAGE_NAME } "
163
- f'/bin/bash -c "cd /dependencies && pip download -r requirements.txt"'
169
+ f"{ PLATFORM_ENV_VAR } docker run --rm "
170
+ f"-v { temp_dir } :/workspace "
171
+ f"{ DOCKER_IMAGE_NAME } "
164
172
)
165
173
cmd_output (cmd )
174
+ archives_temp_path = os .path .join (temp_dir , DEPENDENCIES_ARCHIVE_FULL_NAME )
175
+ os .makedirs (os .path .dirname (DEPENDENCIES_ARCHIVE_PATH ), exist_ok = True )
176
+ shutil .copy (archives_temp_path , DEPENDENCIES_ARCHIVE_PATH )
166
177
167
- archives_dir = os .path .join (directory , "archives" )
168
- os .makedirs (archives_dir , exist_ok = True )
169
- archive_file = os .path .join (archives_dir , DEPENDENCIES_ARCHIVE_NAME )
170
- with tarfile .open (archive_file , "w:gz" ) as tar :
171
- for file in os .listdir (temp_dir ):
172
- # Exclude requirements.txt from the archive
173
- if file == "requirements.txt" :
174
- continue
175
- tar .add (os .path .join (temp_dir , file ), arcname = file )
176
-
177
- logger .debug (f"Dependencies downloaded and archived to { archive_file } " )
178
+ logger .info (f"Dependencies archived to { DEPENDENCIES_ARCHIVE_PATH } " )
178
179
179
180
180
181
class DeploymentsResponse (BaseModel ):
0 commit comments