👷 Add dockerize command
This commit is contained in:
parent
e9d0fb5b80
commit
e2f968bac4
6 changed files with 68 additions and 2 deletions
|
|
@ -1 +1 @@
|
|||
__VERSION__ = "0.2.6"
|
||||
__VERSION__ = "0.2.7"
|
||||
|
|
|
|||
|
|
@ -27,6 +27,12 @@ def startapp(app_name: str, root: str = "."):
|
|||
scaffolding.startapp(app_name, root)
|
||||
|
||||
|
||||
@app.command()
|
||||
def dockerize(root: str = "."):
|
||||
"""Create template Dockerfile and docker-compose.yml."""
|
||||
scaffolding.copy_static("docker", root)
|
||||
|
||||
|
||||
@app.command()
|
||||
def serve(root: str = ".", host="127.0.0.1", port=8000):
|
||||
"""
|
||||
|
|
@ -41,6 +47,7 @@ def serve(root: str = ".", host="127.0.0.1", port=8000):
|
|||
|
||||
@app.command()
|
||||
def shell(root: str = "."):
|
||||
"""An interactive shell with your loaded project runtime."""
|
||||
project_path = Path(root).resolve()
|
||||
project = runtime.Project(project_path)
|
||||
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@ from pathlib import Path
|
|||
|
||||
from jinja2 import Environment, FileSystemLoader
|
||||
|
||||
import shutil
|
||||
|
||||
# Base templates directory
|
||||
TEMPLATE_DIR = Path(__file__).parent / "templates"
|
||||
env = Environment(loader=FileSystemLoader(str(TEMPLATE_DIR)))
|
||||
|
|
@ -53,6 +55,26 @@ def render_template_dir(
|
|||
render_template_file(template_dir / template_rel_path, context, output_path)
|
||||
|
||||
|
||||
def copy_static(dir_name: str, target_dir: Path):
|
||||
"""Statically copy all files from {TEMPLATE_DIR}/{dir_name} to target_dir."""
|
||||
template_dir = TEMPLATE_DIR / dir_name
|
||||
target_dir = Path(target_dir)
|
||||
if not template_dir.exists():
|
||||
print(f"no templates found under: {dir_name}")
|
||||
return
|
||||
|
||||
for root, _, files in template_dir.walk():
|
||||
root_path = Path(root)
|
||||
for file in files:
|
||||
src = root_path / file
|
||||
dst = target_dir / file
|
||||
if dst.exists():
|
||||
print(f"⛔ File exists, skipping: {dst}")
|
||||
continue
|
||||
shutil.copy(src, ".")
|
||||
print(f"✅ Templates created successfully.")
|
||||
print(f"🔧 Next, run `docker compose up -d --build`")
|
||||
|
||||
def startproject(name: str):
|
||||
"""Create a new project: flat structure, all project templates go into <name>/"""
|
||||
target_dir = Path(name).resolve()
|
||||
|
|
|
|||
30
src/ohmyapi/core/templates/docker/Dockerfile
Normal file
30
src/ohmyapi/core/templates/docker/Dockerfile
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
FROM python:3.13-alpine
|
||||
|
||||
ENV PYTHONDONTWRITEBYTECODE=1 \
|
||||
PYTHONUNBUFFERED=1 \
|
||||
POETRY_HOME="/opt/poetry" \
|
||||
POETRY_VIRTUALENVS_IN_PROJECT=true \
|
||||
POETRY_NO_INTERACTION=1
|
||||
|
||||
RUN apk add --no-cache \
|
||||
build-base \
|
||||
curl \
|
||||
git \
|
||||
bash \
|
||||
libffi-dev \
|
||||
openssl-dev \
|
||||
python3-dev \
|
||||
musl-dev
|
||||
|
||||
RUN curl -sSL https://install.python-poetry.org | python3 -
|
||||
ENV PATH="$POETRY_HOME/bin:$PATH"
|
||||
|
||||
WORKDIR /app
|
||||
COPY pyproject.toml poetry.lock* /app/
|
||||
RUN poetry lock
|
||||
RUN poetry install
|
||||
COPY . /app
|
||||
|
||||
EXPOSE 8000
|
||||
|
||||
CMD ["poetry", "run", "ohmyapi", "serve", "--host", "0.0.0.0"]
|
||||
7
src/ohmyapi/core/templates/docker/docker-compose.yml
Normal file
7
src/ohmyapi/core/templates/docker/docker-compose.yml
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
services:
|
||||
app:
|
||||
build:
|
||||
context: .
|
||||
restart: unless-stopped
|
||||
ports:
|
||||
- 8000:8000
|
||||
|
|
@ -10,7 +10,7 @@ readme = "README.md"
|
|||
license = { text = "MIT" }
|
||||
|
||||
dependencies = [
|
||||
"ohmyapi (>=0.1.0,<0.2.0)"
|
||||
"ohmyapi"
|
||||
]
|
||||
|
||||
[tool.poetry.group.dev.dependencies]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue