File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ FROM python:3.10-slim
2+
3+ WORKDIR /app
4+
5+ # Install test tool (no runtime dependencies required for the app itself)
6+ RUN pip install --no-cache-dir pytest
7+
8+ # Copy application files
9+ COPY . /app
10+
11+ # Default to showing help when container runs without args
12+ CMD ["python" , "book_app.py" , "help" ]
Original file line number Diff line number Diff line change 1+ Deployment instructions for the sample book app
2+
3+ Build locally with Docker:
4+
5+ ``` bash
6+ cd samples/book-app-project
7+ docker build -t bookkeeper-app:local .
8+ ```
9+
10+ Run the container (interactive CLI):
11+
12+ ``` bash
13+ docker run --rm -it -v " $( pwd) /data.json:/app/data.json" bookkeeper-app:local python book_app.py list
14+ ```
15+
16+ Or use docker-compose for an interactive shell session:
17+
18+ ``` bash
19+ cd samples/book-app-project
20+ docker-compose run --rm bookkeeper-app list
21+ ```
22+
23+ Run tests inside the image:
24+
25+ ``` bash
26+ docker run --rm bookkeeper-app:local pytest -q
27+ ```
Original file line number Diff line number Diff line change 1+ version : " 3.8"
2+
3+ services :
4+ bookkeeper-app :
5+ build : .
6+ image : bookkeeper-app:local
7+ volumes :
8+ - ./data.json:/app/data.json
9+ stdin_open : true
10+ tty : true
11+ entrypoint : ["python", "book_app.py"]
Original file line number Diff line number Diff line change 1+ Kubernetes deployment for the Bookkeeper sample
2+
3+ This folder contains a ` ConfigMap ` with ` data.json ` and a ` Job ` manifest that runs the CLI command ` python book_app.py list ` .
4+
5+ Usage (build and push image to a registry first):
6+
7+ ``` bash
8+ # Build and tag
9+ cd samples/book-app-project
10+ docker build -t ghcr.io/< your-user> /bookkeeper-app:latest .
11+
12+ # Push (example: GitHub Container Registry)
13+ docker push ghcr.io/< your-user> /bookkeeper-app:latest
14+
15+ # Apply k8s resources
16+ kubectl apply -f k8s/configmap-data.yaml
17+ kubectl apply -f k8s/job-list.yaml
18+
19+ # Watch job
20+ kubectl get jobs
21+ kubectl logs job/bookkeeper-list-job
22+ ```
23+
24+ Notes:
25+ - The sample app is a CLI, not a long-running server. A ` Job ` is used to execute a one-time command.
26+ - If you use a local cluster (kind/minikube) you may need to load the local image into the cluster instead of pushing to a registry.
Original file line number Diff line number Diff line change 1+ apiVersion : v1
2+ kind : ConfigMap
3+ metadata :
4+ name : book-data
5+ data :
6+ data.json : |-
7+ [
8+ {
9+ "title": "The Hobbit",
10+ "author": "J.R.R. Tolkien",
11+ "year": 1937,
12+ "read": false
13+ },
14+ {
15+ "title": "1984",
16+ "author": "George Orwell",
17+ "year": 1949,
18+ "read": true
19+ },
20+ {
21+ "title": "Dune",
22+ "author": "Frank Herbert",
23+ "year": 1965,
24+ "read": false
25+ },
26+ {
27+ "title": "To Kill a Mockingbird",
28+ "author": "Harper Lee",
29+ "year": 1960,
30+ "read": false
31+ },
32+ {
33+ "title": "Mysterious Book",
34+ "author": "",
35+ "year": 0,
36+ "read": false
37+ }
38+ ]
Original file line number Diff line number Diff line change 1+ apiVersion : batch/v1
2+ kind : Job
3+ metadata :
4+ name : bookkeeper-list-job
5+ labels :
6+ app : bookkeeper
7+ spec :
8+ template :
9+ metadata :
10+ labels :
11+ app : bookkeeper
12+ spec :
13+ containers :
14+ - name : bookkeeper
15+ image : bookkeeper-app:latest
16+ imagePullPolicy : IfNotPresent
17+ command : ["python", "book_app.py", "list"]
18+ volumeMounts :
19+ - name : data-json
20+ mountPath : /app/data.json
21+ subPath : data.json
22+ restartPolicy : Never
23+ volumes :
24+ - name : data-json
25+ configMap :
26+ name : book-data
27+ backoffLimit : 2
You can’t perform that action at this time.
0 commit comments