Skip to content

Commit

Permalink
add Initialise Flask API c2siorg#1
Browse files Browse the repository at this point in the history
  • Loading branch information
AyeshGK committed Mar 25, 2023
1 parent bb96d9a commit 3fa61de
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.vscode
*/__pycache__
20 changes: 20 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
FROM python:3.8-bullseye

# Set the working directory to /app
WORKDIR /code

# Copy the requirements file and install the dependencies
COPY ./requirements.txt ./
RUN pip install --no-cache-dir -r requirements.txt

# Copy the source code into the container
COPY ./src ./src

# Expose port 80 to the outside world
EXPOSE 80

# Start the Flask application
# development mode
CMD ["gunicorn", "-b", "0.0.0.0:80", "--log-level", "debug", "--reload", "src.app:app"]
# production mode
# CMD ["gunicorn", "-b", "0.0.0.0:80","src.app:app"]
10 changes: 10 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
services:
app:
build: .
container_name: B0Bot-App
command: gunicorn -b 0.0.0.0:80 --log-level debug --reload "src.app:app" # developement
# command: gunicorn -b 0.0.0.0:80 --reload "src.app:app" # production
ports:
- 80:80
volumes:
- .:/code
3 changes: 3 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Flask==2.2.3
Werkzeug==2.2.3
gunicorn==20.1.0
11 changes: 11 additions & 0 deletions src/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from flask import Flask

def create_app():
app = Flask(__name__)

# set configuration variables here, e.g.


# register blueprints and other components here, e.g.

return app
26 changes: 26 additions & 0 deletions src/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from flask import Flask, jsonify
from src import create_app

app = create_app()

@app.route('/')
def home():
# send json response
return jsonify( {
'org': 'BugZero',
'project': 'B0Bot'
})

@app.route('/search/<query>')
def search(query):
# Code to search Twitter API for latest news on query
news = "here is the news on " + query
return jsonify( {
'news': news
})


if __name__ == '__main__':
app.run(debug=True)
else:
gunicorn_app = app

0 comments on commit 3fa61de

Please sign in to comment.