Skip to content

Typesense service fails to initialize in Github Actions #441

Open

Description

@femtozer

Description

I don't know if it's a Typesense or Github Actions issue.
The service fails to initialize because it's "unhealthy".
But health checks are not even sent, Github Actions performs a check with "docker inspect" which seems to fail.
Typesense works well in local (docker-compose) with the same image, env, and ports.

Steps to reproduce

Define a Github Actions workflow with the following service:

jobs:
  test:
    runs-on: ubuntu-latest
    services:
      typesense:
        image: "typesense/typesense:0.21.0"
        env:
          TYPESENSE_API_KEY: abcd
          TYPESENSE_DATA_DIR: /data
          TYPESENSE_ENABLE_CORS: true
        options: --health-cmd "curl http://localhost:8108/health" --health-interval 10s --health-timeout 5s --health-retries 5 
        ports:
          - 8108:8108

Expected Behavior

Service becomes healthy and the workflow can run properly.

Actual Behavior

Service is unhealthy:

/usr/bin/docker inspect --format="{{if .Config.Healthcheck}}{{print .State.Health.Status}}{{end}}" c45d5a57a553df994ce764614c72decb5c59d195c00ce085cf2dcff1ffc885f5
unhealthy
Error: Failed to initialize, typesense service is unhealthy.

Metadata

Typsense Version: 0.21.0

OS: Ubuntu

Activity

  1. jasonbosco commented on Nov 23, 2021

    @jasonbosco
    Member

    Hi @Femt0, I haven't used Github Actions yet, but one thing that stands out to me is that the data dir defined by TYPESENSE_DATA_DIR: /data is not mounted into the docker container in the snippet you shared. So I suspect the container is actually failing to start.

    Are you able to get the docker logs for the Typesense container?

  2. alexanderjulmer commented on Feb 7, 2022

    @alexanderjulmer

    I am facing the same problem.

    I created a demo repo to include only a Typesense container.

    name: typsense-github-action-demo
    
    on:
      push:
        branches: [main]
    
    jobs:
      build:
        runs-on: ubuntu-latest
    
        services:
          typesense:
            image: typesense/typesense:0.22.0
            env:
              TYPESENSE_API_KEY: dskrpt
              TYPESENSE_DATA_DIR: /data
              TYPESENSE_ENABLE_CORS: true
            ports:
              - 8108:8108
            options: >-
              --health-cmd "curl http://127.0.0.1:8108/health"
              --health-interval 10s
              --health-timeout 5s
              --health-retries 5
            volumes:
              - ts_data:/data
    
        steps:
          - uses: actions/checkout@v2
    
          - name: curl Typesense
            run: curl http://localhost:8108/health
    

    You can find the logs here. It seems like the container is not coming up but the volume wasn't the issue.

    I'd greatly appreciate if you could look into this. Having a one-off Typesense instance in my testing workflow would be great.

  3. jasonbosco commented on Feb 7, 2022

    @jasonbosco
    Member

    @alexanderjulmer Are you able to get the docker logs somehow? That should have the actual logs from Typesense (vs Github actions logs)

  4. jasonbosco commented on Feb 7, 2022

    @jasonbosco
    Member

    Also, I wonder if in --health-cmd "curl http://127.0.0.1:8108/health", may be 127.0.0.1 is not the hostname exposed by docker? Wonder if it's typesense (so may be http://typesense/health works) since that's set as the network alias?

  5. alexanderjulmer commented on Feb 7, 2022

    @alexanderjulmer

    I am afraid, I cannot get any more logs. When I remove the options property, I can get Typesense to start and pass a separate health check (see second step) in this demo repo.

    I think the issue is with the --health-cmd which is part of Docker's HEALTHCHECK. I thought it expects a zero exit code but that is what it get's from curl "http://localhost:8108/health returning {"ok":true}.

  6. jasonbosco commented on Feb 7, 2022

    @jasonbosco
    Member

    @alexanderjulmer I was able to replicate the issue by running docker locally with those health checks. It turns out that the curl command was being run inside the container, and the image doesn't have curl installed. So updating the health check to first install curl worked locally for me"

    docker run \
      --name typesense \
      --health-cmd "apt-get update && apt-get install -y curl && curl http://127.0.0.1:8108/health" \
      --health-interval 10s \
      --health-timeout 5s \
      --health-retries 5 \
      -i -p 8108:8108 \
      -v/tmp/typesense-server-data-1c/:/data \
      typesense/typesense:0.22.2 --data-dir /data  --api-key=xyz  --listen-port 8108  --enable-cors

    After about 20s, I see this:

    $ docker inspect --format='{{.State.Health.Status}}' typesense
    starting
    $ docker inspect --format='{{.State.Health.Status}}' typesense
    healthy

    Previously it used to show "unhealthy".

    Could you update the health check in Github actions similarly and see if it works?

  7. jirevwe commented on Aug 16, 2022

    @jirevwe

    I was able to setup a GitHub Actions Typesense runner you can see it here and I'm using it in my project here. Hopefully it can help others too

  8. alexander-schranz commented on Jan 15, 2023

    @alexander-schranz

    I'm also trying to achieve a healthcheck in my docker-compose file via as I'm using docker-compose locally and in the github CI:

    services:
      typesense:
        image: typesense/typesense:0.24.0.rcn56
        ports:
          - "8108:8108"
        environment:
          TYPESENSE_DATA_DIR: /data
          TYPESENSE_API_KEY: S3CR3T
        # currently not working as curl not available:
        #healthcheck:
        #  test: ["CMD-SHELL", "curl --silent --fail localhost:8108/health || exit 1"]
        #  interval: 5s
        #  timeout: 5s
        #  retries: 10
        volumes:
          - typesense-data:/data
    
    volumes:
      typesense-data:

    I did then try to debug it and run docker ps to get my container id and then did connect then via docker exec -it 3c202f37e9d8 bash into the container.

    I found out that even in the container I can not install curl (not enough space as it seems hard limited) I also did not found any other way to make the healthcheck.

    So I think the best way would be if the typesense/typesense image is shipped with curl so we can make the healthcheck and don't require to create custom containers just for it.

  9. hahouari commented on Apr 22, 2023

    @hahouari

    Thank you for sharing such a piece of code that I was missing, I may add to your solution to fix problem of curl missing if this situation still persists in latest versions:

        healthcheck:
          # there it is installing curl silently if not already installed.
          test: ["CMD-SHELL", "apt install curl -y &>/dev/null || curl --silent --fail localhost:8108/health || exit 1"]
          interval: 5s
          timeout: 5s
          retries: 10

    Again Thank you! I'm new to typesense and docker healthchecks so your code was much helpful. 😄

  10. tonybolzan commented on Nov 1, 2024

    @tonybolzan

    You can use raw bash to make a HTTP request and dont install curl or wget.
    This command can be included in Typesense Docker to call this with cmd name typesense-ping

    healthcheck:
      test: ["CMD", "bash", "-c", "exec 3<>/dev/tcp/localhost/8108 && printf 'GET /health HTTP/1.1\\r\\nConnection: close\\r\\n\\r\\n' >&3 && head -n1 <&3 | grep '200' && exec 3>&-"]
      interval: 10s
      timeout: 1s
  11. almereyda commented on Mar 15, 2025

    @almereyda

    Shipping curl in the image seems to be the preferred resolution with this. Unfortunately I was not able to find the manifests and workflows that build to Docker Hub, why I'm not able to send in a PR.

  12. ZRktty commented on Aug 19, 2025

    @ZRktty

    @tonybolzan Thanks! It works like a charm!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions