From 8a977d6714f4800450e908dddc9406587ad989ef Mon Sep 17 00:00:00 2001 From: Sebastian Utz Date: Fri, 14 Jun 2024 10:34:11 +0200 Subject: [PATCH 1/2] CFR: Build as a self-contained program using PyInstaller --- CHANGES.md | 1 + cratedb_toolkit/cfr/cli.py | 8 ++++++++ pyproject.toml | 10 ++++++++-- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 0a881545..75ea8f69 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -7,6 +7,7 @@ - MongoDB: Added adapter amalgamating PyMongo to use CrateDB as backend - SQLAlchemy: Clean up and refactor SQLAlchemy polyfills to `cratedb_toolkit.util.sqlalchemy` +- CFR: Build as a self-contained program using PyInstaller ## 2024/06/18 v0.0.14 - Add `ctk cfr` and `ctk wtf` diagnostics programs diff --git a/cratedb_toolkit/cfr/cli.py b/cratedb_toolkit/cfr/cli.py index e39b0b98..0850305c 100644 --- a/cratedb_toolkit/cfr/cli.py +++ b/cratedb_toolkit/cfr/cli.py @@ -1,6 +1,7 @@ # Copyright (c) 2021-2024, Crate.io Inc. # Distributed under the terms of the AGPLv3 license, see LICENSE. import logging +import multiprocessing import sys import click @@ -77,3 +78,10 @@ def sys_import(ctx: click.Context, source: str): except Exception as ex: error_logger(ctx)(ex) sys.exit(1) + + +if getattr(sys, "frozen", False): + # https://github.com/pyinstaller/pyinstaller/issues/6368 + multiprocessing.freeze_support() + # https://stackoverflow.com/questions/45090083/freeze-a-program-created-with-pythons-click-pacage + cli(sys.argv[1:]) diff --git a/pyproject.toml b/pyproject.toml index ac6a9d97..138c63d8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -110,8 +110,8 @@ all = [ "cratedb-toolkit[full,influxdb,mongodb]", ] cfr = [ - "pandas<3,>=1", - "pyarrow<17", + "pandas<2.2", + "pyarrow<16.1", ] cloud = [ "croud==1.11.1", @@ -167,6 +167,9 @@ release = [ "build<2", "twine<6", ] +release-cfr = [ + "pyinstaller<7", +] service = [ "fastapi<0.112", "uvicorn<0.31", @@ -195,6 +198,7 @@ documentation = "https://github.com/crate-workbench/cratedb-toolkit" homepage = "https://github.com/crate-workbench/cratedb-toolkit" repository = "https://github.com/crate-workbench/cratedb-toolkit" [project.scripts] +cratedb-cfr = "cratedb_toolkit.cfr.cli:cli" cratedb-retention = "cratedb_toolkit.retention.cli:cli" cratedb-toolkit = "cratedb_toolkit.cli:cli" cratedb-wtf = "cratedb_toolkit.wtf.cli:cli" @@ -355,3 +359,5 @@ release = [ ] test = { cmd = "pytest" } + +build-cfr = { cmd = "pyinstaller cratedb_toolkit/cfr/cli.py --onefile --name cratedb-cfr"} From 7fb9df3bb05bed804c41ae8808ff6513d4bdc580 Mon Sep 17 00:00:00 2001 From: Andreas Motl Date: Sat, 6 Jul 2024 23:10:48 +0200 Subject: [PATCH 2/2] CFR: Publish self-contained application bundle to GH Workflow Artifacts --- .github/workflows/release-app.yml | 75 +++++++++++++++++++++++++++++++ CHANGES.md | 1 + pyproject.toml | 1 + 3 files changed, 77 insertions(+) create mode 100644 .github/workflows/release-app.yml diff --git a/.github/workflows/release-app.yml b/.github/workflows/release-app.yml new file mode 100644 index 00000000..588863e0 --- /dev/null +++ b/.github/workflows/release-app.yml @@ -0,0 +1,75 @@ +# Stage PyInstaller application bundles through GitHub Actions (GHA) to GitHub Workflow Artifacts. +# https://github.com/actions/upload-artifact#where-does-the-upload-go + +name: "Release: Application Bundle" + +on: + pull_request: ~ + push: + tags: + - '*' + +jobs: + + cfr: + name: "CFR for OS ${{ matrix.os }}" + + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: [ + "macos-13", # Intel + "macos-latest", # ARM + "ubuntu-latest", # Intel + "windows-latest", # Intel + ] + # TODO: Also build for Linux/ARM, because this platform gets more traction in datacenters. + # - https://github.blog/changelog/2024-06-03-actions-arm-based-linux-and-windows-runners-are-now-in-public-beta/ + # - https://arm-software.github.io/AVH/main/infrastructure/html/avh_gh.html + # - via: https://github.com/actions/partner-runner-images + + steps: + + - name: Acquire sources + uses: actions/checkout@v4 + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: '3.12' + cache: 'pip' + cache-dependency-path: 'pyproject.toml' + + - name: Set up project + run: pip install --use-pep517 --prefer-binary --editable='.[cfr,release-cfr]' + + - name: Build application bundle + run: poe build-cfr + + - name: Compute artifact suffix (OS-ARCH) + id: artifact-suffix + uses: ASzc/change-string-case-action@v6 + with: + string: "${{ runner.os }}-${{ runner.arch }}" + + - name: Upload artifact to Workflow Artifacts (Linux and macOS) + if: runner.os != 'Windows' + uses: actions/upload-artifact@v4 + with: + name: "cratedb-cfr-${{ steps.artifact-suffix.outputs.lowercase }}" + path: dist/cratedb-cfr + + - name: Upload artifact to Workflow Artifacts (Windows) + if: runner.os == 'Windows' + uses: actions/upload-artifact@v4 + with: + name: "cratedb-cfr-${{ steps.artifact-suffix.outputs.lowercase }}" + path: dist/cratedb-cfr.exe + + - name: Upload artifact to release assets + if: startsWith(github.event.ref, 'refs/tags') + run: echo "Not implemented yet." + # TODO: Upload to release assets, when invoked on "tag" event. + # https://github.com/grafana-toolbox/grafana-client/blob/4.1.0/.github/workflows/release.yml#L27-L42 + # https://github.com/marketplace/actions/create-release diff --git a/CHANGES.md b/CHANGES.md index 75ea8f69..c0f0433e 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -8,6 +8,7 @@ - SQLAlchemy: Clean up and refactor SQLAlchemy polyfills to `cratedb_toolkit.util.sqlalchemy` - CFR: Build as a self-contained program using PyInstaller +- CFR: Publish self-contained application bundle to GitHub Workflow Artifacts ## 2024/06/18 v0.0.14 - Add `ctk cfr` and `ctk wtf` diagnostics programs diff --git a/pyproject.toml b/pyproject.toml index 138c63d8..8194a46a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -168,6 +168,7 @@ release = [ "twine<6", ] release-cfr = [ + "poethepoet<0.28", "pyinstaller<7", ] service = [