# PostgreSQL service Run a background PostgreSQL test service through FluentCI's native workspace service manager and Docker backend. Typed PureScript Wasm component; requires FluentCI **v0.17.4+**, with the native services apply/status lifecycle API. ```sh fluentci run postgres start --version 17-alpine fluentci run postgres status fluentci run postgres logs --tail 50 fluentci run postgres logs --tail 50 --follow true fluentci run postgres restart fluentci run postgres stop ``` For live logs, use `logs --follow true`. Press Ctrl-C to stop following; the background service keeps running. The native shorthand is `fluentci logs module-postgres-default -f` in the same project workspace. ## Default profile - Image: `postgres:17-alpine`. - Primary container port: `5432`; exposed TCP ports: `5432`. - Readiness: `exec: pg_isready -h 127.0.0.1 -U fluentci -d fluentci_test`; startup deadline: `60000` ms. - Native recurring health check uses the same probe by default. - Name: `module-postgres-default`; custom names must start with `module-postgres-`. Default environment values are disposable CI fixtures: - `POSTGRES_USER=fluentci` - `POSTGRES_PASSWORD=fluentci-test` - `POSTGRES_DB=fluentci_test` ## Typed configuration and lifecycle --version selects the image tag. --image accepts a complete image/digest reference; do not combine them. Start waits for readiness and returns name, state, backend, host, primary port, endpoint and every container/host port binding. Dynamic ports are returned as allocated; do not assume the host port equals the container port. Restart uses the saved native definition. Reconfiguration requires stop first. Repeated unchanged start reuses the service, and repeated stop is safe. Stop also affects native dependents, while explicit bind/named volume data is preserved. Use project to select the same workspace across calls. Docker must be installed and its daemon and loopback port bindings accessible to the caller. Readiness, Docker/image, manager and health failures propagate without successful startup. Use cleanup/finally to stop manually started services after tests. Public list inputs are comma-separated strings. env uses KEY=VALUE entries; ports use CONTAINER or HOST:CONTAINER; volumes use /CONTAINER or SOURCE:/CONTAINER[:ro|rw]. Optional blank lists retain defaults. Empty entries, invalid selectors and duplicate mappings are rejected before installation. CSV double quotes preserve commas within a literal token. command and readiness-command remain foreground literal argv, without shell expansion. See [COMPONENT.md](./COMPONENT.md) for every named argument, description and native return, [the shared service guide](../README.md) for platform/data/lifecycle semantics, and the [upstream reference](https://hub.docker.com/_/postgres). ## Development Mocked unit/contract tests run in normal module CI. The dedicated Services E2E workflow builds every real component, starts/reuses/restarts/stops it through the native manager, and checks real protocol connectivity sequentially on one runner. No services or images are run by the source generators. License: MIT. ## Compose this module from code Requires FluentCI **0.17.6 or newer** for generated pipeline bindings. From your **caller module's directory**, add the dependency: ```sh fluentci add postgres --path /path/to/fluentci-modules/services/postgres ``` For a published module, use `fluentci add @fluentci.io/postgres@VERSION` with an available version. Commit the caller's manifest and lockfile. FluentCI generates named bindings from the installed component's WIT; no handwritten FFI or CLI subprocess is needed. Include generated source directories in the caller's SDK project. The callee can use a different SDK from the caller. Start postgres for integration tests using postgres:17-alpine. Return the allocated endpoint to the caller; use it when configuring your test client. Replace the sample organization, paths and identifiers with your own. Configure credentials through your CI secret provider before running authenticated operations. Optional arguments use the callee's defaults, and public list fields use comma-separated strings. See [COMPONENT.md](./COMPONENT.md) for argument descriptions and return types. These examples use the generated composition API and builder chaining in FluentCI 0.17.6; full cross-SDK compilation and execution coverage is still pending. See [composition support and limitations](../../docs/COMPOSITION.md). For services, register `stop` with the same project/name in failure-safe cleanup before running tests. A later ordinary `stop` step will be skipped when a preceding step fails. This short example starts the service using its default scoped name; it is not a complete service lifecycle. Elixir Flow does not yet offer failure-safe cleanup. ### PureScript ```purescript module Main where import Prelude import Effect (Effect) import FluentCI.Flow as Flow import FluentCI.Modules.Postgres as Postgres run :: Effect String run = Flow.pipeline "postgres-start" # Flow.workdir "." # Postgres.start (Postgres.startArgs) # Flow.map (\result -> result.endpoint) # Flow.run ``` ### Gleam ```gleam import fluentci/flow import fluentci_modules/postgres pub fn run() -> String { flow.pipeline("postgres-start") |> flow.workdir(".") |> postgres.start(postgres.start_args()) |> flow.map(fn(result) { result.endpoint }) |> flow.run } ``` Use Gleam's JavaScript target for the Wasm guest. BEAM escripts used for repository automation are separate from component guests. ### Elixir ```elixir defmodule Main do use FluentCI.Plugin alias FluentCI.Flow alias FluentCI.Modules.Postgres defplugin run do Flow.pipeline("postgres-start") |> Flow.workdir(".") |> Postgres.start(%{}) |> Flow.stdout() end end ``` Elixir compiles this sequence to Rust/Wasm. Its initial Flow API does not yet provide the typed result callbacks or cleanup combinators of the other examples. ### ClojureScript ```clojure (ns main.plugin (:require [fluentci.flow :as flow] [fluentci-modules.postgres :as postgres])) (defn run [] (-> (flow/pipeline "postgres-start") (flow/workdir ".") (postgres/start {}) flow/run!)) ``` ### ReScript ```rescript let run = (): string => Flow.pipeline("postgres-start") ->Flow.workdir(".") ->FluentciModulesPostgres.start(FluentciModulesPostgres.startArgs) ->Flow.map(result => result.endpoint) ->Flow.run ``` ### Python ```python from fluentci.flow import pipeline from fluentci_modules import postgres def run() -> str: return ( pipeline("postgres-start") .workdir(".") .pipe(postgres.start, {}) .map(lambda result: result.endpoint) .run() ) ``` ### TypeScript ```typescript import * as flow from "./fluentci_modules/flow"; import * as postgres from "./fluentci_modules/postgres/index"; export function run(): string { return flow.pipeline("postgres-start") .workdir(".") .pipe(postgres.start, {}) .map(result => result.endpoint) .run(); } ``` Python and TypeScript use FluentCI builder chains: `.pipe(module.function, args)` composes generated module functions with `.workdir`, `.env`, and `.exec`. Functions return a pipeline carrying their typed result. Use a generated result callback (`With`/`_with`, or a callback argument in TypeScript/Python) when a later module needs a preceding result; use Flow's map operation to select a result field. Execution begins at `run` (or the Elixir plugin terminal), in declared order. ### Exported functions | Function | Purpose | | --- | --- | | `start` | Start an idempotent background service through FluentCI’s native workspace service manager and wait for readiness. | | `stop` | Stop only this named service through the native manager; preserve explicitly mounted data. Native dependents are stopped too. | | `restart` | Restart the existing native service definition and wait for readiness. | | `status` | Return the service’s native lifecycle state and actual loopback port bindings. | | `logs` | Read native service logs; optionally follow new output until interrupted, without starting or stopping a service. |