Compare commits
3 Commits
4b71b84543
...
c240f085ef
Author | SHA1 | Date |
---|---|---|
Paul Harrison | c240f085ef | |
Paul Harrison | c114366357 | |
Paul Harrison | 484c636513 |
|
@ -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
|
8
Makefile
8
Makefile
|
@ -3,7 +3,7 @@ SHELL := /bin/bash
|
|||
|
||||
.PHONY: api
|
||||
api: ## Run API
|
||||
@poetry run uvicorn poker.api:app
|
||||
@poetry run uvicorn --host 0.0.0.0 poker.api:app
|
||||
|
||||
.PHONY: black
|
||||
black: ## Run black formatter
|
||||
|
@ -13,6 +13,10 @@ black: ## Run black formatter
|
|||
black-check: ## Run black formatter
|
||||
@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
|
||||
clean: ## Remove python cache files
|
||||
-@find . -name '*.pyc' -exec rm -f {} +;
|
||||
|
@ -79,4 +83,4 @@ uninstall: ## Remove virtual environment
|
|||
|
||||
.PHONY: update
|
||||
update: ## Update poetry.lock using pyproject.toml
|
||||
@poetry update;
|
||||
@poetry update;
|
||||
|
|
12
README.md
12
README.md
|
@ -1,6 +1,10 @@
|
|||
# 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.
|
||||
- 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
|
||||
|
||||
- Python 3.11
|
||||
- [Poetry](https://python-poetry.org/)
|
||||
- [GNU Make](https://www.gnu.org/software/make/)
|
||||
|
||||
## Usage
|
||||
|
||||
- Install with `make install`.
|
||||
- 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`
|
||||
- Query API for rank with e.g.
|
||||
```shell
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
services:
|
||||
api:
|
||||
container_name: poker-api
|
||||
build:
|
||||
context: .
|
||||
dockerfile: Dockerfile
|
||||
ports:
|
||||
- "8000:8000"
|
||||
command: make api
|
Loading…
Reference in New Issue