Skip to content

Commit

Permalink
feat: Use flask run instead of python main.py.
Browse files Browse the repository at this point in the history
  • Loading branch information
BURG3R5 committed Jan 6, 2023
1 parent decea76 commit 410efe4
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 36 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ RUN pip3 install -r requirements.txt

COPY . .

CMD ["python3", "main.py"]
CMD ["flask", "run"]
52 changes: 24 additions & 28 deletions main.py → app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)))
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ services:
context: .
container_name: selene
ports:
- "${HOST_PORT}:${CONTAINER_PORT}"
- "${HOST_PORT}:5000"
volumes:
- type: volume
source: selene
Expand Down
4 changes: 1 addition & 3 deletions samples/.env
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 1 addition & 3 deletions samples/.env.dev
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 410efe4

Please sign in to comment.