From b8d0c0ed6511016fd5b5bffaab869190d6273288 Mon Sep 17 00:00:00 2001 From: d10s <79284025+D10S0VSkY-OSS@users.noreply.github.com> Date: Sat, 11 Nov 2023 20:39:14 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7refactor:=20Dockerfiles=20for=20use?= =?UTF-8?q?=20asdf=20and=20python3.11?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sld-api-backend/Dockerfile | 44 ++++++++++++++++++++++++--------- sld-dashboard/Dockerfile | 49 +++++++++++++++++++++++-------------- sld-remote-state/Dockerfile | 45 ++++++++++++++++++++++------------ 3 files changed, 94 insertions(+), 44 deletions(-) diff --git a/sld-api-backend/Dockerfile b/sld-api-backend/Dockerfile index 614290df..40173997 100644 --- a/sld-api-backend/Dockerfile +++ b/sld-api-backend/Dockerfile @@ -1,32 +1,54 @@ FROM ubuntu:22.04 -MAINTAINER D10S0VSkY +# Metadata +MAINTAINER D10S0VSkY ENV LC_ALL=C.UTF-8 ENV LANG=C.UTF-8 ENV TZ=Europe/Madrid +# Set up working directory WORKDIR /app ADD ./requirements.txt /app/requirements.txt +# Create a user and group RUN groupadd --gid 10000 sld && \ - useradd --uid 10000 --gid sld --shell /bin/bash --create-home sld + useradd --uid 10000 --gid sld --shell /bin/bash --create-home sld +# Set timezone RUN echo $TZ > /etc/timezone && ln -snf /usr/share/zoneinfo/$TZ /etc/localtime - +# Install dependencies including build tools RUN export DEBIAN_FRONTEND=noninteractive && \ -apt-get update && \ -apt-get upgrade -yq && \ -apt-get -yq install \ -python3.10 pip default-libmysqlclient-dev zip git tzdata && \ -pip install --no-cache-dir -r requirements.txt + apt-get update && \ + apt-get -yq install curl git zip tzdata build-essential libssl-dev libffi-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev pkg-config libmysqlclient-dev -RUN apt-get clean autoclean && \ -apt-get autoremove -y && \ -rm -rf /var/lib/{apt,dpkg,cache,log}/ +# Install asdf, Python plugin, and Python version +RUN git clone https://github.com/asdf-vm/asdf.git ~/.asdf --branch v0.10.0 && \ + echo '. $HOME/.asdf/asdf.sh' >> ~/.bashrc && \ + echo '. $HOME/.asdf/completions/asdf.bash' >> ~/.bashrc + +SHELL ["/bin/bash", "-c"] + +RUN . $HOME/.asdf/asdf.sh && \ + asdf plugin add python && \ + asdf install python 3.11.6 && \ + asdf global python 3.11.6 + + +# Install Python packages +RUN . $HOME/.asdf/asdf.sh && \ + python -m pip install --upgrade pip setuptools && \ + python -m pip install --no-cache-dir -r requirements.txt + +# Clean up +RUN apt-get clean autoclean && \ + apt-get autoremove -y && \ + rm -rf /var/lib/{apt,dpkg,cache,log} +# Add the rest of the application ADD . /app/ RUN chown -R sld /app +# Switch to user USER sld \ No newline at end of file diff --git a/sld-dashboard/Dockerfile b/sld-dashboard/Dockerfile index c308f7ed..8eecf14d 100644 --- a/sld-dashboard/Dockerfile +++ b/sld-dashboard/Dockerfile @@ -1,41 +1,54 @@ FROM ubuntu:22.04 -MAINTAINER D10S0VSkY +# Metadata +MAINTAINER D10S0VSkY ENV LC_ALL=C.UTF-8 ENV LANG=C.UTF-8 ENV TZ=Europe/Madrid -ENV FLASK_APP run.py +# Set up working directory WORKDIR /app ADD ./requirements.txt /app/requirements.txt +# Create a user and group RUN groupadd --gid 10000 sld && \ - useradd --uid 10000 --gid sld --shell /bin/bash --create-home sld - -COPY run.py gunicorn-cfg.py requirements.txt config.py .env ./ + useradd --uid 10000 --gid sld --shell /bin/bash --create-home sld +# Set timezone RUN echo $TZ > /etc/timezone && ln -snf /usr/share/zoneinfo/$TZ /etc/localtime +# Install dependencies including build tools RUN export DEBIAN_FRONTEND=noninteractive && \ -apt-get update && \ -apt-get -yq install software-properties-common && \ -add-apt-repository ppa:deadsnakes/ppa + apt-get update && \ + apt-get -yq install curl git zip tzdata build-essential libssl-dev libffi-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev pkg-config libmysqlclient-dev + + +# Install asdf, Python plugin, and Python version +RUN git clone https://github.com/asdf-vm/asdf.git ~/.asdf --branch v0.10.0 && \ + echo '. $HOME/.asdf/asdf.sh' >> ~/.bashrc && \ + echo '. $HOME/.asdf/completions/asdf.bash' >> ~/.bashrc + +SHELL ["/bin/bash", "-c"] + +RUN . $HOME/.asdf/asdf.sh && \ + asdf plugin add python && \ + asdf install python 3.11.6 && \ + asdf global python 3.11.6 -RUN export DEBIAN_FRONTEND=noninteractive && \ -apt-get update && \ -apt-get upgrade -yq && \ -apt-get -yq install \ -python3.11 pip default-libmysqlclient-dev zip git tzdata python3.11-dev -RUN ln -s /usr/bin/python3.11 /usr/bin/python && \ -python -m pip install --upgrade setuptools && \ -python -m pip install --no-cache-dir -r requirements.txt +# Install Python packages +RUN . $HOME/.asdf/asdf.sh && \ + python -m pip install --upgrade pip setuptools && \ + python -m pip install --no-cache-dir -r requirements.txt +# Clean up RUN apt-get clean autoclean && \ -apt-get autoremove -y && \ -rm -rf /var/lib/{apt,dpkg,cache,log}/ + apt-get autoremove -y && \ + rm -rf /var/lib/{apt,dpkg,cache,log} +# Add the rest of the application ADD . /app/ RUN chown -R sld /app +# Switch to user USER sld diff --git a/sld-remote-state/Dockerfile b/sld-remote-state/Dockerfile index ee6e28c4..2ff089a4 100644 --- a/sld-remote-state/Dockerfile +++ b/sld-remote-state/Dockerfile @@ -1,38 +1,53 @@ FROM ubuntu:22.04 -MAINTAINER D10S0VSkY +# Metadata +MAINTAINER D10S0VSkY ENV LC_ALL=C.UTF-8 ENV LANG=C.UTF-8 ENV TZ=Europe/Madrid +# Set up working directory WORKDIR /app ADD ./requirements.txt /app/requirements.txt +# Create a user and group RUN groupadd --gid 10000 sld && \ - useradd --uid 10000 --gid sld --shell /bin/bash --create-home sld + useradd --uid 10000 --gid sld --shell /bin/bash --create-home sld +# Set timezone RUN echo $TZ > /etc/timezone && ln -snf /usr/share/zoneinfo/$TZ /etc/localtime +# Install dependencies including build tools RUN export DEBIAN_FRONTEND=noninteractive && \ -apt-get update && \ -apt-get -yq install software-properties-common && \ -add-apt-repository ppa:deadsnakes/ppa + apt-get update && \ + apt-get -yq install curl git zip tzdata build-essential libssl-dev libffi-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev + +# Install asdf, Python plugin, and Python version +RUN git clone https://github.com/asdf-vm/asdf.git ~/.asdf --branch v0.10.0 && \ + echo '. $HOME/.asdf/asdf.sh' >> ~/.bashrc && \ + echo '. $HOME/.asdf/completions/asdf.bash' >> ~/.bashrc + +SHELL ["/bin/bash", "-c"] + +RUN . $HOME/.asdf/asdf.sh && \ + asdf plugin add python && \ + asdf install python 3.11.6 && \ + asdf global python 3.11.6 -RUN export DEBIAN_FRONTEND=noninteractive && \ -apt-get update && \ -apt-get upgrade -yq && \ -apt-get -yq install \ -python3.11 pip default-libmysqlclient-dev zip git tzdata python3.11-dev -RUN ln -s /usr/bin/python3.11 /usr/bin/python && \ -python -m pip install --upgrade setuptools && \ -python -m pip install --no-cache-dir -r requirements.txt +# Install Python packages +RUN . $HOME/.asdf/asdf.sh && \ + python -m pip install --upgrade pip setuptools && \ + python -m pip install --no-cache-dir -r requirements.txt +# Clean up RUN apt-get clean autoclean && \ -apt-get autoremove -y && \ -rm -rf /var/lib/{apt,dpkg,cache,log} + apt-get autoremove -y && \ + rm -rf /var/lib/{apt,dpkg,cache,log} +# Add the rest of the application ADD . /app/ RUN chown -R sld /app +# Switch to user USER sld