-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #826 from bcgov/dev
Dev
- Loading branch information
Showing
57 changed files
with
1,943 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
name: Document Services CD | ||
|
||
|
||
on: | ||
push: | ||
branches: | ||
- dev | ||
- main | ||
- dev-marshal | ||
- test-marshal | ||
- dev-rook | ||
- test-rook | ||
paths: | ||
- "computingservices/DocumentServices/**" | ||
- ".github/workflows/documentservice-cd.yml" | ||
|
||
defaults: | ||
run: | ||
shell: bash | ||
working-directory: ./computingservices/DocumentServices | ||
|
||
env: | ||
APP_NAME: "reviewer-documentservice" | ||
TOOLS_NAME: "${{secrets.OPENSHIFT4_REPOSITORY}}" | ||
|
||
jobs: | ||
documentServices-cd-by-push: | ||
runs-on: ubuntu-20.04 | ||
|
||
if: github.event_name == 'push' && github.repository == 'bcgov/foi-docreviewer' | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Set ENV variables for dev branch | ||
if: ${{ github.ref_name == 'dev' }} | ||
shell: bash | ||
run: | | ||
echo "For ${{ github.ref_name }} branch" | ||
echo "TAG_NAME=dev" >> $GITHUB_ENV | ||
echo "BRANCH_NAME=dev" >> $GITHUB_ENV | ||
echo "ENV_NAME=dev" >> $GITHUB_ENV | ||
- name: Set ENV variables for main branch | ||
if: ${{ github.ref_name == 'main' }} | ||
shell: bash | ||
run: | | ||
echo "For ${{ github.ref_name }} branch" | ||
echo "TAG_NAME=test" >> $GITHUB_ENV | ||
echo "BRANCH_NAME=main" >> $GITHUB_ENV | ||
echo "ENV_NAME=test" >> $GITHUB_ENV | ||
- name: Set ENV variables for dev-marshal branch | ||
if: ${{ github.ref_name == 'dev-marshal' }} | ||
run: | | ||
echo "For ${{ github.ref_name }} branch" | ||
echo "TAG_NAME=dev-marshal" >> $GITHUB_ENV | ||
echo "BRANCH_NAME=dev-marshal" >> $GITHUB_ENV | ||
echo "ENV_NAME=dev" >> $GITHUB_ENV | ||
- name: Set ENV variables for test-marshal branch | ||
if: ${{ github.ref_name == 'test-marshal' }} | ||
run: | | ||
echo "For ${{ github.ref_name }} branch" | ||
echo "TAG_NAME=test-marshal" >> $GITHUB_ENV | ||
echo "BRANCH_NAME=test-marshal" >> $GITHUB_ENV | ||
echo "ENV_NAME=test" >> $GITHUB_ENV | ||
- name: Set ENV variables for dev-rook branch | ||
if: ${{ github.ref_name == 'dev-rook' }} | ||
run: | | ||
echo "For ${{ github.ref_name }} branch" | ||
echo "TAG_NAME=dev-rook" >> $GITHUB_ENV | ||
echo "BRANCH_NAME=dev-rook" >> $GITHUB_ENV | ||
echo "ENV_NAME=dev" >> $GITHUB_ENV | ||
- name: Set ENV variables for test-rook branch | ||
if: ${{ github.ref_name == 'test-rook' }} | ||
run: | | ||
echo "For ${{ github.ref_name }} branch" | ||
echo "TAG_NAME=test-rook" >> $GITHUB_ENV | ||
echo "BRANCH_NAME=test-rook" >> $GITHUB_ENV | ||
echo "ENV_NAME=test" >> $GITHUB_ENV | ||
- name: Login Openshift | ||
shell: bash | ||
run: | | ||
oc login --server=${{secrets.OPENSHIFT4_LOGIN_REGISTRY}} --token=${{secrets.OPENSHIFT4_SA_TOKEN}} | ||
- name: Tools project | ||
shell: bash | ||
run: | | ||
oc project ${{ env.TOOLS_NAME }}-tools | ||
- name: Build from ${{ env.BRANCH_NAME }} branch | ||
shell: bash | ||
run: | | ||
oc patch bc/${{ env.APP_NAME }}-build -p '{"spec":{"source":{"contextDir":"/computingservices/DocumentServices","git":{"ref":"${{ env.BRANCH_NAME }}"}}}}' | ||
- name: Start Build Openshift | ||
shell: bash | ||
run: | | ||
oc start-build ${{ env.APP_NAME }}-build --wait | ||
- name: Tag+Deploy for ${{ env.TAG_NAME }} | ||
shell: bash | ||
run: | | ||
oc tag ${{ env.APP_NAME }}:latest ${{ env.APP_NAME }}:${{ env.TAG_NAME }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
name: Document Services CI | ||
|
||
|
||
on: | ||
pull_request: | ||
branches: | ||
- main | ||
- dev | ||
- dev-marshal | ||
- test-marshal | ||
- dev-rook | ||
- test-rook | ||
paths: | ||
- "computingservices/DocumentServices/**" | ||
|
||
defaults: | ||
run: | ||
shell: bash | ||
working-directory: ./computingservices/DocumentServices | ||
|
||
jobs: | ||
docker-build-check: | ||
runs-on: ubuntu-20.04 | ||
name: Build dockerfile to ensure it works | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: docker build to check strictness | ||
id: docker-build | ||
run: | | ||
docker build -f Dockerfile.local . | ||
python-build-check: | ||
runs-on: ubuntu-20.04 | ||
name: Build python to ensure it works | ||
|
||
strategy: | ||
matrix: | ||
# python-version: [3.6, 3.7, 3.8, 3.9] | ||
python-version: [3.9] | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Set up Python ${{ matrix.python-version }} | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install flake8 pytest | ||
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
api/reviewer_api/services/external/documentserviceproducerservice.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import os | ||
from walrus import Database | ||
from reviewer_api.models.default_method_result import DefaultMethodResult | ||
import logging | ||
from os import getenv | ||
|
||
class documentserviceproducerservice: | ||
"""This class is reserved for integration with event queue (currently redis streams).""" | ||
|
||
host = os.getenv("DOCUMENTSERVICE_REDIS_HOST") | ||
port = os.getenv("DOCUMENTSERVICE_REDIS_PORT") | ||
password = os.getenv("DOCUMENTSERVICE_REDIS_PASSWORD") | ||
|
||
db = Database(host=host, port=port, db=0, password=password) | ||
|
||
def add(self, payload): | ||
try: | ||
stream = self.db.Stream(self.__streamkey()) | ||
msgid = stream.add(payload, id="*") | ||
return DefaultMethodResult(True, "Added to stream", msgid.decode("utf-8")) | ||
except Exception as err: | ||
logging.error("Error in contacting Redis Stream") | ||
logging.error(err) | ||
return DefaultMethodResult(False, err, -1) | ||
|
||
def __streamkey(self): | ||
return getenv("DOCUMENTSERVICE_STREAM_KEY") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
__pycache__/* | ||
*.pyc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
|
||
#Properties of Document Service - Begin | ||
DOCUMENTSERVICE_REDIS_HOST= | ||
DOCUMENTSERVICE_REDIS_PORT= | ||
DOCUMENTSERVICE_REDIS_PASSWORD= | ||
DOCUMENTSERVICE_STREAM_KEY=DOCUMENTSERVICE | ||
|
||
ZIPPER_REDIS_HOST= | ||
ZIPPER_REDIS_PORT= | ||
ZIPPER_REDIS_PASSWORD= | ||
ZIPPER_STREAM_KEY=ZIPPER_STREAM | ||
|
||
DOCUMENTSERVICE_DB_HOST= | ||
DOCUMENTSERVICE_DB_NAME= | ||
DOCUMENTSERVICE_DB_PORT= | ||
DOCUMENTSERVICE_DB_USER= | ||
DOCUMENTSERVICE_DB_PASSWORD= | ||
|
||
DOCUMENTSERVICE_S3_HOST= | ||
DOCUMENTSERVICE_S3_REGION= | ||
DOCUMENTSERVICE_S3_SERVICE= | ||
DOCUMENTSERVICE_S3_ENV= | ||
|
||
FOI_DB_USER= | ||
FOI_DB_PASSWORD= | ||
FOI_DB_NAME= | ||
FOI_DB_HOST= | ||
FOI_DB_PORT= | ||
#Properties of Document Service - End |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
FROM artifacts.developer.gov.bc.ca/docker-remote/python:3.10.8-buster | ||
|
||
# Keeps Python from generating .pyc files in the container | ||
ENV PYTHONDONTWRITEBYTECODE=1 | ||
|
||
# Turns off buffering for easier container logging | ||
ENV PYTHONUNBUFFERED=1 | ||
|
||
RUN useradd --create-home --shell /bin/bash app_user | ||
WORKDIR /home/app_user | ||
COPY requirements.txt ./ | ||
RUN apt-get update \ | ||
&& apt-get -y install libpq-dev gcc \ | ||
&& pip install psycopg2 | ||
RUN pip install --no-cache-dir -r requirements.txt | ||
USER app_user | ||
COPY . . | ||
ENTRYPOINT ["/bin/sh", "./entrypoint.sh"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
FROM python:3.10.8 | ||
|
||
# Keeps Python from generating .pyc files in the container | ||
ENV PYTHONDONTWRITEBYTECODE=1 | ||
|
||
# Turns off buffering for easier container logging | ||
ENV PYTHONUNBUFFERED=1 | ||
|
||
RUN useradd --create-home --shell /bin/bash app_user | ||
WORKDIR /home/app_user | ||
COPY requirements.txt ./ | ||
RUN apt-get update \ | ||
&& apt-get -y install libpq-dev gcc \ | ||
&& pip install psycopg2 | ||
RUN pip install --no-cache-dir -r requirements.txt | ||
USER app_user | ||
COPY . . | ||
ENTRYPOINT ["/bin/sh", "./entrypoint.sh"] |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from rstreamio.reader import documentservicestreamreader | ||
|
||
|
||
|
||
if __name__ == '__main__': | ||
documentservicestreamreader.app() |
Oops, something went wrong.