Start Elasticsearch with a Github Action (#142)

This commit is contained in:
Tanay Soni 2020-06-09 12:46:15 +02:00 committed by GitHub
parent 2e4d2e792b
commit 180dc8cbd6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 7 deletions

View File

@ -13,16 +13,31 @@ jobs:
steps:
- uses: actions/checkout@v2
- name: Configure sysctl limits for Elasticsearch
run: |
sudo swapoff -a
sudo sysctl -w vm.swappiness=1
sudo sysctl -w fs.file-max=262144
sudo sysctl -w vm.max_map_count=262144
- name: Run Elasticsearch
uses: elastic/elastic-github-actions/elasticsearch@25ad91e35aeee806711d335fc9dec7927ae49bc6
with:
stack-version: 7.6.0
- name: Set up Python 3.7
uses: actions/setup-python@v2
with:
python-version: 3.7
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pytest
pip install -r requirements.txt
pip install -e .
- name: Test with pytest
run: |
cd test && pytest

View File

@ -1,10 +1,10 @@
import tarfile
import time
import urllib.request
from subprocess import Popen, PIPE, STDOUT, run
import pytest
from elasticsearch import Elasticsearch
@pytest.fixture(scope='session')
@ -14,12 +14,17 @@ def elasticsearch_dir(tmpdir_factory):
@pytest.fixture(scope="session")
def elasticsearch_fixture(elasticsearch_dir):
thetarfile = "https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.6.1-linux-x86_64.tar.gz"
ftpstream = urllib.request.urlopen(thetarfile)
thetarfile = tarfile.open(fileobj=ftpstream, mode="r|gz")
thetarfile.extractall(path=elasticsearch_dir)
es_server = Popen([elasticsearch_dir / "elasticsearch-7.6.1/bin/elasticsearch"], stdout=PIPE, stderr=STDOUT)
time.sleep(40)
# test if a ES cluster is already running. If not, download and start an ES instance locally.
try:
client = Elasticsearch(hosts=[{"host": "localhost"}])
client.info()
except:
thetarfile = "https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.6.1-linux-x86_64.tar.gz"
ftpstream = urllib.request.urlopen(thetarfile)
thetarfile = tarfile.open(fileobj=ftpstream, mode="r|gz")
thetarfile.extractall(path=elasticsearch_dir)
es_server = Popen([elasticsearch_dir / "elasticsearch-7.6.1/bin/elasticsearch"], stdout=PIPE, stderr=STDOUT)
time.sleep(40)
@pytest.fixture(scope="session")