Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
.git
.local
.mypy_cache
.next
.pytest_cache
.ruff_cache
.venv
**/__pycache__
**/*.pyc
apps/web/.next
apps/web/node_modules
apps/web/test-results
node_modules
test-results
6 changes: 6 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ APP_ENV=development
LOG_LEVEL=info
DATABASE_URL=postgresql://postgres:postgres@localhost:5432/factory_intelligence
FACTORY_STORAGE_BACKEND=jsonl
NEXT_PUBLIC_API_BASE_URL=http://localhost:8000
FIP_API_URL=http://localhost:8000
DEMO_FACTORY_HOST=host.docker.internal
DEMO_FACTORY_OPCUA_ENDPOINT=opc.tcp://host.docker.internal:4840/ofi/demo
CONNECTOR_INTERVAL_SECONDS=30
SENTINEL_INTERVAL_SECONDS=60
MQTT_BROKER_URL=mqtt://localhost:1883
SIMULATOR_SEED=42
FACTORY_EVENTS_STORE=.local/storage/events.jsonl
Expand Down
25 changes: 23 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,23 @@ OPCUA_ENDPOINT ?= opc.tcp://localhost:4840/ofi/demo
OPCUA_POLL_COUNT ?= 6
OPCUA_POLL_INTERVAL ?= 1
OPCUA_EVENTS_STORE ?= .local/storage/opcua_demo_events.jsonl
COMPOSE_FILE ?= infra/docker/docker-compose.yml
PYTHONPATH := packages/factory-events:services/simulator:services/ingestion:services/process-sentinel:services/api
export PYTHONPATH

.PHONY: help setup dev dev-db simulate ingest opcua-demo-ingest sentinel-run demo demo-reset demo-data demo-ingest demo-sentinel-run demo-api-smoke api api-reload test test-unit test-integration test-contract test-e2e lint typecheck docs
.PHONY: help setup dev dev-db compose-up compose-down compose-ps compose-logs compose-config simulate ingest opcua-demo-ingest sentinel-run demo demo-reset demo-data demo-ingest demo-sentinel-run demo-api-smoke api api-reload test test-unit test-integration test-contract test-e2e lint typecheck docs

help:
@echo "Factory Intelligence Platform"
@echo ""
@echo "Available commands:"
@echo " make setup Install Python development dependencies"
@echo " make dev-db Start local PostgreSQL with Docker Compose"
@echo " make compose-up Start the FIP Compose runtime"
@echo " make compose-down Stop the FIP Compose runtime"
@echo " make compose-ps List FIP Compose services"
@echo " make compose-logs Follow FIP Compose logs"
@echo " make compose-config Validate the FIP Compose file"
@echo " make simulate Generate simulator JSONL events"
@echo " make ingest Validate and ingest simulator events"
@echo " make opcua-demo-ingest Poll the local demo OPC UA server into FactoryEvents"
Expand Down Expand Up @@ -68,7 +74,22 @@ dev:
@echo " make api"

dev-db:
docker compose -f infra/docker/docker-compose.yml up -d
docker compose -f $(COMPOSE_FILE) up -d postgres

compose-up:
docker compose -f $(COMPOSE_FILE) up --build

compose-down:
docker compose -f $(COMPOSE_FILE) down

compose-ps:
docker compose -f $(COMPOSE_FILE) ps

compose-logs:
docker compose -f $(COMPOSE_FILE) logs -f

compose-config:
docker compose -f $(COMPOSE_FILE) config

simulate:
$(PYTHON) -m factory_simulator.cli --scenario $(SCENARIO) --seed $(SEED) $(if $(DURATION_MINUTES),--duration-minutes $(DURATION_MINUTES),--count $(COUNT)) --output $(OUTPUT)
Expand Down
19 changes: 16 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,19 +106,31 @@ Start the FIP Compose stack from this repository:

```bash
cd ../Factory-Intelligence-Platform
make compose-up
make compose-ps
make compose-logs
curl http://localhost:8000/health
make compose-down
```

The wrappers call `docker compose -f infra/docker/docker-compose.yml ...`.
The equivalent direct commands are:

```bash
docker compose -f infra/docker/docker-compose.yml up --build
docker compose -f infra/docker/docker-compose.yml ps
docker compose -f infra/docker/docker-compose.yml logs -f
curl http://localhost:8000/health
docker compose -f infra/docker/docker-compose.yml down
```

Use `docker compose down` for normal shutdown. Use
`docker compose -f infra/docker/docker-compose.yml down -v` only when you
intentionally want to delete FIP named volumes, such as local Postgres data.

Some Compose services are still landing in follow-up issues. Until then,
contributors can run the API and Workbench directly for focused development:
The FIP Compose stack includes `postgres`, `api`, `web`, `connector-worker`,
and `sentinel-worker`. It does not start an in-repo simulator container.
Contributors can still run the API and Workbench directly for focused
development:

```bash
make setup
Expand Down Expand Up @@ -158,6 +170,7 @@ Run these before opening a pull request:

```bash
docker compose -f infra/docker/docker-compose.yml config
make compose-config
make lint
make typecheck
make test
Expand Down
5 changes: 5 additions & 0 deletions apps/web/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.next
node_modules
test-results
playwright-report
*.tsbuildinfo
16 changes: 16 additions & 0 deletions apps/web/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
FROM node:24-slim

WORKDIR /app

ARG NEXT_PUBLIC_API_BASE_URL=http://localhost:8000
ENV NEXT_PUBLIC_API_BASE_URL=${NEXT_PUBLIC_API_BASE_URL}

COPY package.json package-lock.json ./
RUN npm ci

COPY . .
RUN npm run build

EXPOSE 3000

CMD ["npx", "next", "start", "--hostname", "0.0.0.0", "--port", "3000"]
63 changes: 63 additions & 0 deletions docs/LEARNING_LOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,69 @@ This file should be updated by Codex after each meaningful change.
### What to learn next
```

## 2026-05-27 - Compose service images

### What changed

Added Docker build definitions for the shared Python runtime and the Next.js
Workbench, then expanded the FIP Compose stack to include `postgres`, `api`,
`web`, `connector-worker`, and `sentinel-worker`. The default FIP Compose file
no longer starts the in-repo `opcua-simulator`.

### Why it matters

Issue #236 establishes the container shape for the Dockerized runtime without
turning this issue into connector or Sentinel feature work. Demo-Factory stays
separate, and the FIP services use explicit configuration for Postgres, API
URLs, Demo-Factory source endpoints, and worker intervals.

### How it works

`infra/docker/python-runtime.Dockerfile` builds one Python image that can run
the FastAPI app, the existing OPC-UA demo ingestion entrypoint, or the Process
Sentinel CLI. Compose supplies different commands for each service. The web
image builds the Next.js Workbench and exposes it on port `3000`. Postgres
remains the shared runtime store, initialized from
`services/ingestion/schema.sql`.

### How to run it

```bash
cd ../Demo-Factory
docker compose up -d --build

cd ../Factory-Intelligence-Platform
make compose-up
curl http://localhost:8000/health
make compose-down
```

### How to test it

```bash
make compose-config
make lint
make typecheck
make test
cd apps/web && npm test
```

### Key files

- `.dockerignore`
- `infra/docker/python-runtime.Dockerfile`
- `apps/web/Dockerfile`
- `infra/docker/docker-compose.yml`
- `Makefile`
- `docs/runtime/DOCKER_COMPOSE.md`

### What to learn next

Replace the temporary scheduled connector command with the full read-only
connector worker runtime from the next issue, then add the Compose smoke path
that proves API health, ingestion, Sentinel output, and Workbench rendering
together.

## 2026-05-26 - Postgres-backed runtime storage

### What changed
Expand Down
46 changes: 39 additions & 7 deletions docs/runtime/DOCKER_COMPOSE.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ Demo-Factory protocols
-> Next.js Workbench
```

The Dockerized runtime is being built across epic #232. Some FIP services may
remain placeholders until the child issues for Postgres-backed storage, service
images, connector worker, Sentinel worker, Workbench/API wording, and Compose
smoke tests land. Keep using the commands below as the shared local runtime
shape while those pieces are added.
The Dockerized runtime is being built across epic #232. The FIP Compose stack
now defines the API, Workbench, connector worker, Process Sentinel worker, and
Postgres service shape. Follow-up issues continue to harden the connector
runtime, scheduled Sentinel behavior, API/Workbench wording, and Compose smoke
tests.

## Dependency Order

Expand All @@ -43,6 +43,18 @@ DATABASE_URL=postgresql://postgres:postgres@postgres:5432/factory_intelligence
Use `FACTORY_STORAGE_BACKEND=jsonl` only for focused local tests or direct
development loops that intentionally avoid Postgres.

The default Compose services use explicit runtime variables:

| Variable | Default | Used by |
| --- | --- | --- |
| `DATABASE_URL` | `postgresql://postgres:postgres@postgres:5432/factory_intelligence` | API, connector worker, Sentinel worker |
| `NEXT_PUBLIC_API_BASE_URL` | `http://localhost:8000` | Workbench browser bundle |
| `FIP_API_URL` | `http://api:8000` | Container-to-container API target |
| `DEMO_FACTORY_HOST` | `host.docker.internal` | Connector worker source host note |
| `DEMO_FACTORY_OPCUA_ENDPOINT` | `opc.tcp://host.docker.internal:4840/ofi/demo` | Connector worker read-only source endpoint |
| `CONNECTOR_INTERVAL_SECONDS` | `30` | Connector worker schedule interval |
| `SENTINEL_INTERVAL_SECONDS` | `60` | Process Sentinel worker schedule interval |

## Start Demo-Factory

From a sibling checkout:
Expand Down Expand Up @@ -76,6 +88,27 @@ rebuilding images, use:
docker compose -f infra/docker/docker-compose.yml up
```

The FIP stack includes these default services:

- `postgres`
- `api`
- `web`
- `connector-worker`
- `sentinel-worker`

It does not start an in-repo simulator service. Start Demo-Factory separately
when connector source data is required.

Equivalent Makefile wrappers are available:

```bash
make compose-up
make compose-ps
make compose-logs
make compose-config
make compose-down
```

## Inspect FIP

List containers and their health:
Expand Down Expand Up @@ -151,8 +184,7 @@ When service dependencies or Dockerfiles change, rebuild FIP:
docker compose -f infra/docker/docker-compose.yml up --build
```

If a future issue adds multiple service images and only one service needs a
rebuild, prefer rebuilding that service by name once it exists:
If only one service needs a rebuild, prefer rebuilding that service by name:

```bash
docker compose -f infra/docker/docker-compose.yml up --build api
Expand Down
8 changes: 8 additions & 0 deletions docs/runtime/TROUBLESHOOTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,14 @@ docker compose -f infra/docker/docker-compose.yml logs -f
curl http://localhost:8000/connection-profiles
```

The FIP Compose connector worker uses these default local source variables:

```env
DEMO_FACTORY_HOST=host.docker.internal
DEMO_FACTORY_OPCUA_ENDPOINT=opc.tcp://host.docker.internal:4840/ofi/demo
CONNECTOR_INTERVAL_SECONDS=30
```

Then use the read-only test endpoint for a configured profile:

```bash
Expand Down
Loading
Loading