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

Git workflow docker #3

Merged
merged 4 commits into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -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 }}
37 changes: 37 additions & 0 deletions .github/workflows/tester.yml
Original file line number Diff line number Diff line change
@@ -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/
25 changes: 25 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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

14 changes: 7 additions & 7 deletions src/redis_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 9 additions & 1 deletion src/server.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)
Expand Down
Loading