From 1acf94a29369fbaaa815de9fe3229c234f4385bc Mon Sep 17 00:00:00 2001 From: Abdou Seck Date: Wed, 15 Nov 2023 15:33:24 -0500 Subject: [PATCH] docker: Use python3.11-slim as a base image and clean up the build directory after package installation --- .dockerignore | 88 +++++++++++++++++++++++++++++++++++++++++++++++++++ Dockerfile | 36 ++++++++++++++++----- 2 files changed, 116 insertions(+), 8 deletions(-) diff --git a/.dockerignore b/.dockerignore index 9a37eaf..06cf48d 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,3 +1,4 @@ +# Specific to this project .git .gitignore .github/ @@ -14,3 +15,90 @@ simeon.egg-info/ *.json LICENSE README.md + +# More generic stuff +# Git +.gitattributes + + +# CI +.codeclimate.yml +.travis.yml +.taskcluster.yml + +# Docker +docker-compose.yml +Dockerfile +.docker +.dockerignore + +# Byte-compiled / optimized / DLL files +**/__pycache__/ +**/*.py[cod] + +# C extensions +*.so + +# Distribution / packaging +.Python +env/ +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +*.egg-info/ +.installed.cfg +*.egg + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.cache +nosetests.xml +coverage.xml + +# Translations +*.mo +*.pot + +# Django stuff: +*.log + +# Sphinx documentation +docs/_build/ + +# PyBuilder +target/ + +# Virtual environment +.env +.venv/ + +# PyCharm +.idea + +# Python mode for VIM +.ropeproject +**/.ropeproject + +# Vim swap files +**/*.swp + +# VS Code +.vscode/ diff --git a/Dockerfile b/Dockerfile index d068931..1036b39 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,18 +1,38 @@ # Dockerfile for running simeon in a container -FROM python:3.8-slim -# set a key-value label for the Docker image +FROM python:3.11-slim +# Set a key-value label for the Docker image LABEL maintainer="MIT Institutional Research" LABEL email="irx@mit.edu" -COPY . /simeon -# defines the working directory within the container + +# Create the home directory +RUN mkdir /simeon + +# Create the simeon user and group +RUN useradd -d /simeon -r -U simeon +RUN chown simeon:simeon /simeon + +# Define the working directory within the container WORKDIR /simeon -# Update the repositories used by apt + +# Add the requirements.txt file to start building the package +ADD requirements.txt /simeon/build_dir/requiremens.txt + +# Update the repositories used by apt and install gpg RUN apt-get update -y -# Install gpg RUN apt-get install -y gnupg2 + # Install python packages needed by simeon -RUN pip install -U wheel +RUN pip install -U pip wheel + # Install simeon with geoip support -RUN pip install .[geoip] +ADD . /simeon/build_dir/ + +# Clean up +RUN pip install /simeon/build_dir[geoip] +RUN rm -rf /simeon/* + +# Set the user to simeon +USER simeon:simeon + # Start a shell CMD [ "bash" ]