Skip to content

Commit

Permalink
feat(py): update README and refactor Dockerfile and compose
Browse files Browse the repository at this point in the history
  • Loading branch information
pplmx committed Aug 17, 2024
1 parent a587fd2 commit 5c177cf
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 11 deletions.
5 changes: 3 additions & 2 deletions template/py/{{cookiecutter.project_slug}}/.dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
.*
CHANGELOG.md
CODE_OF_CONDUCT.md
CONTRIBUTING.md
compose.yml
CONTRIBUTING.md
Dockerfile
LICENSE*
Makefile
README.md
SECURITY.md
16 changes: 11 additions & 5 deletions template/py/{{cookiecutter.project_slug}}/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@ RUN uv venv venv && \
. venv/bin/activate && \
uv pip install .[dev]

# Separate stage for validation (build and test)
FROM builder AS validator

WORKDIR /app
COPY . .

# Run build and test as part of the validation
RUN hatch build && hatch test

# Final image for running the application
FROM python:{{cookiecutter.python_version}}-slim-bullseye

Expand All @@ -32,11 +41,8 @@ WORKDIR /app
# Copy the virtual environment and application code
COPY --from=builder /app/venv /app/venv
COPY --from=builder /root/.local /root/.local
COPY . .

# Ensure the application builds and tests are executed correctly
RUN hatch build && hatch test
COPY src ./src

HEALTHCHECK --start-period=30s CMD python -c "import requests; requests.get('http://localhost:8000', timeout=2)"

CMD ["python", "src/app.py"]
CMD ["python", "src/{{cookiecutter.package_name}}/app.py"]
2 changes: 2 additions & 0 deletions template/py/{{cookiecutter.project_slug}}/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ compose-down:
# Clean build artifacts
clean:
@rm -rf build dist *.egg-info htmlcov .coverage coverage.xml coverage.lcov
@docker compose -f ./compose.yml down -v
@docker image rm -f $(APP_NAME)

# Show help
help:
Expand Down
44 changes: 40 additions & 4 deletions template/py/{{cookiecutter.project_slug}}/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,50 @@ For more detailed usage instructions, please refer to our [Usage Guide](docs/usa
To set up the development environment:

1. Ensure `uv`, `ruff`, and `hatch` are installed.

- Using `pipx`
```bash
# you can use `pipx`
pipx install uv ruff hatch

# or
# Firstly, install `uv` (macOS and Linux)
curl -LsSf https://astral.sh/uv/install.sh | sh
# (Windows)
powershell -c "irm https://astral.sh/uv/install.ps1 | iex"

# Then
uv tool install ruff
uv tool install hatch
```
- Using `uv`
```bash
# macOS and Linux
curl -LsSf https://astral.sh/uv/install.sh | sh
# Windows
powershell -c "irm https://astral.sh/uv/install.ps1 | iex"
# Then
uv tool install ruff
uv tool install hatch
```
- BTW
> `pipx` and `uv tool install` will usually install the binaries in your `~/.local/bin` directory.
>
> Please ensure the `~/.local/bin` directory is in your `PATH` environment variable.

2. Clone the repository and navigate to the project directory.
3. Run the following commands:

```bash
make init # Create a virtual env using uv
make install-dev # Install development dependencies
make build # Build wheel package
make test # Run tests
make init # Create a virtual env using uv
make install-dev # Install development dependencies
make build # Build wheel package
make test # Run tests
make image # Build Docker image
make compose-up # Run Docker Compose
make compose-down # Stop and remove Docker Compose
make clean # Remove build artifacts
```

For more details, see our [Contributing Guide](CONTRIBUTING.md).
Expand Down
1 change: 1 addition & 0 deletions template/py/{{cookiecutter.project_slug}}/compose.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
services:
{{cookiecutter.project_slug}}:
build: .
image: {{cookiecutter.project_slug}}
ports:
- 8000:8000

Expand Down

0 comments on commit 5c177cf

Please sign in to comment.