Skip to content

Commit 7df13f7

Browse files
authored
Merge pull request #1 from droq-ai/ahmed/feat/docker-registry-template
feat: add Docker publishing with environment variable conventions
2 parents 59ef34e + a144bb6 commit 7df13f7

File tree

7 files changed

+739
-91
lines changed

7 files changed

+739
-91
lines changed

.env.example

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,37 @@
1-
# Droq Node Template Environment Variables
2-
# Copy this file to .env and update with your values
1+
# Environment Variable Naming Convention:
2+
# NODE_ - Node configuration
3+
# NATS_ - NATS configuration
4+
# LOG_ - Logging configuration
5+
# DB_ - Database configuration
6+
# HTTP_ - HTTP client configuration
7+
# SERVICE_ - Service-specific configuration
8+
# METRICS_ - Metrics and monitoring
39

410
# Node Configuration
511
NODE_NAME=droq-node-template
12+
NODE_PORT=8000
13+
NODE_EXTERNAL_PORT=8000
14+
NODE_HEALTH_CHECK_ENABLED=true
15+
16+
# Logging
617
LOG_LEVEL=INFO
718

819
# NATS Configuration
920
NATS_URL=nats://localhost:4222
21+
NATS_CLIENT_NAME=${NODE_NAME:-droq-node-template}
1022
STREAM_NAME=droq-stream
1123

12-
# HTTP Client Configuration (optional)
13-
# BASE_URL=https://api.example.com
24+
# Optional: NATS Authentication
25+
# NATS_USERNAME=nats-user
26+
# NATS_PASSWORD=nats-pass
27+
28+
# Optional: HTTP Configuration
29+
# HTTP_BASE_URL=https://api.example.com
30+
# HTTP_API_KEY=your-api-key
31+
32+
# Optional: Database Configuration
33+
# DB_URL=postgresql://user:pass@localhost/dbname
1434

15-
# Add your custom environment variables below
16-
# API_KEY=your-api-key-here
17-
# DATABASE_URL=postgresql://user:pass@localhost/dbname
35+
# Optional: Metrics Configuration
36+
# METRICS_PORT=8081
37+
# METRICS_ENABLED=true

Dockerfile

Lines changed: 6 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,28 @@
1-
# Dockerfile template for Droq nodes
2-
# This is an agnostic template - customize as needed for your node
3-
41
FROM python:3.11-slim
52

6-
# Set working directory
73
WORKDIR /app
84

9-
# Install system dependencies
10-
# Uncomment and add system packages as needed:
11-
# RUN apt-get update && apt-get install -y \
12-
# gcc \
13-
# g++ \
14-
# make \
15-
# curl \
16-
# && rm -rf /var/lib/apt/lists/*
17-
18-
# Install uv
195
COPY --from=ghcr.io/astral-sh/uv:latest /uv /usr/local/bin/uv
206

21-
# Copy dependency files
227
COPY pyproject.toml uv.lock* ./
238

24-
# Install dependencies using uv
25-
# Install dependencies directly (not as editable package)
269
RUN uv pip install --system nats-py aiohttp || \
2710
(uv pip compile pyproject.toml -o requirements.txt && \
2811
uv pip install --system -r requirements.txt)
2912

30-
# Copy source code
3113
COPY src/ ./src/
3214

33-
# Create non-root user for security
3415
RUN useradd -m -u 1000 nodeuser && chown -R nodeuser:nodeuser /app
3516
USER nodeuser
3617

37-
# Set environment variables
3818
ENV PYTHONPATH=/app
3919
ENV PYTHONUNBUFFERED=1
20+
ENV NODE_PORT=8000
21+
22+
EXPOSE ${NODE_PORT}
4023

41-
# Optional: Health check
42-
# Uncomment and customize as needed:
43-
# HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
44-
# CMD python -c "import sys; sys.exit(0)"
24+
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
25+
CMD python -c "import sys; sys.exit(0)" || exit 1
4526

46-
# Run the node
47-
# Update this command to match your entry point
48-
CMD ["uv", "run", "python", "-m", "node.main"]
27+
CMD ["sh", "-c", "exec uv run python -m node.main --port=${NODE_PORT:-8000}"]
4928

README.md

Lines changed: 34 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,36 @@
11
# Droq Node Template
22

3-
A Python template for building Droq nodes. Works with any Python code - minimal updates needed.
3+
A Python template for building Droqflow nodes.
44

55
## Quick Start
66

77
```bash
8-
# 1. Clone and setup
9-
git clone <repository-url>
10-
cd droq-node-template-py
8+
git clone git@github.com:droq-ai/dfx-base-node-template-py.git
9+
cd dfx-base-node-template-py
1110
uv sync
1211

13-
# 2. Replace src/node/main.py with your code
12+
# Replace src/node/main.py with your code
13+
# Add dependencies: uv add your-package
1414

15-
# 3. Add dependencies
16-
uv add your-package
15+
# Configure node.json with your node information
16+
# Configure environment variables
1717

18-
# 4. Test locally
18+
# Test locally
1919
PYTHONPATH=src uv run python -m node.main
20-
# or
21-
docker compose up
2220

23-
# 5. Build
24-
docker build -t your-node:latest .
21+
# Run with Docker
22+
docker compose up
2523
```
2624

27-
## Documentation
25+
## Next Steps
2826

29-
- [Usage Guide](docs/usage.md) - How to use the template
30-
- [NATS Examples](docs/nats.md) - NATS publishing and consuming examples
27+
1. Complete your node development
28+
2. Configure [node.json](docs/node-configuration.md) with your node metadata
29+
3. Register your node [TBD]
3130

32-
## Development
3331

34-
```bash
35-
# Run tests
36-
PYTHONPATH=src uv run pytest
3732

38-
# Format code
39-
uv run black src/ tests/
40-
uv run ruff check src/ tests/
4133

42-
# Add dependencies
43-
uv add package-name
44-
```
4534

4635
## Docker
4736

@@ -50,32 +39,34 @@ uv add package-name
5039
docker build -t your-node:latest .
5140

5241
# Run
53-
docker run --rm your-node:latest
54-
55-
# Development (with hot reload)
56-
docker compose up
42+
docker run -p 8000:8000 \
43+
-e NODE_NAME=my-node \
44+
-e NATS_URL=nats://localhost:4222 \
45+
your-node:latest
5746
```
5847

59-
## Environment Variables
60-
61-
Copy `.env.example` to `.env` and update with your values:
48+
## Development
6249

6350
```bash
64-
cp .env.example .env
51+
# Run tests
52+
PYTHONPATH=src uv run pytest
53+
54+
# Format code
55+
uv run black src/ tests/
56+
uv run ruff check src/ tests/
57+
58+
# Add dependencies
59+
uv add package-name
6560
```
6661

67-
Or set in `compose.yml` or pass to Docker:
68-
- `NATS_URL` - NATS server URL (default: `nats://localhost:4222`)
69-
- `STREAM_NAME` - JetStream name (default: `droq-stream`)
70-
- `NODE_NAME` - Node identifier
71-
- `LOG_LEVEL` - Logging level
7262

73-
## Next Steps
7463

75-
1. Test locally
76-
2. Build Docker image
77-
3. Register metadata in `droq-node-registry` (separate repo)
64+
## Documentation
65+
66+
- [Usage Guide](docs/usage.md)
67+
- [Configuration Guide](docs/node-configuration.md)
68+
- [NATS Examples](docs/nats.md)
7869

7970
## License
8071

81-
Apache License 2.0
72+
Apache License 2.0

compose.yml

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,33 +6,25 @@ services:
66
container_name: droq-node-template
77
environment:
88
- NODE_NAME=droq-node-template
9+
- NODE_PORT=8000
910
- LOG_LEVEL=INFO
1011
- NATS_URL=nats://nats:4222
12+
- NATS_CLIENT_NAME=${NODE_NAME:-droq-node-template}
1113
- STREAM_NAME=droq-stream
12-
# Add your environment variables here
13-
# - API_KEY=${API_KEY}
14-
# - DATABASE_URL=${DATABASE_URL}
15-
# - BASE_URL=https://api.example.com
1614
volumes:
17-
# Mount source code for development (hot reload)
1815
- ./src:/app/src:ro
19-
# Mount additional volumes as needed
20-
# - ./data:/app/data
2116
networks:
2217
- droq-network
2318
restart: unless-stopped
24-
# Uncomment to expose ports if your node needs them
25-
# ports:
26-
# - "8080:8080"
19+
ports:
20+
- "${NODE_EXTERNAL_PORT:-8000}:${NODE_PORT:-8000}"
2721

28-
# NATS server for local development and testing
2922
nats:
3023
image: nats:latest
3124
container_name: droq-nats
3225
ports:
33-
- "4222:4222" # Client connections
34-
- "8222:8222" # HTTP monitoring
35-
- "6222:6222" # Cluster routing
26+
- "4222:4222"
27+
- "8222:8222"
3628
command: ["-js", "-m", "8222"]
3729
networks:
3830
- droq-network

0 commit comments

Comments
 (0)