From 9badf4c8ac93e6c5c74a0755c84dbedbf33ef902 Mon Sep 17 00:00:00 2001 From: Matthew Davis <7035647+mdavis-xyz@users.noreply.github.com> Date: Tue, 7 Nov 2023 03:41:12 +0100 Subject: [PATCH] Cache pip install in python Dockerfiles (#461) * Cache pip install in python Dockerfiles * Update Dockerfile * Update Dockerfile * fix Dockerfile --------- Co-authored-by: Mohamed Elasmar <71043312+moelasmar@users.noreply.github.com> --- .../{{cookiecutter.project_name}}/app/Dockerfile | 6 ++++-- .../{{cookiecutter.project_name}}/app/Dockerfile | 6 ++++-- .../{{cookiecutter.project_name}}/app/Dockerfile | 6 ++++-- .../{{cookiecutter.project_name}}/app/Dockerfile | 6 ++++-- .../{{cookiecutter.project_name}}/hello_world/Dockerfile | 4 +++- .../{{cookiecutter.project_name}}/app/Dockerfile | 6 ++++-- .../{{cookiecutter.project_name}}/app/Dockerfile | 6 ++++-- .../{{cookiecutter.project_name}}/app/Dockerfile | 6 ++++-- .../{{cookiecutter.project_name}}/app/Dockerfile | 6 ++++-- .../{{cookiecutter.project_name}}/hello_world/Dockerfile | 4 +++- 10 files changed, 38 insertions(+), 18 deletions(-) diff --git a/python3.10/apigw-pytorch/{{cookiecutter.project_name}}/app/Dockerfile b/python3.10/apigw-pytorch/{{cookiecutter.project_name}}/app/Dockerfile index 28d2d8e70..0e0cbd429 100644 --- a/python3.10/apigw-pytorch/{{cookiecutter.project_name}}/app/Dockerfile +++ b/python3.10/apigw-pytorch/{{cookiecutter.project_name}}/app/Dockerfile @@ -1,8 +1,10 @@ FROM public.ecr.aws/lambda/python:3.10 -COPY app.py requirements.txt ./ -COPY model /opt/ml/model +COPY requirements.txt ./ RUN python3.10 -m pip install -r requirements.txt -t . +COPY model /opt/ml/model +COPY app.py ./ + CMD ["app.lambda_handler"] diff --git a/python3.10/apigw-scikit/{{cookiecutter.project_name}}/app/Dockerfile b/python3.10/apigw-scikit/{{cookiecutter.project_name}}/app/Dockerfile index 73c37d39d..16b7d3374 100644 --- a/python3.10/apigw-scikit/{{cookiecutter.project_name}}/app/Dockerfile +++ b/python3.10/apigw-scikit/{{cookiecutter.project_name}}/app/Dockerfile @@ -1,11 +1,13 @@ FROM public.ecr.aws/lambda/python:3.10 -COPY app.py requirements.txt ./ -COPY model /opt/ml/model +COPY requirements.txt ./ # temporarily install gcc so that scikit-learn can be built RUN yum install gcc-c++ -y RUN python3.10 -m pip install -r requirements.txt -t . +COPY model /opt/ml/model +COPY app.py ./ + CMD ["app.lambda_handler"] diff --git a/python3.10/apigw-tensorflow/{{cookiecutter.project_name}}/app/Dockerfile b/python3.10/apigw-tensorflow/{{cookiecutter.project_name}}/app/Dockerfile index 28d2d8e70..0e0cbd429 100644 --- a/python3.10/apigw-tensorflow/{{cookiecutter.project_name}}/app/Dockerfile +++ b/python3.10/apigw-tensorflow/{{cookiecutter.project_name}}/app/Dockerfile @@ -1,8 +1,10 @@ FROM public.ecr.aws/lambda/python:3.10 -COPY app.py requirements.txt ./ -COPY model /opt/ml/model +COPY requirements.txt ./ RUN python3.10 -m pip install -r requirements.txt -t . +COPY model /opt/ml/model +COPY app.py ./ + CMD ["app.lambda_handler"] diff --git a/python3.10/apigw-xgboost/{{cookiecutter.project_name}}/app/Dockerfile b/python3.10/apigw-xgboost/{{cookiecutter.project_name}}/app/Dockerfile index 28d2d8e70..0e0cbd429 100644 --- a/python3.10/apigw-xgboost/{{cookiecutter.project_name}}/app/Dockerfile +++ b/python3.10/apigw-xgboost/{{cookiecutter.project_name}}/app/Dockerfile @@ -1,8 +1,10 @@ FROM public.ecr.aws/lambda/python:3.10 -COPY app.py requirements.txt ./ -COPY model /opt/ml/model +COPY requirements.txt ./ RUN python3.10 -m pip install -r requirements.txt -t . +COPY model /opt/ml/model +COPY app.py ./ + CMD ["app.lambda_handler"] diff --git a/python3.10/hello-img/{{cookiecutter.project_name}}/hello_world/Dockerfile b/python3.10/hello-img/{{cookiecutter.project_name}}/hello_world/Dockerfile index 4f9ce8135..f0f9847ca 100644 --- a/python3.10/hello-img/{{cookiecutter.project_name}}/hello_world/Dockerfile +++ b/python3.10/hello-img/{{cookiecutter.project_name}}/hello_world/Dockerfile @@ -1,8 +1,10 @@ FROM public.ecr.aws/lambda/python:3.10 -COPY app.py requirements.txt ./ +COPY requirements.txt ./ RUN {{cookiecutter.runtime}} -m pip install -r requirements.txt -t . +COPY app.py ./ + # Command can be overwritten by providing a different command in the template directly. CMD ["app.lambda_handler"] diff --git a/python3.11/apigw-pytorch/{{cookiecutter.project_name}}/app/Dockerfile b/python3.11/apigw-pytorch/{{cookiecutter.project_name}}/app/Dockerfile index c4ceacbd1..f67bba022 100644 --- a/python3.11/apigw-pytorch/{{cookiecutter.project_name}}/app/Dockerfile +++ b/python3.11/apigw-pytorch/{{cookiecutter.project_name}}/app/Dockerfile @@ -1,8 +1,10 @@ FROM public.ecr.aws/lambda/python:3.11 -COPY app.py requirements.txt ./ -COPY model /opt/ml/model +COPY requirements.txt ./ RUN python3.11 -m pip install -r requirements.txt -t . +COPY model /opt/ml/model +COPY app.py ./ + CMD ["app.lambda_handler"] diff --git a/python3.11/apigw-scikit/{{cookiecutter.project_name}}/app/Dockerfile b/python3.11/apigw-scikit/{{cookiecutter.project_name}}/app/Dockerfile index 93086a2ca..6226fa4f7 100644 --- a/python3.11/apigw-scikit/{{cookiecutter.project_name}}/app/Dockerfile +++ b/python3.11/apigw-scikit/{{cookiecutter.project_name}}/app/Dockerfile @@ -1,11 +1,13 @@ FROM public.ecr.aws/lambda/python:3.11 -COPY app.py requirements.txt ./ -COPY model /opt/ml/model +COPY requirements.txt ./ # temporarily install gcc so that scikit-learn can be built RUN yum install gcc-c++ -y RUN python3.11 -m pip install -r requirements.txt -t . +COPY model /opt/ml/model +COPY app.py ./ + CMD ["app.lambda_handler"] diff --git a/python3.11/apigw-tensorflow/{{cookiecutter.project_name}}/app/Dockerfile b/python3.11/apigw-tensorflow/{{cookiecutter.project_name}}/app/Dockerfile index c4ceacbd1..f67bba022 100644 --- a/python3.11/apigw-tensorflow/{{cookiecutter.project_name}}/app/Dockerfile +++ b/python3.11/apigw-tensorflow/{{cookiecutter.project_name}}/app/Dockerfile @@ -1,8 +1,10 @@ FROM public.ecr.aws/lambda/python:3.11 -COPY app.py requirements.txt ./ -COPY model /opt/ml/model +COPY requirements.txt ./ RUN python3.11 -m pip install -r requirements.txt -t . +COPY model /opt/ml/model +COPY app.py ./ + CMD ["app.lambda_handler"] diff --git a/python3.11/apigw-xgboost/{{cookiecutter.project_name}}/app/Dockerfile b/python3.11/apigw-xgboost/{{cookiecutter.project_name}}/app/Dockerfile index c4ceacbd1..f67bba022 100644 --- a/python3.11/apigw-xgboost/{{cookiecutter.project_name}}/app/Dockerfile +++ b/python3.11/apigw-xgboost/{{cookiecutter.project_name}}/app/Dockerfile @@ -1,8 +1,10 @@ FROM public.ecr.aws/lambda/python:3.11 -COPY app.py requirements.txt ./ -COPY model /opt/ml/model +COPY requirements.txt ./ RUN python3.11 -m pip install -r requirements.txt -t . +COPY model /opt/ml/model +COPY app.py ./ + CMD ["app.lambda_handler"] diff --git a/python3.11/hello-img/{{cookiecutter.project_name}}/hello_world/Dockerfile b/python3.11/hello-img/{{cookiecutter.project_name}}/hello_world/Dockerfile index d67bc6fee..e839b50b4 100644 --- a/python3.11/hello-img/{{cookiecutter.project_name}}/hello_world/Dockerfile +++ b/python3.11/hello-img/{{cookiecutter.project_name}}/hello_world/Dockerfile @@ -1,8 +1,10 @@ FROM public.ecr.aws/lambda/python:3.11 -COPY app.py requirements.txt ./ +COPY requirements.txt ./ RUN {{cookiecutter.runtime}} -m pip install -r requirements.txt -t . +COPY app.py ./ + # Command can be overwritten by providing a different command in the template directly. CMD ["app.lambda_handler"]