From 2f66c04d1bc34b7412f3a5551b0c428ec32b5138 Mon Sep 17 00:00:00 2001 From: Shihaam Abdul Rahman Date: Sat, 1 Aug 2026 00:27:38 +0500 Subject: [PATCH] build backend and auto build and push everything --- .build/dev/backend.Dockerfile | 5 ++++ .build/prod/README.md | 42 ++++++++++++++++++++++++++------- .build/prod/backend.Dockerfile | 7 ++++++ .build/prod/compose.yml | 10 ++++++-- .build/prod/frontend.Dockerfile | 1 + .build/prod/nginx.conf | 19 +++++++++++++++ .gitea/workflows/build.yml | 29 +++++++++++++++++++++++ 7 files changed, 102 insertions(+), 11 deletions(-) create mode 100644 .build/dev/backend.Dockerfile create mode 100644 .build/prod/backend.Dockerfile create mode 100644 .build/prod/nginx.conf create mode 100644 .gitea/workflows/build.yml diff --git a/.build/dev/backend.Dockerfile b/.build/dev/backend.Dockerfile new file mode 100644 index 0000000..8350cd6 --- /dev/null +++ b/.build/dev/backend.Dockerfile @@ -0,0 +1,5 @@ +FROM python:3.12-slim + +WORKDIR /var/www/html/ + +CMD pip install -r requirements.txt && uvicorn app.main:app --host 0.0.0.0 --port 8000 --reload diff --git a/.build/prod/README.md b/.build/prod/README.md index 3735302..ec189bd 100644 --- a/.build/prod/README.md +++ b/.build/prod/README.md @@ -1,16 +1,40 @@ ## Production deployment -it is assumed that you will be using backend on the same machine, so this compose is for both services + +Both services build from the repo root (monorepo). The frontend container runs +nginx, which serves the built SPA at `/` and reverse-proxies `/api` to the +backend container. Only the frontend port needs to be published — the backend +is reached internally over the compose network as `backend:8000`. + +``` +host.com/ -> frontend (nginx static SPA) +host.com/api/... -> backend (FastAPI, /api prefix stripped) +``` + +### Build & run + +```sh +cp .env.example .env # VITE_API_TARGET (dev proxy only) +cp ../../backend/.env.example ../../backend/.env # DB creds, API_KEY, etc. +docker compose -f .build/prod/compose.yml up -d --build +``` + +The portal is then available on `http://HOST:8000`. + +### Running from published images + ```yml services: - frontend: - hostname: frontend - image: git.shihaam.dev/sarlink/radui - ports: - - 8000:80 backend: hostname: backend - image: git.shihaam.dev/sarlink/radapi - ports: - - 8001:80 + image: git.shihaam.dev/sarlink/radadmin/backed + env_file: + - backend.env + frontend: + hostname: frontend + image: git.shihaam.dev/sarlink/radadmin/frontend + ports: + - 8000:80 + depends_on: + - backend ``` diff --git a/.build/prod/backend.Dockerfile b/.build/prod/backend.Dockerfile new file mode 100644 index 0000000..09831dc --- /dev/null +++ b/.build/prod/backend.Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.12-slim + +WORKDIR /app +COPY backend/ . +RUN pip install --no-cache-dir -r requirements.txt + +CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"] diff --git a/.build/prod/compose.yml b/.build/prod/compose.yml index 7a27dc3..51d4460 100644 --- a/.build/prod/compose.yml +++ b/.build/prod/compose.yml @@ -1,9 +1,15 @@ services: frontend: build: - context: ../../frontend + context: ../../ dockerfile: .build/prod/frontend.Dockerfile args: VITE_API_TARGET: ${VITE_API_TARGET} hostname: frontend - image: git.shihaam.dev/sarlink/radui + image: git.shihaam.dev/sarlink/radadmin/backend + backend: + build: + context: ../../ + dockerfile: .build/prod/backend.Dockerfile + hostname: backend + image: git.shihaam.dev/sarlink/radadmin/frontend diff --git a/.build/prod/frontend.Dockerfile b/.build/prod/frontend.Dockerfile index bbca419..3edd780 100644 --- a/.build/prod/frontend.Dockerfile +++ b/.build/prod/frontend.Dockerfile @@ -10,3 +10,4 @@ RUN echo VITE_API_TARGET=$VITE_API_TARGET > .env \ FROM nginx COPY --from=frontendbuilder /var/www/html/dist /usr/share/nginx/html +COPY .build/prod/nginx.conf /etc/nginx/conf.d/default.conf diff --git a/.build/prod/nginx.conf b/.build/prod/nginx.conf new file mode 100644 index 0000000..5faed92 --- /dev/null +++ b/.build/prod/nginx.conf @@ -0,0 +1,19 @@ +server { + listen 80; + server_name _; + + root /usr/share/nginx/html; + index index.html; + + location /api/ { + proxy_pass http://backend:8000/; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + } + + location / { + try_files $uri $uri/ /index.html; + } +} diff --git a/.gitea/workflows/build.yml b/.gitea/workflows/build.yml new file mode 100644 index 0000000..52af335 --- /dev/null +++ b/.gitea/workflows/build.yml @@ -0,0 +1,29 @@ +name: build-and-push + +on: + push: + branches: + - main + workflow_dispatch: + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Log in to registry + uses: docker/login-action@v3 + with: + registry: git.shihaam.dev + username: ${{ secrets.DOCKER_REGISTRY_USER }} + password: ${{ secrets.DOCKER_REGISTRY_PASSWORD }} + + - name: Build and push + env: + VITE_API_TARGET: ${{ vars.VITE_API_TARGET }} + run: docker compose -f .build/prod/compose.yml build --push