From 041d82fdd40e2d4014d17689259966cf3adf0f49 Mon Sep 17 00:00:00 2001 From: Benjoyo Date: Fri, 2 Feb 2024 13:27:23 +0100 Subject: [PATCH] wip --- .github/workflows/release.yml | 78 ++++++++++++++++++++--------------- Dockerfile | 2 +- Dockerfile.prebuilt | 44 ++++++++++++++++++++ 3 files changed, 90 insertions(+), 34 deletions(-) create mode 100644 Dockerfile.prebuilt diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 73823b4..38281c5 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -13,8 +13,12 @@ jobs: build-jvm: strategy: matrix: - os: [ {name: ubuntu-latest, arch: amd64}, {name: macos-14, arch: arm64} ] - runs-on: ${{ matrix.os.name }} + include: + - runner: ubuntu-latest + arch: amd64 + - runner: buildjet-4vcpu-ubuntu-2204-arm + arch: arm64 + runs-on: ${{ matrix.runner }} defaults: run: working-directory: ./feel-engine-wrapper @@ -38,8 +42,8 @@ jobs: name: Upload Artifact uses: actions/upload-artifact@v4 with: - name: feel-engine-wrapper-${{ matrix.os.name }}-${{ matrix.os.arch }} - path: /target/*-runner + name: feel-engine-wrapper-${{ matrix.arch }}-runner + path: feel-engine-wrapper/target/*-runner # action does not respect working-directory... if-no-files-found: error build-python: @@ -48,7 +52,9 @@ jobs: run: working-directory: ./bpm-ai-connectors-c8 steps: - - uses: actions/checkout@v3 + - + name: Checkout code + uses: actions/checkout@v3 - name: Set up Python 3.12 uses: actions/setup-python@v4 @@ -74,13 +80,28 @@ jobs: path: bpm-ai-connectors-c8/dist/ # action does not respect working-directory... if-no-files-found: error - build-push-amd64: - #needs: [build-jvm, build-python] + build-push: + needs: [build-jvm] + strategy: + matrix: + include: + - arch: amd64 + - arch: arm64 runs-on: ubuntu-latest steps: - - name: Checkout + name: Checkout code uses: actions/checkout@v3 + - + uses: actions/download-artifact@v4 + with: + name: feel-engine-wrapper-${{ matrix.arch }}-runner + path: feel-engine-wrapper/target + - + run: ls -la feel-engine-wrapper/target + - + name: Set up QEMU + uses: docker/setup-qemu-action@v3 - run: docker context create builders - @@ -103,32 +124,24 @@ jobs: name: Build and push uses: docker/build-push-action@v5 with: - platforms: linux/amd64 - build-args: | - TARGETARCH=amd64 + platforms: linux/${{ matrix.arch }} + file: ./Dockerfile.prebuilt push: true tags: | - ${{ env.REGISTRY_IMAGE }}:${{ steps.vars.outputs.tag }}-amd64 - ${{ env.REGISTRY_IMAGE }}:latest-amd64 + ${{ env.REGISTRY_IMAGE }}:${{ steps.vars.outputs.tag }}-${{ matrix.arch }} + ${{ env.REGISTRY_IMAGE }}:latest-${{ matrix.arch }} build-push-arm64: + if: ${{ false }} # disable for now #needs: [build-jvm, build-python] runs-on: macos-14 steps: - - name: Checkout + name: Checkout code uses: actions/checkout@v3 - - name: Setup docker (missing on MacOS) - if: runner.os == 'macos' - run: | - brew config - brew install docker colima - colima delete - colima start debug --arch aarch64 --ssh-agent - # For testcontainers to find the Colima socket - # https://github.com/abiosoft/colima/blob/main/docs/FAQ.md#cannot-connect-to-the-docker-daemon-at-unixvarrundockersock-is-the-docker-daemon-running - sudo ln -sf $HOME/.colima/default/docker.sock /var/run/docker.sock + name: Set up QEMU + uses: docker/setup-qemu-action@v3 - run: docker context create builders - @@ -164,9 +177,11 @@ jobs: defaults: run: working-directory: ./bpm-ai-connectors-c8/tests - needs: [build-push-amd64] + needs: [build-push] steps: - - uses: actions/checkout@v4 + - + name: Checkout code + uses: actions/checkout@v4 - name: Set up Python 3.12 uses: actions/setup-python@v4 @@ -186,11 +201,8 @@ jobs: create-push-manifest: runs-on: ubuntu-latest - needs: [build-push-amd64, build-push-arm64, pytest-docker] + needs: [build-push, pytest-docker] steps: - - - name: Checkout - uses: actions/checkout@v3 - name: Login to Docker Hub uses: docker/login-action@v2 @@ -198,11 +210,11 @@ jobs: username: ${{ secrets.DOCKER_USERNAME }} password: ${{ secrets.DOCKER_PASSWORD }} - - name: Get the version + name: Get version id: vars run: echo ::set-output name=tag::$(echo ${GITHUB_REF:10}) - - name: Create version manifest and push + name: Create version-manifest and push run: | docker manifest create \ ${{ env.REGISTRY_IMAGE }}:${{ steps.vars.outputs.tag }} \ @@ -210,7 +222,7 @@ jobs: --amend ${{ env.REGISTRY_IMAGE }}:${{ steps.vars.outputs.tag }}-arm64 docker manifest push ${{ env.REGISTRY_IMAGE }}:${{ steps.vars.outputs.tag }} - - name: Create latest manifest and push + name: Create latest-manifest and push run: | docker manifest create \ ${{ env.REGISTRY_IMAGE }}:latest \ diff --git a/Dockerfile b/Dockerfile index ca1c065..6ef261b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -18,7 +18,7 @@ COPY feel-engine-wrapper/src /code/src RUN ./mvnw package -Dnative-compress ############################################################################### -# 2. build python connectors as native executable using nuitka +# 2. install python connector dependencies ############################################################################### # poetry setup code copied from https://github.com/thehale/docker-python-poetry, due to missing multiarch images # POETRY BASE IMAGE - Provides environment variables for poetry diff --git a/Dockerfile.prebuilt b/Dockerfile.prebuilt new file mode 100644 index 0000000..e7866ea --- /dev/null +++ b/Dockerfile.prebuilt @@ -0,0 +1,44 @@ +ARG PYTHON_VERSION="3.12" + +############################################################################### +# 1. install python connector dependencies +############################################################################### +# poetry setup code copied from https://github.com/thehale/docker-python-poetry, due to missing multiarch images +# POETRY BASE IMAGE - Provides environment variables for poetry +FROM python:${PYTHON_VERSION}-slim AS python-poetry-base +ARG POETRY_VERSION="1.6.1" +ENV POETRY_VERSION=${POETRY_VERSION} +ENV POETRY_HOME="/opt/poetry" +ENV POETRY_VIRTUALENVS_IN_PROJECT=true +ENV POETRY_NO_INTERACTION=1 +ENV PATH="$POETRY_HOME/bin:$PATH" +# POETRY BUILDER IMAGE - Installs Poetry and dependencies +FROM python-poetry-base AS python-poetry-builder +RUN apt-get update && apt-get install -y --no-install-recommends curl +# Install Poetry via the official installer: https://python-poetry.org/docs/master/#installing-with-the-official-installer +# This script respects $POETRY_VERSION & $POETRY_HOME +RUN curl -sSL https://install.python-poetry.org | python3 - +# POETRY RUNTIME IMAGE - Copies the poetry installation into a smaller image and builds target app +FROM python-poetry-base AS build-python +COPY --from=python-poetry-builder $POETRY_HOME $POETRY_HOME +# only install dependencies into project virtualenv +COPY bpm-ai-connectors-c8/pyproject.toml bpm-ai-connectors-c8/poetry.lock ./app/ +WORKDIR /app +RUN poetry install --without dev,test --no-root --no-cache + +############################################################################### +# 3. Final, minimal image +############################################################################### +FROM cgr.dev/chainguard/python:latest + +ARG PYTHON_VERSION +ENV PYTHONUNBUFFERED=1 + +WORKDIR /app +COPY ./feel-engine-wrapper/target/*-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 + +# Run two processes: connector runtime + feel engine wrapper +COPY docker/init.py . +CMD ["init.py", "./feel-wrapper", "python -m bpm_ai_connectors_c8.main"]