diff --git a/.github/workflows/example-bank-api-docker-publish.yml b/.github/workflows/api-branch.yml similarity index 80% rename from .github/workflows/example-bank-api-docker-publish.yml rename to .github/workflows/api-branch.yml index f1fb394..81100a3 100644 --- a/.github/workflows/example-bank-api-docker-publish.yml +++ b/.github/workflows/api-branch.yml @@ -1,12 +1,15 @@ -name: Bridge Example Bank API Docker Publish +name: Example Bank API Branch Workflow on: push: - workflow_dispatch: + branches-ignore: + - develop + tags-ignore: + - '*' jobs: - docker-build: - name: Docker Build and Push + docker-build-for-branch: + name: Docker Build and Push For API Branch runs-on: ubuntu-latest env: NAMESPACE: ${{ secrets.docker_hub_organisation || 'openg2p' }} @@ -22,15 +25,12 @@ jobs: # 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 \ + docker build ./openg2p-g2p-bridge-example-bank-api -f ./openg2p-g2p-bridge-example-bank-api/Dockerfile-git \ --tag $IMAGE_ID:$VERSION if [[ '${{ secrets.docker_hub_token }}' != '' && '${{ secrets.docker_hub_actor }}' != '' ]]; then export DOCKER_PUSH="true" diff --git a/.github/workflows/api-tag.yml b/.github/workflows/api-tag.yml new file mode 100644 index 0000000..452c659 --- /dev/null +++ b/.github/workflows/api-tag.yml @@ -0,0 +1,96 @@ +name: Example Bank API Tag Workflow + +on: + push: + tags: + - "*" + branches-ignore: + - '*' + workflow_dispatch: + +jobs: + publish-to-pypi: + name: Publish to PyPI For API Tag + 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 ./openg2p-g2p-bridge-example-bank-api + - name: Publish + uses: pypa/gh-action-pypi-publish@release/v1 + with: + password: ${{ secrets.PYPI_API_TOKEN }} + packages-dir: ./openg2p-g2p-bridge-example-bank-api/dist/ + + openapi-publish: + name: OpenAPI Generate and Publish For API Tag + needs: publish-to-pypi + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Get branch name (merge) + run: | + echo "TAG_NAME=${GITHUB_REF#refs/tags/}" >> $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/openg2p-fastapi-common@develop\#subdirectory=openg2p-fastapi-common + python -m pip install git+https://github.com/openg2p/openg2p-fastapi-common@develop\#subdirectory=openg2p-fastapi-auth + python -m pip install git+https://github.com/openg2p/openg2p-g2p-bridge-example-bank@develop\#subdirectory=openg2p-g2p-bridge-example-bank-models + python -m pip install openg2p-g2p-bridge-example-bank-api==develop + - name: Generate openapi json + run: | + mkdir -p openg2p-g2p-bridge-example-bank-api/api-docs/generated + python3 openg2p-g2p-bridge-example-bank-api/main.py getOpenAPI openg2p-g2p-bridge-example-bank-api/api-docs/generated/openapi.json + - name: Setup nodejs + uses: actions/setup-node@v4 + with: + node-version: '18' + - name: Publish to stoplight + run: | + npx @stoplight/cli@5 push --ci-token ${{ secrets.STOPLIGHT_PROJECT_TOKEN }} --url https://openg2p.stoplight.io --branch ${{ env.TAG_NAME }} --directory openg2p-g2p-bridge-example-bank-api/api-docs/generated + + + docker-build-for-tag: + name: Docker Build and Push For API Tag + needs: publish-to-pypi + 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: | + echo "TAG_NAME=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV + + IMAGE_ID=$NAMESPACE/$SERVICE_NAME + + # Change all uppercase to lowercase + IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]') + VERSION=TAG_NAME + 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 -f ./openg2p-g2p-bridge-example-bank-api/Dockerfile-pypi \ + --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 }} diff --git a/.github/workflows/example-bank-tests.yml b/.github/workflows/api-tests.yml similarity index 100% rename from .github/workflows/example-bank-tests.yml rename to .github/workflows/api-tests.yml diff --git a/.github/workflows/example-bank-celery-pypi-publish.yml b/.github/workflows/bank-models-tag.yml similarity index 59% rename from .github/workflows/example-bank-celery-pypi-publish.yml rename to .github/workflows/bank-models-tag.yml index ae520c7..73a94ba 100644 --- a/.github/workflows/example-bank-celery-pypi-publish.yml +++ b/.github/workflows/bank-models-tag.yml @@ -1,10 +1,16 @@ -name: Bridge API PyPI Publish +name: Bank Models PyPI Publish on: - workflow_dispatch + push: + tags: + - "*" + branches-ignore: + - '*' + workflow_dispatch: jobs: publish-to-pypi: + name: Publish to PyPI For Models Tag runs-on: ubuntu-latest steps: - name: Set up Python @@ -15,8 +21,9 @@ jobs: - name: Install build dependencies run: pip install build - name: Build distribution - run: python -m build -s openg2p-g2p-bridge-example-bank-celery/ + run: python -m build ./openg2p-g2p-bridge-example-bank-models - name: Publish uses: pypa/gh-action-pypi-publish@release/v1 with: password: ${{ secrets.PYPI_API_TOKEN }} + packages-dir: ./openg2p-g2p-bridge-example-bank-models/dist/ diff --git a/.github/workflows/example-bank-celery-docker-publish.yml b/.github/workflows/celery-branch.yml similarity index 83% rename from .github/workflows/example-bank-celery-docker-publish.yml rename to .github/workflows/celery-branch.yml index aa4b1dc..fb437d8 100644 --- a/.github/workflows/example-bank-celery-docker-publish.yml +++ b/.github/workflows/celery-branch.yml @@ -1,12 +1,15 @@ -name: Bridge Celery Beat Producers Docker Publish +name: Example Bank Celery Branch Workflow on: push: - workflow_dispatch: + branches-ignore: + - develop + tags-ignore: + - '*' jobs: - docker-build: - name: Docker Build and Push + docker-build-for-branch: + name: Docker Build and Push For Celery Branch runs-on: ubuntu-latest env: NAMESPACE: ${{ secrets.docker_hub_organisation || 'openg2p' }} @@ -22,15 +25,12 @@ jobs: # 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 \ + docker build ./openg2p-g2p-bridge-example-bank-celery -f ./openg2p-g2p-bridge-example-bank-celery/Dockerfile-git \ --tag $IMAGE_ID:$VERSION if [[ '${{ secrets.docker_hub_token }}' != '' && '${{ secrets.docker_hub_actor }}' != '' ]]; then export DOCKER_PUSH="true" diff --git a/.github/workflows/celery-tag.yml b/.github/workflows/celery-tag.yml new file mode 100644 index 0000000..a660187 --- /dev/null +++ b/.github/workflows/celery-tag.yml @@ -0,0 +1,64 @@ +name: Example Bank Celery Tag Workflow + +on: + push: + tags: + - "*" + branches-ignore: + - '*' + workflow_dispatch: + +jobs: + publish-to-pypi: + name: Publish to PyPI For Celery Tag + 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 ./openg2p-g2p-bridge-example-bank-celery + - name: Publish + uses: pypa/gh-action-pypi-publish@release/v1 + with: + password: ${{ secrets.PYPI_API_TOKEN }} + packages-dir: ./openg2p-g2p-bridge-example-bank-celery/dist/ + + docker-build-for-tag: + name: Docker Build and Push For Celery Tag + needs: publish-to-pypi + 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: | + echo "TAG_NAME=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV + + IMAGE_ID=$NAMESPACE/$SERVICE_NAME + + # Change all uppercase to lowercase + IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]') + VERSION=TAG_NAME + 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 -f ./openg2p-g2p-bridge-example-bank-celery/Dockerfile-pypi \ + --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 }} diff --git a/.github/workflows/example-bank-api-openapi-publish.yml b/.github/workflows/example-bank-api-openapi-publish.yml deleted file mode 100644 index 9a3ff45..0000000 --- a/.github/workflows/example-bank-api-openapi-publish.yml +++ /dev/null @@ -1,53 +0,0 @@ -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/openg2p-fastapi-common@1.1.0\#subdirectory=openg2p-fastapi-common - python -m pip install git+https://github.com/openg2p/openg2p-fastapi-common@1.1.0\#subdirectory=openg2p-fastapi-auth - python -m pip install git+https://github.com/openg2p/openg2p-g2pconnect-common@1.0.0\#subdirectory=openg2p-g2pconnect-common-lib - python -m pip install git+https://github.com/openg2p/openg2p-g2p-bridge@1.0.0\#subdirectory=openg2p-g2p-bridge-models - python -m pip install -e openg2p-g2p-bridge-api/ - - name: Generate openapi json - run: | - mkdir -p openg2p-g2p-bridge-example-bank-api/api-docs/generated - python3 openg2p-g2p-bridge-example-bank-api/main.py getOpenAPI openg2p-g2p-bridge-example-bank-api/api-docs/generated/openapi.json - if ! [ -z "$(git status --porcelain=v1 2>/dev/null -- openg2p-g2p-bridge-example-bank-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-example-bank-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-example-bank-api/api-docs/generated diff --git a/.github/workflows/example-bank-api-pypi-publish.yml b/.github/workflows/example-bank-api-pypi-publish.yml deleted file mode 100644 index 27b82f1..0000000 --- a/.github/workflows/example-bank-api-pypi-publish.yml +++ /dev/null @@ -1,22 +0,0 @@ -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 }} diff --git a/.github/workflows/example-bank-models-pypi-publish.yml b/.github/workflows/example-bank-models-pypi-publish.yml deleted file mode 100644 index f078eed..0000000 --- a/.github/workflows/example-bank-models-pypi-publish.yml +++ /dev/null @@ -1,22 +0,0 @@ -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 }} diff --git a/.github/workflows/tag.yml b/.github/workflows/tag.yml new file mode 100644 index 0000000..bb86777 --- /dev/null +++ b/.github/workflows/tag.yml @@ -0,0 +1,21 @@ +name: Tag the repo +on: + workflow_dispatch: + inputs: + new-tag: + description: Tag in "vN.N.N" format + required: true + type: string + previous-tag: + description: Previous tag. "None" if no previous tag + required: true + type: string + default: latest +jobs: + tag-repo: + uses: openg2p/openg2p-packaging/.github/workflows/tag.yml@main + with: + new-tag: ${{ inputs.new-tag }} + previous-tag: ${{ inputs.previous-tag }} + secrets: + OPENG2P_BOT_GITHUB_PAT: ${{ secrets.OPENG2P_BOT_GITHUB_PAT }} \ No newline at end of file diff --git a/openg2p-g2p-bridge-example-bank-api/.dockerignore b/openg2p-g2p-bridge-example-bank-api/.dockerignore index d47f7ee..219ea33 100644 --- a/openg2p-g2p-bridge-example-bank-api/.dockerignore +++ b/openg2p-g2p-bridge-example-bank-api/.dockerignore @@ -11,7 +11,7 @@ # Docker docker-compose.yml -Dockerfile +Dockerfile-git .docker .dockerignore diff --git a/openg2p-g2p-bridge-example-bank-api/Dockerfile b/openg2p-g2p-bridge-example-bank-api/Dockerfile-git similarity index 100% rename from openg2p-g2p-bridge-example-bank-api/Dockerfile rename to openg2p-g2p-bridge-example-bank-api/Dockerfile-git diff --git a/openg2p-g2p-bridge-example-bank-api/Dockerfile-pypi b/openg2p-g2p-bridge-example-bank-api/Dockerfile-pypi new file mode 100644 index 0000000..ab1d8d7 --- /dev/null +++ b/openg2p-g2p-bridge-example-bank-api/Dockerfile-pypi @@ -0,0 +1,32 @@ +FROM bitnami/python:3.12.5-debian-12-r0 + +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 + +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 \ + openg2p-fastapi-common==develop \ + openg2p-fastapi-auth==develop \ + openg2p-g2p-bridge-example-bank-models==develop \ + openg2p-g2p-bridge-example-bank-api==develop + +USER ${container_user} + +CMD python3 main.py migrate; \ + gunicorn "main:app" --workers ${EXAMPLE_BANK_NO_OF_WORKERS} --worker-class uvicorn.workers.UvicornWorker --bind ${EXAMPLE_BANK_HOST}:${EXAMPLE_BANK_PORT} diff --git a/openg2p-g2p-bridge-example-bank-celery/Dockerfile b/openg2p-g2p-bridge-example-bank-celery/Dockerfile-git similarity index 84% rename from openg2p-g2p-bridge-example-bank-celery/Dockerfile rename to openg2p-g2p-bridge-example-bank-celery/Dockerfile-git index 4d7bc82..5c89419 100644 --- a/openg2p-g2p-bridge-example-bank-celery/Dockerfile +++ b/openg2p-g2p-bridge-example-bank-celery/Dockerfile-git @@ -1,4 +1,4 @@ -FROM bitnami/python:3.10.13-debian-11-r24 +FROM bitnami/python:3.12.5-debian-12-r0 ARG container_user=openg2p ARG container_user_group=openg2p @@ -29,5 +29,4 @@ RUN python3 -m pip install \ USER ${container_user} CMD python3 main.py migrate; \ - celery -A main.celery_app worker --loglevel=info --beat & \ - celery -A main.celery_app worker --loglevel=info -Q g2p_bridge_celery_worker_tasks + gunicorn "main:app" --workers ${EXAMPLE_BANK_NO_OF_WORKERS} --worker-class uvicorn.workers.UvicornWorker --bind ${EXAMPLE_BANK_HOST}:${EXAMPLE_BANK_PORT} diff --git a/openg2p-g2p-bridge-example-bank-celery/Dockerfile-pypi b/openg2p-g2p-bridge-example-bank-celery/Dockerfile-pypi new file mode 100644 index 0000000..dc76772 --- /dev/null +++ b/openg2p-g2p-bridge-example-bank-celery/Dockerfile-pypi @@ -0,0 +1,32 @@ +FROM bitnami/python:3.12.5-debian-12-r0 + +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 + +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 \ + openg2p-fastapi-common==develop \ + openg2p-fastapi-auth==develop \ + openg2p-g2p-bridge-example-bank-models==develop \ + openg2p-g2p-bridge-example-bank-celery==develop + +USER ${container_user} + +CMD python3 main.py migrate; \ + gunicorn "main:app" --workers ${EXAMPLE_BANK_NO_OF_WORKERS} --worker-class uvicorn.workers.UvicornWorker --bind ${EXAMPLE_BANK_HOST}:${EXAMPLE_BANK_PORT}