Skip to content

Docker Template for the Project #267

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
FROM python:3.11-slim

# Install system dependencies, docker CLI, git, 'just', and 'uv'
RUN apt-get update && apt-get install -y --no-install-recommends \
curl unzip ca-certificates gnupg docker.io git \
&& curl --proto '=https' --tlsv1.2 -sSf https://just.systems/install.sh | bash -s -- --to /usr/local/bin \
&& curl -LsSf https://astral.sh/uv/install.sh | sh \
&& mv /root/.local/bin/uv /usr/local/bin/ \
&& mv /root/.local/bin/uvx /usr/local/bin/ \
&& apt-get clean && rm -rf /var/lib/apt/lists/*

WORKDIR /app

# Copy project files
COPY pyproject.toml ./
COPY README.md ./
COPY py_launch_blueprint/ ./py_launch_blueprint/
COPY .git/ ./.git/
COPY tests/ ./tests/
COPY Justfile ./

# Install build dependencies
RUN pip install --no-cache-dir --upgrade pip hatchling hatch-vcs

# Install the package using uv
RUN uv pip install --system --no-cache .

# Use correct entrypoint (CLI command name, not package name)
ENTRYPOINT ["py-launch"]
7 changes: 7 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
__pycache__/
.devcontainer/
.vscode/
*.pyc
*.pyo
*.pyd
*.pytest_cache/
15 changes: 15 additions & 0 deletions Justfile
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,21 @@ clean-pr-to-testrepo new_repo_name="test-actions-repo":
# Alias for dev (full developer cycle: format → lint → test → build)
alias cycle := dev

# Build Docker container
[group('build'), group('dev')]
@container-setup:
echo "🔨 Building Docker container..."
docker build -t py-launch-dev:latest -f .devcontainer/Dockerfile .
echo "✅ Built py-launch-dev:latest"

# Test Docker container functionality
[group('test')]
@container-test: container-setup
echo "🧪 Testing Docker container..."
docker run --rm py-launch-dev:latest --help
docker run --rm py-launch-dev:latest --version
echo "✅ Docker integration working!"

# Install Go
[group('setup'), group('install')]
@install-go:
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ Teams and professionals needing maintainable, type-safe Python projects followin

- **YAML validation with [yamllint](docs/source/tools/yaml_lint.md)**: Verify YAML files for syntax correctness, preventing configuration errors and deployment failures.

- **Docker & Dev Container support with [VS Code](docs/source/tools/docker.md)**: Reproduce identical environments across systems using Docker and Dev Containers. Simplify onboarding, eliminate setup issues, and enable Docker-in-Docker workflows for testing CLI tools in isolated, production-like environments.

### Project Structure & Management

- **Project configuration with `pyproject.toml`**: Organize all project settings in one standardized location, simplifying maintenance and configuration.
Expand Down
91 changes: 91 additions & 0 deletions docs/source/tools/docker.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
# Using Docker with `py-launch-blueprint`

This project includes Docker support for running and testing the CLI tool in a consistent, isolated environment. The containerized version includes all necessary dependencies and tools — including the CLI, `just`, `uv`, Docker CLI, and development tools.

## Purpose and Problem Solved
Docker support automates the setup of a consistent development and runtime environment for the py-launch CLI tool. It eliminates "works on my machine" issues and provides a reproducible environment with all dependencies pre-installed, helping maintain development consistency and simplifying deployment.

## Key Benefits and Value Proposition
- **Consistent environment** across all development machines and CI/CD
- **Pre-installed dependencies** including Python 3.11, uv, just, and Docker CLI
- **Isolated execution** preventing conflicts with local Python installations
- **Fast setup** with single command container builds
- **CI/CD ready** for automated testing and deployment

---

## Getting Started

### Prerequisites

- [Docker](https://www.docker.com/) installed and running

### Basic Setup Steps
1. Ensure Docker is installed and running on your system
2. Build the container using the provided justfile commands
3. The container includes all necessary tools and your CLI application pre-installed

### Quick Example
```bash
# Build the Docker container
just container-setup

# Test the CLI tool
just container-test
```

---

## Usage

### Common Use Cases
- **Development**: Test CLI changes in isolated environment
- **CI/CD**: Run automated tests and builds
- **Distribution**: Package and deploy the CLI tool
- **Troubleshooting**: Debug issues in clean environment

---

## Configuration

### Key Configuration Options
- **Base Image**: `python:3.11-slim` (lightweight and secure)
- **Working Directory**: `/app`
- **Build Backend**: Hatchling with hatch-vcs for version management
- **Package Manager**: uv for fast dependency installation

---

## Testing

### Standalone Testing
```bash
# Build and test the container
just container-setup
just container-test
```

---

## Troubleshooting

### Common Issues
1. **Build Failures**: Clean rebuild with `docker build --no-cache`
2. **Permission Issues**: Run as current user with `--user $(id -u):$(id -g)`
3. **Token Authentication**: Verify `PY_TOKEN` environment variable is set

### Debug Commands
```bash
# Access container shell for debugging
docker run --rm -it --entrypoint /bin/bash py-launch-dev:latest

# Check build logs
docker build --no-cache -t py-launch-dev:latest -f .devcontainer/Dockerfile . --progress=plain
```

---

## References

- [Docker Documentation](https://docs.docker.com/)
- [Python 3.11 Docker Images](https://hub.docker.com/_/python)
3 changes: 3 additions & 0 deletions docs/source/tools/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ Welcome to the Tools section of the Py Launch Blueprint documentation. This sect
- [Justfiles](justfiles.md)
- [precommit_hooks](precommit_hooks.md)
- [CLA Assistant](cla-assistant.md)
- [Docker](docker.md)


Each of these sections contains detailed instructions and best practices to help you effectively use the tools in your development workflow.

Expand All @@ -34,5 +36,6 @@ vs_code
makefiles
justfiles
cla-assistant
docker

```
4 changes: 2 additions & 2 deletions py_launch_blueprint/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@
__version_tuple__: VERSION_TUPLE
version_tuple: VERSION_TUPLE

__version__ = version = '0.1.dev338'
__version_tuple__ = version_tuple = (0, 1, 'dev338')
__version__ = version = "0.1.dev338"
__version_tuple__ = version_tuple = (0, 1, "dev338")
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ docs = [


[project.scripts]
py-launch = "py_launch_blueprint.projects:main" #This creates the Docker Template
py-projects = "py_launch_blueprint.projects:main"

[build-system]
Expand Down
Loading