Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support to publish cfr as a binary using PyInstaller #175

Merged
merged 2 commits into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 75 additions & 0 deletions .github/workflows/release-app.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# Stage PyInstaller application bundles through GitHub Actions (GHA) to GitHub Workflow Artifacts.
# https:/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:/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:/grafana-toolbox/grafana-client/blob/4.1.0/.github/workflows/release.yml#L27-L42
# https:/marketplace/actions/create-release
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
- 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
- CFR: Publish self-contained application bundle to GitHub Workflow Artifacts

## 2024/06/18 v0.0.14
- Add `ctk cfr` and `ctk wtf` diagnostics programs
Expand Down
8 changes: 8 additions & 0 deletions cratedb_toolkit/cfr/cli.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -77,3 +78,10 @@
except Exception as ex:
error_logger(ctx)(ex)
sys.exit(1)


if getattr(sys, "frozen", False):
# https:/pyinstaller/pyinstaller/issues/6368
multiprocessing.freeze_support()

Check warning on line 85 in cratedb_toolkit/cfr/cli.py

View check run for this annotation

Codecov / codecov/patch

cratedb_toolkit/cfr/cli.py#L85

Added line #L85 was not covered by tests
# https://stackoverflow.com/questions/45090083/freeze-a-program-created-with-pythons-click-pacage
cli(sys.argv[1:])

Check warning on line 87 in cratedb_toolkit/cfr/cli.py

View check run for this annotation

Codecov / codecov/patch

cratedb_toolkit/cfr/cli.py#L87

Added line #L87 was not covered by tests
11 changes: 9 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -167,6 +167,10 @@ release = [
"build<2",
"twine<6",
]
release-cfr = [
"poethepoet<0.28",
"pyinstaller<7",
]
service = [
"fastapi<0.112",
"uvicorn<0.31",
Expand Down Expand Up @@ -195,6 +199,7 @@ documentation = "https:/crate-workbench/cratedb-toolkit"
homepage = "https:/crate-workbench/cratedb-toolkit"
repository = "https:/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"
Expand Down Expand Up @@ -355,3 +360,5 @@ release = [
]

test = { cmd = "pytest" }

build-cfr = { cmd = "pyinstaller cratedb_toolkit/cfr/cli.py --onefile --name cratedb-cfr"}