Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
eb2f99c
convert into web_api_poc python package
jdhoffa May 27, 2025
dc47052
add dvdrental PostGres database
jdhoffa May 27, 2025
a1631ba
mv source into api service
jdhoffa May 27, 2025
fb77e48
move FastApi into api dir
jdhoffa May 27, 2025
105030b
wire up docker-compose with .env
jdhoffa May 27, 2025
e07ac70
wire up unit tests
jdhoffa May 27, 2025
1593745
remove search endpoint
jdhoffa May 27, 2025
9b77d7c
remove category endpoint
jdhoffa May 27, 2025
ac4b58b
add integration testing
jdhoffa May 27, 2025
25a6c51
wire up GH actions
jdhoffa May 27, 2025
7a354a1
rename actions
jdhoffa May 27, 2025
ee15879
gains README.md
jdhoffa May 27, 2025
460c24c
update API readme
jdhoffa May 27, 2025
f1dbd5f
update links to GH actions in main README
jdhoffa May 27, 2025
86964c6
ruff fix
jdhoffa May 27, 2025
e3d05c2
update integration test filename
jdhoffa May 27, 2025
5911217
add pbtar API
jdhoffa May 28, 2025
d16503b
add pbtar database
jdhoffa May 28, 2025
a640b6b
add pbtar integration tests
jdhoffa May 28, 2025
d426793
add pbtar GH actions
jdhoffa May 28, 2025
447de4a
add pbtar .gitignore
jdhoffa May 28, 2025
539acb7
add pbtar README
jdhoffa May 28, 2025
bddd4b7
rename docker compose
jdhoffa May 28, 2025
1f5e165
add example env
jdhoffa May 28, 2025
fc043ea
pbtar -> poc
jdhoffa May 28, 2025
8a33f9b
update README
jdhoffa May 28, 2025
21f0a0a
update name of API package
jdhoffa May 28, 2025
aa0d9a7
remove frontend service
jdhoffa May 28, 2025
74aa0a8
align package name
jdhoffa May 28, 2025
5626131
update status badge links and package name
jdhoffa May 28, 2025
f8e65d1
re-add dockerignore
jdhoffa May 28, 2025
47da6e8
re-add LICENSE
jdhoffa May 28, 2025
1c8b6bd
add README blurb
jdhoffa May 28, 2025
8f080ca
update api/README
jdhoffa May 28, 2025
78945a7
update api/README
jdhoffa May 28, 2025
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
97 changes: 97 additions & 0 deletions .github/workflows/api-docker-build-and-push.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
name: "Docker build and push API service to ghcr.io"

on:
schedule: # Scheduled workflows only run on the default branch
- cron: '0 3 * * *' # Nightly at 3 AM UTC
push:
branches:
- main
pull_request:
branches:
- main
workflow_dispatch:

env:
SERVICE: api
REGISTRY: ghcr.io
REPO: ${{ github.repository }}
REPO_OWNER: ${{ github.repository_owner }}
EVENT: ${{ github.event_name }}

jobs:
build-and-push:
name: "Docker build and push API service to ghcr.io"
runs-on: ubuntu-latest

permissions:
contents: read
packages: write # Needed to push to GHCR

steps:
- name: Set ENV vars
run: |
# remove owner from repo URI, e.g. "owner/repo_name", to get repo name
echo "REPO_NAME=${REPO#$REPO_OWNER/}" >> "$GITHUB_ENV"

# determine tag based on type of GH event
if [[ "$EVENT" == "schedule" ]]; then
echo "TAG=nightly" >> "$GITHUB_ENV"
elif [[ "$EVENT" == "push" ]]; then
echo "TAG=latest" >> "$GITHUB_ENV"
elif [[ "$EVENT" == "pull_request" ]]; then
echo "TAG=pr-${{ github.event.pull_request.number }}" >> "$GITHUB_ENV"
else
echo "TAG=unknown" >> "$GITHUB_ENV"
fi

- name: Checkout repository
uses: actions/checkout@v4

- name: Build and start container (as backing service)
run: |
docker compose up --build --detach $SERVICE

- name: Wait for container to be ready
run: |
RETRIES=10
for i in `seq 1 $RETRIES`; do
echo "Checking health... attempt $i"
status=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:8000/health || true)
if [ "$status" == "200" ]; then
echo "✅ Health check passed!"
exit 0
fi
sleep 5
done
echo "❌ Health check failed after $RETRIES retries."
docker compose logs
exit 1

- name: Log in to GHCR
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Tag and push image
run: |
# make sure all values are lowercase for repository image name
registry="$(echo $REGISTRY | tr '[:upper:]' '[:lower:]')"
repo_owner="$(echo $REPO_OWNER | tr '[:upper:]' '[:lower:]')"
repo_name="$(echo $REPO_NAME | tr '[:upper:]' '[:lower:]')"
service="$(echo $SERVICE | tr '[:upper:]' '[:lower:]')"
tag="$(echo $TAG | tr '[:upper:]' '[:lower:]')"

image_name="$repo_name-$service"
source_image="$image_name:latest"
target_image="$registry/$repo_owner/$image_name:$tag"

echo "source_image: $source_image"
echo "target_image: $target_image"

docker tag $source_image $target_image
docker push $target_image

- name: Clean up
run: docker compose down
18 changes: 9 additions & 9 deletions .github/workflows/lint.yml → .github/workflows/api-lint.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Lint
name: Lint API service

on:
push:
Expand All @@ -7,26 +7,26 @@ on:
pull_request:
branches:
- main

workflow_dispatch:
jobs:
black:
name: Run black code formatter
ruff:
name: Run ruff code formatter
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Install uv
uses: astral-sh/setup-uv@v5
uses: astral-sh/setup-uv@v6

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version-file: ".python-version"
python-version-file: "api/.python-version"

- name: Install the project
run: uv sync --only-dev
run: uv sync --only-dev --directory api

- name: Run Black Check
run: uv run black --check .
- name: Run Ruff Check
run: uvx --directory api ruff check .

16 changes: 9 additions & 7 deletions .github/workflows/test.yml → .github/workflows/api-test.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Test
name: Test API service

on:
push:
Expand All @@ -7,6 +7,7 @@ on:
pull_request:
branches:
- main
workflow_dispatch:

jobs:
test:
Expand All @@ -17,23 +18,24 @@ jobs:
- uses: actions/checkout@v4

- name: Install uv
uses: astral-sh/setup-uv@v5
uses: astral-sh/setup-uv@v6

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version-file: ".python-version"
python-version-file: "api/.python-version"

- name: Install the project
run: uv sync --all-extras --dev
run: uv sync --all-extras --dev --directory api

- name: "Run tests"
run: |
set -o pipefail
uv run pytest --junitxml=pytest.xml --cov-report=term-missing:skip-covered --cov=src tests/ | tee pytest-coverage.txt
uv run --directory api pytest --junitxml=pytest.xml --cov-report=term-missing:skip-covered --cov=src tests/ | tee pytest-coverage.txt

- name: "Pytest coverage comment"
uses: MishaKav/pytest-coverage-comment@main
if: github.actor != 'dependabot[bot]'
with:
pytest-coverage-path: ./pytest-coverage.txt
junitxml-path: ./pytest.xml
junitxml-path: ./api/pytest.xml
93 changes: 93 additions & 0 deletions .github/workflows/db-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
name: Test DB service

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

jobs:
test-database:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Start PostgreSQL database
run: |
docker compose up -d db
# Wait for the database to be ready (using the healthcheck)
attempt=1
max_attempts=30
until docker compose ps | grep "db" | grep -q "healthy" || [ $attempt -eq $max_attempts ]
do
echo "Waiting for database to be ready... (attempt $attempt/$max_attempts)"
sleep 2
attempt=$((attempt+1))
done

if [ $attempt -eq $max_attempts ]; then
echo "Database failed to become ready in time"
docker compose logs db
exit 1
fi

echo "Database is ready!"
docker compose ps

- name: Run database initialization check
run: |
# Check if the database initialized correctly
docker exec $(docker compose ps -q db) psql -U postgres -d poc -c "SELECT version(), current_database();"

# List schemas and tables to verify initialization
docker exec $(docker compose ps -q db) psql -U postgres -d poc -c "SELECT schema_name FROM information_schema.schemata WHERE schema_name = 'poc';"
docker exec $(docker compose ps -q db) psql -U postgres -d poc -c "SELECT table_name FROM information_schema.tables WHERE table_schema = 'poc';"

- name: Run test_scenario.sql
run: |
# Use -v ON_ERROR_STOP=1 to make psql exit with non-zero status on error
cat database/test/test_scenario.sql | docker exec -i $(docker compose ps -q db) psql -U postgres -d poc -v ON_ERROR_STOP=1
if [ $? -ne 0 ]; then
echo "❌ test_scenario.sql failed"
exit 1
fi
echo "✅ test_scenario.sql executed successfully"

- name: Run read.sql
run: |
cat database/test/read.sql | docker exec -i $(docker compose ps -q db) psql -U postgres -d poc -v ON_ERROR_STOP=1
if [ $? -ne 0 ]; then
echo "❌ read.sql failed"
exit 1
fi
echo "✅ read.sql executed successfully"

- name: Run update.sql
run: |
cat database/test/update.sql | docker exec -i $(docker compose ps -q db) psql -U postgres -d poc -v ON_ERROR_STOP=1
if [ $? -ne 0 ]; then
echo "❌ update.sql failed"
exit 1
fi
echo "✅ update.sql executed successfully"

- name: Run delete.sql
run: |
cat database/test/delete.sql | docker exec -i $(docker compose ps -q db) psql -U postgres -d poc -v ON_ERROR_STOP=1
if [ $? -ne 0 ]; then
echo "❌ delete.sql failed"
exit 1
fi
echo "✅ delete.sql executed successfully"

- name: Database logs on failure
if: failure()
run: docker compose logs db

- name: Clean up
if: always()
run: docker compose down -v
98 changes: 0 additions & 98 deletions .github/workflows/docker-build-and-push.yml

This file was deleted.

Loading