Skip to content
Open

Test #40

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
44 changes: 44 additions & 0 deletions .github/workflows/python-ci-docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# python-ci.yml
name: Test API on Push with Docker

on:
push:
branches: [master, main]
pull_request:
branches: [master, main]

jobs:
build-and-run-pytest:
runs-on: ubuntu-latest

steps:
# 1. Checkout to the branch that triggered the event
- uses: actions/checkout@v3

# 2. Install python 3.10
- name: Set up Python 3.10
uses: actions/setup-python@v2
with:
python-version: "3.10"

# 3. Install python packages using a requirements file
- name: Install dependencies
run: |
python -m pip install --upgrade pip cython wheel
pip install -r tests/requirements.txt

# 4. Build test image
- name: Build test Docker image
run: docker build -f tests/Dockerfile.test -t api-test .

# 5. Run test container
- name: Run testing Container
run: docker run -d -e PORT=8000 --name api-test-container -p 8080:8000 api-test

# 6. Run tests
- name: Run tests on API
run: make

# Last step: Stop and remove container
- name: Stop API Container
run: docker stop api-test-container && docker rm api-test-container
53 changes: 20 additions & 33 deletions .github/workflows/python-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,43 +3,30 @@ name: Test API on Push

on:
push:
branches: [ master, main ]
branches: [master, main]
pull_request:
branches: [ master, main ]
branches: [master, main]

jobs:
build-and-run-pytest:

runs-on: ubuntu-latest

steps:
# 1. Checkout to the branch that triggered the event
- uses: actions/checkout@v3

# 2. Install python 3.10
- name: Set up Python 3.10
uses: actions/setup-python@v2
with:
python-version: "3.10"

# 3. Install python packages using a requirements file
- name: Install dependencies
run: |
python -m pip install --upgrade pip cython wheel
pip install -r tests/requirements.txt

# 4. Build test image
- name: Build test Docker image
run: docker build -f tests/Dockerfile.test -t api-test .

# 5. Run test container
- name: Run testing Container
run: docker run -d -e PORT=8000 --name api-test-container -p 8080:8000 api-test

# 6. Run tests
- name: Run tests on API
run: make

# Last step: Stop and remove container
- name: Stop API Container
run: docker stop api-test-container && docker rm api-test-container
# 1. Checkout to the branch that triggered the event
- uses: actions/checkout@v3

# 2. Install python 3.10
- name: Set up Python 3.10
uses: actions/setup-python@v2
with:
python-version: "3.10"

# 3. Install python packages using a requirements file
- name: Install dependencies
run: |
python -m pip install --upgrade pip cython wheel
pip install -r tests/requirements.txt

# 4. Run tests
- name: Run tests on API
run: make
34 changes: 33 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,39 @@
PROJECT := hip-voyager-421200
IMAGE := test-app
REGION := europe-west1
DOCKER_REPO_NAME := my-docker-repo
TAG := 0.1

IMAGE_URI := $(REGION)-docker.pkg.dev/$(PROJECT)/$(DOCKER_REPO_NAME)/$(IMAGE):$(TAG)

default: pylint pytest

# -------------------------
# Python checks
# -------------------------

pylint:
find . -iname "*.py" -not -path "./tests/*" | xargs -n1 -I {} pylint --output-format=colorized {}; true
find . -iname "*.py" -not -path "./tests/*" | xargs -n1 pylint --output-format=colorized; true

pytest:
PYTHONDONTWRITEBYTECODE=1 pytest -v --color=yes

# -------------------------
# Docker
# -------------------------

build:
docker build --platform=linux/amd64 -t $(IMAGE_URI) .

push: build
docker push $(IMAGE_URI)

run:
docker run --rm -p 8080:8080 $(IMAGE_URI)

# -------------------------
# Debug helpers
# -------------------------

print-image:
@echo $(IMAGE_URI)
3 changes: 2 additions & 1 deletion api/fast.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
def root():
response = {
'greeting': 'Servus, griaß di!', # This is a typical Bavarian greeting ;)
'timestamp': datetime.now()
'timestamp': datetime.now(),
'greeting_german': "Servus, grüß Dich"
}

return response
17 changes: 0 additions & 17 deletions tests/test_api_root.py

This file was deleted.