diff --git a/base/buildspec.yml b/base/buildspec.yml index 1f8f4358..1d121ddf 100644 --- a/base/buildspec.yml +++ b/base/buildspec.yml @@ -21,6 +21,9 @@ context: requirements: source: ../../base/jobs/docker/1.0/py3/requirements.txt target: requirements.txt + dockerignore: + source: ../../base/jobs/docker/1.0/py3/.dockerignore + target: .dockerignore images: BuildBaseCPUJobsPy3DockerImage: diff --git a/base/jobs/docker/1.0/py3/.dockerignore b/base/jobs/docker/1.0/py3/.dockerignore new file mode 100644 index 00000000..c9f75756 --- /dev/null +++ b/base/jobs/docker/1.0/py3/.dockerignore @@ -0,0 +1,15 @@ +pip-log.txt +pip-delete-this-directory.txt +.tox +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +*.log +.git +.mypy_cache +.pytest_cache +.hypothesis +.DS_Store diff --git a/base/jobs/docker/1.0/py3/Dockerfile.cpu b/base/jobs/docker/1.0/py3/Dockerfile.cpu index 9fa7d9ac..503af8b5 100644 --- a/base/jobs/docker/1.0/py3/Dockerfile.cpu +++ b/base/jobs/docker/1.0/py3/Dockerfile.cpu @@ -1,10 +1,8 @@ # This is based loosely on : # https://github.com/aws/amazon-sagemaker-examples/blob/master/advanced_functionality/custom-training-containers/script-mode-container/docker/Dockerfile -FROM public.ecr.aws/lts/ubuntu:22.04 - -LABEL maintainer="Amazon Braket" -LABEL major_version="1" +# Has Python 3.10 +FROM public.ecr.aws/lts/ubuntu:22.04 as common # prevent stopping by user interaction ENV DEBIAN_FRONTEND noninteractive @@ -16,11 +14,19 @@ ENV PYTHONIOENCODING=UTF-8 ENV LANG=C.UTF-8 ENV LC_ALL=C.UTF-8 +# Switch off pip cache in the env +ENV PIP_NO_CACHE_DIR=1 + ARG PYTHON=python3.10 ARG PYTHON_PIP=python3-pip -ARG PIP=pip3 +ARG PIP=pip ARG PYTHON_VERSION=3.10.11 +# To be passed to later stages +ENV PYTHON=${PYTHON} +ENV PYTHON_VERSION=${PYTHON_VERSION} +ENV PIP=${PIP} + RUN apt-get update \ && apt-get install -y --no-install-recommends \ build-essential \ @@ -32,15 +38,14 @@ RUN apt-get update \ libtemplate-perl \ libssl3 \ openssl \ + python3-dev \ + python3-pip \ unzip \ wget \ zlib1g-dev \ - # Install dependent library for OpenCV libgtk2.0-dev \ - && rm -rf /var/lib/apt/lists/* - -# Install Open MPI -RUN mkdir /tmp/openmpi \ + && rm -rf /var/lib/apt/lists/* \ + && mkdir /tmp/openmpi \ && cd /tmp/openmpi \ && curl -fSsL -O https://download.open-mpi.org/release/open-mpi/v4.0/openmpi-4.0.4.tar.gz \ && tar zxf openmpi-4.0.4.tar.gz \ @@ -49,15 +54,15 @@ RUN mkdir /tmp/openmpi \ && make -j $(nproc) all \ && make install \ && ldconfig \ - && rm -rf /tmp/openmpi + && rm -rf /tmp/openmpi \ # Create a wrapper for OpenMPI to allow running as root by default -RUN mv /usr/local/bin/mpirun /usr/local/bin/mpirun.real \ + && mv /usr/local/bin/mpirun /usr/local/bin/mpirun.real \ && echo '#!/bin/bash' > /usr/local/bin/mpirun \ && echo 'mpirun.real --allow-run-as-root "$@"' >> /usr/local/bin/mpirun \ - && chmod a+x /usr/local/bin/mpirun + && chmod a+x /usr/local/bin/mpirun \ -RUN echo "hwloc_base_binding_policy = none" >> /usr/local/etc/openmpi-mca-params.conf \ + && echo "hwloc_base_binding_policy = none" >> /usr/local/etc/openmpi-mca-params.conf \ && echo "rmaps_base_mapping_policy = slot" >> /usr/local/etc/openmpi-mca-params.conf ENV LD_LIBRARY_PATH=/usr/local/openmpi/lib:/usr/local/lib:$LD_LIBRARY_PATH @@ -87,17 +92,14 @@ RUN apt-get update \ && rm -rf /var/lib/apt/lists/* \ && apt-get clean -# Installing Python3 -RUN wget https://www.python.org/ftp/python/$PYTHON_VERSION/Python-$PYTHON_VERSION.tgz \ - && tar -xvf Python-$PYTHON_VERSION.tgz \ - && cd Python-$PYTHON_VERSION \ - && ./configure && make && make install \ - && rm -rf ../Python-$PYTHON_VERSION* +COPY .dockerignore .dockerignore + +RUN ln -s $(which ${PYTHON}) /usr/local/bin/python -# Upgrading pip and creating symbolic link for python3 -RUN ${PIP} --no-cache-dir install --upgrade pip setuptools -RUN ln -s $(which ${PYTHON}) /usr/local/bin/python \ - && ln -s $(which ${PIP}) /usr/bin/pip +RUN ${PIP} --no-cache-dir install --upgrade \ + pip \ + requests \ + setuptools WORKDIR / @@ -105,7 +107,6 @@ RUN apt-get update && apt-get -y install cmake protobuf-compiler # Copy the dependencies file COPY requirements.txt / -# Installing our custom python libraries RUN ${PIP} install --no-cache --upgrade \ -r requirements.txt