mirror of
https://github.com/cookiecutter/cookiecutter-django.git
synced 2025-09-10 05:52:34 +03:00
Use minimal Docker image to run uv resolution
This commit is contained in:
parent
4397073541
commit
ab20e20e60
|
@ -1,6 +1,5 @@
|
||||||
# ruff: noqa: PLR0133
|
# ruff: noqa: PLR0133
|
||||||
import json
|
import json
|
||||||
import os
|
|
||||||
import random
|
import random
|
||||||
import shutil
|
import shutil
|
||||||
import string
|
import string
|
||||||
|
@ -515,15 +514,29 @@ def setup_dependencies():
|
||||||
print("Installing python dependencies using uv...")
|
print("Installing python dependencies using uv...")
|
||||||
|
|
||||||
if "{{ cookiecutter.use_docker }}".lower() == "y":
|
if "{{ cookiecutter.use_docker }}".lower() == "y":
|
||||||
# Build the Docker service using Docker Compose
|
# Build a trimmed down Docker image add dependencies with uv
|
||||||
|
uv_docker_image_path = Path("compose/local/uv/Dockerfile")
|
||||||
|
uv_image_tag = "cookiecutter-django-uv-runner:latest"
|
||||||
try:
|
try:
|
||||||
subprocess.run(["docker", "compose", "-f", "docker-compose.local.yml", "build", "django"], check=True) # noqa: S607
|
subprocess.run( # noqa: S603
|
||||||
|
[ # noqa: S607
|
||||||
|
"docker",
|
||||||
|
"build",
|
||||||
|
"-t",
|
||||||
|
uv_image_tag,
|
||||||
|
"-f",
|
||||||
|
str(uv_docker_image_path),
|
||||||
|
"-q",
|
||||||
|
".",
|
||||||
|
],
|
||||||
|
check=True,
|
||||||
|
)
|
||||||
except subprocess.CalledProcessError as e:
|
except subprocess.CalledProcessError as e:
|
||||||
print(f"Error building Docker service: {e}", file=sys.stderr)
|
print(f"Error building Docker image: {e}", file=sys.stderr)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
# Use Docker to run the uv command
|
# Use Docker to run the uv command
|
||||||
uv_cmd = ["docker", "compose", "-f", "docker-compose.local.yml", "run", "--rm", "django", "uv"]
|
uv_cmd = ["docker", "run", "--rm", "-v", ".:/app", uv_image_tag, "uv"]
|
||||||
else:
|
else:
|
||||||
# Use uv command directly
|
# Use uv command directly
|
||||||
uv_cmd = ["uv"]
|
uv_cmd = ["uv"]
|
||||||
|
@ -543,13 +556,18 @@ def setup_dependencies():
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
# Remove the requirements directory
|
# Remove the requirements directory
|
||||||
if os.path.exists("requirements"): # noqa: PTH110
|
requirements_dir = Path("requirements")
|
||||||
|
if requirements_dir.exists():
|
||||||
try:
|
try:
|
||||||
shutil.rmtree("requirements")
|
shutil.rmtree(requirements_dir)
|
||||||
except Exception as e: # noqa: BLE001
|
except Exception as e: # noqa: BLE001
|
||||||
print(f"Error removing 'requirements' folder: {e}", file=sys.stderr)
|
print(f"Error removing 'requirements' folder: {e}", file=sys.stderr)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
uv_image_parent_dir_path = Path("compose/local/uv")
|
||||||
|
if uv_image_parent_dir_path.exists():
|
||||||
|
shutil.rmtree(str(uv_image_parent_dir_path))
|
||||||
|
|
||||||
print("Setup complete!")
|
print("Setup complete!")
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
FROM ghcr.io/astral-sh/uv:python3.12-bookworm-slim AS python
|
||||||
|
|
||||||
|
ARG APP_HOME=/app
|
||||||
|
|
||||||
|
WORKDIR ${APP_HOME}
|
Loading…
Reference in New Issue
Block a user