From 99095c41daee511d0d4c9f77565924ad60efab37 Mon Sep 17 00:00:00 2001 From: Tim Sogard Date: Tue, 10 Mar 2020 12:30:18 -0400 Subject: [PATCH] Docker build speedup Re-order docker file so that layers which are unlikely to change between builds appear first. Layers are now: clamav packages, pip requirements, and finally lambda code. This means that changing lambda code will not require re-installing clamav packages or rebuilding the rest of the image. Added a cleandocker target to the Makefile in order to explicitly rebuild from scratch (useful for when an update to clamav packages is required) --- Dockerfile | 11 ++++++----- Makefile | 4 ++++ 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/Dockerfile b/Dockerfile index a59b66e3..62a54838 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,20 +5,21 @@ RUN mkdir -p /opt/app RUN mkdir -p /opt/app/build RUN mkdir -p /opt/app/bin/ -# Copy in the lambda source -WORKDIR /opt/app -COPY ./*.py /opt/app/ -COPY requirements.txt /opt/app/requirements.txt - # Install packages RUN yum update -y RUN yum install -y cpio python3-pip yum-utils zip unzip less RUN yum install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm +# Install requirements +WORKDIR /opt/app +COPY requirements.txt /opt/app/requirements.txt # This had --no-cache-dir, tracing through multiple tickets led to a problem in wheel RUN pip3 install -r requirements.txt RUN rm -rf /root/.cache/pip +# Copy in the lambda source +COPY ./*.py /opt/app/ + # Download libraries we need to run in lambda WORKDIR /tmp RUN yumdownloader -x \*i686 --archlist=x86_64 clamav clamav-lib clamav-update json-c pcre2 diff --git a/Makefile b/Makefile index a527b641..b17373f2 100644 --- a/Makefile +++ b/Makefile @@ -32,6 +32,10 @@ clean: ## Clean build artifacts find ./ -type d -name '__pycache__' -delete find ./ -type f -name '*.pyc' -delete +.PHONY: cleandocker +cleandocker: clean + docker rmi bucket-antivirus-function:latest + .PHONY: archive archive: clean ## Create the archive for AWS lambda docker build -t bucket-antivirus-function:latest .