diff --git a/Dockerfile b/Dockerfile index 09dc315..3c961ba 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,4 +7,4 @@ RUN pip3 install -r requirements.txt COPY . . -CMD ["python3", "main.py"] +CMD ["flask", "run"] diff --git a/main.py b/app.py similarity index 77% rename from main.py rename to app.py index 7587ac1..38f3d28 100644 --- a/main.py +++ b/app.py @@ -28,6 +28,30 @@ from bot.slack.templates import error_message from bot.utils.log import Logger +load_dotenv(Path(".") / ".env") + +debug = os.environ["FLASK_DEBUG"] == "1" + +if (not debug) and ("SENTRY_DSN" in os.environ): + sentry_sdk.init( + dsn=os.environ["SENTRY_DSN"], + integrations=[FlaskIntegration()], + ) + +slack_bot = SlackBot( + token=os.environ["SLACK_OAUTH_TOKEN"], + logger=Logger(int(os.environ.get("LOG_LAST_N_COMMANDS", 100))), + base_url=os.environ["BASE_URL"], + secret=os.environ["SLACK_SIGNING_SECRET"], + bot_id=os.environ["SLACK_BOT_ID"], +) + +github_app = GitHubApp( + base_url=os.environ["BASE_URL"], + client_id=os.environ["GITHUB_APP_CLIENT_ID"], + client_secret=os.environ["GITHUB_APP_CLIENT_SECRET"], +) + app = Flask(__name__) app.add_url_rule("/", view_func=views.test_get) @@ -88,31 +112,3 @@ def complete_auth(): code=request.args.get("code"), state=request.args.get("state"), ) - - -if __name__ == "__main__": - load_dotenv(Path(".") / ".env") - - debug = os.environ["FLASK_DEBUG"] == "True" - - if (not debug) and ("SENTRY_DSN" in os.environ): - sentry_sdk.init( - dsn=os.environ["SENTRY_DSN"], - integrations=[FlaskIntegration()], - ) - - slack_bot = SlackBot( - token=os.environ["SLACK_OAUTH_TOKEN"], - logger=Logger(int(os.environ.get("LOG_LAST_N_COMMANDS", 100))), - base_url=os.environ["BASE_URL"], - secret=os.environ["SLACK_SIGNING_SECRET"], - bot_id=os.environ["SLACK_BOT_ID"], - ) - - github_app = GitHubApp( - base_url=os.environ["BASE_URL"], - client_id=os.environ["GITHUB_APP_CLIENT_ID"], - client_secret=os.environ["GITHUB_APP_CLIENT_SECRET"], - ) - - app.run(port=int(os.environ.get("CONTAINER_PORT", 5000))) diff --git a/docker-compose.yml b/docker-compose.yml index ce74163..087ab1f 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -6,7 +6,7 @@ services: context: . container_name: selene ports: - - "${HOST_PORT}:${CONTAINER_PORT}" + - "${HOST_PORT}:5000" volumes: - type: volume source: selene diff --git a/samples/.env b/samples/.env index a081770..dbb494b 100644 --- a/samples/.env +++ b/samples/.env @@ -1,7 +1,5 @@ BASE_URL=subdomain.domain.tld/path1/path2 -CONTAINER_PORT=5000 -FLASK_APP=main -FLASK_DEBUG=True +FLASK_DEBUG=1 GITHUB_APP_CLIENT_ID=0123456789abcdefghij GITHUB_APP_CLIENT_SECRET=e2fbe2fbe2fbe2fbe2fbe2e2fbe2fbe2e2fbe2fb GITHUB_WEBHOOK_SECRET=3dbd2c253813c65b296b7acf67470b7e7bc116e3 diff --git a/samples/.env.dev b/samples/.env.dev index 2993408..0c17089 100644 --- a/samples/.env.dev +++ b/samples/.env.dev @@ -1,8 +1,6 @@ SLACK_APP_ID=A0101010101 BASE_URL=blah-111-22-333-444.ngrok.io -CONTAINER_PORT=5000 -FLASK_APP=main -FLASK_DEBUG=True +FLASK_DEBUG=1 GITHUB_APP_CLIENT_ID=0123456789abcdefghij GITHUB_APP_CLIENT_SECRET=e2fbe2fbe2fbe2fbe2fbe2e2fbe2fbe2e2fbe2fb GITHUB_WEBHOOK_SECRET=3dbd2c253813c65b296b7acf67470b7e7bc116e3