reply:10/19

You’re right: the current repository doesn’t include a docker-compose.yml.
The earlier guide section was generic and accidentally referenced a different project’s local-Kubernetes instructions. For this repo, local development is docker-compose first (K8s is optional).

Please drop the files below into the repo root and you can run locally right away.


1) docker-compose.yml (place at repo root)

version: "3.9"

services:
  db:
    image: postgres:15-alpine
    container_name: portal-db
    environment:
      POSTGRES_USER: ${DB_USER}
      POSTGRES_PASSWORD: ${DB_PASSWORD}
      POSTGRES_DB: ${DB_NAME}
    ports:
      - "5432:5432"
    volumes:
      - db_data:/var/lib/postgresql/data
      # auto-init schema & seed for local dev
      - ./dev/sql:/docker-entrypoint-initdb.d:ro
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U $$POSTGRES_USER -d $$POSTGRES_DB"]
      interval: 5s
      timeout: 3s
      retries: 20

  api:
    build:
      context: .
      dockerfile: Dockerfile
    container_name: portal-api
    env_file:
      - ./.env
    environment:
      # If your code reads DATABASE_URL, keep this; otherwise adapt to your settings.
      DATABASE_URL: postgresql+psycopg2://${DB_USER}:${DB_PASSWORD}@db:5432/${DB_NAME}
      APP_PORT: "8080"
    ports:
      - "8080:8080"
    depends_on:
      db:
        condition: service_healthy
    command: >
      sh -c "
      # run migrations here if you use Alembic; otherwise remove this line
      # alembic upgrade head || true;
      uvicorn app.main:app --host 0.0.0.0 --port 8080
      "

volumes:
  db_data:

メモ: もし本リポジトリに Dockerfile がない場合は、既存のイメージ名を api.image: ... に差し替えるか、簡易 Dockerfile を追加してください。


2) .env.example(コピーして .env を作成)

# Postgres
DB_USER=portal
DB_PASSWORD=portal
DB_NAME=portal

# Optional app settings
APP_ENV=local
LOG_LEVEL=INFO

3) 最小スキーマ&シード(ローカル検証用)

下記を dev/sql/10_schema.sqldev/sql/20_seed.sql として保存してください(compose が起動時に自動適用します)。

dev/sql/10_schema.sql

-- Minimal DB function used by the app (safe fallback)
CREATE OR REPLACE FUNCTION public._pick_jp_datatype_label(t text)
RETURNS text LANGUAGE sql AS $$
  SELECT CASE lower($1)
           WHEN 'char' THEN 'テキスト'
           WHEN 'text' THEN 'テキスト'
           WHEN 'integer' THEN '整数'
           WHEN 'float' THEN '小数'
           WHEN 'boolean' THEN '真偽'
           WHEN 'date' THEN '日付'
           WHEN 'datetime' THEN '日時'
           ELSE '文字列'
         END;
$$;

-- IR sources (what import endpoints read)
CREATE TABLE IF NOT EXISTS public.ir_field_src (
  model_table   text NOT NULL,
  field_name    text NOT NULL,
  ttype         text,
  label_ja_jp   text,
  label_en_us   text,
  notes         text
);

CREATE TABLE IF NOT EXISTS public.ir_view_src (
  action_xmlid       text PRIMARY KEY,
  action_id          integer,
  action_name        text,
  model_label        text,
  model_tech         text,
  model_table        text,
  view_types         jsonb,
  primary_view_type  text,
  help_i18n_html     jsonb,
  help_ja_html       text,
  help_ja_text       text,
  help_en_html       text,
  help_en_text       text,
  view_mode          text,
  context            jsonb,
  domain             jsonb,
  ai_purpose         text
);

-- App tables
CREATE TABLE IF NOT EXISTS public.portal_fields (
  id            bigserial PRIMARY KEY,
  model         text NOT NULL,
  model_table   text,
  field_name    text NOT NULL,
  ttype         text,
  label_i18n    jsonb,
  notes         text,
  origin        text,
  "データ型"     text DEFAULT '文字列',
  created_at    timestamptz DEFAULT now(),
  updated_at    timestamptz DEFAULT now(),
  CONSTRAINT uq_portal_fields UNIQUE (model, field_name)
);

CREATE TABLE IF NOT EXISTS public.portal_view_common (
  id                bigserial PRIMARY KEY,
  action_xmlid      text UNIQUE NOT NULL,
  action_id         integer,
  action_name       text,
  model_label       text,
  model_tech        text,
  model_table       text,
  view_types        jsonb,
  primary_view_type text,
  help_ja_text      text,
  help_en_text      text,
  ai_purpose        text,
  help_i18n_html    jsonb,
  display_fields    jsonb,
  default_filters   jsonb,
  context           jsonb,
  domain            jsonb,
  created_at        timestamptz DEFAULT now(),
  updated_at        timestamptz DEFAULT now()
);

dev/sql/20_seed.sql

-- minimal seed so import endpoints have something to read
-- stock.picking / origin
INSERT INTO public.ir_field_src(model_table, field_name, ttype, label_ja_jp, label_en_us, notes)
VALUES ('stock_picking','origin','char','参照元','Source Document','Reference of the document')
ON CONFLICT DO NOTHING;

-- a view/action to test /portal/view_common/import
INSERT INTO public.ir_view_src(
  action_xmlid, action_id, action_name, model_tech, model_table,
  view_types, primary_view_type, help_ja_text, help_en_text, ai_purpose
) VALUES (
  'stock.action_picking_tree_all', 1, 'Pickings', 'stock.picking', 'stock_picking',
  '["tree","form"]'::jsonb, 'tree',
  '在庫移動一覧', 'Stock transfers', 'Find and manage transfers'
)
ON CONFLICT (action_xmlid) DO NOTHING;

4) Run

cp .env.example .env
docker compose up -d --build

# verify
curl http://localhost:8080/healthz
open http://localhost:8080/docs

Quick checks that match your earlier tests:

# Field import (reads from ir_field_src)
curl -s -X POST 'http://localhost:8080/portal/field/import' \
  -H 'content-type: application/json' \
  -d '{ "model": "stock.picking", "fields": ["origin"] }'

# View common import (reads from ir_view_src)
curl -s -X POST 'http://localhost:8080/portal/view_common/import' \
  -H 'content-type: application/json' \
  -d '{ "action_xmlids": ["stock.action_picking_tree_all"] }'

Clarification – Compose is the official local path; Minikube notes corrected

Thanks for checking. The earlier message stands:

  • The official local run path for this repo is Docker Compose + .env (there’s no apply_dev.sh in this repo).
  • Minikube is optional, only for those who prefer a local K8s workflow.

Small corrections to avoid confusion:

  • Ignore the “undefined” lines you saw — those were formatting artifacts.
  • If you do use Minikube, please pass a single DATABASE_URL env/secret so it matches this repo’s configuration.

Minikube quick notes (optional):

# Start Minikube
minikube start --cpus=4 --memory=6g

# Namespace
kubectl create ns portal

# App config (optional)
kubectl -n portal create configmap portal-env \
  --from-literal=APP_ENV=local \
  --from-literal=LOG_LEVEL=INFO

# Secrets (use DATABASE_URL so it’s consistent with this repo)
kubectl -n portal create secret generic portal-secrets \
  --from-literal=DATABASE_URL='postgresql+psycopg2://portal:portal@postgres:5432/portal' \
  --from-literal=OPENAI_API_KEY=''

# Apply manifests (if you keep K8s manifests in this repo)
kubectl -n portal apply -f k8s/postgres.yaml
# kubectl -n portal apply -f k8s/chroma.yaml   # only if this service is used
kubectl -n portal apply -f k8s/api.yaml

# Access the API
kubectl -n portal port-forward svc/api 8080:8080
# open http://localhost:8080/docs

If you follow the .env + docker compose guide we shared, you can run the backend locally without Kubernetes, which is the supported path for this repository. Minikube above is just for those who prefer local K8s.


Comments

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です