Meilisearch: GitHub Actions & GitLab CI
Spin up a real Meilisearch service from your GitHub Actions or GitLab CI pipeline, run your tests against it, and tear it down automatically
Welcome to the Stackhero documentation!
If you need a fast, typo-tolerant search engine that is easy to deploy, Stackhero's Meilisearch cloud service lets you get started in minutes. Here is what you get:
- Custom domain support with integrated HTTPS for secure access.
- Simple, one-click updates. No manual work is needed.
- Consistent performance and strong isolation with your own private, dedicated infrastructure.
You can be up and running with Meilisearch cloud hosting on Stackhero in just 5 minutes. The setup is designed to save you time and keep your deployment straightforward.
This guide will walk you through running a real, dedicated Meilisearch service inside your CI pipeline using either GitHub Actions or GitLab CI. By following these steps, you can test your code against a live Meilisearch instance under production-like conditions, so you no longer need to rely on mocks or simulations. Meilisearch is a fast, open source, typo-tolerant search engine that delivers instant, relevant results out of the box.
Each time your pipeline runs, you will get a brand new Meilisearch instance. This means your tests interact with the same kind of service your users will see in production. The workflow adds Meilisearch to a stack dedicated to CI, waits for it to be ready, retrieves the generated credentials, runs a smoke test using curl, and then always deletes the service once the run is complete.
You will use the Stackhero CLI, a standalone command-line tool that makes launching and managing Stackhero services quick and straightforward.
1. Create an access token and store it as a CI secret
To enable the CLI to work non-interactively, you will need an access token (format: usr-xxxxxx:tokenId). You only need to create this token once and then add it to your CI pipeline as a secure, encrypted secret.
- Create the token: In your Stackhero dashboard, click your profile picture at the top right, go to Your account, then Access tokens, and click Create token.
- For GitHub Actions: In your repository, go to Settings > Secrets and variables > Actions > New repository secret, and enter the token as
STACKHERO_TOKEN. - For GitLab CI: In your project, go to Settings > CI/CD > Variables > Add variable, set the key to
STACKHERO_TOKEN, and check Masked (and Protected if your CI runs only on protected branches).
Do not include your access token directly in your pipeline YAML file. If it is present in YAML, it could be exposed to anyone with repository access and may appear in build logs. Storing it as a CI secret keeps it encrypted and masked, ensuring your token stays secure.
2. Create a stack for your CI, once
Every run adds its own Meilisearch service to one stack that you keep for your CI. You only create it once, from your computer:
stackhero login
stackhero stack-create --name="CI"
You can also create it from your Stackhero dashboard. Runs can overlap safely: each one adds and deletes its own service, and the stack stays ready for the next run.
3. The lifecycle script
Here is a complete example script that manages the full service lifecycle. It demonstrates how little setup is required, just a few commands. You can copy the ready-made YAML for your platform from the sections below.
#!/bin/bash
set -euo pipefail
# STACKHERO_TOKEN is supplied by the CI secret, the CLI picks it up automatically.
stack="CI" # The stack created in step 2
serviceStore="meilisearch" # The Meilisearch service store
instance="10G" # Change this as needed (see step 4)
region="europe" # Region name (see stackhero regions-list)
# 1. Install the client used by the smoke test (as root, or prefix it with sudo)
apt-get update && apt-get install -y --no-install-recommends ca-certificates jq curl
# 2. Install the CLI on the runner
curl -fsSL https://www.stackhero.io/install.sh | STACKHERO_INSTALL_DIR="$HOME/.local/bin" sh
export PATH="$HOME/.local/bin:$PATH"
# 3. Add Meilisearch to the CI stack and capture its service ID
serviceId=$(stackhero --format=script service-add \
--stack="$stack" \
--service-store="$serviceStore" \
--instance="$instance" \
--region="$region")
echo "Service added: $serviceId"
# 4. Delete the service when the script ends, whether it succeeds or fails
trap 'stackhero service-delete --service="$serviceId" --confirm' EXIT
# 5. Wait until the service is running (this usually takes a couple of minutes)
timeout 15m stackhero service-wait-for --service="$serviceId"
# 6. Read the configuration (contains the generated credentials)
config=$(stackhero service-configuration-get --service="$serviceId" --format=json)
# 7. Extract the credentials you need
host=$(echo "$config" | jq -r '.configuration.domain')
# 8. Smoke test: Call the Meilisearch health endpoint.
curl -fsS "https://$host/health" | grep -q '"status":"available"'
echo "✅ Meilisearch is reachable from CI."
The only cleanup is the deletion of the service: the stack stays for the next run. In the YAML below, this deletion is a separate step that the CI always runs, even when a test fails, so you are never billed for a service you no longer use.
timeout 15m puts a limit on the wait. If the service does not start, the run fails within minutes and the service is deleted, instead of waiting for the time limit of your CI.
4. Pick the instance size
The examples below use the entry-level instance 10G for Meilisearch by default. This is a solid choice for most workloads, but you are welcome to adjust it as needed. To view all available instance types for Meilisearch, you can run:
# The NAME column shows the value to pass to --instance
stackhero instances-store-list --service-store=meilisearch
5. GitHub Actions
To get started, you can save the following as .github/workflows/ci.yml. From now on, every push and pull request will run tests against a real Meilisearch instance.
name: CI with Meilisearch
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
timeout-minutes: 30
env:
STACKHERO_TOKEN: ${{ secrets.STACKHERO_TOKEN }}
STACK: CI # The stack created in step 2
INSTANCE: "10G" # Change this as needed (see step 4)
REGION: europe
steps:
- uses: actions/checkout@v4
- name: Install the client and the Stackhero CLI
run: |
sudo sh -c "apt-get update && apt-get install -y --no-install-recommends ca-certificates jq curl"
curl -fsSL https://www.stackhero.io/install.sh | STACKHERO_INSTALL_DIR="$HOME/.local/bin" sh
echo "$HOME/.local/bin" >> "$GITHUB_PATH"
- name: Add the Meilisearch service
run: |
set -euo pipefail
SERVICE_ID=$(stackhero --format=script service-add \
--stack="$STACK" \
--service-store="meilisearch" \
--instance="$INSTANCE" \
--region="$REGION")
echo "SERVICE_ID=$SERVICE_ID" >> "$GITHUB_ENV"
- name: Wait for Meilisearch to be running
run: timeout 15m stackhero service-wait-for --service="$SERVICE_ID"
- name: Run tests against Meilisearch
run: |
set -euo pipefail
config=$(stackhero service-configuration-get --service="$SERVICE_ID" --format=json)
host=$(echo "$config" | jq -r '.configuration.domain')
# Call the Meilisearch health endpoint.
curl -fsS "https://$host/health" | grep -q '"status":"available"'
echo "✅ Meilisearch is reachable from CI."
# You can run your own test suite here using the credentials above ...
- name: Delete the service (always, even on failure)
if: always()
run: |
if [ -n "${SERVICE_ID:-}" ]; then
stackhero service-delete --service="$SERVICE_ID" --confirm
fi
The deletion step is configured with if: always(), so it runs no matter what: after a failed test, and also when you cancel the run. Adding the service and waiting for it are two separate steps, so the service ID is already saved when the wait fails.
6. GitLab CI
You can save this configuration as .gitlab-ci.yml. With this setup, every pipeline run spins up a fresh real Meilisearch for your tests.
test:
image: ubuntu:24.04
timeout: 30m
variables:
STACK: "CI" # The stack created in step 2
INSTANCE: "10G" # Change this as needed (see step 4)
REGION: "europe"
SERVICE_STORE: "meilisearch"
# STACKHERO_TOKEN comes from the CI/CD variable you created in step 1.
script:
- set -euo pipefail
- apt-get update && apt-get install -y --no-install-recommends ca-certificates jq curl
- curl -fsSL https://www.stackhero.io/install.sh | sh
- SERVICE_ID=$(stackhero --format=script service-add --stack="$STACK" --service-store="$SERVICE_STORE" --instance="$INSTANCE" --region="$REGION")
- echo "SERVICE_ID=$SERVICE_ID" > service.env
- timeout 15m stackhero service-wait-for --service="$SERVICE_ID"
- config=$(stackhero service-configuration-get --service="$SERVICE_ID" --format=json)
- host=$(echo "$config" | jq -r '.configuration.domain')
# Call the Meilisearch health endpoint.
- curl -fsS "https://$host/health" | grep -q '"status":"available"'
- echo "✅ Meilisearch is reachable from CI."
# You can run your own test suite here using the credentials above ...
after_script:
- test -f service.env && . ./service.env || true
- >
if [ -n "${SERVICE_ID:-}" ]; then
stackhero service-delete --service="$SERVICE_ID" --confirm
fi
In GitLab, the deletion happens inside after_script. This section runs even when the job fails, so your Meilisearch service is removed and you are not charged for a service you are not using.
In GitLab,
after_scriptruns in a fresh shell. To handle this, the script writes the service ID toservice.envas soon as the service is added, and reloads it before the deletion. This makes sure that even if something fails mid-job, your service is still deleted.
7. Check that nothing is left
A runner that is killed abruptly (a lost machine, for example) cannot run its cleanup. To see the services left in your CI stack, run:
stackhero services-list --stack="CI"
Between two runs, this list is empty. You can delete a leftover service with stackhero service-delete --service=svc-xxxxxx --confirm.
That is the complete CI lifecycle for Meilisearch: add the service to your CI stack, wait, retrieve credentials, smoke-test, and always delete it. Each pipeline run gets a real, isolated service, and nothing is left running when you are done. For more information about available commands and non-interactive STACKHERO_TOKEN authentication, you may want to explore the full CLI documentation.