Skip to content

Commit

Permalink
improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
Benjoyo committed Feb 17, 2024
1 parent 88b5c50 commit 4a37c0f
Show file tree
Hide file tree
Showing 50 changed files with 3,560 additions and 521 deletions.
5 changes: 2 additions & 3 deletions .github/workflows/connectors.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,14 @@ jobs:
run:
working-directory: ./bpm-ai-connectors-c8/tests
runs-on: ubuntu-latest
environment: integration
steps:
- name: Checkout code
uses: actions/checkout@v4
-
name: Set up Python 3.12
name: Set up Python 3.11
uses: actions/setup-python@v4
with:
python-version: '3.12'
python-version: '3.11'
-
name: Set up poetry
uses: abatilo/actions-poetry@v2
Expand Down
127 changes: 122 additions & 5 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,10 @@ jobs:
name: Checkout code
uses: actions/checkout@v4
-
name: Set up Python 3.12
name: Set up Python 3.11
uses: actions/setup-python@v4
with:
python-version: '3.12'
python-version: '3.11'
-
name: Set up poetry
uses: abatilo/actions-poetry@v2
Expand Down Expand Up @@ -111,6 +111,8 @@ jobs:
- arch: amd64
- arch: arm64
runs-on: ubuntu-latest
outputs:
image: ${{ steps.image.outputs.image }}
steps:
-
name: Checkout code
Expand Down Expand Up @@ -153,6 +155,59 @@ jobs:
tags: |
${{ env.REGISTRY_IMAGE }}:${{ steps.vars.outputs.tag }}-${{ matrix.arch }}
${{ env.REGISTRY_IMAGE }}:latest-${{ matrix.arch }}
-
id: image
run: echo "::set-output name=image::$(echo ${{ env.REGISTRY_IMAGE }}:latest)"

build-push-inference:
needs: [ build-jvm ]
strategy:
matrix:
include:
- arch: amd64
- arch: arm64
runs-on: ubuntu-latest
outputs:
image: ${{ steps.image.outputs.image }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- uses: actions/download-artifact@v4
with:
name: feel-engine-wrapper-${{ matrix.arch }}-runner
path: feel-engine-wrapper/target
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- run: docker context create builders
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
version: latest
endpoint: builders
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Get the version
id: vars
run: echo ::set-output name=tag::$(echo ${GITHUB_REF:10})
- name: Build and push
uses: docker/build-push-action@v5
with:
platforms: linux/${{ matrix.arch }}
provenance: false # otherwise a manifest list is created and create-push-manifest job fails
context: .
file: ./Dockerfile.prebuilt
build-args: |
FLAVOR=inference
PYTHON_VERSION=3.11
push: true
tags: |
${{ env.REGISTRY_IMAGE }}:${{ steps.vars.outputs.tag }}-inference-${{ matrix.arch }}
${{ env.REGISTRY_IMAGE }}:latest-inference-${{ matrix.arch }}
- id: image
run: echo "::set-output name=image::$(echo ${{ env.REGISTRY_IMAGE }}:latest-inference)"

pytest-docker:
needs: [build-push]
Expand All @@ -165,10 +220,10 @@ jobs:
name: Checkout code
uses: actions/checkout@v4
-
name: Set up Python 3.12
name: Set up Python 3.11
uses: actions/setup-python@v4
with:
python-version: '3.12'
python-version: '3.11'
-
name: Set up poetry
uses: abatilo/actions-poetry@v2
Expand All @@ -190,7 +245,38 @@ jobs:
run: poetry install --only test --no-root --no-cache
-
name: Run pytest
run: ZEEBE_TEST_IMAGE_TAG=8.4.0 OPENAI_API_KEY=${{ secrets.OPENAI_API_KEY }} TEST_RUNTIME=docker poetry run pytest
run: ZEEBE_TEST_IMAGE_TAG=8.4.0 CONNECTOR_IMAGE=${{ needs.build-push.outputs.image }}-amd64 OPENAI_API_KEY=${{ secrets.OPENAI_API_KEY }} poetry run pytest

pytest-docker-inference:
needs: [ build-push-inference ]
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./bpm-ai-connectors-c8/tests
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Python 3.11
uses: actions/setup-python@v4
with:
python-version: '3.11'
- name: Set up poetry
uses: abatilo/actions-poetry@v2
with:
poetry-version: "1.6.1"
- name: Create local environment in project for caching
run: |
poetry config virtualenvs.create true --local
poetry config virtualenvs.in-project true --local
- uses: actions/cache@v3
name: Set up cache based on dependencies lock file
with:
path: ./bpm-ai-connectors-c8/.venv
key: venv-${{ hashFiles('**/poetry.lock') }}
- name: Install dependencies
run: poetry install --only test --no-root --no-cache
- name: Run pytest
run: ZEEBE_TEST_IMAGE_TAG=8.4.0 CONNECTOR_IMAGE=${{ needs.build-push-inference.outputs.image }}-amd64 OPENAI_API_KEY=${{ secrets.OPENAI_API_KEY }} poetry run pytest

create-push-manifest:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -222,3 +308,34 @@ jobs:
--amend ${{ env.REGISTRY_IMAGE }}:latest-amd64 \
--amend ${{ env.REGISTRY_IMAGE }}:latest-arm64
docker manifest push ${{ env.REGISTRY_IMAGE }}:latest
create-push-manifest-inference:
runs-on: ubuntu-latest
needs: [build-push-inference, pytest-docker-inference]
steps:
-
name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
-
name: Get version
id: vars
run: echo ::set-output name=tag::$(echo ${GITHUB_REF:10})
-
name: Create version-manifest and push
run: |
docker manifest create \
${{ env.REGISTRY_IMAGE }}:${{ steps.vars.outputs.tag }}-inference \
--amend ${{ env.REGISTRY_IMAGE }}:${{ steps.vars.outputs.tag }}-inference-amd64 \
--amend ${{ env.REGISTRY_IMAGE }}:${{ steps.vars.outputs.tag }}-inference-arm64
docker manifest push ${{ env.REGISTRY_IMAGE }}:${{ steps.vars.outputs.tag }}-inference
-
name: Create latest-manifest and push
run: |
docker manifest create \
${{ env.REGISTRY_IMAGE }}:latest-inference \
--amend ${{ env.REGISTRY_IMAGE }}:latest-inference-amd64 \
--amend ${{ env.REGISTRY_IMAGE }}:latest-inference-arm64
docker manifest push ${{ env.REGISTRY_IMAGE }}:latest-inference
35 changes: 31 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
ARG FLAVOR=default
ARG PYTHON_VERSION="3.12"

###############################################################################
Expand All @@ -19,8 +20,10 @@ RUN ./mvnw package -Dnative
# 2. Install python connector dependencies
###############################################################################
# poetry setup code based on https://github.com/thehale/docker-python-poetry (does not provide multiarch images)
FROM python:${PYTHON_VERSION}-slim AS build-python
FROM python:${PYTHON_VERSION} AS build-python
ARG FLAVOR
ARG POETRY_VERSION="1.6.1"

ENV POETRY_VERSION=${POETRY_VERSION}
ENV POETRY_HOME="/opt/poetry"
ENV POETRY_VIRTUALENVS_IN_PROJECT=true
Expand All @@ -33,21 +36,45 @@ RUN apt-get update && apt-get install -y --no-install-recommends curl
RUN curl -sSL https://install.python-poetry.org | python3 -
# only install dependencies into project virtualenv
WORKDIR /app
COPY bpm-ai-connectors-c8/pyproject.toml bpm-ai-connectors-c8/poetry.lock ./
COPY bpm-ai-connectors-c8/requirements.inference.txt \
bpm-ai-connectors-c8/requirements.default.txt \
bpm-ai-connectors-c8/pyproject.toml \
bpm-ai-connectors-c8/poetry.lock ./
RUN poetry run python -m pip install -r requirements.${FLAVOR}.txt
RUN poetry install --only main --no-root --no-cache

###############################################################################
# 3. Final, minimal image that starts the connectors and feel engine process
###############################################################################
FROM cgr.dev/chainguard/python:latest
FROM cgr.dev/chainguard/python:latest AS default
ARG PYTHON_VERSION

ENV PYTHONUNBUFFERED=1

WORKDIR /app
COPY --from=build-jvm /app/target/feel-engine-wrapper-runner feel-wrapper
COPY ./bpm-ai-connectors-c8/bpm_ai_connectors_c8/ ./bpm_ai_connectors_c8/
COPY --from=build-python /app/.venv/lib/python${PYTHON_VERSION}/site-packages /home/nonroot/.local/lib/python${PYTHON_VERSION}/site-packages
COPY --from=build-python /app/.venv/lib/python${PYTHON_VERSION}/site-packages /home/nonroot/.local/lib/python3.12/site-packages

# Run two processes: connector runtime + feel engine wrapper
COPY init.py .
CMD ["init.py", "./feel-wrapper", "python -m bpm_ai_connectors_c8.main"]

###############################################################################
FROM python:${PYTHON_VERSION}-slim AS inference
ARG PYTHON_VERSION

ENV PYTHONUNBUFFERED=1

WORKDIR /app
COPY --from=build-jvm /app/target/feel-engine-wrapper-runner feel-wrapper
COPY ./bpm-ai-connectors-c8/bpm_ai_connectors_c8/ ./bpm_ai_connectors_c8/
COPY --from=build-python /app/.venv/lib/python${PYTHON_VERSION}/site-packages /usr/local/lib/python${PYTHON_VERSION}/site-packages

# Run two processes: connector runtime + feel engine wrapper
COPY init.py .
CMD ["python3", "init.py", "./feel-wrapper", "python -m bpm_ai_connectors_c8.main"]

###############################################################################

FROM ${FLAVOR}
35 changes: 31 additions & 4 deletions Dockerfile.prebuilt
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
ARG FLAVOR=default
ARG PYTHON_VERSION="3.12"

###############################################################################
# 1. Install python connector dependencies
###############################################################################
# poetry setup code based on https://github.com/thehale/docker-python-poetry (does not provide multiarch images)
FROM python:${PYTHON_VERSION}-slim AS build-python
FROM python:${PYTHON_VERSION} AS build-python
ARG FLAVOR
ARG POETRY_VERSION="1.6.1"

ENV POETRY_VERSION=${POETRY_VERSION}
ENV POETRY_HOME="/opt/poetry"
ENV POETRY_VIRTUALENVS_IN_PROJECT=true
Expand All @@ -18,21 +21,45 @@ RUN apt-get update && apt-get install -y --no-install-recommends curl
RUN curl -sSL https://install.python-poetry.org | python3 -
# only install dependencies into project virtualenv
WORKDIR /app
COPY bpm-ai-connectors-c8/pyproject.toml bpm-ai-connectors-c8/poetry.lock ./
COPY bpm-ai-connectors-c8/requirements.inference.txt \
bpm-ai-connectors-c8/requirements.default.txt \
bpm-ai-connectors-c8/pyproject.toml \
bpm-ai-connectors-c8/poetry.lock ./
RUN poetry run python -m pip install -r requirements.${FLAVOR}.txt
RUN poetry install --only main --no-root --no-cache

###############################################################################
# 3. Final, minimal image that starts the connectors and feel engine process
###############################################################################
FROM cgr.dev/chainguard/python:latest
FROM cgr.dev/chainguard/python:latest AS default
ARG PYTHON_VERSION

ENV PYTHONUNBUFFERED=1

WORKDIR /app
COPY --chmod=755 ./feel-engine-wrapper/target/feel-engine-wrapper-runner feel-wrapper
COPY ./bpm-ai-connectors-c8/bpm_ai_connectors_c8/ ./bpm_ai_connectors_c8/
COPY --from=build-python /app/.venv/lib/python${PYTHON_VERSION}/site-packages /home/nonroot/.local/lib/python${PYTHON_VERSION}/site-packages
COPY --from=build-python /app/.venv/lib/python${PYTHON_VERSION}/site-packages /home/nonroot/.local/lib/python3.12/site-packages

# Run two processes: connector runtime + feel engine wrapper
COPY init.py .
CMD ["init.py", "./feel-wrapper", "python -m bpm_ai_connectors_c8.main"]

###############################################################################
FROM python:${PYTHON_VERSION}-slim AS inference
ARG PYTHON_VERSION

ENV PYTHONUNBUFFERED=1

WORKDIR /app
COPY --chmod=755 ./feel-engine-wrapper/target/feel-engine-wrapper-runner feel-wrapper
COPY ./bpm-ai-connectors-c8/bpm_ai_connectors_c8/ ./bpm_ai_connectors_c8/
COPY --from=build-python /app/.venv/lib/python${PYTHON_VERSION}/site-packages /usr/local/lib/python${PYTHON_VERSION}/site-packages

# Run two processes: connector runtime + feel engine wrapper
COPY init.py .
CMD ["python3", "init.py", "./feel-wrapper", "python -m bpm_ai_connectors_c8.main"]

###############################################################################

FROM ${FLAVOR}
Loading

0 comments on commit 4a37c0f

Please sign in to comment.