-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
285 additions
and
229 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,23 @@ | ||
FROM python:3.8-slim | ||
FROM python:3.9-slim | ||
|
||
# Create working folder and install dependencies | ||
WORKDIR /app | ||
COPY requirements.txt . | ||
RUN pip install --no-cache-dir -r requirements.txt | ||
RUN pip install -U pip wheel && \ | ||
pip install --no-cache-dir -r requirements.txt | ||
|
||
# Copy the application contents | ||
COPY service/ ./service/ | ||
|
||
# Switch to a non-root user | ||
RUN useradd appuser && chown -R appuser /app | ||
USER appuser | ||
RUN useradd --uid 1000 vagrant && chown -R vagrant /app | ||
USER vagrant | ||
|
||
# Expose any ports the app is expecting in the environment | ||
ENV FLASK_APP=service:app | ||
ENV PORT 8080 | ||
EXPOSE $PORT | ||
|
||
ENV GUNICORN_BIND 0.0.0.0:$PORT | ||
CMD ["gunicorn", "--log-level=info", "service:app"] | ||
ENTRYPOINT ["gunicorn"] | ||
CMD ["--log-level=info", "service:app"] |
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
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 @@ | ||
PORT=8080 | ||
FLASK_APP=service:app |
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,20 +1,14 @@ | ||
# Lock down these dependencies | ||
Werkzeug==1.0.1 | ||
|
||
# Developmeent | ||
Flask==1.1.2 | ||
Flask-API==1.1 | ||
# Runtime dependencies | ||
Flask==2.0.2 | ||
redis==3.5.3 | ||
python-dotenv==0.15.0 | ||
|
||
# Runtime | ||
gunicorn==20.0.4 | ||
honcho==1.0.1 | ||
httpie==1.0.3 | ||
gunicorn==20.1.0 | ||
honcho==1.1.0 | ||
python-dotenv==0.19.2 | ||
|
||
# Testing | ||
# Testing dependencies | ||
nose==1.3.7 | ||
pinocchio==0.4.2 | ||
coverage==4.5.4 | ||
codecov==2.0.15 | ||
pylint>=2.4.1 | ||
pinocchio==0.4.3 | ||
coverage==6.1.2 | ||
codecov==2.1.12 | ||
httpie==2.6.0 | ||
pylint==2.11.1 |
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 @@ | ||
#!/bin/bash | ||
echo "Creating Kubernetes cluster with a registry..." | ||
k3d cluster create --registry-create cluster-registry:0.0.0.0:32000 --port '8080:80@loadbalancer' | ||
echo "Complete." |
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 @@ | ||
#!/bin/bash | ||
echo "Deleting Kubernetes cluster..." | ||
k3d cluster delete | ||
echo "Complete." |
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,60 @@ | ||
from flask import jsonify | ||
from . import app, status | ||
|
||
###################################################################### | ||
# Error Handlers | ||
###################################################################### | ||
|
||
@app.errorhandler(status.HTTP_404_NOT_FOUND) | ||
def not_found(error): | ||
""" Handles resources not found with 404_NOT_FOUND """ | ||
message = str(error) | ||
app.logger.warning(message) | ||
return ( | ||
jsonify(status=status.HTTP_404_NOT_FOUND, error="Not Found", message=message), | ||
status.HTTP_404_NOT_FOUND, | ||
) | ||
|
||
|
||
@app.errorhandler(status.HTTP_405_METHOD_NOT_ALLOWED) | ||
def method_not_supported(error): | ||
""" Handles unsupported HTTP methods with 405_METHOD_NOT_SUPPORTED """ | ||
message = str(error) | ||
app.logger.warning(message) | ||
return ( | ||
jsonify( | ||
status=status.HTTP_405_METHOD_NOT_ALLOWED, | ||
error="Method not Allowed", | ||
message=message, | ||
), | ||
status.HTTP_405_METHOD_NOT_ALLOWED, | ||
) | ||
|
||
|
||
@app.errorhandler(status.HTTP_500_INTERNAL_SERVER_ERROR) | ||
def internal_server_error(error): | ||
""" Handles unexpected server error with 500_SERVER_ERROR """ | ||
message = str(error) | ||
app.logger.error(message) | ||
return ( | ||
jsonify( | ||
status=status.HTTP_500_INTERNAL_SERVER_ERROR, | ||
error="Internal Server Error", | ||
message=message, | ||
), | ||
status.HTTP_500_INTERNAL_SERVER_ERROR, | ||
) | ||
|
||
@app.errorhandler(status.HTTP_503_SERVICE_UNAVAILABLE) | ||
def service_unavailable(error): | ||
""" Handles unexpected server error with 503_SERVICE_UNAVAILABLE """ | ||
message = str(error) | ||
app.logger.error(message) | ||
return ( | ||
jsonify( | ||
status=status.HTTP_503_SERVICE_UNAVAILABLE, | ||
error="Service is unavailable", | ||
message=message, | ||
), | ||
status.HTTP_503_SERVICE_UNAVAILABLE, | ||
) |
Oops, something went wrong.