mirror of
https://github.com/furyhawk/api_gateway.git
synced 2026-07-20 09:47:59 +00:00
Add Docker and Makefile for containerized workflow
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
.git
|
||||
.github
|
||||
.venv
|
||||
__pycache__
|
||||
*.pyc
|
||||
.pytest_cache
|
||||
.ruff_cache
|
||||
.mypy_cache
|
||||
.coverage
|
||||
.env
|
||||
.env.*
|
||||
config/api_keys.json
|
||||
tests
|
||||
htmlcov
|
||||
build
|
||||
dist
|
||||
*.egg-info
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
FROM python:3.13-slim
|
||||
|
||||
ENV PYTHONDONTWRITEBYTECODE=1 \
|
||||
PYTHONUNBUFFERED=1
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
RUN pip install --no-cache-dir uv
|
||||
|
||||
COPY pyproject.toml uv.lock README.md ./
|
||||
RUN uv sync --frozen --no-dev
|
||||
|
||||
COPY src ./src
|
||||
COPY config ./config
|
||||
COPY openapi_json ./openapi_json
|
||||
|
||||
EXPOSE 8000
|
||||
|
||||
CMD ["uv", "run", "uvicorn", "gateway_framework.main:app", "--host", "0.0.0.0", "--port", "8000", "--app-dir", "src"]
|
||||
@@ -0,0 +1,57 @@
|
||||
SHELL := /bin/sh
|
||||
|
||||
CONTAINER_ENGINE ?= $(shell command -v podman >/dev/null 2>&1 && echo podman || echo docker)
|
||||
IMAGE_NAME ?= openapi-api-gateway
|
||||
IMAGE_TAG ?= latest
|
||||
CONTAINER_NAME ?= openapi-api-gateway
|
||||
PORT ?= 8000
|
||||
ENV_FILE ?= .env
|
||||
|
||||
RUN_ENV := $(if $(wildcard $(ENV_FILE)),--env-file $(ENV_FILE),)
|
||||
|
||||
.PHONY: help build run stop logs shell test test-container fmt clean
|
||||
|
||||
help:
|
||||
@echo "Targets:"
|
||||
@echo " make build Build container image"
|
||||
@echo " make run Run gateway container"
|
||||
@echo " make stop Stop and remove container"
|
||||
@echo " make logs Follow container logs"
|
||||
@echo " make shell Open shell in running container"
|
||||
@echo " make test Run local pytest suite with uv"
|
||||
@echo " make test-container Run tests in container image"
|
||||
@echo " make fmt Run ruff format checks"
|
||||
@echo " make clean Remove image and stopped container"
|
||||
|
||||
build:
|
||||
$(CONTAINER_ENGINE) build -t $(IMAGE_NAME):$(IMAGE_TAG) -f Dockerfile .
|
||||
|
||||
run:
|
||||
$(MAKE) stop >/dev/null 2>&1 || true
|
||||
$(CONTAINER_ENGINE) run -d \
|
||||
--name $(CONTAINER_NAME) \
|
||||
-p $(PORT):8000 \
|
||||
$(RUN_ENV) \
|
||||
$(IMAGE_NAME):$(IMAGE_TAG)
|
||||
@echo "Gateway is running on http://127.0.0.1:$(PORT)"
|
||||
|
||||
stop:
|
||||
-$(CONTAINER_ENGINE) rm -f $(CONTAINER_NAME)
|
||||
|
||||
logs:
|
||||
$(CONTAINER_ENGINE) logs -f $(CONTAINER_NAME)
|
||||
|
||||
shell:
|
||||
$(CONTAINER_ENGINE) exec -it $(CONTAINER_NAME) sh
|
||||
|
||||
test:
|
||||
uv run pytest -q
|
||||
|
||||
test-container:
|
||||
$(CONTAINER_ENGINE) run --rm $(IMAGE_NAME):$(IMAGE_TAG) uv run pytest -q
|
||||
|
||||
fmt:
|
||||
uv run ruff check .
|
||||
|
||||
clean: stop
|
||||
-$(CONTAINER_ENGINE) rmi $(IMAGE_NAME):$(IMAGE_TAG)
|
||||
@@ -114,3 +114,41 @@ Optional admin auth:
|
||||
- Run lint: `uv run ruff check .`
|
||||
- Add dependency: `uv add <package>`
|
||||
- Add dev dependency: `uv add --dev <package>`
|
||||
|
||||
## Container (Docker or Podman) + Makefile
|
||||
The repository includes a containerized workflow via `Dockerfile` and `Makefile`.
|
||||
|
||||
### Prerequisites
|
||||
- Install either Docker or Podman.
|
||||
- By default, Makefile uses Podman when available; otherwise Docker.
|
||||
|
||||
### Build Image
|
||||
```bash
|
||||
make build
|
||||
```
|
||||
|
||||
### Run Container
|
||||
```bash
|
||||
make run
|
||||
```
|
||||
|
||||
Gateway will be available at `http://127.0.0.1:8000`.
|
||||
|
||||
### Stop and Inspect
|
||||
```bash
|
||||
make logs
|
||||
make stop
|
||||
```
|
||||
|
||||
### Useful Variables
|
||||
- `CONTAINER_ENGINE=docker` (or `podman`)
|
||||
- `PORT=8080`
|
||||
- `IMAGE_NAME=openapi-api-gateway`
|
||||
- `IMAGE_TAG=latest`
|
||||
- `ENV_FILE=.env`
|
||||
|
||||
Example:
|
||||
```bash
|
||||
make build CONTAINER_ENGINE=docker IMAGE_TAG=dev
|
||||
make run CONTAINER_ENGINE=docker PORT=8080 ENV_FILE=.env
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user