Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a github workflow #5

Merged
merged 4 commits into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions .github/workflows/python-app.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: Python application

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

permissions:
contents: write

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Set up Python 3.10
uses: actions/setup-python@v3
with:
python-version: "3.10"
- name: Install dependencies
run: |
sudo python -m pip install --upgrade pip
sudo pip install flake8
if [ -f requirements.txt ]; then sudo pip install -r requirements.txt; fi
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Start server
run: |
sudo python main.py &

- name: Wait for server to be up
run: |
for i in {1..30}; do
if curl -s http://localhost:8080 > /dev/null; then
echo "Server is up!"
break
fi
echo "Waiting for server to be up..."
sleep 2
done

- name: Send test request
run: |
OUT=$(cat example_image.json | curl -X POST http://localhost:8080/classify -H "Content-Type: application/json" -d @-)
echo $OUT
if echo $OUT | grep '"success": true'; then
echo "passed"
else
exit 1
fi

1 change: 1 addition & 0 deletions example_image.json

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
print("ResNet50 model loaded.")

hostName = os.getenv("HOSTNAME") or "localhost"
serverPort = int(os.getenv("PORT")) or 8080
serverPort = os.getenv("PORT") or 8080
serverPort = int(serverPort)
imagesPath = os.getenv("IMAGES_PATH") or ""

if(not imagesPath == "" and not os.path.exists("imagesPath")):
Expand Down Expand Up @@ -131,4 +132,4 @@ def error_json(server, code, msg):
pass

webServer.server_close()
print("Server stopped.")
print("Server stopped.")
3 changes: 3 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
load-dotenv==0.1.0
pillow==10.3.0
tensorflow==2.16.1
Loading