Skip to content

Commit

Permalink
update deps + docker
Browse files Browse the repository at this point in the history
  • Loading branch information
Hackerjef committed Feb 16, 2024
1 parent 525a65f commit b49a85b
Show file tree
Hide file tree
Showing 21 changed files with 1,113 additions and 996 deletions.
36 changes: 0 additions & 36 deletions .docker/entry_point.sh

This file was deleted.

2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
static/modules
.env
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,5 @@ dmypy.json
.idea/dynamic.xml
.idea/uiDesigner.xml

static/modules
static/modules
docker-compose.override.yml
2 changes: 1 addition & 1 deletion .idea/logviewer2.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 14 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
FROM python:3.10-alpine3.15
ENV PYTHONUNBUFFERED 1
FROM python:3.12.2-bookworm
ENV PYTHONFAULTHANDLER=1 \
PYTHONUNBUFFERED=1 \
PYTHONHASHSEED=random \
PIP_NO_CACHE_DIR=off \
PIP_DISABLE_PIP_VERSION_CHECK=on \
PIP_DEFAULT_TIMEOUT=100 \
OAUTHLIB_INSECURE_TRANSPORT=1
ENV ENV docker
STOPSIGNAL SIGINT
RUN apk update && apk add --no-cache git bash yarn curl
RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - && echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list
RUN apt update && apt install -y git bash yarn curl gcc build-essential yarn
RUN curl -sSL install.python-poetry.org | POETRY_HOME=/opt/poetry python -
ENV PATH /opt/poetry/bin:$PATH
WORKDIR /logviewer2
ENTRYPOINT [ "/logviewer2/.docker/entry_point.sh" ]
CMD ["poetry", "run", "webd"]
COPY . .
RUN poetry config virtualenvs.create false && poetry install --no-interaction --no-ansi
RUN yarn install --frozen-lockfile
CMD ["poetry", "run", "web"]
7 changes: 2 additions & 5 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,8 @@ services:
stop_signal: SIGINT
restart: unless-stopped
build: .
env_file: ./.env
environment:
ENV: docker
volumes:
- './:/logviewer2'
- '/logviewer2/static/modules'
- '/version'
ports:
- "8001:8001"
- "${PORT}:${PORT}"
15 changes: 0 additions & 15 deletions example.env

This file was deleted.

14 changes: 14 additions & 0 deletions logviewer2/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import os

import sentry_sdk
from sentry_sdk.integrations.excepthook import ExcepthookIntegration
from sentry_sdk.integrations.flask import FlaskIntegration

from logviewer2.utils import GET_REV

sentry_sdk.init(
dsn=os.environ.get("SENTRY_DSN", None),
release=GET_REV(),
integrations=[FlaskIntegration(), ExcepthookIntegration(always_run=True)],
traces_sample_rate=1.0
)
7 changes: 3 additions & 4 deletions logviewer2/utils/db.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from dotenv import dotenv_values
import os

from pymongo import MongoClient

from logviewer2.utils import GET_INSTANCE
Expand All @@ -7,15 +8,13 @@

class DB:
def __init__(self):
self.envfile = dotenv_values(".env")
self.dbs = GET_MCONFIG(self.envfile)
self.dbs = GET_MCONFIG(os.environ)
self.dbs_conns = dict()

for (gid, connURI) in self.dbs.items():
gid, instance = GET_INSTANCE(gid)
if gid not in self.dbs_conns:
self.dbs_conns[gid] = dict()

self.dbs_conns[gid].update({instance: MongoClient(connURI).modmail_bot})

def get(self, gid, instance_id):
Expand Down
14 changes: 8 additions & 6 deletions logviewer2/web.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import logging
import os
import signal

from dotenv import dotenv_values
from flask import Flask, render_template, Response, g
from flask_discord import DiscordOAuth2Session

Expand All @@ -13,18 +13,21 @@
from logviewer2.utils.regexcfg import GET_DCONFIG
from logviewer2.views import Auth, Fproxy

config = dotenv_values(".env")
app = Flask(__name__, template_folder="../templates", static_folder="../static")
app.wsgi_app = ProxyFix(app.wsgi_app)
app.config.from_object(__name__)
app.config.update(
SECRET_KEY=GET_SECRET_KEY(config),
SECRET_KEY=GET_SECRET_KEY(os.environ),
MAX_CONTENT_LENGTH=(16 * 1024 * 1024),
FDIR=DOWNLOAD_FONTS(),
ISSHUTDOWN=False,
SHUTDOWNC=0
)

gunicorn_logger = logging.getLogger('gunicorn.error')
app.logger.handlers = gunicorn_logger.handlers
app.logger.setLevel(gunicorn_logger.level)


def keyboardInterruptHandler(s, frame):
if not app.config['ISSHUTDOWN']:
Expand All @@ -47,7 +50,7 @@ def keyboardInterruptHandler(s, frame):

app.db = DB()
# Auth :)
dconfig = GET_DCONFIG(config)
dconfig = GET_DCONFIG(os.environ)
DiscordOAuth2Session(app, client_id=dconfig["CLIENT_ID"], client_secret=dconfig["CLIENT_SECRET"],
redirect_uri=dconfig["CLIENT_REDIRECT_URI"])
app.register_blueprint(Auth)
Expand Down Expand Up @@ -101,8 +104,7 @@ def logviewer_render_evidence(qid, logkey):
return g.document.render_html(user=g.user)


# API killme
@app.route("/api/raw/<string:qid>/<logkey>")
@with_logs
def api_raw_render(qid, logkey):
return Response(g.document.render_plain_text(), mimetype="text/plain"), 200
return Response(g.document.render_plain_text(), mimetype="text/plain"), 200
43 changes: 18 additions & 25 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
from gevent import monkey
monkey.patch_all()

import sentry_sdk

from sentry_sdk.integrations.excepthook import ExcepthookIntegration
from sentry_sdk.integrations.flask import FlaskIntegration

from logviewer2.utils import GET_REV
from gevent import monkey # noqa
monkey.patch_all() # noqa
import psycogreen.gevent # noqa
psycogreen.gevent.patch_psycopg() # noqa

# Needs to be above to patch for gevent
from logging.config import dictConfig
from logviewer2.constants import Constants

Expand All @@ -16,8 +12,9 @@
os.environ['OAUTHLIB_INSECURE_TRANSPORT'] = '1'

import click
from dotenv import dotenv_values
import dotenv
from werkzeug.serving import run_simple
dotenv.load_dotenv()


@click.group()
Expand All @@ -31,29 +28,25 @@ def cli():


@cli.command()
@click.option('--debug/--no-debug', '-d', default=True)
def serve(debug):
config = dotenv_values(".env")
sentry_sdk.init(
dsn=config.get("SENTRY_DSN", None),
release=GET_REV(),
integrations=[FlaskIntegration(), ExcepthookIntegration(always_run=True)],
traces_sample_rate=1.0
)
def serve():
from logviewer2.web import app

if debug:
app.debug = True
return run_simple(config.get("HOST", "localhost"), int(config.get("PORT", "5214")), app, use_debugger=True, use_reloader=True, use_evalex=True, threaded=True)
else:
return run_simple(config.get("HOST", "localhost"), int(config.get("PORT", "5214")), app, threaded=True)
app.debug = True
return run_simple(os.environ.get("HOST", "localhost"), int(os.environ.get("PORT", "5214")), app, use_debugger=True,
use_reloader=True, use_evalex=True, threaded=True)
# options = {
# "bind": f"{os.environ.get('HOST', 'localhost')}:{os.environ.get('PORT', '5214')}",
# "workers": 1,
# "worker_class": "gunicorn.workers.ggevent.GeventPyWSGIWorker",
# }
# return StandaloneApplication(app, options).run()


@cli.command()
@click.option('--new/--no-new', '-n', default=False)
def secretkey(new):
from logviewer2.utils import GET_SECRET_KEY
key = GET_SECRET_KEY({} if new else dotenv_values(".env"))
key = GET_SECRET_KEY({} if new else os.environ)
if not new:
print(key.decode("utf-8"))
return key if not new else ""
Expand Down
Loading

0 comments on commit b49a85b

Please sign in to comment.