Skip to content

Commit 5ed3069

Browse files
committed
refactor: Update README for development and production modes; enhance Dockerfile cleanup and user permissions; adjust pyproject.toml for local dependencies
1 parent a5b8302 commit 5ed3069

4 files changed

Lines changed: 68 additions & 33 deletions

File tree

README.md

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -225,25 +225,60 @@ cd infrastructure/rag;helm dependency update; cd ../..
225225
226226
After the initial build of the helm chart *Tilt* is able to update the files.
227227

228+
##### Development vs Production Mode
229+
230+
The template supports two deployment modes for local development:
231+
232+
- **Production Mode** (default): Uses production Dockerfiles with local library dependencies for realistic testing
233+
- **Development Mode**: Uses development Dockerfiles with live code updates for fast iteration
234+
228235
The following will tear up the microservices in *k3d*.
229236
For the following steps, it is assumed your current working directory is the root of the git-repository.
230237

238+
**Production Mode (default):**
239+
231240
```shell
232241
tilt up
233242
```
234243

244+
**Development Mode:**
245+
246+
```shell
247+
tilt up -- --dev=true
248+
```
249+
250+
##### Docker File Structure
251+
252+
Each service now has separate Docker files optimized for different use cases:
253+
254+
- `Dockerfile`: Production-optimized builds with multi-stage architecture and security hardening
255+
- `Dockerfile.dev`: Development-optimized builds with faster build times and development tools
256+
257+
The Tilt configuration automatically selects the appropriate Dockerfile based on the mode:
258+
259+
- Production mode uses `Dockerfile` with local library dependencies (`prod-local` group)
260+
- Development mode uses `Dockerfile.dev` with live code updates and development dependencies
261+
235262
Environment variables are loaded from `.env` file in the root of this git-repository.
236263

237264
The *Tilt* UI is available at [http://localhost:10350/](http://localhost:10350/)
238265

239266
If you want to access *Qdrant* etc. just click the resource in the UI. In the upper corner will be the link, to access the resource.
240267

268+
##### Debugging
269+
241270
To enable debugging, start tilt with the following command:
242271

243272
```shell
244273
tilt up -- --debug=true
245274
```
246275

276+
It is recommended to combine debugging with development mode:
277+
278+
```shell
279+
tilt up -- --debug=true --dev=true
280+
```
281+
247282
The backend will wait until your debugger is connected before it will fully start.
248283
The debugger used is `debugpy` which is compatible with VS Code.
249284
To connect the debugger, you can use the following `launch.json`:
@@ -368,10 +403,12 @@ A detailed explanation of, how to access a service via ingress, can be found in
368403
### 2.1 Server provisioning
369404

370405
The RAG template requires *at least*:
371-
- A Kubernetes Cluster
372-
- S3 ObjectStorage
406+
407+
- A Kubernetes Cluster
408+
- S3 ObjectStorage
373409

374410
Provided is an example Terraform script, using the [STACKIT Terrraform Provider](https://registry.terraform.io/providers/stackitcloud/stackit/latest/docs):
411+
375412
```terraform
376413
resource "stackit_ske_project" "rag-ske" {
377414
project_id = var.stackit_project_id
@@ -429,8 +466,8 @@ Further requirements for the server can be found in the [infrastructure README](
429466

430467
A detailed description regarding the configuration of Langfuse can be found in the [infrastructure README](./infrastructure/README.md).
431468

432-
433469
## 3. Build and Test
470+
434471
The example `Tiltfile` provides a triggered linting and testing.
435472
The linting-settings can be changed in the `services/rag-backend/pyproject.toml` file under section `tool.flake8`.
436473

services/admin-backend/Dockerfile

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,19 @@ COPY --from=build /usr/local/bin/ /usr/local/bin/
4040
COPY --from=build /usr/bin/make /usr/bin/make
4141
COPY --from=build /usr/local/lib/ /usr/local/lib/
4242

43+
# cleanup
44+
RUN apt-get clean autoclean && apt-get autoremove --yes \
45+
&& while read -r shell; do rm -f "$shell"; done < /etc/shells || true \
46+
&& rm -rf /var/lib/{apt,dpkg,cache,log}/ || true
47+
48+
ENV VIRTUAL_ENV="${POETRY_VIRTUALENVS_PATH}"
49+
ENV PATH="${POETRY_VIRTUALENVS_PATH}/bin:${PATH}"
50+
51+
USER nonroot
52+
53+
COPY --chown=nonroot:nonroot services/admin-backend .
54+
COPY --from=build --chown=nonroot:nonroot /app/services/admin-backend/log /app/services/admin-backend/log
55+
4356
# Copy the library source code to the final stage only for local path dependencies
4457
ARG DEPENDENCY_GROUP=prod
4558
COPY --from=build --chown=nonroot:nonroot \
@@ -56,18 +69,3 @@ RUN if [ "$DEPENDENCY_GROUP" = "prod-local" ]; then \
5669
chown -R nonroot:nonroot /app/libs; \
5770
fi && \
5871
rm -rf /tmp/conditional-libs
59-
60-
# cleanup
61-
RUN apt-get clean autoclean && apt-get autoremove --yes \
62-
&& while read -r shell; do rm -f "$shell"; done < /etc/shells || true \
63-
&& rm -rf /var/lib/{apt,dpkg,cache,log}/ || true
64-
65-
ENV VIRTUAL_ENV="${POETRY_VIRTUALENVS_PATH}"
66-
ENV PATH="${POETRY_VIRTUALENVS_PATH}/bin:${PATH}"
67-
68-
USER nonroot
69-
70-
COPY --chown=nonroot:nonroot services/admin-backend .
71-
COPY --from=build --chown=nonroot:nonroot /app/services/admin-backend/log /app/services/admin-backend/log
72-
73-

services/rag-backend/Dockerfile

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,20 @@ COPY --from=build /usr/local/bin/ /usr/local/bin/
4444
COPY --from=build /usr/bin/make /usr/bin/make
4545
COPY --from=build /usr/local/lib/ /usr/local/lib/
4646

47+
# cleanup
48+
RUN apt-get clean autoclean && apt-get autoremove --yes \
49+
&& while read -r shell; do rm -f "$shell"; done < /etc/shells || true \
50+
&& rm -rf /var/lib/{apt,dpkg,cache,log}/ || true
51+
52+
ENV VIRTUAL_ENV="${POETRY_VIRTUALENVS_PATH}"
53+
ENV PATH="${POETRY_VIRTUALENVS_PATH}/bin:${PATH}"
54+
55+
USER nonroot
56+
57+
COPY --chown=nonroot:nonroot services/rag-backend .
58+
# Preserve log directory from build stage
59+
COPY --from=build --chown=nonroot:nonroot /app/services/rag-backend/log /app/services/rag-backend/log
60+
4761
# Copy the library source code to the final stage only for local path dependencies
4862
ARG DEPENDENCY_GROUP=prod
4963
COPY --from=build --chown=nonroot:nonroot \
@@ -60,17 +74,3 @@ RUN if [ "$DEPENDENCY_GROUP" = "prod-local" ]; then \
6074
chown -R nonroot:nonroot /app/libs; \
6175
fi && \
6276
rm -rf /tmp/conditional-libs
63-
64-
# cleanup
65-
RUN apt-get clean autoclean && apt-get autoremove --yes \
66-
&& while read -r shell; do rm -f "$shell"; done < /etc/shells || true \
67-
&& rm -rf /var/lib/{apt,dpkg,cache,log}/ || true
68-
69-
ENV VIRTUAL_ENV="${POETRY_VIRTUALENVS_PATH}"
70-
ENV PATH="${POETRY_VIRTUALENVS_PATH}/bin:${PATH}"
71-
72-
USER nonroot
73-
74-
COPY --chown=nonroot:nonroot services/rag-backend .
75-
# Preserve log directory from build stage
76-
COPY --from=build --chown=nonroot:nonroot /app/services/rag-backend/log /app/services/rag-backend/log

services/rag-backend/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,6 @@ rag-core-api = "==2.2.1"
107107
rag-core-lib = "==2.2.1"
108108

109109
[tool.poetry.group.prod-local.dependencies]
110-
# Use local path for Tilt/development with production Dockerfile
110+
# Use local path for Tilt/development with production Dockerfile
111111
rag-core-api = {path = "../../libs/rag-core-api"}
112112
rag-core-lib = {path = "../../libs/rag-core-lib"}

0 commit comments

Comments
 (0)