feat: Dockerize API
This commit is contained in:
parent
aaea9c8aa3
commit
6f3de3a885
|
@ -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;
|
||||
|
|
|
@ -97,7 +97,7 @@ Result: "straight flush: 10-high diamonds"
|
|||
## 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