From 5e63565985b0ed6c2e65f6d7e7b380baae4092ed Mon Sep 17 00:00:00 2001 From: Matti Eiden Date: Wed, 16 Oct 2024 15:53:22 +0300 Subject: [PATCH] build: migrate to ubi9 image and drop postgis In an effort to reduce dependency on dockerhub, switching to use ubi9 rhel image. Additionally dropping postgis as it simplifies transitioning to ubi9 because gdal is no longer a required dependency. Refs: HP-2685 --- .github/workflows/ci.yml | 5 +---- Dockerfile | 28 ++++++++++------------------ README.md | 4 ---- docker-compose.yml | 2 +- docker-entrypoint.sh | 2 +- open_city_profile/settings.py | 3 --- tools/apt-cleanup.sh | 9 --------- tools/apt-install.sh | 4 ---- 8 files changed, 13 insertions(+), 44 deletions(-) delete mode 100755 tools/apt-cleanup.sh delete mode 100755 tools/apt-install.sh diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9ac645cf..422f7871 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,7 +17,7 @@ jobs: services: postgres: - image: postgis/postgis:13-3.2 + image: postgres:13 ports: - 5432:5432 options: >- @@ -50,9 +50,6 @@ jobs: ${{ runner.os }}-build-${{ env.cache-name }}- ${{ runner.os }}-build- ${{ runner.os }}- - - - name: Install system packages - run: sudo apt-get install -y gdal-bin - name: Install Python dependencies run: | pip install -r requirements.txt -r requirements-dev.txt codecov diff --git a/Dockerfile b/Dockerfile index 922aacd4..c2475a05 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,7 @@ +# Used by Azure Devops to pull from internal registry +ARG BUILDER_REGISTRY=registry.access.redhat.com # ============================== -FROM python:3.11-slim-bookworm as appbase +FROM ${BUILDER_REGISTRY}/ubi9/python-311:latest AS appbase # ============================== ENV PYTHONDONTWRITEBYTECODE 1 @@ -7,28 +9,19 @@ ENV PYTHONUNBUFFERED 1 WORKDIR /app -COPY tools /tools -ENV PATH="/tools:${PATH}" - +USER root RUN groupadd -g 1000 appuser \ && useradd -u 1000 -g appuser -ms /bin/bash appuser \ && chown -R appuser:appuser /app COPY --chown=appuser:appuser requirements*.txt /app/ -RUN apt-install.sh \ - git \ - curl \ - build-essential \ - libpq-dev \ - gdal-bin \ - netcat-openbsd \ - python3-gdal \ - postgresql-client \ +RUN dnf update -y \ + && dnf install -y nmap-ncat \ + && dnf clean all \ && pip install --upgrade pip setuptools wheel \ && pip install --no-cache-dir --no-deps -r /app/requirements.txt \ - && pip install --no-cache-dir -r /app/requirements-prod.txt \ - && apt-cleanup.sh build-essential + && pip install --no-cache-dir -r /app/requirements-prod.txt COPY --chown=appuser:appuser docker-entrypoint.sh /entrypoint/docker-entrypoint.sh ENTRYPOINT ["/entrypoint/docker-entrypoint.sh"] @@ -37,9 +30,8 @@ ENTRYPOINT ["/entrypoint/docker-entrypoint.sh"] FROM appbase as development # ============================== -RUN apt-install.sh build-essential \ - && pip install --no-cache-dir -r /app/requirements-dev.txt \ - && apt-cleanup.sh build-essential +RUN pip install --no-cache-dir -r /app/requirements-dev.txt + ENV DEV_SERVER=1 diff --git a/README.md b/README.md index 9cb5d4d2..d1fb2b48 100644 --- a/README.md +++ b/README.md @@ -116,10 +116,6 @@ Create user and database sudo -u postgres createuser -P -R -S open_city_profile # use password `open_city_profile` sudo -u postgres createdb -O open_city_profile open_city_profile -Create extensions in the database - - sudo -u postgres psql open_city_profile -c "CREATE EXTENSION postgis;" - Allow user to create test database sudo -u postgres psql -c "ALTER USER open_city_profile CREATEDB;" diff --git a/docker-compose.yml b/docker-compose.yml index 380df336..829fd5f1 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,6 +1,6 @@ services: postgres: - image: postgis/postgis:13-3.2-alpine + image: postgres:13-alpine restart: on-failure environment: POSTGRES_USER: open_city_profile diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index ceb040e1..f6071c6a 100755 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -3,7 +3,7 @@ set -e if [ -z "$SKIP_DATABASE_CHECK" -o "$SKIP_DATABASE_CHECK" = "0" ]; then - until nc -z -v -w30 "$DATABASE_HOST" 5432 + until nc --verbose --wait 30 --send-only "$DATABASE_HOST" 5432 do echo "Waiting for postgres database connection..." sleep 1 diff --git a/open_city_profile/settings.py b/open_city_profile/settings.py index 71968610..5c2e8655 100644 --- a/open_city_profile/settings.py +++ b/open_city_profile/settings.py @@ -134,8 +134,6 @@ CSRF_TRUSTED_ORIGINS = env.list("CSRF_TRUSTED_ORIGINS") DATABASES = {"default": env.db()} -# Ensure postgis engine -DATABASES["default"]["ENGINE"] = "django.contrib.gis.db.backends.postgis" if env("DATABASE_PASSWORD"): DATABASES["default"]["PASSWORD"] = env("DATABASE_PASSWORD") @@ -190,7 +188,6 @@ "django.contrib.sites", "django.contrib.messages", "open_city_profile.apps.OpenCityProfileStaticFilesConfig", - "django.contrib.gis", "django_filters", "parler", "corsheaders", diff --git a/tools/apt-cleanup.sh b/tools/apt-cleanup.sh deleted file mode 100755 index 9b48d4e8..00000000 --- a/tools/apt-cleanup.sh +++ /dev/null @@ -1,9 +0,0 @@ -#!/usr/bin/env bash - -if [[ ! -z "$@" ]]; then - apt-get remove -y "$@" -fi - -apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false -apt-get clean -rm -rf /var/lib/apt/lists/* diff --git a/tools/apt-install.sh b/tools/apt-install.sh deleted file mode 100755 index 6b67c3fd..00000000 --- a/tools/apt-install.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/usr/bin/env bash - -apt-get update -apt-get install -y --no-install-recommends "$@"