99from flytekit .clis .sdk_in_container .constants import CTX_PACKAGES
1010from flytekit .configuration import FastSerializationSettings , ImageConfig , SerializationSettings
1111from flytekit .exceptions .scopes import system_entry_point
12+ from flytekit .interaction .click_types import key_value_callback
1213from flytekit .tools .fast_registration import fast_package
1314from flytekit .tools .repo import serialize_to_folder
1415
1516CTX_IMAGE = "image"
1617CTX_LOCAL_SRC_ROOT = "local_source_root"
1718CTX_FLYTEKIT_VIRTUALENV_ROOT = "flytekit_virtualenv_root"
1819CTX_PYTHON_INTERPRETER = "python_interpreter"
20+ CTX_ENV = "env"
1921
2022
2123class SerializationMode (_Enum ):
@@ -33,6 +35,7 @@ def serialize_all(
3335 flytekit_virtualenv_root : typing .Optional [str ] = None ,
3436 python_interpreter : typing .Optional [str ] = None ,
3537 config_file : typing .Optional [str ] = None ,
38+ env : typing .Optional [typing .Dict [str , str ]] = None ,
3639):
3740 """
3841 This function will write to the folder specified the following protobuf types ::
@@ -64,6 +67,7 @@ def serialize_all(
6467 ),
6568 flytekit_virtualenv_root = flytekit_virtualenv_root ,
6669 python_interpreter = python_interpreter ,
70+ env = env ,
6771 )
6872
6973 serialize_to_folder (pkgs , serialization_settings , local_source_root , folder )
@@ -106,9 +110,23 @@ def serialize_all(
106110 "installed inside your container. Required for running `pyflyte serialize` in out of container mode when "
107111 "your container installs the flytekit virtualenv outside of the default `/opt/venv`" ,
108112)
113+ @click .option (
114+ "--env" ,
115+ "--envvars" ,
116+ required = False ,
117+ multiple = True ,
118+ type = str ,
119+ callback = key_value_callback ,
120+ help = "Environment variables to set in the container, of the format `ENV_NAME=ENV_VALUE`" ,
121+ )
109122@click .pass_context
110123def serialize (
111- ctx , image_config : ImageConfig , local_source_root , in_container_config_path , in_container_virtualenv_root
124+ ctx ,
125+ image_config : ImageConfig ,
126+ local_source_root ,
127+ in_container_config_path ,
128+ in_container_virtualenv_root ,
129+ env : typing .Optional [typing .Dict [str , str ]],
112130):
113131 """
114132 This command produces protobufs for tasks and templates.
@@ -119,6 +137,7 @@ def serialize(
119137 """
120138 ctx .obj [CTX_IMAGE ] = image_config
121139 ctx .obj [CTX_LOCAL_SRC_ROOT ] = local_source_root
140+ ctx .obj [CTX_ENV ] = env
122141 click .echo (f"Serializing Flyte elements with image { image_config } " )
123142
124143 if in_container_virtualenv_root :
@@ -155,6 +174,7 @@ def workflows(ctx, folder=None):
155174 flytekit_virtualenv_root = ctx .obj [CTX_FLYTEKIT_VIRTUALENV_ROOT ],
156175 python_interpreter = ctx .obj [CTX_PYTHON_INTERPRETER ],
157176 config_file = ctx .obj .get (constants .CTX_CONFIG_FILE , None ),
177+ env = ctx .obj .get (CTX_ENV , None ),
158178 )
159179
160180
@@ -194,6 +214,7 @@ def fast_workflows(ctx, folder=None, deref_symlinks=False):
194214 flytekit_virtualenv_root = ctx .obj [CTX_FLYTEKIT_VIRTUALENV_ROOT ],
195215 python_interpreter = ctx .obj [CTX_PYTHON_INTERPRETER ],
196216 config_file = ctx .obj .get (constants .CTX_CONFIG_FILE , None ),
217+ env = ctx .obj .get (CTX_ENV , None ),
197218 )
198219
199220
0 commit comments