Skip to content

Commit

Permalink
Move backend to rust
Browse files Browse the repository at this point in the history
  • Loading branch information
Hoff97 committed Sep 24, 2024
1 parent 6115736 commit 159556d
Show file tree
Hide file tree
Showing 21 changed files with 4,446 additions and 50 deletions.
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
backend/data/
backend-rust/data/
backend-rust/target/
__pycache__
frontend/node_modules
41 changes: 29 additions & 12 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ FROM node:20.5.1 AS frontend_build

WORKDIR /app

COPY ./backend-rust/download_data.sh ./
RUN ./download_data.sh && ls && ls data

COPY ./frontend/package.json ./
COPY ./frontend/package-lock.json ./

Expand All @@ -11,23 +14,37 @@ COPY ./frontend ./

RUN npm run build

FROM python:3.11
FROM docker.io/rust:1-slim-bookworm AS backend_build

ARG pkg=backend-rust

WORKDIR /build

ENV PROD=true
COPY ./backend-rust .

WORKDIR /code
RUN --mount=type=cache,target=/build/target \
--mount=type=cache,target=/usr/local/cargo/registry \
--mount=type=cache,target=/usr/local/cargo/git \
set -eux; \
cargo build --release --target-dir /build/target; \
ls; \
objcopy --compress-debug-sections target/release/$pkg ./main

COPY ./backend/download_data.sh /code
RUN ./download_data.sh
FROM docker.io/debian:bookworm-slim

WORKDIR /app

COPY ./backend/requirements.txt /code
COPY --from=frontend_build /app/data ./data

RUN pip install --no-cache-dir --upgrade -r requirements.txt
## copy the main binary
COPY --from=backend_build /build/main ./

COPY ./backend /code
RUN mkdir static
COPY --from=frontend_build /app/build/index.html ./static
COPY --from=frontend_build /app/build ./static

RUN mkdir -p /static
COPY --from=frontend_build /app/build/index.html /static
COPY --from=frontend_build /app/build /static
## ensure the container listens globally on port 8080
ENV ROCKET_ADDRESS=0.0.0.0
ENV ROCKET_PORT=8080

CMD ["fastapi", "run", "src/server.py", "--port", "80"]
CMD ./main
33 changes: 33 additions & 0 deletions Dockerfile_python_backend
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
FROM node:20.5.1 AS frontend_build

WORKDIR /app

COPY ./frontend/package.json ./
COPY ./frontend/package-lock.json ./

RUN npm install

COPY ./frontend ./

RUN npm run build

FROM python:3.11

ENV PROD=true

WORKDIR /code

COPY ./backend/download_data.sh /code
RUN ./download_data.sh

COPY ./backend/requirements.txt /code

RUN pip install --no-cache-dir --upgrade -r requirements.txt

COPY ./backend /code

RUN mkdir -p /static
COPY --from=frontend_build /app/build/index.html /static
COPY --from=frontend_build /app/build /static

CMD ["fastapi", "run", "src/server.py", "--port", "80"]
2 changes: 2 additions & 0 deletions backend-rust/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
target
data
3 changes: 3 additions & 0 deletions backend-rust/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"editor.formatOnSave": true,
}
Loading

0 comments on commit 159556d

Please sign in to comment.