def install_binaries(self, url): """Return Dockerfile instructions to install FSL using binaries hosted on FSL's website. """ from neurodocker.generate import _add_to_entrypoint cmd = self._install_binaries_deps() cmd += ('\n&& echo "Downloading FSL ..."' '\n&& curl -sSL --retry 5 {}' '\n| tar zx -C /opt'.format(url)) if self.version >= LooseVersion('5.0.10'): fsl_python = "/opt/fsl/etc/fslconf/fslpython_install.sh" cmd += "\n&& /bin/bash {} -q -f /opt/fsl".format(fsl_python) if self.eddy_5011: cmd += self._install_eddy_5011() ent_cmds = ["echo Some packages in this Docker container are non-free", ("echo If you are considering commercial use of this" " container, please consult the relevant license:"), "echo https://fsl.fmrib.ox.ac.uk/fsl/fslwiki/Licence", "source $FSLDIR/etc/fslconf/fsl.sh"] cmd += "\n&& {}".format(_add_to_entrypoint(ent_cmds, with_run=False)) cmd = indent("RUN", cmd) env_cmd = ("FSLDIR=/opt/fsl" "\nPATH=/opt/fsl/bin:$PATH") env_cmd = indent("ENV", env_cmd) return "\n".join((cmd, env_cmd))
def install_miniconda(self): """Return Dockerfile instructions to install Miniconda.""" install_url = ("https://repo.continuum.io/miniconda/" "Miniconda3-{}-Linux-x86_64.sh" "".format(self.miniconda_version)) if self.check_urls: check_url(install_url) env_cmd = ("CONDA_DIR={0}" "\nPATH={0}/bin:$PATH".format(Miniconda.INSTALL_PATH)) env_cmd = indent("ENV", env_cmd) cmds = ['echo "Downloading Miniconda installer ..."', "miniconda_installer=/tmp/miniconda.sh", "curl -sSL --retry 5 -o $miniconda_installer {url}", "/bin/bash $miniconda_installer -b -p $CONDA_DIR", "rm -f $miniconda_installer", "conda config --system --prepend channels conda-forge", "conda config --system --set auto_update_conda false", "conda config --system --set show_channel_urls true", "conda clean -tipsy && sync", ] if self.miniconda_version == 'latest': cmds.insert(-1, 'conda update -n base conda') cmd = indent("RUN", '\n&& '.join(cmds).format(url=install_url)) Miniconda.INSTALLED = True return "\n".join((env_cmd, cmd))
def install_miniconda(self): """Return Dockerfile instructions to install Miniconda.""" install_url = ("https://repo.continuum.io/miniconda/" "Miniconda3-{}-Linux-x86_64.sh" "".format(self.miniconda_version)) if self.check_urls: check_url(install_url) env_cmd = ("CONDA_DIR={0}" "\nPATH={0}/bin:$PATH".format(Miniconda.INSTALL_PATH)) env_cmd = indent("ENV", env_cmd) cmd = ('echo "Downloading Miniconda installer ..."' "\n&& miniconda_installer=/tmp/miniconda.sh" "\n&& curl -sSL -o $miniconda_installer {url}" "\n&& /bin/bash $miniconda_installer -b -p $CONDA_DIR" "\n&& rm -f $miniconda_installer" "\n&& conda config --system --prepend channels conda-forge" "\n&& conda config --system --set auto_update_conda false" "\n&& conda config --system --set show_channel_urls true" "\n&& conda update -y -q --all && sync" "\n&& conda clean -tipsy && sync" "".format(Miniconda.INSTALL_PATH, url=install_url)) cmd = indent("RUN", cmd) Miniconda.INSTALLED = True return "\n".join((env_cmd, cmd))
def create_from_yaml(self): """Return Dockerfile instructions to create conda environment from a YAML file. """ tmp_yml = "/tmp/environment.yml" cmd = ("conda env create -q --name {n} --file {tmp}" "\n&& rm -f {tmp}") if is_url(self.yaml_file): get_file = "curl -sSL {f} > {tmp}" cmd = get_file + "\n&& " + cmd if self.check_urls: check_url(self.yaml_file) cmd = indent("RUN", cmd) else: get_file = 'COPY ["{f}", "{tmp}"]' cmd = indent("RUN", cmd) cmd = "\n".join((get_file, cmd)) cmd = cmd.format(n=self.env_name, f=self.yaml_file, tmp=tmp_yml) if self.add_to_path: bin_path = posixpath.join(Miniconda.INSTALL_PATH, 'envs', self.env_name, 'bin') env_cmd = "ENV PATH={}:$PATH".format(bin_path) return "\n".join((cmd, env_cmd)) return cmd
def test_indent(): pre = "FROM" cmd = "centos:latest" indented = ' '.join((pre, cmd)) assert utils.indent( pre, cmd) == indented, "error prepending Dockerfile instruction" pre = "RUN" cmd = ("echo 'green eggs'\n" "&& echo ' and'\n" "&& echo ' ham'") indented = ("RUN echo 'green eggs' \\\n" " && echo ' and' \\\n" " && echo ' ham'") assert utils.indent( pre, cmd) == indented, "error indenting multi-line instruction"
def build_from_source(self): """Return Dockerfile instructions to build dcm2niix from source. """ pkgs = { 'apt': 'cmake g++ gcc git make pigz zlib1g-dev', 'yum': 'cmake gcc-c++ git libstdc++-static make pigz zlib-devel' } url = ("https://github.com/rordenlab/dcm2niix/tarball/{}".format( self.version)) if self.check_urls: check_url(url) workdir_cmd = "WORKDIR /tmp" cmd = ("deps='{pkgs}'" "\n&& {install}" "\n&& {clean}" "\n&& mkdir dcm2niix" "\n&& curl -sSL {url} | tar xz -C dcm2niix --strip-components 1" "\n&& mkdir dcm2niix/build && cd dcm2niix/build" "\n&& cmake .. && make" "\n&& make install" "\n&& rm -rf /tmp/*" "".format(pkgs=pkgs[self.pkg_manager], url=url, **manage_pkgs[self.pkg_manager])) cmd = cmd.format(pkgs='$deps') cmd = indent("RUN", cmd) return "\n".join((workdir_cmd, cmd))
def create_conda_env(self): """Return Dockerfile instructions to create conda environment with desired version of Python and desired conda and pip packages. """ cmd = "conda create -y -q --name {}".format(self.env_name) if self.conda_opts: cmd = "{} {}".format(cmd, self.conda_opts) cmd = "{} python={}".format(cmd, self.python_version) if self.conda_install: if isinstance(self.conda_install, (list, tuple)): self.conda_install = " ".join(self.conda_install) cmd += "\n\t{}".format(self.conda_install) cmd += "\n&& sync && conda clean -tipsy && sync" if self.pip_install: cmd += self._install_pip_pkgs() cmd = indent("RUN", cmd) if self.add_to_path: bin_path = posixpath.join(Miniconda.INSTALL_PATH, 'envs', self.env_name, 'bin') env_cmd = "ENV PATH={}:$PATH".format(bin_path) return "\n".join((cmd, env_cmd)) return cmd
def install_spm(self): """Return Dockerfile instructions to install standalone SPM.""" from neurodocker.generate import _add_to_entrypoint url = self._get_spm_url() mcr_path = posixpath.join(SPM.MCR_DEST, SPM.MCR_VERSIONS[str(self.matlab_version)], '') spm_cmd = '/opt/spm{0}/run_spm{0}.sh {1}'.format( self.version, mcr_path) spmmcrcmd = 'export SPMMCRCMD="{} script"'.format(spm_cmd) entrypoint_cmd = _add_to_entrypoint(spmmcrcmd, with_run=False) comment = "# Install standalone SPM" cmd = ('echo "Downloading standalone SPM ..."' "\n&& curl -sSL --retry 5 -o spm.zip {url}" "\n&& unzip -q spm.zip -d /opt" "\n&& chmod -R 777 /opt/spm*" "\n&& rm -rf spm.zip" "\n&& {spm_cmd} quit" "\n&& {entrypoint_cmd}" "".format(url=url, spm_cmd=spm_cmd, entrypoint_cmd=entrypoint_cmd)) cmd = indent("RUN", cmd) env_cmd = self._get_spm_env_cmd(mcr_path, spm_cmd) return '\n'.join((comment, cmd, env_cmd))
def conda_and_pip_install(self, create=True): """Return Dockerfile instructions to create conda environment with desired version of Python and desired conda and pip packages. """ conda_cmd = "conda create" if create else "conda install" cmd = "{} -y -q --name {}".format(conda_cmd, self.env_name) if self.conda_opts: cmd = "{} {}".format(cmd, self.conda_opts) if self.conda_install: if isinstance(self.conda_install, (list, tuple)): self.conda_install = " ".join(self.conda_install) cmd += "\n\t{}".format(self.conda_install) cmd += "\n&& sync && conda clean -tipsy && sync" if not self.conda_install and not create: cmd = "" if self.pip_install: if self.conda_install or create: cmd += "\n&& " cmd += self._pip_install() cmd = indent("RUN", cmd) self.created_envs.append(self.env_name) if self.add_to_path: bin_path = posixpath.join(Miniconda.INSTALL_PATH, 'envs', self.env_name, 'bin') env_cmd = "ENV PATH={}:$PATH".format(bin_path) return "\n".join((cmd, env_cmd)) return cmd
def conda_and_pip_install(self, create=True): """Return Dockerfile instructions to create conda environment with desired version of Python and desired conda and pip packages. """ conda_cmd = "conda create" if create else "conda install" cmd = "{} -y -q --name {}".format(conda_cmd, self.env_name) if self.conda_opts: cmd = "{} {}".format(cmd, self.conda_opts) if self.conda_install: if isinstance(self.conda_install, str): self.conda_install = self.conda_install.split() pkgs = _indent_pkgs(len(cmd.split('\n')[-1]), self.conda_install) cmd += pkgs # cmd += "\n\t{}".format(self.conda_install) cmd += "\n&& sync && conda clean -tipsy && sync" if not self.conda_install and not create: cmd = "" if self.pip_install: if self.conda_install or create: cmd += "\n&& " cmd += self._pip_install() if self.activate: cmd += self._get_source_activate_cmd() cmd = indent("RUN", cmd) self.created_envs.append(self.env_name) return cmd
def _add_install(pkgs, pkg_manager): """Return Dockerfile RUN instruction that installs system packages. Parameters ---------- pkgs : list List of system packages to install. pkg_manager : {'apt', 'yum'} Linux package manager. """ comment = ("#------------------------" "\n# Install system packages" "\n#------------------------") installers = { 'apt': apt_get_install, 'yum': yum_install, } # pkgs = ' '.join(pkgs) # cmd = "{install}\n&& {clean}".format(**manage_pkgs[pkg_manager]) # cmd = cmd.format(pkgs=pkgs) flags = [jj for jj in pkgs if jj.startswith('flags=')] pkgs = [kk for kk in pkgs if kk not in flags] if flags: flags = flags[0].replace('flags=', '') else: flags = None cmd = installers[pkg_manager](pkgs, flags) cmd += "\n&& {clean}".format(**manage_pkgs[pkg_manager]) return indent("RUN", cmd)
def build_from_source(self): """Return Dockerfile instructions to build MRtrix from source. Checkout to git_hash if specified. """ # QUESTION: how to download eigen3-devel? Have to add EPEL. pkgs = { 'apt': 'g++ git libeigen3-dev zlib1g-dev', 'yum': 'eigen3-devel gcc-c++ git zlib-devel' } if self.git_hash == None: checkout = "" else: checkout = ("\n&& git checkout {}".format(self.git_hash)) workdir_cmd = "WORKDIR /opt" cmd = ("deps='{pkgs}'" "\n&& {install}" "\n&& {clean}" "\n&& git clone https://github.com/MRtrix3/mrtrix3.git" "\n&& cd mrtrix3" "{checkout}" "\n&& ./configure -nogui" "\n&& ./build" "\n&& rm -rf tmp/* /tmp/*" "\n&& {remove}" "".format(pkgs=pkgs[self.pkg_manager], checkout=checkout, **manage_pkgs[self.pkg_manager])) cmd = cmd.format(pkgs='$deps') cmd = indent("RUN", cmd) env_cmd = ("ENV PATH=/opt/mrtrix3/bin:$PATH") return "\n".join((workdir_cmd, cmd, env_cmd))
def install_binaries(self): """Return command to download and install FreeSurfer binaries.""" from neurodocker.generate import _add_to_entrypoint url = self._get_binaries_url() if self.check_urls and self.version == 'dev': raise ValueError( "check_urls=True and version='dev' cannot be used " "together. Set check_urls to False.") elif self.check_urls: check_url(url) if self.exclude: excluded_dirs = _get_dirs_to_exclude(self.exclude) else: excluded_dirs = '' cmd = self._install_binaries_deps() ent = _add_to_entrypoint("source $FREESURFER_HOME/SetUpFreeSurfer.sh", with_run=False) cmd += ('\n&& echo "Downloading FreeSurfer ..."' "\n&& curl -sSL --retry 5 {url}" "\n| tar xz -C /opt\n{excluded}" "\n&& {entrypoint_cmd}" "".format(url=url, excluded=excluded_dirs, entrypoint_cmd=ent)) cmd = indent("RUN", cmd) env_cmd = "ENV FREESURFER_HOME=/opt/freesurfer" return "\n".join((cmd, env_cmd))
def build_from_source_github(self): """Return Dockerfile instructions to build ANTs from source. Checkout to commit based on git_hash or version. If 'latest', build from master. """ pkgs = { 'apt': 'cmake g++ gcc git make zlib1g-dev', 'yum': 'cmake gcc-c++ git make zlib-devel' } if self.git_hash is None: try: self.git_hash = ANTs.VERSION_HASHES[self.version] except KeyError: raise ValueError("git hash not known for version {}" "".format(self.version)) if self.version == "latest": checkout = "" else: checkout = ("\n&& cd ANTs" "\n&& git checkout {}" "\n&& cd .." "".format(self.git_hash)) workdir_cmd = "WORKDIR /tmp/ants-build" cmd = ("deps='{pkgs}'" "\n&& {install}" "\n&& {clean}" "\n&& git clone https://github.com/stnava/ANTs.git" "{checkout}" "\n&& mkdir build && cd build" "\n&& cmake ../ANTs && make -j 1" "\n&& mkdir -p /opt/ants" "\n&& mv bin/* /opt/ants && mv ../ANTs/Scripts/* /opt/ants" "\n&& rm -rf /tmp/*" "\n&& {remove}" "".format(pkgs=pkgs[self.pkg_manager], checkout=checkout, **manage_pkgs[self.pkg_manager])) cmd = cmd.format(pkgs='$deps') cmd = indent("RUN", cmd) env_cmd = ("ANTSPATH=/opt/ants\n" "PATH=/opt/ants:$PATH") env_cmd = indent("ENV", env_cmd) return "\n".join((workdir_cmd, cmd, env_cmd))
def _install_pkgs(self): """Return instruction to install NeuroDebian packages.""" if isinstance(self.pkgs, (list, tuple)): self.pkgs = " ".join(self.pkgs) cmd = ("{install}\n&& {clean}".format(**manage_pkgs['apt']).format( pkgs=self.pkgs)) comment = "\n# Install NeuroDebian packages" return "\n".join((comment, indent("RUN", cmd)))
def _add_run_bash(bash_code, **kwargs): """Return Dockerfile RUN instruction to execute bash code.""" import json comment = "# User-defined BASH instruction" escaped_bash_code = json.dumps(bash_code) cmd = 'bash -c {}'.format(escaped_bash_code) cmd = indent("RUN", cmd) return "\n".join((comment, cmd))
def _add_common_dependencies(pkg_manager): """Return Dockerfile instructions to download dependencies common to many software packages. Parameters ---------- pkg_manager : {'apt', 'yum'} Linux package manager. """ deps = ['bzip2', 'ca-certificates', 'curl', 'unzip'] if pkg_manager == "apt": deps.append('locales') if pkg_manager == "yum": deps.append('epel-release') deps = " ".join(sorted(deps)) deps = "\n\t" + deps comment = ("#----------------------------------------------------------" "\n# Install common dependencies and create default entrypoint" "\n#----------------------------------------------------------") env = ('LANG="en_US.UTF-8"' '\nLC_ALL="C.UTF-8"' '\nND_ENTRYPOINT="{}"'.format(ENTRYPOINT_FILE)) env = indent("ENV", env) cmd = "{install}\n&& {clean}".format(**manage_pkgs[pkg_manager]) cmd = cmd.format(pkgs=deps) cmd += ( "\n&& localedef --force --inputfile=en_US --charmap=UTF-8 C.UTF-8" "\n&& chmod 777 /opt && chmod a+s /opt" "\n&& mkdir -p /neurodocker" '\n&& if [ ! -f "$ND_ENTRYPOINT" ]; then' "\n echo '#!/usr/bin/env bash' >> $ND_ENTRYPOINT" "\n && echo 'set +x' >> $ND_ENTRYPOINT" "\n && echo 'if [ -z \"$*\" ]; then /usr/bin/env bash; else $*; fi' >> $ND_ENTRYPOINT;" "\n fi" "\n&& chmod -R 777 /neurodocker && chmod a+s /neurodocker") cmd = indent("RUN", cmd) entrypoint = 'ENTRYPOINT ["{}"]'.format(ENTRYPOINT_FILE) return "\n".join((comment, env, cmd, entrypoint))
def install_binaries(self): """Return command to download and install ANTs binaries.""" try: url = ANTs.VERSION_TARBALLS[self.version] except KeyError: raise ValueError("Tarball not available for version {}." "".format(self.version)) if self.check_urls: check_url(url) cmd = ('echo "Downloading ANTs ..."' "\n&& curl -sSL --retry 5 {}" "\n| tar zx -C /opt".format(url)) cmd = indent("RUN", cmd) env_cmd = ("ANTSPATH=/opt/ants" "\nPATH=/opt/ants:$PATH") env_cmd = indent("ENV", env_cmd) return "\n".join((cmd, env_cmd))
def install_with_pyinstaller(check_urls=False): """Return Dockerfile instructions to install FSL using FSL's Python installer. This will install the latest version and only works on CentOS/RHEL. """ workdir_cmd = "WORKDIR /opt" url = "https://fsl.fmrib.ox.ac.uk/fsldownloads/fslinstaller.py" if check_urls: check_url(url) cmd = ("curl -sSL -o fslinstaller.py {url}" "\n&& python fslinstaller.py --dest=/opt --quiet" "\n&& . /opt/fsl/etc/fslconf/fsl.sh" "\n&& rm -f fslinstaller.py" "".format(url=url)) cmd = indent("RUN", cmd) path_cmd = ("FSLDIR=/opt/fsl" "\n&& PATH=/opt/fsl/bin:$PATH") path_cmd = indent("ENV", path_cmd) return "\n".join((workdir_cmd, cmd, path_cmd))
def install_mcr(self): """Return Dockerfile instructions to install MATLAB Compiler Runtime.""" url = self._get_mcr_url() comment = "# Install MATLAB Compiler Runtime" cmd = self._install_libs() cmd += ('\n&& echo "Downloading MATLAB Compiler Runtime ..."' "\n&& curl -sSL --retry 5 -o /tmp/mcr.zip {url}" "\n&& unzip -q /tmp/mcr.zip -d /tmp/mcrtmp" "\n&& /tmp/mcrtmp/install -destinationFolder {dest}" " -mode silent -agreeToLicense yes" "\n&& rm -rf /tmp/*".format(url=url, dest=SPM.MCR_DEST)) cmd = indent("RUN", cmd) return '\n'.join((comment, cmd))
def install_binaries(self): """Return Dockerfile instructions to download and install PETPVC binaries. """ petpvc_url = self._get_binaries_urls(self.version) if self.check_urls: check_url(petpvc_url) cmd = self._get_install_cmd(petpvc_url) cmd = indent("RUN", cmd) env_cmd = ("ENV PATH=/opt/petpvc/bin:$PATH") return "\n".join((cmd, env_cmd))
def install_binaries(self): """Return command to download and install C3D binaries.""" try: url = Convert3D.VERSION_TARBALLS[self.version.lower()] except KeyError: raise ValueError("Unsupported version: {}".format(self.version)) if self.check_urls: check_url(url) cmd = ('echo "Downloading C3D ..."' "\n&& mkdir /opt/c3d" "\n&& curl -sSL --retry 5 {}" "\n| tar -xzC /opt/c3d --strip-components=1".format(url)) cmd = indent("RUN", cmd) c3d_path = "/opt/c3d" c3d_bin_path = posixpath.join(c3d_path, 'bin') env_cmd = ("C3DPATH={}" "\nPATH={}:$PATH").format(c3d_path, c3d_bin_path) env_cmd = indent("ENV", env_cmd) return "\n".join((cmd, env_cmd))
def _add_common_dependencies(pkg_manager): """Return Dockerfile instructions to download dependencies common to many software packages. Parameters ---------- pkg_manager : {'apt', 'yum'} Linux package manager. """ deps = "\n\tbzip2 ca-certificates curl unzip" if pkg_manager == "yum": deps += " epel-release" comment = ("#----------------------------------------------------------" "\n# Install common dependencies and create default entrypoint" "\n#----------------------------------------------------------") env = ('LANG="C.UTF-8"' '\nLC_ALL="C"' '\nND_ENTRYPOINT="{}"'.format(ENTRYPOINT_FILE)) env = indent("ENV", env) cmd = "{install}\n&& {clean}".format(**manage_pkgs[pkg_manager]) cmd = cmd.format(pkgs=deps) cmd += ( "\n&& chmod 777 /opt && chmod a+s /opt" "\n&& mkdir /neurodocker" "\n&& echo '#!/usr/bin/env bash' >> $ND_ENTRYPOINT" "\n&& echo 'set +x' >> $ND_ENTRYPOINT" "\n&& echo 'if [ -z \"$*\" ]; then /usr/bin/env bash; else $*; fi' >> $ND_ENTRYPOINT" "\n&& chmod -R 777 /neurodocker && chmod a+s /neurodocker") cmd = indent("RUN", cmd) entrypoint = 'ENTRYPOINT ["{}"]'.format(ENTRYPOINT_FILE) return "\n".join((comment, env, cmd, entrypoint))
def _get_spm_env_cmd(mcr_path, spm_cmd): matlabcmd = posixpath.join(mcr_path, 'toolbox', 'matlab') spmmcrcmd = spm_cmd + ' script' ld_lib_path = '/usr/lib/x86_64-linux-gnu' for relpath in ['runtime/glnxa64', 'bin/glnxa64', 'sys/os/glnxa64']: ld_lib_path += ":{}".format(posixpath.join(mcr_path, relpath)) ld_lib_path += ":$LD_LIBRARY_PATH" env = ("MATLABCMD={}" # '\nSPMMCRCMD="{}"' "\nFORCE_SPMMCR=1" '\nLD_LIBRARY_PATH={}' "".format(matlabcmd, ld_lib_path)) return indent("ENV", env)
def create_from_yaml(self): """Return Dockerfile instructions to create conda environment from a YAML file. """ tmp_yml = "/tmp/environment.yml" cmd = ("conda env create -q --name {n} --file {tmp}" "\n&& rm -f {tmp}") if self.activate: cmd += self._get_source_activate_cmd() if is_url(self.yaml_file): get_file = "curl -sSL {f} > {tmp}" cmd = get_file + "\n&& " + cmd if self.check_urls: check_url(self.yaml_file) cmd = indent("RUN", cmd) else: get_file = 'COPY ["{f}", "{tmp}"]' cmd = indent("RUN", cmd) cmd = "\n".join((get_file, cmd)) cmd = cmd.format(n=self.env_name, f=self.yaml_file, tmp=tmp_yml) return cmd
def _add_label(labels, **kwargs): """Return Dockerfile LABEL instruction to set image labels. Parameters ---------- labels : dict Dictionary of label names and values. """ import json out = "" for k, v in labels.items(): newline = "\n" if out else "" v = json.dumps(v) # Escape double quotes and other things. out += '{}{}={}'.format(newline, k, v) return indent("LABEL", out)
def install_binaries(self): """Return command to download and install MRtrix3 binaries.""" url = ("https://dl.dropbox.com/s/2g008aaaeht3m45/" "mrtrix3-Linux-centos6.tar.gz") if self.check_urls: check_url(url) cmd = ('echo "Downloading MRtrix3 ..."' '\n&& curl -sSL --retry 5 {}' '\n| tar zx -C /opt'.format(url)) cmd = indent("RUN", cmd) env_cmd = ("ENV PATH=/opt/mrtrix3/bin:$PATH") return "\n".join((cmd, env_cmd))
def _add_neurodebian(self): """Return instruction to add NeuroDebian repository.""" pkgs = "dirmngr gnupg" cmd = ( "{install}" "\n&& {clean}" "\n&& curl -sSL {url}" "\n> /etc/apt/sources.list.d/neurodebian.sources.list" "\n&& apt-key adv --fetch-keys https://dl.dropbox.com/s/zxs209o955q6vkg/neurodebian.gpg" # Syntax from # https://github.com/poldracklab/fmriprep/blob/master/Dockerfile#L21 "\n&& (apt-key adv --refresh-keys --keyserver" " hkp://pool.sks-keyservers.net:80 0xA5D32F012649A5A9 || true)" "\n&& apt-get update" "".format(url=self.url, **manage_pkgs['apt']).format(pkgs=pkgs)) return indent("RUN", cmd)
def _add_env_vars(env_vars, **kwargs): """Return Dockerfile ENV instruction to set environment variables. Parameters ---------- env_vars : dict Environment variables where keys are the environment variables names, and values are the values assigned to those environment variable names. """ import json out = "" for k, v in env_vars.items(): newline = "\n" if out else "" v = json.dumps(v) # Escape double quotes and other things. out += '{}{}={}'.format(newline, k, v) return indent("ENV", out)
def _add_install(pkgs, pkg_manager): """Return Dockerfile RUN instruction that installs system packages. Parameters ---------- pkgs : list List of system packages to install. pkg_manager : {'apt', 'yum'} Linux package manager. """ comment = ("#------------------------" "\n# Install system packages" "\n#------------------------") pkgs = ' '.join(pkgs) cmd = "{install}\n&& {clean}".format(**manage_pkgs[pkg_manager]) cmd = cmd.format(pkgs=pkgs) return indent("RUN", cmd)