From 1d5b98a88edf113125e3d0ed58be183dd2b0bd56 Mon Sep 17 00:00:00 2001 From: Eshaan Bansal Date: Thu, 29 Jul 2021 15:49:55 +0530 Subject: [PATCH] update python version in runtime.txt and Dockerfile, fix sqlalchemy 1.4.x bug --- Dockerfile | 10 ++++++---- docker-compose-for-tests.yml | 4 ++-- docker-compose.yml | 6 +++--- runtime.txt | 2 +- src/FlaskRTBCTF/config.py | 5 ++++- 5 files changed, 16 insertions(+), 11 deletions(-) diff --git a/Dockerfile b/Dockerfile index b3c3c66..19c4fd1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,17 +1,19 @@ -FROM python:3.8.3-alpine3.12 +FROM python:3.9-alpine LABEL maintainer="eshaan7bansal@gmail.com" # Env -RUN export DATABASE_URL="postgres://${DB_USER}:${DB_PASSWORD}@postgres:${DB_PORT}/${DB_NAME}" \ +RUN export DATABASE_URL="postgresql://${DB_USER}:${DB_PASSWORD}@postgres:${DB_PORT}/${DB_NAME}" \ && export REDIS_URL="redis://redis:6379/0" # update and install packages RUN apk update --no-cache \ && apk add --no-cache postgresql-dev build-base g++ libffi-dev -# Add a new low-privileged user -RUN adduser --shell /sbin/login www-data -DH +# ensure www-data user exists (low-privileged user) +RUN set -x ; \ + addgroup -g 82 -S www-data ; \ + adduser -u 82 -D -S -G www-data www-data && exit 0 ; exit 1 # Install RTB-CTF-Framework WORKDIR /usr/src/app diff --git a/docker-compose-for-tests.yml b/docker-compose-for-tests.yml index 32c309b..85a969a 100644 --- a/docker-compose-for-tests.yml +++ b/docker-compose-for-tests.yml @@ -28,9 +28,9 @@ services: restart: unless-stopped expose: - "6379" - + nginx: - image: library/nginx:1.16.1-alpine + image: library/nginx:1.21-alpine container_name: rtb_nginx restart: unless-stopped hostname: nginx diff --git a/docker-compose.yml b/docker-compose.yml index b681d93..f1a4684 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -19,7 +19,7 @@ services: expose: - "5432" env_file: - - .env_postgres + - .env_postgres redis: image: redis:alpine3.12 @@ -27,9 +27,9 @@ services: restart: unless-stopped expose: - "6379" - + nginx: - image: library/nginx:1.16.1-alpine + image: library/nginx:1.21-alpine container_name: rtb_nginx restart: unless-stopped hostname: nginx diff --git a/runtime.txt b/runtime.txt index 3e4835c..9bff0e0 100644 --- a/runtime.txt +++ b/runtime.txt @@ -1 +1 @@ -python-3.8.7 +python-3.9.6 diff --git a/src/FlaskRTBCTF/config.py b/src/FlaskRTBCTF/config.py index 8dd22d0..0a0b827 100644 --- a/src/FlaskRTBCTF/config.py +++ b/src/FlaskRTBCTF/config.py @@ -6,7 +6,10 @@ class Config: DEBUG = False # Turn DEBUG OFF before deployment SECRET_KEY = os.environ.get("SECRET_KEY", "you-will-never-guess") - SQLALCHEMY_DATABASE_URI = os.environ.get("DATABASE_URL") or "sqlite:///site.db" + _uri = os.environ.get("DATABASE_URL") or "sqlite:///site.db" + if _uri.startswith("postgres://"): + _uri = _uri.replace("postgres://", "postgresql://", 1) + SQLALCHEMY_DATABASE_URI = _uri # For local use, one can simply use SQLlite with: 'sqlite:///site.db' # For deployment on Heroku use: `os.environ.get('DATABASE_URL')` # in all other cases: `os.environ.get('SQLALCHEMY_DATABASE_URI')`