From 9fafa31fe5613cfec4bce1996f441c82c5572c16 Mon Sep 17 00:00:00 2001 From: Ethan-clay03 <ethanclay2017@gmail.com> Date: Mon, 3 Feb 2025 16:08:38 +0000 Subject: [PATCH] Fix docker containers and updated READ ME with instructions to run locally --- .env-example | 6 ++++-- Dockerfile | 5 ++--- README | 16 ++++++++++++---- app/__init__.py | 2 +- compose.yaml | 41 ---------------------------------------- docker-compose.debug.yml | 1 + docker-compose.yml | 40 +++++++++++++++++++++++++++++++++++---- requirements.txt | 3 ++- 8 files changed, 58 insertions(+), 56 deletions(-) delete mode 100644 compose.yaml diff --git a/.env-example b/.env-example index ef3a6d6..5055aab 100644 --- a/.env-example +++ b/.env-example @@ -1,5 +1,7 @@ DEVELOPMENT_MODE=True -DATABASE_HOST=localhost +DATABASE_HOST=database +#If using pydebug you will need to use 127.0.0.1 DATABASE_USER=root DATABASE_PASSWORD=password1 -DATABASE_NAME=database \ No newline at end of file +DATABASE_NAME=database +SECRET_KEY=fsodfhiosdfhdsiofh34903urwej09jf \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index ed09238..5160026 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -# For more information, please refer to https://aka.ms/vscode-docker-python +# Based initially from https://aka.ms/vscode-docker-python FROM python:3-slim EXPOSE 5000 @@ -11,16 +11,15 @@ ENV PYTHONUNBUFFERED=1 # Install pip requirements COPY requirements.txt . +RUN apt-get update && apt-get install -y netcat-openbsd RUN python -m pip install -r requirements.txt WORKDIR /app COPY . /app # Creates a non-root user with an explicit UID and adds permission to access the /app folder -# For more info, please refer to https://aka.ms/vscode-docker-python-configure-containers RUN adduser -u 5678 --disabled-password --gecos "" appuser && chown -R appuser /app USER appuser -# During debugging, this entry point will be overridden. For more information, please refer to https://aka.ms/vscode-docker-python-debug CMD ["flask", "run", "--host=0.0.0.0", "--port=5000"] diff --git a/README b/README index 22df961..b8b1b48 100644 --- a/README +++ b/README @@ -1,3 +1,6 @@ +## PLEASE READ ALL SETUP INSTRUCTIONS CAREFULLY AND IN FULL + + ## IMPORTANT, PLEASE READ THE BELOW BEFORE USING THE PROJECT ## Important Notice @@ -21,8 +24,6 @@ All updates and planned changes are made via a public Trello which tracks what t https://trello.com/b/WILg5Qio/flask-website -## Current setup documentation is out of date and may result in errors. Please contact me for help getting setup if you are NOT using Docker. - ## Getting setup @@ -88,5 +89,12 @@ flask db migrate -m "Add age column to User model" ########################################## # Database Commands # ########################################## -# Login to CSCT cloud and connect to ethan2clay_prj, alternatively copy .env-example and change the copy to .env and add your own database connection. -# It is advised to use the dockerised containers as this will mount a volume and retain your database entries. \ No newline at end of file +# Within the PR a MySQL dump is provided and loaded upon building of the docker container. If you are running the site outside a docker container +# you will either need to follow one of the below options: + +# It is advised to use the dockerised containers as this will mount a SQL volume automatically. + +# Login to CSCT cloud and connect to ethan2clay_prj +# Manually import the mysql dump provided within the sql folder + +# Add your own connector which can be done by changing .env diff --git a/app/__init__.py b/app/__init__.py index 47ce0e3..1720146 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -48,7 +48,7 @@ def create_app(config_class=Config): db_password = os.getenv("DATABASE_PASSWORD") db_name = os.getenv("DATABASE_NAME") - app.config['SECRET_KEY'] = os.getenv('SECRET_KEY') or 'your_secret_key' + app.config['SECRET_KEY'] = os.getenv('SECRET_KEY') app.config['SQLALCHEMY_DATABASE_URI'] = f"mysql+pymysql://{db_user}:{db_password}@{db_host}/{db_name}" # Initialize extensions with the app diff --git a/compose.yaml b/compose.yaml deleted file mode 100644 index 781e71f..0000000 --- a/compose.yaml +++ /dev/null @@ -1,41 +0,0 @@ -services: - flask: - build: - context: . - dockerfile: Dockerfile - stop_signal: SIGINT - ports: - - '5000:5000' - volumes: - - ./app:/flask/app - depends_on: - - database - networks: - - network - environment: - DEVELOPMENT_MODE: ${DEVELOPMENT_MODE} - DATABASE_HOST: ${DATABASE_HOST} - DATABASE_USER: ${DATABASE_USER} - DATABASE_PASSWORD: ${DATABASE_PASSWORD} - DATABASE_NAME: ${DATABASE_NAME} - database: - image: mysql:8.3 - ports: - - '3306:3306' - environment: - MYSQL_ROOT_PASSWORD: ${DATABASE_PASSWORD} - MYSQL_DATABASE: ${DATABASE_NAME} - MYSQL_USER: ${DATABASE_USER} - MYSQL_PASSWORD: ${DATABASE_PASSWORD} - - volumes: - - mysql_data:/var/lib/mysql - networks: - - network - -volumes: - mysql_data: - -networks: - network: - driver: bridge diff --git a/docker-compose.debug.yml b/docker-compose.debug.yml index 37266e1..0de32e3 100644 --- a/docker-compose.debug.yml +++ b/docker-compose.debug.yml @@ -20,6 +20,7 @@ services: DATABASE_USER: ${DATABASE_USER} DATABASE_PASSWORD: ${DATABASE_PASSWORD} DATABASE_NAME: ${DATABASE_NAME} + SECRET_KEY: ${SECRET_KEY} FLASK_APP: app\__init__.py database: image: mysql:8.0 diff --git a/docker-compose.yml b/docker-compose.yml index f028cec..8b59898 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,10 +1,42 @@ -version: '3.4' - services: flask: image: flask build: context: . - dockerfile: ./Dockerfile + dockerfile: Dockerfile + stop_signal: SIGINT + ports: + - '5000:5000' + depends_on: + - database + networks: + - network + environment: + DEVELOPMENT_MODE: ${DEVELOPMENT_MODE} + DATABASE_HOST: ${DATABASE_HOST} + DATABASE_USER: ${DATABASE_USER} + DATABASE_PASSWORD: ${DATABASE_PASSWORD} + DATABASE_NAME: ${DATABASE_NAME} + SECRET_KEY: ${SECRET_KEY} + FLASK_APP: app/__init__.py + command: ["flask", "run", "--host=0.0.0.0", "--port=5000"] + database: + image: mysql:8.0 ports: - - 5000:5000 + - '3306:3306' + environment: + MYSQL_ROOT_PASSWORD: ${DATABASE_PASSWORD} + MYSQL_DATABASE: ${DATABASE_NAME} + MYSQL_USER: ${DATABASE_USER} + MYSQL_PASSWORD: ${DATABASE_PASSWORD} + volumes: + - mysql_data:/var/lib/mysql + networks: + - network + +volumes: + mysql_data: + +networks: + network: + driver: bridge diff --git a/requirements.txt b/requirements.txt index 19f100b..9945e84 100644 --- a/requirements.txt +++ b/requirements.txt @@ -9,4 +9,5 @@ flask-login debugpy flask-wtf flask-security -flask-principal \ No newline at end of file +flask-principal +setuptools \ No newline at end of file -- GitLab