From 3d15f7ea009d26005b6658c02a14e5a5bd2d015a Mon Sep 17 00:00:00 2001 From: Bruno Ciconelle Date: Mon, 7 Feb 2022 10:37:06 -0300 Subject: [PATCH 1/5] Update container base image to ubi8 --- Dockerfile | 39 ++++++++++++++------------------------- deploy/server_run.sh | 4 ++-- requirements.txt | 3 ++- 3 files changed, 18 insertions(+), 28 deletions(-) diff --git a/Dockerfile b/Dockerfile index 9f798888a..c03ed62ff 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,26 +1,21 @@ -FROM fedora:26 +FROM redhat/ubi8 -RUN dnf -y groupinstall "Development tools" \ - && dnf -y install python-devel python-tools python3-devel python3-tools sshpass which supervisor procps\ - && dnf clean all \ - && rm -rf /var/cache/dnf +RUN dnf -yq install python39 make openssh-clients glibc-langpack-en &&\ + dnf update &&\ + dnf clean all &&\ + python3 -m venv /opt/venv -RUN pip install --no-cache-dir virtualenv -RUN virtualenv -p python3 ~/venv -# Create base directory -RUN mkdir -p /app +ENV PATH="/opt/venv/bin:${PATH}" -# Setup dependencies -COPY requirements.txt /app/requirements.txt -RUN . ~/venv/bin/activate; pip install -r /app/requirements.txt gunicorn==20.0.4 +RUN pip install --upgrade pip + +WORKDIR /app +COPY requirements.txt . +RUN pip install -r requirements.txt # Create /etc/ssl/qpc RUN mkdir -p /etc/ssl/qpc/ -VOLUME /etc/ssl/qpc/ -COPY deploy/ssl/server.crt /etc/ssl/qpc/ -COPY deploy/ssl/server.csr /etc/ssl/qpc/ -COPY deploy/ssl/server.key /etc/ssl/qpc/ - +COPY deploy/ssl/* /etc/ssl/qpc/ # Create /deploy RUN mkdir -p /deploy @@ -36,10 +31,6 @@ COPY deploy/supervisord.conf /etc/supervisor/conf.d/supervisord.conf RUN mkdir -p /var/log/supervisor/ VOLUME /var/log -# Create /sshkeys -RUN mkdir -p /sshkeys -VOLUME /sshkeys - # Create /var/data RUN mkdir -p /var/data VOLUME /var/data @@ -50,9 +41,7 @@ COPY quipucords/scanner/network/runner/roles/ /etc/ansible/roles/ VOLUME /etc/ansible/roles/ # Copy server code -COPY . /app/ -WORKDIR /app -VOLUME /app +COPY . . # Set production environment ARG BUILD_COMMIT=master @@ -71,7 +60,7 @@ ENV LANG=en_US.UTF-8 ENV PYTHONHASHSEED=0 # Initialize database & Collect static files -RUN . ~/venv/bin/activate;make server-static +RUN make server-static RUN ls -lta /var/data WORKDIR /var/log diff --git a/deploy/server_run.sh b/deploy/server_run.sh index e4d941ee4..cfff1ac1d 100755 --- a/deploy/server_run.sh +++ b/deploy/server_run.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash -source ~/venv/bin/activate +source /opt/venv/bin/activate make server-migrate server-set-superuser -C /app @@ -8,4 +8,4 @@ if [[ ${USE_SUPERVISORD,,} = "false" ]]; then cd /app/quipucords fi -~/venv/bin/gunicorn quipucords.wsgi -c /deploy/gunicorn.conf.py +/opt/venv/bin/gunicorn quipucords.wsgi -c /deploy/gunicorn.conf.py diff --git a/requirements.txt b/requirements.txt index 89efc1222..9a6634a26 100644 --- a/requirements.txt +++ b/requirements.txt @@ -10,4 +10,5 @@ PyYAML==5.4 requests==2.25.1 whitenoise==5.2.0 psycopg2-binary==2.8.6 -ansible-runner==1.4.6 \ No newline at end of file +ansible-runner==1.4.6 +gunicorn==20.0.4 \ No newline at end of file From d4b1838406737a65c80c132e06987d74ad2c767d Mon Sep 17 00:00:00 2001 From: Bruno Ciconelle Date: Mon, 7 Feb 2022 10:38:29 -0300 Subject: [PATCH 2/5] Remove envvar PYTHONHASHSEED PYTHONHASHSEED must be set to 0 only on test environments. --- Dockerfile | 1 - 1 file changed, 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index c03ed62ff..2a4da50b1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -57,7 +57,6 @@ ENV DJANGO_LOG_FILE=/var/log/app.log ENV QUIPUCORDS_LOGGING_LEVEL=INFO ENV LC_ALL=en_US.UTF-8 ENV LANG=en_US.UTF-8 -ENV PYTHONHASHSEED=0 # Initialize database & Collect static files RUN make server-static From 0f9c3f0d3117f3c1e6d60bb807b285aa7cda8acb Mon Sep 17 00:00:00 2001 From: Bruno Ciconelle Date: Mon, 7 Feb 2022 11:04:24 -0300 Subject: [PATCH 3/5] Allow the quipucords to run on any folder --- Dockerfile | 1 + deploy/server_run.sh | 8 +------- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/Dockerfile b/Dockerfile index 2a4da50b1..a99e5b244 100644 --- a/Dockerfile +++ b/Dockerfile @@ -57,6 +57,7 @@ ENV DJANGO_LOG_FILE=/var/log/app.log ENV QUIPUCORDS_LOGGING_LEVEL=INFO ENV LC_ALL=en_US.UTF-8 ENV LANG=en_US.UTF-8 +ENV PYTHONPATH=/app/quipucords # Initialize database & Collect static files RUN make server-static diff --git a/deploy/server_run.sh b/deploy/server_run.sh index cfff1ac1d..69eb4ebc3 100755 --- a/deploy/server_run.sh +++ b/deploy/server_run.sh @@ -1,11 +1,5 @@ #!/usr/bin/env bash -source /opt/venv/bin/activate - make server-migrate server-set-superuser -C /app -if [[ ${USE_SUPERVISORD,,} = "false" ]]; then - cd /app/quipucords -fi - -/opt/venv/bin/gunicorn quipucords.wsgi -c /deploy/gunicorn.conf.py +gunicorn quipucords.wsgi -c /deploy/gunicorn.conf.py From d12a8cd8ca09c8fd5b375a38317f87cc0746682a Mon Sep 17 00:00:00 2001 From: Bruno Ciconelle Date: Tue, 8 Feb 2022 19:00:23 -0300 Subject: [PATCH 4/5] Drop supervisor support There's no benefit on running the application behind supervisor on a container. --- Dockerfile | 4 ---- deploy/docker_run.sh | 8 +------- 2 files changed, 1 insertion(+), 11 deletions(-) diff --git a/Dockerfile b/Dockerfile index a99e5b244..f42e5b95f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,6 @@ FROM redhat/ubi8 RUN dnf -yq install python39 make openssh-clients glibc-langpack-en &&\ - dnf update &&\ dnf clean all &&\ python3 -m venv /opt/venv @@ -24,9 +23,6 @@ COPY deploy/docker_run.sh /deploy COPY deploy/server_run.sh /deploy COPY deploy/setup_user.py /deploy -# Config supervisor -COPY deploy/supervisord.conf /etc/supervisor/conf.d/supervisord.conf - # Create log directories RUN mkdir -p /var/log/supervisor/ VOLUME /var/log diff --git a/deploy/docker_run.sh b/deploy/docker_run.sh index c9a08a67c..d896626c0 100755 --- a/deploy/docker_run.sh +++ b/deploy/docker_run.sh @@ -1,10 +1,4 @@ #!/usr/bin/env bash eval `ssh-agent -s` -if [[ ${USE_SUPERVISORD,,} = "false" ]]; then - echo "Running without supervisord" - /deploy/server_run.sh >& /var/log/quipucords.log -else - echo "Running with supervisord" - /usr/bin/supervisord -c /etc/supervisor/conf.d/supervisord.conf -fi +/deploy/server_run.sh >& /var/log/quipucords.log From cf5fa2512334339a28fb86a7a687c2987f97f64b Mon Sep 17 00:00:00 2001 From: Bruno Ciconelle Date: Fri, 4 Feb 2022 19:40:21 -0300 Subject: [PATCH 5/5] Send gunicorn logs to stdout Mantain compatibility with the orginal way logs are handled. --- deploy/docker_run.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deploy/docker_run.sh b/deploy/docker_run.sh index d896626c0..cb78111cf 100755 --- a/deploy/docker_run.sh +++ b/deploy/docker_run.sh @@ -1,4 +1,4 @@ #!/usr/bin/env bash eval `ssh-agent -s` -/deploy/server_run.sh >& /var/log/quipucords.log +/deploy/server_run.sh 2>&1 | tee /var/log/quipucords.log