Skip to content

Commit

Permalink
🔧refactor: Dockerfiles for use asdf and python3.11
Browse files Browse the repository at this point in the history
  • Loading branch information
D10S0VSkY-OSS committed Nov 11, 2023
1 parent 4631c32 commit b8d0c0e
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 44 deletions.
44 changes: 33 additions & 11 deletions sld-api-backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -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
49 changes: 31 additions & 18 deletions sld-dashboard/Dockerfile
Original file line number Diff line number Diff line change
@@ -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
45 changes: 30 additions & 15 deletions sld-remote-state/Dockerfile
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit b8d0c0e

Please sign in to comment.