diff --git a/.gitea/workflows/ci.yml b/.gitea/workflows/ci.yml index 0059c5a..9ed2c24 100644 --- a/.gitea/workflows/ci.yml +++ b/.gitea/workflows/ci.yml @@ -6,7 +6,8 @@ on: tags: ["v*"] 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 jobs: @@ -76,8 +77,8 @@ jobs: - name: Test run: go test ./... - build-backend: - needs: [test, test-analytics] + build-api: + needs: test runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 @@ -95,11 +96,36 @@ jobs: context: backend file: backend/Dockerfile push: true - cache-from: type=registry,ref=${{ env.IMAGE_BACKEND }}:latest + cache-from: type=registry,ref=${{ env.IMAGE_API }}:latest cache-to: type=inline tags: | - ${{ env.IMAGE_BACKEND }}:${{ github.sha }} - ${{ env.IMAGE_BACKEND }}:latest + ${{ env.IMAGE_API }}:${{ github.sha }} + ${{ 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: needs: test diff --git a/backend/Dockerfile b/backend/Dockerfile index b5a1289..ed8907a 100644 --- a/backend/Dockerfile +++ b/backend/Dockerfile @@ -1,21 +1,5 @@ # 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 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 -# --------------------------------------------------------------------------- -# Stage 3 — Python dependencies -# --------------------------------------------------------------------------- FROM base AS deps COPY pyproject.toml uv.lock* ./ RUN --mount=type=cache,target=/root/.cache/uv \ uv sync --frozen --no-install-project --no-dev -# --------------------------------------------------------------------------- -# Stage 4 — Python application -# --------------------------------------------------------------------------- FROM deps AS app-build COPY app/ ./app/ RUN --mount=type=cache,target=/root/.cache/uv \ uv sync --frozen --no-dev -# --------------------------------------------------------------------------- -# Stage 5 — Final image (Python + Go binary) -# --------------------------------------------------------------------------- FROM base AS final RUN groupadd --gid 10001 appgroup && \ 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 USER appuser WORKDIR /app -ENV PATH="/app/.venv/bin:$PATH" \ - ROLE=api +ENV PATH="/app/.venv/bin:$PATH" -EXPOSE 8000 8080 +EXPOSE 8000 -ENTRYPOINT ["/bin/sh", "-c", "\ - 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"] +ENTRYPOINT ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000", "--no-access-log"] diff --git a/backend/Dockerfile.analytics b/backend/Dockerfile.analytics new file mode 100644 index 0000000..e389e86 --- /dev/null +++ b/backend/Dockerfile.analytics @@ -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"]