dockergithub-actionsopensearch

Run OpenSearch image in Docker on GitHub Actions


I need to validate test cases on any pull or push command on GitHub for which I am using GitHub Actions. Now in this test cases I need to query OpenSearch to perform end to end testing.

In order to run my test cases I need an OpenSearch URL. So I added a step which runs Docker image of OpenSearch. And the step runs successfully but now when I try to query OpenSearch URL I get following error:

enter image description here

Step definition:

  - name: Setup opensearch
    uses: addnab/docker-run-action@v3
    with:
      image: opensearchproject/opensearch:latest
      options:  --entrypoint ./opensearch-docker-entrypoint.sh -p 9200:9200 -p 9600:9600 -e OPENSEARCH_INITIAL_ADMIN_PASSWORD=bgnYFGR2RhN3SCX -e "discovery.type=single-node"

  - name: Test opensearch
    run: curl -X GET "http://localhost:9200" -ku admin:bgnYFGR2RhN3SCX

What can I do to fix this issue or is there a better way to implement this functionality?


Latest update:

I tried using service containers and ran into following error: enter image description here

Step defination:

name: Run Lint and Unit Test on PR
on:
  push:
    branches:
      - main
  pull_request:

jobs:

  run-lint-and-unit-tests:
    name: Run Lint and Unit Tests and Coverage
    runs-on: ubuntu-latest
    services:
      opensearch:
        image: opensearchproject/opensearch:latest
        env:
          OPENSEARCH_INITIAL_ADMIN_PASSWORD: bgnYFGR2RhN3SCX
        options: >-
          -e "discovery.type=single-node"
        ports:
          - 9200:9200
          - 9600:9600

    steps:
      - name: Set actions/checkout
        uses: actions/checkout@v4
        with:
          fetch-depth: 0

      - name: Set up Python 3.12
        uses: actions/setup-python@v5
        with:
          python-version: '3.12'
          cache: 'pip'

      - name: Test opensearch
        run: curl -X GET "http://0.0.0.0:9200" -ku admin:bgnYFGR2RhN3SCX

Solution

  • Here's a working example with service container:

    name: opensearch_service_container
    
    on: workflow_dispatch
    
    jobs:
      ci:
        runs-on: ubuntu-latest
    
        services:
          opensearch:
            image: opensearchproject/opensearch:latest
            options: >-
              -e OPENSEARCH_INITIAL_ADMIN_PASSWORD=bgnYFGR2RhN3SCX
              -e "discovery.type=single-node"
            ports:
              - 9200:9200
              - 9600:9600
    
        steps:
        - name: Update
          run: sudo apt update && sudo apt upgrade -y
    
        - name: Check
          run: |
            curl -X GET "https://localhost:9200" -ku admin:bgnYFGR2RhN3SCX
            curl -X GET "https://localhost:9200/_cat/nodes?v" -ku admin:bgnYFGR2RhN3SCX
            curl -X GET "https://localhost:9200/_cat/plugins?v" -ku admin:bgnYFGR2RhN3SCX
    

    Output:

    output

    On Ubuntu 22.04, curl command failed with this error:

    error:0A000126:SSL routines::unexpected eof while reading

    This SO thread, OpenSSL Error messages: error:0A000126:SSL routines::unexpected eof while reading, helped fix that. After adding update/upgrade step, it worked just fine.

    The ubuntu-latest label is currently pointed to Ubuntu 22.04 and is being migrated to Ubuntu 24.04 as announced in the changelog.

    However, on Ubuntu 24.04 (ubuntu-24.04), I got this error:

    curl: (35) OpenSSL SSL_connect: SSL_ERROR_SYSCALL in connection to localhost:9200

    Again, adding update/upgrade step helped fix this too.