Skip to content

Commit

Permalink
Merge pull request #3 from PSNAppz/develop
Browse files Browse the repository at this point in the history
Example Bank API GitHub Workflows
  • Loading branch information
venky-ganapathy authored Aug 12, 2024
2 parents 1fc0d37 + 8a52184 commit 8c96a1f
Show file tree
Hide file tree
Showing 22 changed files with 340 additions and 443 deletions.
43 changes: 43 additions & 0 deletions .github/workflows/example-bank-api-docker-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Bridge Example Bank API Docker Publish

on:
push:
workflow_dispatch:

jobs:
docker-build:
name: Docker Build and Push
runs-on: ubuntu-latest
env:
NAMESPACE: ${{ secrets.docker_hub_organisation || 'openg2p' }}
SERVICE_NAME: openg2p-g2p-bridge-example-bank-api
steps:
- uses: actions/checkout@v3
- name: Docker build
run: |
BRANCH_NAME=$(echo ${{ github.ref }} | sed -e 's,.*/\(.*\),\1,')
IMAGE_ID=$NAMESPACE/$SERVICE_NAME
# Change all uppercase to lowercase
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')
VERSION=$BRANCH_NAME
if [[ $BRANCH_NAME == master || $BRANCH_NAME == main ]]; then
VERSION=develop
fi
echo IMAGE_ID=$IMAGE_ID
echo VERSION=$VERSION
echo IMAGE_ID=$IMAGE_ID >> $GITHUB_ENV
echo VERSION=$VERSION >> $GITHUB_ENV
docker build ./openg2p-g2p-bridge-example-bank-api \
--tag $IMAGE_ID:$VERSION
if [[ '${{ secrets.docker_hub_token }}' != '' && '${{ secrets.docker_hub_actor }}' != '' ]]; then
export DOCKER_PUSH="true"
echo DOCKER_PUSH=$DOCKER_PUSH >> $GITHUB_ENV
fi
- name: Docker push
if: env.DOCKER_PUSH == 'true'
run: |
echo "${{ secrets.docker_hub_token }}" | docker login -u ${{ secrets.docker_hub_actor }} --password-stdin
docker push ${{ env.IMAGE_ID }}:${{ env.VERSION }}
53 changes: 53 additions & 0 deletions .github/workflows/example-bank-api-openapi-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: Bridge API OpenAPI Publish

on:
push:
workflow_dispatch:

jobs:
openapi-publish:
name: OpenAPI Generate and Publish
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Get branch name (merge)
run: |
echo "BRANCH_NAME=$(echo ${{ github.ref }} | sed -e 's,.*/\(.*\),\1,')" >> $GITHUB_ENV
- name: Setup python for openapi generate
uses: actions/setup-python@v4
with:
python-version: "3.10"
- name: Install app
run: |
python -m pip install git+https://github.com/openg2p/[email protected]\#subdirectory=openg2p-fastapi-common
python -m pip install git+https://github.com/openg2p/[email protected]\#subdirectory=openg2p-fastapi-auth
python -m pip install git+https://github.com/openg2p/[email protected]\#subdirectory=openg2p-g2pconnect-common-lib
python -m pip install git+https://github.com/openg2p/[email protected]\#subdirectory=openg2p-g2p-bridge-models
python -m pip install -e openg2p-g2p-bridge-api/
- name: Generate openapi json
run: |
mkdir -p openg2p-g2p-bridge-api/api-docs/generated
python3 openg2p-g2p-bridge-api/main.py getOpenAPI openg2p-g2p-bridge-api/api-docs/generated/openapi.json
if ! [ -z "$(git status --porcelain=v1 2>/dev/null -- openg2p-g2p-bridge-api/api-docs/generated/openapi.json)" ]; then
shopt -s nocasematch
if [[ ${{ github.repository_owner }} == 'OpenG2P' ]]; then
export OPENAPI_CHANGED="true"
echo OPENAPI_CHANGED=$OPENAPI_CHANGED >> $GITHUB_ENV
fi
fi
- name: Commit Changes
uses: EndBug/add-and-commit@v7
if: env.OPENAPI_CHANGED == 'true'
with:
default_author: github_actions
message: "Generated new openapi.json on push to ${{ github.event.inputs.git-ref }}"
add: "openg2p-g2p-bridge-api/api-docs/generated/openapi.json"
- name: Setup nodejs
uses: actions/setup-node@v4
if: env.OPENAPI_CHANGED == 'true'
with:
node-version: '18'
- name: Publish to stoplight
if: env.OPENAPI_CHANGED == 'true'
run: |
npx @stoplight/cli@5 push --ci-token ${{ secrets.STOPLIGHT_PROJECT_TOKEN }} --url https://openg2p.stoplight.io --branch ${{ env.BRANCH_NAME }} --directory openg2p-g2p-bridge-api/api-docs/generated
22 changes: 22 additions & 0 deletions .github/workflows/example-bank-api-pypi-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Bridge API PyPI Publish

on:
workflow_dispatch

jobs:
publish-to-pypi:
runs-on: ubuntu-latest
steps:
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.10"
- uses: actions/checkout@v3
- name: Install build dependencies
run: pip install build
- name: Build distribution
run: python -m build -s openg2p-g2p-bridge-example-bank-api/
- name: Publish
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI_API_TOKEN }}
43 changes: 43 additions & 0 deletions .github/workflows/example-bank-celery-docker-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Bridge Celery Beat Producers Docker Publish

on:
push:
workflow_dispatch:

jobs:
docker-build:
name: Docker Build and Push
runs-on: ubuntu-latest
env:
NAMESPACE: ${{ secrets.docker_hub_organisation || 'openg2p' }}
SERVICE_NAME: openg2p-g2p-bridge-example-bank-celery
steps:
- uses: actions/checkout@v3
- name: Docker build
run: |
BRANCH_NAME=$(echo ${{ github.ref }} | sed -e 's,.*/\(.*\),\1,')
IMAGE_ID=$NAMESPACE/$SERVICE_NAME
# Change all uppercase to lowercase
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')
VERSION=$BRANCH_NAME
if [[ $BRANCH_NAME == master || $BRANCH_NAME == main ]]; then
VERSION=develop
fi
echo IMAGE_ID=$IMAGE_ID
echo VERSION=$VERSION
echo IMAGE_ID=$IMAGE_ID >> $GITHUB_ENV
echo VERSION=$VERSION >> $GITHUB_ENV
docker build ./openg2p-g2p-bridge-example-bank-celery \
--tag $IMAGE_ID:$VERSION
if [[ '${{ secrets.docker_hub_token }}' != '' && '${{ secrets.docker_hub_actor }}' != '' ]]; then
export DOCKER_PUSH="true"
echo DOCKER_PUSH=$DOCKER_PUSH >> $GITHUB_ENV
fi
- name: Docker push
if: env.DOCKER_PUSH == 'true'
run: |
echo "${{ secrets.docker_hub_token }}" | docker login -u ${{ secrets.docker_hub_actor }} --password-stdin
docker push ${{ env.IMAGE_ID }}:${{ env.VERSION }}
22 changes: 22 additions & 0 deletions .github/workflows/example-bank-celery-pypi-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Bridge API PyPI Publish

on:
workflow_dispatch

jobs:
publish-to-pypi:
runs-on: ubuntu-latest
steps:
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.10"
- uses: actions/checkout@v3
- name: Install build dependencies
run: pip install build
- name: Build distribution
run: python -m build -s openg2p-g2p-bridge-example-bank-celery/
- name: Publish
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI_API_TOKEN }}
22 changes: 22 additions & 0 deletions .github/workflows/example-bank-models-pypi-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Bridge API PyPI Publish

on:
workflow_dispatch

jobs:
publish-to-pypi:
runs-on: ubuntu-latest
steps:
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.10"
- uses: actions/checkout@v3
- name: Install build dependencies
run: pip install build -s openg2p-g2p-bridge-example-bank-models/
- name: Build distribution
run: python -m build
- name: Publish
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI_API_TOKEN }}
51 changes: 51 additions & 0 deletions .github/workflows/example-bank-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: Test and coverage

on:
pull_request:
push:
workflow_dispatch:

concurrency:
group: check-${{ github.ref }}
cancel-in-progress: true

jobs:
test:
name: test with ${{ matrix.py }} on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
py:
- "3.10"
os:
- ubuntu-latest
services:
postgres:
image: postgres:9.6
env:
POSTGRES_USER: openg2p
POSTGRES_PASSWORD: openg2p
POSTGRES_DB: openg2p
ports:
- 5432:5432
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Setup python for test ${{ matrix.py }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.py }}
- name: Install test requirements
run: |
python -m pip install -r test-requirements.txt
python -m pip install -e openg2p-g2p-bridge-example-bank-api
# TODO: add other packages here
- name: Run test suite
run: |
pytest --cov-branch --cov-report=term-missing --cov=openg2p-g2p-bridge-example-bank-api --cov=tests
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
16 changes: 16 additions & 0 deletions .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: pre-commit

on:
pull_request:
push:
workflow_dispatch:

jobs:
pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v3
- uses: pre-commit/[email protected]
with:
extra_args: --all-files --show-diff-on-failure
File renamed without changes.
File renamed without changes.
31 changes: 31 additions & 0 deletions openg2p-g2p-bridge-example-bank-api/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
FROM bitnami/python:3.10.13-debian-11-r24

ARG container_user=openg2p
ARG container_user_group=openg2p
ARG container_user_uid=1001
ARG container_user_gid=1001

RUN groupadd -g ${container_user_gid} ${container_user_group} \
&& useradd -mN -u ${container_user_uid} -G ${container_user_group} -s /bin/bash ${container_user}

WORKDIR /app

RUN install_packages libpq-dev \
&& apt-get clean && rm -rf /var/lib/apt/lists /var/cache/apt/archives

RUN chown -R ${container_user}:${container_user_group} /app
USER ${container_user}

ADD --chown=${container_user}:${container_user_group} . /app/src
ADD --chown=${container_user}:${container_user_group} main.py /app

RUN python3 -m venv venv \
&& . ./venv/bin/activate
RUN python3 -m pip install \
git+https://github.com/openg2p/[email protected]\#subdirectory=openg2p-fastapi-common \
git+https://github.com/openg2p/[email protected]\#subdirectory=openg2p-fastapi-auth \
git+https://github.com/openg2p/[email protected]\#subdirectory=openg2p-g2p-bridge-example-bank-models \
./src

CMD python3 main.py migrate; \
gunicorn "openg2p-g2p-bridge-example-bank-api.main:app" --workers ${SPAR_MAPPER_NO_OF_WORKERS} --worker-class uvicorn.workers.UvicornWorker --bind ${SPAR_MAPPER_HOST}:${SPAR_MAPPER_PORT}
5 changes: 3 additions & 2 deletions openg2p-g2p-bridge-example-bank-api/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ classifiers = [
"Operating System :: OS Independent",
]
dependencies = [
"openg2p-fastapi-common",
"openg2p-fastapi-auth",
"openg2p-fastapi-common",
"openg2p-fastapi-auth",
"celery",
]
dynamic = ["version"]

Expand Down
Empty file.
Loading

0 comments on commit 8c96a1f

Please sign in to comment.