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..a4f6756 --- /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 redis + run: docker run --name redis-container -d -p 6379:6379 -t redis --password nop + + - 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..9e6aab7 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,25 @@ +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 + +# 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 +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 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)