Add Docker Compose stack (Meilisearch + API image) and compose-based Task targets
This commit is contained in:
1 parent
a9674ce14e
commit
d51eda8290
4 files changed
+80
-16
No files matched your search
+14
@@ -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"]
|
||||
@@ -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 |
|
||||
|
||||
+23
-13
@@ -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
|
||||
|
||||
@@ -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:
|
||||
Reference in new issue
Block a user