Skip to content

Commit 1f17a91

Browse files
authored
Add a Dockerfile and some examples in README (#1)
1 parent 294f7b8 commit 1f17a91

File tree

3 files changed

+225
-0
lines changed

3 files changed

+225
-0
lines changed

.dockerignore

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
.git/
2+
.gitignore
3+
4+
build
5+
dist
6+
.venv/
7+
*.egg-info
8+
*.egg/
9+
*.pyc
10+
*.swp
11+
12+
.hypothesis/
13+
.idea/
14+
.pytest_cache/
15+
__pycache__/
16+
*/__pycache__/
17+
18+
Dockerfile
19+
.dockerignore
20+
21+
tests/

Dockerfile

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
FROM python:3.13-slim
2+
3+
# Install uv by copying it from the official uv image
4+
COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/
5+
6+
# Copy your application code into the container
7+
COPY . /app
8+
9+
WORKDIR /app
10+
11+
# Install dependencies using uv
12+
RUN uv sync --frozen --no-cache
13+
14+
# Run the app using uv's managed environment
15+
CMD ["/app/.venv/bin/python", "main.py"]

README.md

Lines changed: 189 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,192 @@
22

33
A sample application written to illustrate the consistency of business operations in a microservices
44
architecture.
5+
6+
## Building process
7+
8+
After cloning the repository, `cd` into it and just create a Docker image running:
9+
10+
```sh
11+
docker build -t factory:local .
12+
```
13+
14+
## Running the application
15+
16+
Once you have an image built, run it like
17+
18+
```sh
19+
docker run --rm --name factory --network=host -p 8000:8000 factory:local
20+
```
21+
22+
This snippet is intended just for testing the app, it is usually not a good
23+
idea to run any containers like that in production.
24+
25+
## Testing it
26+
27+
In another terminal window simple `curl` can be used to test the application, e.g.
28+
29+
### Creating new materials (oxygen, hydrogen and sulphur)
30+
```sh
31+
curl -X POST -H "Content-Type: application/json" \
32+
-d '{"name": "Oxygen", "quantity_unit": "mole"}' \
33+
http://localhost:8000/materials/
34+
35+
curl -X POST -H "Content-Type: application/json" \
36+
-d '{"name": "Hydrogen", "quantity_unit": "mole"}' \
37+
http://localhost:8000/materials/
38+
39+
curl -X POST -H "Content-Type: application/json" \
40+
-d '{"name": "Sulphur", "quantity_unit": "mole"}' \
41+
http://localhost:8000/materials/
42+
```
43+
44+
### Listing materials
45+
```sh
46+
curl -s http://localhost:8000/materials/ | jq
47+
[
48+
{
49+
"name": "Oxygen",
50+
"slug": "oxygen",
51+
"quantity_unit": "mole",
52+
"id": "699139c4-eb11-4815-9021-2c8f66b38d5f"
53+
},
54+
{
55+
"name": "Hydrogen",
56+
"slug": "hydrogen",
57+
"quantity_unit": "mole",
58+
"id": "c18605cd-3e1e-4898-8192-1da5662bc30a"
59+
},
60+
{
61+
"name": "Sulphur",
62+
"slug": "sulphur",
63+
"quantity_unit": "mole",
64+
"id": "f49a9fff-8345-41cb-934f-f75adc3161b5"
65+
}
66+
]
67+
```
68+
69+
### Updating a material
70+
```sh
71+
curl -X PATCH -H "Content-Type: application/json" \
72+
-d '{"quantity_unit": "µg"}' \
73+
http://localhost:8000/materials/sulphur
74+
```
75+
76+
### Fetching information about a single material
77+
```sh
78+
curl -s http://localhost:8000/materials/sulphur | jq
79+
{
80+
"name": "Sulphur",
81+
"slug": "sulphur",
82+
"quantity_unit": "µg",
83+
"id": "f49a9fff-8345-41cb-934f-f75adc3161b5",
84+
"created_at": "2025-06-17T07:25:13",
85+
"boms": [],
86+
"stock": [],
87+
"products": []
88+
}
89+
```
90+
91+
### Removing a material
92+
```sh
93+
curl -X DELETE http://localhost:8000/materials/sulphur
94+
```
95+
96+
### Creating a warehouse
97+
```sh
98+
curl -X POST -H "Content-Type: application/json" \
99+
-d '{"name": "Chemicals-1", "location": "Wien", "max_capacity": 1000000}' \
100+
http://localhost:8000/warehouses/
101+
```
102+
103+
other operations look just like operations on materials, e.g. fetching
104+
information about a single warehouse would be
105+
106+
```sh
107+
curl -s http://localhost:8000/warehouses/chemicals-1 | jq
108+
{
109+
"name": "Chemicals-1",
110+
"slug": "chemicals-1",
111+
"location": "Wien",
112+
"capacity": 1000000,
113+
"max_capacity": 1000000,
114+
"id": "ad02b895-ea98-4bd5-a889-7869f3e521fb",
115+
"created_at": "2025-06-17T07:28:47",
116+
"stock": []
117+
}
118+
```
119+
120+
### Delivery process
121+
```sh
122+
curl -X POST -H "Content-Type: application/json" \
123+
-d '{"warehouse_id": "ad02b895-ea98-4bd5-a889-7869f3e521fb", \
124+
"positions": [{"material_id": "699139c4-eb11-4815-9021-2c8f66b38d5f",
125+
"quantity": 10}, {"material_id": "c18605cd-3e1e-4898-8192-1da5662bc30a", \
126+
"quantity": 20}]}' \
127+
http://localhost:8000/delivery/
128+
```
129+
130+
Delivered materials stored in a warehouse will diminish its capacity, so after
131+
testing a delivery something will change, e.g.
132+
133+
```sh
134+
curl -s http://localhost:8000/warehouses/chemicals-1 | jq
135+
{
136+
"name": "Chemicals-1",
137+
"slug": "chemicals-1",
138+
"location": "Wien",
139+
"capacity": 999970,
140+
"max_capacity": 1000000,
141+
"id": "ad02b895-ea98-4bd5-a889-7869f3e521fb",
142+
"created_at": "2025-06-17T07:28:47",
143+
"stock": [
144+
{
145+
"id": "d9b1f90d-8559-46e5-b6c3-546d16666aa0",
146+
"quantity": 10,
147+
"material_name": "Oxygen",
148+
"material_slug": "oxygen"
149+
},
150+
{
151+
"id": "31ed7603-43f2-41a9-a817-10ce54fbdf29",
152+
"quantity": 20,
153+
"material_name": "Hydrogen",
154+
"material_slug": "hydrogen"
155+
}
156+
]
157+
}
158+
```
159+
160+
```sh
161+
curl -s http://localhost:8000/materials/oxygen | jq
162+
{
163+
"name": "Oxygen",
164+
"slug": "oxygen",
165+
"quantity_unit": "mole",
166+
"id": "699139c4-eb11-4815-9021-2c8f66b38d5f",
167+
"created_at": "2025-06-17T07:24:50",
168+
"boms": [],
169+
"stock": [
170+
{
171+
"id": "d9b1f90d-8559-46e5-b6c3-546d16666aa0",
172+
"warehouse_id": "ad02b895-ea98-4bd5-a889-7869f3e521fb",
173+
"quantity": 10,
174+
"warehouse_name": "Chemicals-1",
175+
"warehouse_slug": "chemicals-1"
176+
},
177+
{
178+
"id": "ca6bd72a-48ec-4a29-a3d9-545d09f8b7e9",
179+
"warehouse_id": "daae3903-dd42-473b-a160-0a838ccf65f0",
180+
"quantity": 10000,
181+
"warehouse_name": "Chemicals-2",
182+
"warehouse_slug": "chemicals-2"
183+
}
184+
],
185+
"products": []
186+
}
187+
```
188+
189+
### Further testing
190+
191+
There are other endpoints, not described in this short README file. Feel
192+
free to investigate them on your own by browsing files in the `routers/`
193+
directory.

0 commit comments

Comments
 (0)