@@ -126,6 +126,8 @@ class CreateVerbArgs:
126126 enable_ipc : bool = False
127127 disable_upgrade : bool = False
128128 update_key : bool = False
129+ env_file : str = ""
130+ proxy_server : str = ""
129131
130132 @property
131133 def ws_name (self ) -> str :
@@ -541,6 +543,18 @@ def add_arguments(self, parser: argparse.ArgumentParser, cli_name: str):
541543 help = "update the key for ros2." ,
542544 default = False ,
543545 )
546+ parser .add_argument (
547+ "--env-file" ,
548+ type = str ,
549+ help = "Path to environment file for rocker" ,
550+ default = None ,
551+ )
552+ parser .add_argument (
553+ "--proxy-server" ,
554+ type = str ,
555+ help = "Proxy server URL for setting proxy environment variables" ,
556+ default = None ,
557+ )
544558
545559 def generate_intermediate_dockerfile_content (self , create_args : CreateVerbArgs ) -> str :
546560 if create_args .apt_packages :
@@ -561,8 +575,22 @@ def generate_intermediate_dockerfile_content(self, create_args: CreateVerbArgs)
561575 """
562576 )
563577
578+ trusted_hosts = (
579+ [
580+ "--trusted-host" ,
581+ "pypi.org" ,
582+ "--trusted-host" ,
583+ "pypi.python.org" ,
584+ "--trusted-host" ,
585+ "files.pythonhosted.org" ,
586+ ]
587+ if create_args .proxy_server
588+ else []
589+ )
564590 python_packages_cmd = mv_externally_managed_cmd + " " .join (
565- ["RUN" , "pip3" , "install" , "-U" , "-I" ] + create_args .python_packages
591+ ["RUN" , "pip3" , "install" , "-U" , "-I" ]
592+ + trusted_hosts
593+ + create_args .python_packages
566594 )
567595 else :
568596 python_packages_cmd = "# no python packages to install"
@@ -640,19 +668,44 @@ def generate_intermediate_dockerfile_content(self, create_args: CreateVerbArgs)
640668 else :
641669 update_key_cmds = ""
642670
671+ proxy_env_cmds = ""
672+ if create_args .proxy_server :
673+ proxy_env_cmds = textwrap .dedent (
674+ f"""
675+ ENV http_proxy={ create_args .proxy_server }
676+ ENV https_proxy={ create_args .proxy_server }
677+ ENV HTTP_PROXY={ create_args .proxy_server }
678+ ENV HTTPS_PROXY={ create_args .proxy_server }
679+ ENV PIP_PROXY={ create_args .proxy_server }
680+ ENV no_proxy=localhost,127.0.0.1
681+ ENV NO_PROXY=localhost,127.0.0.1
682+ """
683+ )
684+
685+ pip_config_cmd = ""
686+ if create_args .proxy_server :
687+ pip_config_cmd = textwrap .dedent (
688+ f"""
689+ RUN mkdir -p /root/.config/pip && \\
690+ echo -e "[global]\\ nproxy = { create_args .proxy_server } \\ ntrusted-host = pypi.org pypi.python.org files.pythonhosted.org" > /root/.config/pip/pip.conf
691+ """
692+ )
693+
643694 return textwrap .dedent (
644695 f"""
645- FROM { create_args .base_image_name }
646- { update_key_cmds }
647- RUN apt-get update { "&& apt-get upgrade -y" if not create_args .disable_upgrade else "" }
648- { apt_packages_cmd }
649- { python_packages_cmd }
650- { rtw_clone_cmd }
651- { rtw_install_cmd }
652- { copy_workspace_cmd }
653- { copy_upstream_workspace_cmd }
654- RUN rm -rf /var/lib/apt/lists/*
655- """
696+ FROM { create_args .base_image_name }
697+ { proxy_env_cmds }
698+ { update_key_cmds }
699+ RUN apt-get update { "&& apt-get upgrade -y" if not create_args .disable_upgrade else "" }
700+ { apt_packages_cmd }
701+ { pip_config_cmd }
702+ { python_packages_cmd }
703+ { rtw_clone_cmd }
704+ { rtw_install_cmd }
705+ { copy_workspace_cmd }
706+ { copy_upstream_workspace_cmd }
707+ RUN rm -rf /var/lib/apt/lists/*
708+ """
656709 )
657710
658711 def build_intermediate_docker_image (self , create_args : CreateVerbArgs ):
@@ -928,6 +981,9 @@ def main(self, *, args):
928981 rich .print (create_args )
929982 logger .info ("### CREATE ARGS ###" )
930983
984+ if create_args .env_file and not os .path .exists (create_args .env_file ):
985+ raise RuntimeError (f"Environment file '{ create_args .env_file } ' does not exist." )
986+
931987 if create_args .docker and docker_container_exists (create_args .container_name ):
932988 raise RuntimeError (
933989 f"Docker container with name '{ create_args .container_name } ' already exists.\n "
@@ -974,6 +1030,7 @@ def main(self, *, args):
9741030 final_image_name = create_args .final_image_name ,
9751031 ws_volumes = rocker_ws_volumes ,
9761032 user_override_name = create_args .user_override_name ,
1033+ env_file = create_args .env_file ,
9771034 )
9781035
9791036 if not execute_rocker_cmd (rocker_flags , create_args .rocker_base_image_name ):
0 commit comments