-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes django project, resolves numerous config issues and allows the …
…app to run
- Loading branch information
Showing
170 changed files
with
585 additions
and
505 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# Use the Python 3.10.2 image as the base image | ||
|
||
FROM python:3.10.2 | ||
|
||
# Install required tools | ||
#RUN apt-get update && apt-get install -y curl build-essential | ||
|
||
# Install Rust and Cargo | ||
#RUN curl https://sh.rustup.rs -sSf | sh -s -- -y | ||
|
||
# Add Rust to PATH | ||
#ENV PATH="/root/.cargo/bin:${PATH}" | ||
|
||
# Install required tools | ||
RUN apt-get update && apt-get install -y bash g++ gcc make redis redis-tools | ||
|
||
# Create non-root user | ||
RUN useradd -m -u 1001 atc_api | ||
|
||
# Upgrade pip and certifi | ||
RUN python3 -m pip install --upgrade pip && pip install --upgrade certifi | ||
|
||
|
||
|
||
# Set environment variables | ||
ENV PYTHONDONTWRITEBYTECODE 1 | ||
ENV PYTHONUNBUFFERED 1 | ||
|
||
# Create working directory with correct ownership | ||
RUN mkdir /code && chown atc_api:atc_api /code | ||
WORKDIR /code | ||
|
||
# Install dependencies | ||
COPY --chown=atc_api:atc_api ./pe_reports_django_project/pe_reports_django/requirements.txt /code/ | ||
RUN pip install --no-cache-dir -r requirements.txt | ||
RUN pip install --upgrade numpy spacy | ||
# Copy the project code | ||
COPY --chown=atc_api:atc_api pe_reports_django_project /code | ||
|
||
# Switch to non-root user | ||
USER atc_api | ||
|
||
# Set Django environment variable | ||
ENV DJANGO_SETTINGS_MODULE=pe_reports_django.settings | ||
|
||
# Run the application | ||
CMD uvicorn --workers 4 pe_reports_django.asgi:app1 --host 0.0.0.0 --port 8000 --reload | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,105 +0,0 @@ | ||
"""The pe_reports library.""" | ||
# We disable a Flake8 check for "Module imported but unused (F401)" here because | ||
# although this import is not directly used, it populates the value | ||
# package_name.__version__, which is used to get version information about this | ||
# Python package. | ||
|
||
# Standard Python Libraries | ||
import logging | ||
from logging.handlers import RotatingFileHandler | ||
import os | ||
|
||
# Third-Party Libraries | ||
# from celery import Celery | ||
from flask import Flask, render_template | ||
from flask_login import LoginManager | ||
from flask_migrate import Migrate | ||
from flask_sqlalchemy import SQLAlchemy | ||
|
||
# cisagov Libraries | ||
from pe_reports.data.config import config | ||
|
||
from ._version import __version__ # noqa: F401 | ||
|
||
# Stakeholder views | ||
# from pe_reports.home.views import home_blueprint | ||
# from pe_reports.report_gen.views import report_gen_blueprint | ||
# from pe_reports.stakeholder.views import stakeholder_blueprint | ||
# from pe_reports.stakeholder_bulk_upload.views import stakeholder_bulk_upload_blueprint | ||
# from pe_reports.stakeholder_full.views import stakeholder_full_blueprint | ||
|
||
|
||
params = config() | ||
login_manager = LoginManager() | ||
# Flask implementation | ||
app = Flask(__name__) | ||
app.config["SECRET_KEY"] = os.getenv("FLASK_SECRET_KEY", "dev") | ||
app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False | ||
app.config[ | ||
"SQLALCHEMY_DATABASE_URI" | ||
] = f'postgresql+psycopg2://{params["user"]}:{params["password"]}@{params["host"]}:{params["port"]}/{params["database"]}' | ||
|
||
|
||
# Configure the redis server | ||
# app.config["CELERY_BROKER_URL"] = "redis://localhost:6379/0" | ||
# app.config["CELERY_RESULT_BACKEND"] = "redis://localhost:6379/0" | ||
app.config["UPLOAD_FOLDER"] = "src/pe_reports/uploads/" | ||
app.config["ALLOWED_EXTENSIONS"] = {"txt", "csv"} | ||
|
||
CENTRAL_LOGGING_FILE = "pe_reports_logging.log" | ||
DEBUG = False | ||
# Setup Logging | ||
"""Set up logging and call the run_pe_script function.""" | ||
if DEBUG is True: | ||
level = "DEBUG" | ||
else: | ||
level = "INFO" | ||
|
||
# Logging will rotate at 2GB | ||
logging.basicConfig( | ||
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s", | ||
datefmt="%m/%d/%Y %I:%M:%S", | ||
level=level, | ||
handlers=[ | ||
RotatingFileHandler(CENTRAL_LOGGING_FILE, maxBytes=2000000, backupCount=10) | ||
], | ||
) | ||
|
||
app.config["LOGGER"] = logging.getLogger(__name__) | ||
|
||
# with open('username.txt', 'w') as file: | ||
# file.write(pwd.getpwuid(os.getuid())[0]) | ||
|
||
# Creates a Celery object | ||
# celery = Celery(app.name, broker=app.config["CELERY_BROKER_URL"]) | ||
# celery.conf.update(app.config) | ||
|
||
# Config DB | ||
db = SQLAlchemy(app) | ||
Migrate(app, db) | ||
|
||
# TODO: Add a login page in the future. Issue #207 contains details | ||
# login_manager.init_app(app) | ||
# login_manager.login_view = "login" | ||
|
||
__all__ = ["app", "pages", "report_generator", "stylesheet"] | ||
|
||
|
||
# Register the flask apps | ||
# app.register_blueprint(stakeholder_blueprint) | ||
# app.register_blueprint(stakeholder_full_blueprint) | ||
# app.register_blueprint(stakeholder_bulk_upload_blueprint) | ||
# app.register_blueprint(report_gen_blueprint) | ||
# TODO: Add login blueprint. Issue #207 contains details | ||
# app.register_blueprint(manage_login_blueprint) | ||
# app.register_blueprint(home_blueprint) | ||
|
||
|
||
@app.errorhandler(404) | ||
def page_not_found(e): | ||
return render_template("404.html") | ||
|
||
|
||
if __name__ == "__main__": | ||
logging.info("The program has started...") | ||
app.run(host="127.0.0.1", debug=DEBUG, port=8000) | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
src/pe_reports/pe_reports_django_project/config/nginx_config_conf.d/nginx.conf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
server { | ||
listen 8091; | ||
server_name localhost; | ||
|
||
location / { | ||
proxy_pass http://web:8000; # Assuming 'web' is the service name and '8000' is the port where Gunicorn runs | ||
proxy_set_header Host $host; | ||
proxy_set_header X-Real-IP $remote_addr; | ||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | ||
proxy_set_header X-Forwarded-Proto $scheme; | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
src/pe_reports/pe_reports_django_project/config/rabbitmq.conf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
loopback_users.guest = false | ||
listeners.tcp.default = 5672 | ||
default_pass = guest1 | ||
default_user = admin |
2 changes: 2 additions & 0 deletions
2
...pe_reports/pe_reports_django_project/data/rabbitmq/data/rabbit@atc_rabbitmq-feature_flags
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[implicit_default_bindings,maintenance_mode_status,quorum_queue,user_limits, | ||
virtual_host_metadata]. |
1 change: 1 addition & 0 deletions
1
src/pe_reports/pe_reports_django_project/data/rabbitmq/data/rabbit@atc_rabbitmq.pid
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
465 |
1 change: 1 addition & 0 deletions
1
...rts/pe_reports_django_project/data/rabbitmq/data/rabbit@atc_rabbitmq/cluster_nodes.config
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{[rabbit@atc_rabbitmq],[rabbit@atc_rabbitmq]}. |
1 change: 1 addition & 0 deletions
1
...data/rabbitmq/data/rabbit@atc_rabbitmq/msg_stores/vhosts/628WB79CIFDYO9LJI6DKMI09L/.vhost
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/ |
Empty file.
Empty file.
Binary file added
BIN
+5.34 KB
...bbitmq/data/rabbit@atc_rabbitmq/msg_stores/vhosts/628WB79CIFDYO9LJI6DKMI09L/recovery.dets
Binary file not shown.
1 change: 1 addition & 0 deletions
1
...e_reports_django_project/data/rabbitmq/data/rabbit@atc_rabbitmq/nodes_running_at_shutdown
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
[rabbit@atc_rabbitmq]. |
Binary file added
BIN
+5.34 KB
...jango_project/data/rabbitmq/data/rabbit@atc_rabbitmq/quorum/rabbit@atc_rabbitmq/meta.dets
Binary file not shown.
Binary file added
BIN
+5.34 KB
...ango_project/data/rabbitmq/data/rabbit@atc_rabbitmq/quorum/rabbit@atc_rabbitmq/names.dets
Binary file not shown.
Binary file added
BIN
+1.3 KB
...reports_django_project/data/rabbitmq/data/rabbit@atc_rabbitmq/rabbit_durable_exchange.DCD
Binary file not shown.
Binary file added
BIN
+94 Bytes
...pe_reports_django_project/data/rabbitmq/data/rabbit@atc_rabbitmq/rabbit_durable_queue.DCD
Binary file not shown.
1 change: 1 addition & 0 deletions
1
...pe_reports_django_project/data/rabbitmq/data/rabbit@atc_rabbitmq/rabbit_durable_route.DCD
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
cXM |
Binary file added
BIN
+195 Bytes
...ports_django_project/data/rabbitmq/data/rabbit@atc_rabbitmq/rabbit_runtime_parameters.DCD
Binary file not shown.
1 change: 1 addition & 0 deletions
1
...pe_reports/pe_reports_django_project/data/rabbitmq/data/rabbit@atc_rabbitmq/rabbit_serial
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
26. |
1 change: 1 addition & 0 deletions
1
...reports_django_project/data/rabbitmq/data/rabbit@atc_rabbitmq/rabbit_topic_permission.DCD
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
cXM |
Binary file added
BIN
+232 Bytes
..._reports/pe_reports_django_project/data/rabbitmq/data/rabbit@atc_rabbitmq/rabbit_user.DCD
Binary file not shown.
Binary file added
BIN
+190 Bytes
..._reports_django_project/data/rabbitmq/data/rabbit@atc_rabbitmq/rabbit_user_permission.DCD
Binary file not shown.
Binary file added
BIN
+172 Bytes
...reports/pe_reports_django_project/data/rabbitmq/data/rabbit@atc_rabbitmq/rabbit_vhost.DCD
Binary file not shown.
Binary file added
BIN
+32.9 KB
src/pe_reports/pe_reports_django_project/data/rabbitmq/data/rabbit@atc_rabbitmq/schema.DAT
Binary file not shown.
1 change: 1 addition & 0 deletions
1
...e_reports/pe_reports_django_project/data/rabbitmq/data/rabbit@atc_rabbitmq/schema_version
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
[store_msg,persistent_bytes,multiple_routing_keys,exchange_options,queue_options,topic_permission,vhost_limits,user_password_hashing,cluster_name,policy_apply_to,topic_trie_node,mirrored_supervisor,gm,user_admin_to_tags,exchange_event_serial,semi_durable_route,topic_trie,add_opts_to_listener,remove_user_scope,move_messages_to_vhost_store]. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.