From d51eda82905a0efe13f0f343875b0549aaba0564 Mon Sep 17 00:00:00 2001 From: hermes Date: Wed, 9 Sep 2026 21:10:21 +0000 Subject: [PATCH] Add Docker Compose stack (Meilisearch + API image) and compose-based Task targets --- Dockerfile | 14 ++++++++++++++ README.md | 19 ++++++++++++++++--- Taskfile.yml | 36 +++++++++++++++++++++++------------- compose.yaml | 27 +++++++++++++++++++++++++++ 4 files changed, 80 insertions(+), 16 deletions(-) create mode 100644 Dockerfile create mode 100644 compose.yaml diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..fb4518d --- /dev/null +++ b/Dockerfile @@ -0,0 +1,14 @@ +FROM golang:1.27-alpine AS build +WORKDIR /src +COPY go.mod go.sum ./ +RUN go mod download +COPY . . +RUN CGO_ENABLED=0 go build -o /out/api ./cmd/api && CGO_ENABLED=0 go build -o /out/seed ./cmd/seed + +FROM gcr.io/distroless/static-debian12 +WORKDIR /app +COPY --from=build /out/api /out/seed /app/ +COPY data /app/data +EXPOSE 8080 +USER nonroot:nonroot +ENTRYPOINT ["/app/api"] diff --git a/README.md b/README.md index a7e4113..043a1a9 100644 --- a/README.md +++ b/README.md @@ -38,21 +38,34 @@ change without breaking invariants. ## Requirements - Go 1.27+ -- Docker (for `task meili:up`) — or any reachable Meilisearch, set `MEILI_HOST` +- Docker + Compose v2 (for `task meili:up`) — or any reachable Meilisearch, set `MEILI_HOST` - [Task](https://taskfile.dev/installation/) ## Quick start ```bash -task meili:up # Meilisearch v1.24 on :7700 +task meili:up # Compose: Meilisearch v1.24 on :7700 task seed # create index, apply settings, load data/movies.json -task run # API on :8080 +task run # API on :8080 (go run, fast dev loop) # in another shell: task query # runs scripts/demo-queries.sh ``` `task demo` chains up + seed + queries in one go. `task --list` shows everything. +### Everything in containers + +```bash +task up # build API image, start engine + API, seed the index +task meili:logs # tail the engine +task meili:down # stop (keeps the volume) +task meili:reset # stop and drop the index volume +``` + +`compose.yaml` keeps the API behind the `full` profile, so a plain +`docker compose up -d` gives you just the search engine to develop against. +Index data lives in the named volume `meili-data`. + ## API | Method | Path | Description | diff --git a/Taskfile.yml b/Taskfile.yml index 4cc63a3..1628055 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -6,9 +6,6 @@ env: MEILI_INDEX: movies HTTP_ADDR: ":8080" -vars: - MEILI_DATA: .meili-data - tasks: default: desc: List available tasks @@ -41,18 +38,31 @@ tasks: - go build -o bin/seed ./cmd/seed meili:up: - desc: Start Meilisearch in Docker on :7700 + desc: Start Meilisearch via Docker Compose on :7700 cmds: - - docker run -d --name meili-showcase -p 7700:7700 - -e MEILI_MASTER_KEY=$MEILI_MASTER_KEY -e MEILI_ENV=development - -v "$PWD/{{.MEILI_DATA}}:/meili_data" getmeili/meilisearch:v1.24 - status: - - docker ps --filter name=meili-showcase --filter status=running --format '{{"{{"}}.Names{{"}}"}}' | grep -q meili-showcase + - docker compose up -d meilisearch meili:down: - desc: Stop and remove the Meilisearch container + desc: Stop Compose services (keeps the data volume) cmds: - - docker rm -f meili-showcase + - docker compose down + + meili:reset: + desc: Stop Compose services and delete the index volume + cmds: + - docker compose down -v + + meili:logs: + desc: Tail Meilisearch logs + cmds: + - docker compose logs -f meilisearch + + up: + desc: Run engine + API in Compose (API on :8080) + cmds: + - docker compose --profile full up -d --build + - task: meili:wait + - docker compose --profile full run --rm --entrypoint /app/seed api meili:wait: desc: Block until Meilisearch answers /health @@ -88,9 +98,9 @@ tasks: - ./scripts/demo-queries.sh clean: - desc: Remove build artifacts and local index data + desc: Remove build artifacts (see meili:reset for index data) cmds: - - rm -rf bin {{.MEILI_DATA}} + - rm -rf bin ci: desc: fmt + vet + test diff --git a/compose.yaml b/compose.yaml new file mode 100644 index 0000000..1256e3f --- /dev/null +++ b/compose.yaml @@ -0,0 +1,27 @@ +services: + meilisearch: + image: getmeili/meilisearch:v1.24 + container_name: meili-showcase + ports: ["7700:7700"] + environment: + MEILI_MASTER_KEY: ${MEILI_MASTER_KEY:-masterKey} + MEILI_ENV: development + volumes: + - meili-data:/meili_data + + api: + build: . + ports: ["8080:8080"] + environment: + MEILI_HOST: http://meilisearch:7700 + MEILI_MASTER_KEY: ${MEILI_MASTER_KEY:-masterKey} + HTTP_ADDR: ":8080" + depends_on: [meilisearch] + # The API applies index settings at boot and exits if the engine is not up + # yet; restarting is the whole retry policy this demo needs. + restart: unless-stopped + # Only the engine starts by default; add --profile full for the API too. + profiles: ["full"] + +volumes: + meili-data: