Compare commits

...

3 Commits

4 changed files with 55 additions and 5 deletions

31
Dockerfile Normal file
View File

@ -0,0 +1,31 @@
FROM python:3.11-slim AS os-cache
ENV TZ=UTC
ENV PYTHONUNBUFFERED=1
ENV POETRY_NO_INTERACTION=1
ENV POETRY_VIRTUALENVS_CREATE=true
ENV POETRY_VIRTUALENVS_IN_PROJECT=true
ARG DEBIAN_FRONTEND=noninteractive
RUN apt update -y
RUN apt upgrade -y
RUN apt install -y build-essential
WORKDIR /app
# FIXME: README.md seemed to be required here but I'm not sure why!
COPY poetry.lock pyproject.toml Makefile README.md ./
RUN pip install "poetry~=1.2"
FROM os-cache AS image
COPY poker ./poker
RUN make install-prod
FROM os-cache AS test-image
COPY setup.cfg ./
COPY poker ./poker
COPY tests ./tests
RUN make install

View File

@ -3,7 +3,7 @@ SHELL := /bin/bash
.PHONY: api .PHONY: api
api: ## Run API api: ## Run API
@poetry run uvicorn poker.api:app @poetry run uvicorn --host 0.0.0.0 poker.api:app
.PHONY: black .PHONY: black
black: ## Run black formatter black: ## Run black formatter
@ -13,6 +13,10 @@ black: ## Run black formatter
black-check: ## Run black formatter black-check: ## Run black formatter
@poetry run black poker tests --check; @poetry run black poker tests --check;
.PHONY: build
build: ## Build Docker container
@COMPOSE_DOCKER_CLI_BUILD=1 DOCKER_BUILDKIT=1 docker compose -f compose.yml build;
.PHONY: clean .PHONY: clean
clean: ## Remove python cache files clean: ## Remove python cache files
-@find . -name '*.pyc' -exec rm -f {} +; -@find . -name '*.pyc' -exec rm -f {} +;

View File

@ -1,6 +1,10 @@
# Single Poker Hand Ranking Service # Single Poker Hand Ranking Service
## Requirements
This service comprises an API to compute the rank of an individual poker hand. The requirements are to: This project started as a take-home interview task for an MLOps Engineer role. It is a very simple calculation I've wildly overengineered into a demonstration of how I go about building APIs.
## Project Scope
This service comprises an API to compute the rank of an individual poker hand. The scope of this project is to:
- Write an algorithm that takes a hand of cards and identifies the ranking of the given hand. - Write an algorithm that takes a hand of cards and identifies the ranking of the given hand.
- Expose an API to serve this algorithm via an endpoint `/rank`, that accepts a valid poker hand and returns its ranking. - Expose an API to serve this algorithm via an endpoint `/rank`, that accepts a valid poker hand and returns its ranking.
@ -90,14 +94,16 @@ Result: "straight flush: 10-high diamonds"
``` ```
## Requirements ## Requirements
- Python 3.11 - Python 3.11
- [Poetry](https://python-poetry.org/) - [Poetry](https://python-poetry.org/)
- [GNU Make](https://www.gnu.org/software/make/) - [GNU Make](https://www.gnu.org/software/make/)
## Usage ## Usage
- Install with `make install`. - Install with `make install`.
- Run linting and tests with `make quality test coverage clean`. - Run linting and tests with `make quality test coverage clean`.
- Run API with `make API`. - Build the API container with `make build`, then run API with `docker compose up -d`.
- Check API health with `curl localhost:8000` - Check API health with `curl localhost:8000`
- Query API for rank with e.g. - Query API for rank with e.g.
```shell ```shell

9
compose.yml Normal file
View File

@ -0,0 +1,9 @@
services:
api:
container_name: poker-api
build:
context: .
dockerfile: Dockerfile
ports:
- "8000:8000"
command: make api