Split backend properly
All checks were successful
CI / test (push) Successful in 53s
CI / test-analytics (push) Successful in 2m1s
CI / build-api (push) Successful in 3m22s
CI / build-frontend (push) Successful in 2m6s
CI / build-analytics (push) Successful in 2m45s

This commit is contained in:
2026-05-11 13:56:20 +02:00
parent b7c38c8377
commit dbf1a05b08
3 changed files with 59 additions and 41 deletions

View File

@@ -6,7 +6,8 @@ on:
tags: ["v*"] tags: ["v*"]
env: env:
IMAGE_BACKEND: ${{ secrets.REGISTRY_HOST }}/domagoj/otel-bi-backend IMAGE_API: ${{ secrets.REGISTRY_HOST }}/domagoj/otel-bi-api
IMAGE_ANALYTICS: ${{ secrets.REGISTRY_HOST }}/domagoj/otel-bi-analytics
IMAGE_FRONTEND: ${{ secrets.REGISTRY_HOST }}/domagoj/otel-bi-frontend IMAGE_FRONTEND: ${{ secrets.REGISTRY_HOST }}/domagoj/otel-bi-frontend
jobs: jobs:
@@ -76,8 +77,8 @@ jobs:
- name: Test - name: Test
run: go test ./... run: go test ./...
build-backend: build-api:
needs: [test, test-analytics] needs: test
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
@@ -95,11 +96,36 @@ jobs:
context: backend context: backend
file: backend/Dockerfile file: backend/Dockerfile
push: true push: true
cache-from: type=registry,ref=${{ env.IMAGE_BACKEND }}:latest cache-from: type=registry,ref=${{ env.IMAGE_API }}:latest
cache-to: type=inline cache-to: type=inline
tags: | tags: |
${{ env.IMAGE_BACKEND }}:${{ github.sha }} ${{ env.IMAGE_API }}:${{ github.sha }}
${{ env.IMAGE_BACKEND }}:latest ${{ env.IMAGE_API }}:latest
build-analytics:
needs: test-analytics
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: docker/login-action@v3
with:
registry: ${{ secrets.REGISTRY_HOST }}
username: ${{ secrets.REGISTRY_USERNAME }}
password: ${{ secrets.REGISTRY_TOKEN }}
- uses: docker/setup-buildx-action@v3
- uses: docker/build-push-action@v6
with:
context: backend
file: backend/Dockerfile.analytics
push: true
cache-from: type=registry,ref=${{ env.IMAGE_ANALYTICS }}:latest
cache-to: type=inline
tags: |
${{ env.IMAGE_ANALYTICS }}:${{ github.sha }}
${{ env.IMAGE_ANALYTICS }}:latest
build-frontend: build-frontend:
needs: test needs: test

View File

@@ -1,21 +1,5 @@
# syntax=docker/dockerfile:1.7 # syntax=docker/dockerfile:1.7
# ---------------------------------------------------------------------------
# Stage 1 — Build Go analytics service
# ---------------------------------------------------------------------------
FROM rockylinux/rockylinux:10 AS go-build
RUN dnf install -y golang && dnf clean all
WORKDIR /src
COPY analytics/go.mod analytics/go.sum ./
RUN go mod download
COPY analytics/ .
RUN CGO_ENABLED=0 GOOS=linux go build -o /analytics-server ./cmd/server
# ---------------------------------------------------------------------------
# Stage 2 — Python base
# ---------------------------------------------------------------------------
FROM rockylinux/rockylinux:10 AS base FROM rockylinux/rockylinux:10 AS base
RUN dnf install -y python3 && dnf clean all RUN dnf install -y python3 && dnf clean all
@@ -30,44 +14,28 @@ COPY --from=ghcr.io/astral-sh/uv:latest /uv /usr/local/bin/uv
WORKDIR /app WORKDIR /app
# ---------------------------------------------------------------------------
# Stage 3 — Python dependencies
# ---------------------------------------------------------------------------
FROM base AS deps FROM base AS deps
COPY pyproject.toml uv.lock* ./ COPY pyproject.toml uv.lock* ./
RUN --mount=type=cache,target=/root/.cache/uv \ RUN --mount=type=cache,target=/root/.cache/uv \
uv sync --frozen --no-install-project --no-dev uv sync --frozen --no-install-project --no-dev
# ---------------------------------------------------------------------------
# Stage 4 — Python application
# ---------------------------------------------------------------------------
FROM deps AS app-build FROM deps AS app-build
COPY app/ ./app/ COPY app/ ./app/
RUN --mount=type=cache,target=/root/.cache/uv \ RUN --mount=type=cache,target=/root/.cache/uv \
uv sync --frozen --no-dev uv sync --frozen --no-dev
# ---------------------------------------------------------------------------
# Stage 5 — Final image (Python + Go binary)
# ---------------------------------------------------------------------------
FROM base AS final FROM base AS final
RUN groupadd --gid 10001 appgroup && \ RUN groupadd --gid 10001 appgroup && \
useradd --uid 10001 --gid 10001 --no-create-home --shell /sbin/nologin appuser useradd --uid 10001 --gid 10001 --no-create-home --shell /sbin/nologin appuser
COPY --from=go-build /analytics-server /usr/local/bin/analytics-server
COPY --from=app-build --chown=appuser:appgroup /app /app COPY --from=app-build --chown=appuser:appgroup /app /app
USER appuser USER appuser
WORKDIR /app WORKDIR /app
ENV PATH="/app/.venv/bin:$PATH" \ ENV PATH="/app/.venv/bin:$PATH"
ROLE=api
EXPOSE 8000 8080 EXPOSE 8000
ENTRYPOINT ["/bin/sh", "-c", "\ ENTRYPOINT ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000", "--no-access-log"]
if [ \"$ROLE\" = 'analytics' ]; then \
/usr/local/bin/analytics-server; \
else \
uvicorn app.main:app --host 0.0.0.0 --port 8000 --no-access-log; \
fi"]

View File

@@ -0,0 +1,24 @@
# syntax=docker/dockerfile:1.7
FROM rockylinux/rockylinux:10 AS build
RUN dnf install -y golang && dnf clean all
WORKDIR /src
COPY analytics/go.mod analytics/go.sum ./
RUN go mod download
COPY analytics/ .
RUN CGO_ENABLED=0 GOOS=linux go build -o /analytics-server ./cmd/server
FROM rockylinux/rockylinux:10 AS final
RUN groupadd --gid 10001 appgroup && \
useradd --uid 10001 --gid 10001 --no-create-home --shell /sbin/nologin appuser
COPY --from=build /analytics-server /usr/local/bin/analytics-server
USER appuser
EXPOSE 8080
ENTRYPOINT ["/usr/local/bin/analytics-server"]