Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

What is the best way to use elasticsearch as services in GHA #44

Open
sh977218 opened this issue Dec 9, 2024 · 4 comments
Open

What is the best way to use elasticsearch as services in GHA #44

sh977218 opened this issue Dec 9, 2024 · 4 comments

Comments

@sh977218
Copy link

sh977218 commented Dec 9, 2024

jobs:
  buikd:
    name: build
    runs-on: ubuntu-latest
    services:
      elasticsearch:
        image: elastic/elastic-github-actions/elasticsearch@master
        /*         how do I specific the volume/es's version etc here?
         **
         */
        ports:
        - 9200:9200
    steps:
      - run: curl -X GET http://localhost:9200/_cluster/health
@picandocodigo
Copy link
Member

Hi @sh977218,
I think for using Elasticsearch as a service in GitHub Actions, you'd have to use the docker images instead of this action.

This is untested code, but you can try something like this:

    services:
      elasticsearch:
        image: docker.elastic.co/elasticsearch/elasticsearch:VERSION
        ports:
        - 9200:9200

You can probably pass in the volumes as an option key, something like:

    services:
      elasticsearch:
        image: docker.elastic.co/elasticsearch/elasticsearch:VERSION
        options: >-
           --volume example:example
        ports:
        - 9200:9200

Hope this helps.

@sh977218
Copy link
Author

Hi, @picandocodigo If I remove those 2 lines below, the workflow works fine, as you suggested. Thanks!

    container:
      image: mcr.microsoft.com/playwright:v1.46.0-noble

However, if I use playwright docker image in the workflow, it does not work anymore. Do you know how to fix this?

name: tests
on:
  pull_request:

jobs:
  es-as-service:
    name: Start es as service
    runs-on: ubuntu-latest
    services:
      elasticsearch:
        image: docker.elastic.co/elasticsearch/elasticsearch:7.9.2
        env:
            discovery.type: single-node
        options:
          --health-cmd "curl http://localhost:9200/_cluster/health"
          --health-interval 10s
          --health-timeout 30s
          --health-retries 10
        ports:
          - 9200:9200
    container:
      image: mcr.microsoft.com/playwright:v1.46.0-noble
    steps:
      - uses: actions/checkout@v4

      - run: curl -X GET http://localhost:9200/_cluster/health

      - name: Create es index
        run: curl -X PUT "localhost:9200/heroes"

      - name: Inject data into es
        run: |
          curl -XPOST http://localhost:9200/heroes/doc -H "Content-Type: application/json" -d @test/heroes.json

      - run: curl http://localhost:9200/heroes/_search

@picandocodigo
Copy link
Member

I'm glad Elasticsearch is working now!

I'm not familiar with using services in GitHub Actions with a container. Is there an error? Is it that the container can't reach Elasticsearch when using the playwright image? Maybe there's something in the playwright container that's different from the base ubuntu-latest that makes it so that it can't contact Elasticsearch running on a service?

@sh977218
Copy link
Author

I'm glad Elasticsearch is working now!

I'm not familiar with using services in GitHub Actions with a container. Is there an error? Is it that the container can't reach Elasticsearch when using the playwright image? Maybe there's something in the playwright container that's different from the base ubuntu-latest that makes it so that it can't contact Elasticsearch running on a service?

Yes, I believe the playwright image is within docker container, Elasticsearch is also within in docker container (GitHub Action's services), both run on the docker host 'ubuntu-latest'. Is there anyway for Elasticsearch docker container to establish a bridge network with the Playwright docker container, through the host (Ubuntu), so both dockers are able to be communicated each other?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants