From 040faf8e7865769fe6eac4ad0112e163ba935cab Mon Sep 17 00:00:00 2001 From: YaphetKG Date: Tue, 5 Dec 2023 11:17:44 -0500 Subject: [PATCH 1/4] adding os environ --- src/server.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/server.py b/src/server.py index 2d9b9a7..cd28bd3 100644 --- a/src/server.py +++ b/src/server.py @@ -1,4 +1,5 @@ from fastapi import FastAPI +import os from fastapi.middleware.cors import CORSMiddleware from reasoner_pydantic import Response as PDResponse, Result as PDResult, Analysis as PDAnalysis, KnowledgeGraph as PDKG from src.redis_connector import RedisConnection @@ -24,7 +25,14 @@ ) descender = Descender() -rc = RedisConnection("localhost", 6379, "nop") +REDIS_HOST = os.environ.get("REDIS_HOST", "localhost") +REDIS_PORT = int(os.environ.get("REDIS_PORT", "6379")) +REDIS_PASSWORD = os.environ.get("REDIS_PASSWORD") +rc = RedisConnection( + REDIS_HOST, + REDIS_PORT, + REDIS_PASSWORD + ) @APP.post("/query", tags=["Query"], response_model=PDResponse, response_model_exclude_none=True, status_code=200) From c61a07708739c5a15f435e6117fd0f64c8c66051 Mon Sep 17 00:00:00 2001 From: YaphetKG Date: Tue, 5 Dec 2023 11:18:00 -0500 Subject: [PATCH 2/4] add docker image and workflow --- .github/workflows/release.yml | 42 +++++++++++++++++++++++++++++++++++ .github/workflows/tester.yml | 37 ++++++++++++++++++++++++++++++ Dockerfile | 20 +++++++++++++++++ 3 files changed, 99 insertions(+) create mode 100644 .github/workflows/release.yml create mode 100644 .github/workflows/tester.yml create mode 100644 Dockerfile diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..9c1904c --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,42 @@ +name: 'Release a new version of Redis-TPF to Github Packages' + +on: + release: + types: [published] + +env: + REGISTRY: ghcr.io + +jobs: + push_to_registry: + name: Push Docker image to GitHub Packages tagged with "latest" and version number. + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + steps: + - name: Check out the repo + uses: actions/checkout@v2 + - name: Get the version + id: get_version + run: echo ::set-output name=VERSION::${GITHUB_REF/refs\/tags\//} + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38 + with: + images: + ghcr.io/${{ github.repository }} + - name: Login to ghcr + uses: docker/login-action@v1 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + - name: Push to GitHub Packages + uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc + with: + context: . + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + build-args: BRANCH_NAME=${{ github.event.release.target_commitish }} diff --git a/.github/workflows/tester.yml b/.github/workflows/tester.yml new file mode 100644 index 0000000..26270fe --- /dev/null +++ b/.github/workflows/tester.yml @@ -0,0 +1,37 @@ +name: 'test' + +on: [push] + +jobs: + test: + name: test + runs-on: ubuntu-latest + strategy: + matrix: + python-version: [3.11.0] + steps: + - name: Checkout the repository + uses: actions/checkout@v2 + + - name: Create environment variables + run: | + echo "PYTHONPATH=$PWD" >> $GITHUB_ENV + + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python-version }} + + - name: Run SOLR + run: docker run --name name_lookup -d -p 8983:8983 -t solr -DzkRun + + - name: Install dependencies + run: | + if [ -f requirements.txt ]; then pip install -r requirements.txt; fi + + - name: Install pytest + run: pip install pytest + + - name: Run the tests + run: | + python -m pytest tests/ diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..3d8a205 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,20 @@ +from ghcr.io/translatorsri/renci-python-image:3.11.5 + + + +# make a directory for the repo +RUN mkdir /repo + +# go to the directory where we are going to upload the repo +WORKDIR /repo + +RUN mkdir redis-tpf +RUN chown nru redis-tpf +USER nru + +COPY . redis-tpf + +WORKDIR redis-tpf + +RUN pip install -r requirements.txt + From a01a56330704fae12b125bde26cb76fdd028242e Mon Sep 17 00:00:00 2001 From: YaphetKG Date: Tue, 5 Dec 2023 11:24:25 -0500 Subject: [PATCH 3/4] change to redis-container --- .github/workflows/tester.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/tester.yml b/.github/workflows/tester.yml index 26270fe..a4f6756 100644 --- a/.github/workflows/tester.yml +++ b/.github/workflows/tester.yml @@ -22,8 +22,8 @@ jobs: with: python-version: ${{ matrix.python-version }} - - name: Run SOLR - run: docker run --name name_lookup -d -p 8983:8983 -t solr -DzkRun + - name: Run redis + run: docker run --name redis-container -d -p 6379:6379 -t redis --password nop - name: Install dependencies run: | From e558156d5eab9ed2fd8f5a9572a0cd3f0d11ee7b Mon Sep 17 00:00:00 2001 From: YaphetKG Date: Thu, 7 Dec 2023 09:53:53 -0500 Subject: [PATCH 4/4] adding python path , redis connector password --- Dockerfile | 5 +++++ src/redis_connector.py | 14 +++++++------- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/Dockerfile b/Dockerfile index 3d8a205..9e6aab7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,9 @@ from ghcr.io/translatorsri/renci-python-image:3.11.5 +RUN mkdir /home/nru + +RUN chown nru /home/nru # make a directory for the repo RUN mkdir /repo @@ -14,7 +17,9 @@ USER nru COPY . redis-tpf + WORKDIR redis-tpf +ENV PYTHONPATH=/repo/redis-tpf RUN pip install -r requirements.txt diff --git a/src/redis_connector.py b/src/redis_connector.py index d1e9822..c303aac 100644 --- a/src/redis_connector.py +++ b/src/redis_connector.py @@ -4,13 +4,13 @@ class RedisConnection: # it is a context manager and can be used in a with statement def __init__(self,host,port,password): self.r = [] - self.r.append(redis.StrictRedis(host=host, port=port, db=0)) # , password=password) - self.r.append(redis.StrictRedis(host=host, port=port, db=1)) # , password=password) - self.r.append(redis.StrictRedis(host=host, port=port, db=2)) # , password=password) - self.r.append(redis.StrictRedis(host=host, port=port, db=3)) # , password=password) - self.r.append(redis.StrictRedis(host=host, port=port, db=4)) # , password=password) - self.r.append(redis.StrictRedis(host=host, port=port, db=5)) # , password=password) - self.r.append(redis.StrictRedis(host=host, port=port, db=6)) # , password=password) + self.r.append(redis.StrictRedis(host=host, port=port, db=0, password=password)) + self.r.append(redis.StrictRedis(host=host, port=port, db=1, password=password)) + self.r.append(redis.StrictRedis(host=host, port=port, db=2, password=password)) + self.r.append(redis.StrictRedis(host=host, port=port, db=3, password=password)) + self.r.append(redis.StrictRedis(host=host, port=port, db=4, password=password)) + self.r.append(redis.StrictRedis(host=host, port=port, db=5, password=password)) + self.r.append(redis.StrictRedis(host=host, port=port, db=6, password=password)) self.p = [ rc.pipeline() for rc in self.r ] def __enter__(self): return self