diff --git a/.env-example b/.env-example index ef3a6d67e3403d71d6b48ffac1117a93f0c63a15..5055aabcefe1d259553f159e8c5202abb80e285b 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 ed092382bbf13387f018c1ded75670d15dba156f..516002667a7324d043e624c4e6e339320d01494b 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 22df961a646c007a69621c24f166ca67df55a58f..b8b1b480735527d4663923e770cd60972b1b88bb 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 47ce0e3e1a5657d2b9dc1a54b950dd720039049f..1720146613c00a5161c7a4bc8d7c03665a0dc81c 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 781e71f26cc68bb660860bb64ea2345221573e55..0000000000000000000000000000000000000000 --- 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 37266e1587647cb918710f1eefd82e3dc78016d1..0de32e33c089ccf2c77c1b85cd6db7a03ee6e341 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 f028cec80dd4b1a1560548f1b6dffecc0a5bff3a..8b59898d9dd3d9bfab2de75e76aaf6fee78ab02e 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 19f100b7c8d8625dfff47bdad0b237b2a169217d..9945e842e5a7f4f54a60ed3fea364d9b5dc048a3 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