From f0225d6c1d4afe2dca36b723db684c7c6ed4243c Mon Sep 17 00:00:00 2001 From: Diego La Falce <79284025+D10S0VSkY-OSS@users.noreply.github.com> Date: Sat, 11 Nov 2023 22:21:32 +0100 Subject: [PATCH] Refactor/k8s (#169) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 🔧refactor: Migrate to python 3.11 * 🔧refactor: outputs * 🔧refactor: outputs symbol colors * 🔧refactor: outputs symbol colors update in place * 🔧refactor: deploy set pagination and search * 🔧refactor: add stack pagination and search * 🔧refactor: add pagination and search component js * 🔧refactor: add pagination and search component js for users * 🐛fix: edit deploy * 🐛fix: edit users * 🐛fix: add destroy for plan UI * 🔧refactor: stacks forms * 🔧refactor: stacks forms variables * 🔧refactor: Dockerfiles for use asdf and python3.11 * 🔧refactor: github action bump version * 🔧refactor: k8s images --- .../kubernetes/k8s/sld-api-backend.yml | 2 +- sld-api-backend/Dockerfile | 45 +++++++++-------- sld-dashboard/Dockerfile | 47 +++++++++-------- sld-remote-state/Dockerfile | 50 ++++++++++--------- 4 files changed, 77 insertions(+), 67 deletions(-) diff --git a/play-with-sld/kubernetes/k8s/sld-api-backend.yml b/play-with-sld/kubernetes/k8s/sld-api-backend.yml index 0724d1a7..b979063c 100644 --- a/play-with-sld/kubernetes/k8s/sld-api-backend.yml +++ b/play-with-sld/kubernetes/k8s/sld-api-backend.yml @@ -19,7 +19,7 @@ spec: - name: api-backend image: d10s0vsky/sld-api:latest imagePullPolicy: Always - command: ["python3", "-m", "uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000", "--workers", "1"] + command: ["python", "-m", "uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000", "--workers", "1"] ports: - containerPort: 8000 livenessProbe: diff --git a/sld-api-backend/Dockerfile b/sld-api-backend/Dockerfile index 40173997..c7632c5e 100644 --- a/sld-api-backend/Dockerfile +++ b/sld-api-backend/Dockerfile @@ -6,40 +6,43 @@ 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 - # Set timezone -RUN echo $TZ > /etc/timezone && ln -snf /usr/share/zoneinfo/$TZ /etc/localtime +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 curl git zip tzdata build-essential libssl-dev libffi-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev pkg-config libmysqlclient-dev +# Create a user and group +RUN groupadd --gid 10000 sld && \ + useradd --uid 10000 --gid sld --shell /bin/bash --create-home sld -# 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 +# Set up working directory +WORKDIR /app + +# Change to user 'sld' +USER sld -SHELL ["/bin/bash", "-c"] +# Install asdf under user 'sld' +RUN git clone https://github.com/asdf-vm/asdf.git /home/sld/.asdf --branch v0.10.0 && \ + echo '. /home/sld/.asdf/asdf.sh' >> /home/sld/.bashrc && \ + echo '. /home/sld/.asdf/completions/asdf.bash' >> /home/sld/.bashrc -RUN . $HOME/.asdf/asdf.sh && \ +# Install Python using asdf +SHELL ["/bin/bash", "-l", "-c"] +RUN . /home/sld/.asdf/asdf.sh && \ asdf plugin add python && \ asdf install python 3.11.6 && \ asdf global python 3.11.6 +# Switch back to root to perform privileged operations +USER root -# 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 +# Add the requirements file and install Python packages +ADD ./requirements.txt /app/requirements.txt +RUN chown sld:sld /app/requirements.txt && \ + su - sld -c ". /home/sld/.asdf/asdf.sh && python -m pip install --upgrade pip setuptools && python -m pip install --no-cache-dir -r /app/requirements.txt" # Clean up RUN apt-get clean autoclean && \ @@ -48,7 +51,7 @@ RUN apt-get clean autoclean && \ # Add the rest of the application ADD . /app/ -RUN chown -R sld /app +RUN chown -R sld:sld /app -# Switch to user +# Switch to user 'sld' for runtime USER sld \ No newline at end of file diff --git a/sld-dashboard/Dockerfile b/sld-dashboard/Dockerfile index 8eecf14d..c7632c5e 100644 --- a/sld-dashboard/Dockerfile +++ b/sld-dashboard/Dockerfile @@ -6,40 +6,43 @@ 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 - # Set timezone -RUN echo $TZ > /etc/timezone && ln -snf /usr/share/zoneinfo/$TZ /etc/localtime +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 curl git zip tzdata build-essential libssl-dev libffi-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev pkg-config libmysqlclient-dev +# Create a user and group +RUN groupadd --gid 10000 sld && \ + useradd --uid 10000 --gid sld --shell /bin/bash --create-home sld + +# Set up working directory +WORKDIR /app -# 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 +# Change to user 'sld' +USER sld -SHELL ["/bin/bash", "-c"] +# Install asdf under user 'sld' +RUN git clone https://github.com/asdf-vm/asdf.git /home/sld/.asdf --branch v0.10.0 && \ + echo '. /home/sld/.asdf/asdf.sh' >> /home/sld/.bashrc && \ + echo '. /home/sld/.asdf/completions/asdf.bash' >> /home/sld/.bashrc -RUN . $HOME/.asdf/asdf.sh && \ +# Install Python using asdf +SHELL ["/bin/bash", "-l", "-c"] +RUN . /home/sld/.asdf/asdf.sh && \ asdf plugin add python && \ asdf install python 3.11.6 && \ asdf global python 3.11.6 +# Switch back to root to perform privileged operations +USER root -# 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 +# Add the requirements file and install Python packages +ADD ./requirements.txt /app/requirements.txt +RUN chown sld:sld /app/requirements.txt && \ + su - sld -c ". /home/sld/.asdf/asdf.sh && python -m pip install --upgrade pip setuptools && python -m pip install --no-cache-dir -r /app/requirements.txt" # Clean up RUN apt-get clean autoclean && \ @@ -48,7 +51,7 @@ RUN apt-get clean autoclean && \ # Add the rest of the application ADD . /app/ -RUN chown -R sld /app +RUN chown -R sld:sld /app -# Switch to user -USER sld +# Switch to user 'sld' for runtime +USER sld \ No newline at end of file diff --git a/sld-remote-state/Dockerfile b/sld-remote-state/Dockerfile index 2ff089a4..c7632c5e 100644 --- a/sld-remote-state/Dockerfile +++ b/sld-remote-state/Dockerfile @@ -6,39 +6,43 @@ 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 - # Set timezone -RUN echo $TZ > /etc/timezone && ln -snf /usr/share/zoneinfo/$TZ /etc/localtime +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 curl git zip tzdata build-essential libssl-dev libffi-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev + 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 + +# Create a user and group +RUN groupadd --gid 10000 sld && \ + useradd --uid 10000 --gid sld --shell /bin/bash --create-home sld -# 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 +# Set up working directory +WORKDIR /app -SHELL ["/bin/bash", "-c"] +# Change to user 'sld' +USER sld + +# Install asdf under user 'sld' +RUN git clone https://github.com/asdf-vm/asdf.git /home/sld/.asdf --branch v0.10.0 && \ + echo '. /home/sld/.asdf/asdf.sh' >> /home/sld/.bashrc && \ + echo '. /home/sld/.asdf/completions/asdf.bash' >> /home/sld/.bashrc -RUN . $HOME/.asdf/asdf.sh && \ +# Install Python using asdf +SHELL ["/bin/bash", "-l", "-c"] +RUN . /home/sld/.asdf/asdf.sh && \ asdf plugin add python && \ asdf install python 3.11.6 && \ asdf global python 3.11.6 +# Switch back to root to perform privileged operations +USER root -# 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 +# Add the requirements file and install Python packages +ADD ./requirements.txt /app/requirements.txt +RUN chown sld:sld /app/requirements.txt && \ + su - sld -c ". /home/sld/.asdf/asdf.sh && python -m pip install --upgrade pip setuptools && python -m pip install --no-cache-dir -r /app/requirements.txt" # Clean up RUN apt-get clean autoclean && \ @@ -47,7 +51,7 @@ RUN apt-get clean autoclean && \ # Add the rest of the application ADD . /app/ -RUN chown -R sld /app +RUN chown -R sld:sld /app -# Switch to user -USER sld +# Switch to user 'sld' for runtime +USER sld \ No newline at end of file