diff --git a/.github/workflows/release-publish.yaml b/.github/workflows/release-publish.yaml index 52ab4c32..200ed5c3 100644 --- a/.github/workflows/release-publish.yaml +++ b/.github/workflows/release-publish.yaml @@ -13,10 +13,20 @@ jobs: release-publish: env: binary_name: dcontainer - binary_name_nonupx: dcontainer.tgz - - - runs-on: ubuntu-18.04 # critical - glibc from host is leaking into the pyoxidizer binary, see https://pyoxidizer.readthedocs.io/en/stable/pyoxidizer_distributing_linux.html#built-application-dependencies + runs-on: ${{ matrix.config.runner }} + + strategy: + fail-fast: true + matrix: + config: + - { + trippletargets: "x86_64-unknown-linux-gnu", + runner: ubuntu-18.04 # critical - glibc from host is leaking into the pyoxidizer binary, see https://pyoxidizer.readthedocs.io/en/stable/pyoxidizer_distributing_linux.html#built-application-dependencies + } + - { + trippletargets: "x86_64-apple-darwin", + runner: macos-12 + } steps: - uses: actions/checkout@v3 @@ -47,7 +57,7 @@ jobs: oxidizer_location=$GITHUB_WORKSPACE wheel_location=./dist/$(ls dist | grep .whl) - target_triple="x86_64-unknown-linux-gnu" + target_triple=${{ matrix.config.trippletargets }} run_command="from dcontainer.__main__ import main; main()" python_version="3.10" @@ -60,34 +70,37 @@ jobs: --var app_name $binary_name \ --target-triple $target_triple - pyoxidizer analyze "$oxidizer_location/build/$target_triple/release/exe/$binary_name" + if [ "${{ matrix.config.trippletargets }}" == "x86_64-unknown-linux-gnu" ]; then + pyoxidizer analyze "$oxidizer_location/build/$target_triple/release/exe/$binary_name" + fi - mv "$oxidizer_location/build/$target_triple/release/exe/$binary_name" $GITHUB_WORKSPACE/build/$binary_name - tar -zcvf $GITHUB_WORKSPACE/build/$binary_name_nonupx $GITHUB_WORKSPACE/build/$binary_name + mv "$oxidizer_location/build/$target_triple/release/exe/$binary_name" $GITHUB_WORKSPACE/build/$binary_name-$target_triple + tar -zcvf $GITHUB_WORKSPACE/build/$binary_name-$target_triple.tgz $GITHUB_WORKSPACE/build/$binary_name-$target_triple - echo "binary_location=$GITHUB_WORKSPACE/build/$binary_name" >> "$GITHUB_OUTPUT" - echo "binary_location_nonupx=$GITHUB_WORKSPACE/build/$binary_name_nonupx" >> "$GITHUB_OUTPUT" + echo "binary_location=$GITHUB_WORKSPACE/build/$binary_name-$target_triple" >> "$GITHUB_OUTPUT" + echo "binary_location_nonupx=$GITHUB_WORKSPACE/build/$binary_name-$target_triple.tgz" >> "$GITHUB_OUTPUT" - name: Strip Binary - run: strip --strip-all ${{ steps.run_pyoxidizer.outputs.binary_location }} + run: strip ${{ steps.run_pyoxidizer.outputs.binary_location }} - name: Compress Binary using UPX + if: matrix.config.trippletargets == 'x86_64-unknown-linux-gnu' uses: crazy-max/ghaction-upx@v2 with: version: "v4.0.2" files: | ${{ steps.run_pyoxidizer.outputs.binary_location }} - args: --best + + # - name: Create Binary checksum + # id: create_checksum - - name: Create Binary checksum - id: create_checksum + # run: | - run: | - cd $(dirname ${{ steps.run_pyoxidizer.outputs.binary_location }}) - sha256sum $binary_name $binary_name_nonupx > checksums.txt - sha256sum -c checksums.txt - echo "checksum_location=$(dirname ${{ steps.run_pyoxidizer.outputs.binary_location }})/checksums.txt" >> "$GITHUB_OUTPUT" + # cd $(dirname ${{ steps.run_pyoxidizer.outputs.binary_location }}) + # sha256sum $binary_name-${{ matrix.config.trippletargets }} $binary_name-${{ matrix.config.trippletargets }}.tgz > checksums.txt + # sha256sum -c checksums.txt + # echo "checksum_location=$(dirname ${{ steps.run_pyoxidizer.outputs.binary_location }})/checksums.txt" >> "$GITHUB_OUTPUT" - name: Create GH Release and upload Binary and checksum uses: softprops/action-gh-release@v0.1.15 @@ -95,4 +108,3 @@ jobs: files: | ${{ steps.run_pyoxidizer.outputs.binary_location }} ${{ steps.run_pyoxidizer.outputs.binary_location_nonupx }} - ${{ steps.create_checksum.outputs.checksum_location }} diff --git a/dcontainer/cli/generate/file_models/dependencies_sh.py b/dcontainer/cli/generate/file_models/dependencies_sh.py index 96ed7036..27de5f0c 100644 --- a/dcontainer/cli/generate/file_models/dependencies_sh.py +++ b/dcontainer/cli/generate/file_models/dependencies_sh.py @@ -5,23 +5,57 @@ from dcontainer.models.devcontainer_feature import FeatureOption from dcontainer.models.devcontainer_feature_definition import ( FeatureDependencies, - FeatureDependency, ) from dcontainer.settings import ENV_CLI_LOCATION, ENV_FORCE_CLI_INSTALLATION -from dcontainer.utils.version import resolve_own_release_version, resolve_own_package_version +from dcontainer.utils.version import resolve_own_release_version logger = logging.getLogger(__name__) -DCONTAINER_LINK = """https://github.com/devcontainers-contrib/cli/releases/download/{RELEASE_VERSION}/dcontainer""" -CHECKSUM_LINK = """https://github.com/devcontainers-contrib/cli/releases/download/{RELEASE_VERSION}/checksums.txt""" +DCONTAINER_LINK = """https://github.com/devcontainers-contrib/cli/releases/download/{RELEASE_VERSION}/dcontainer-x86_64-unknown-linux-gnu""" + +# CHECKSUM_LINK = """https://github.com/devcontainers-contrib/cli/releases/download/{RELEASE_VERSION}/checksums.txt""" HEADER = """#!/usr/bin/env bash # This code was generated by the dcontainer cli # For more information: https://github.com/devcontainers-contrib/cli set -e +ensure_jq() {{ + # Ensure JQ available + if ! type jq >/dev/null 2>&1; then + apt-get update -y && apt-get -y install --no-install-recommends jq + fi +}} +ensure_pipx() {{ + # Ensure the existance of minimal python3 and pipx + # If no python - install it + if ! type python3 >/dev/null 2>&1; then + echo "installing python3-minimal libffi-dev" + apt-get update -y + apt-get -y install python3-minimal + fi + + # If no pip - install it + if ! type pip3 >/dev/null 2>&1; then + echo "installing python3-pip" + apt-get update -y + apt-get -y install libffi-dev python3-pip + fi + + # If ensurepip fails - install python venv + if ! python3 -Im ensurepip --version >/dev/null 2>&1; then + echo "installing python3-venv" + apt-get update -y + apt-get -y install python3-venv + fi + + # If no pipx - install it + if ! pipx >/dev/null 2>&1; then + pip3 install pipx + fi +}} ensure_curl() {{ # Ensure curl available @@ -49,21 +83,28 @@ # If not previuse installation found, download it temporarly and delete at the end of the script if [[ -z "${{dcontainer_location}}" ]]; then - tmp_dir=$(mktemp -d -t dcontainer-XXXXXXXXXX) - - clean_up () {{ - ARG=$? - rm -rf $tmp_dir - exit $ARG - }} - trap clean_up EXIT - - curl -sSL -o $tmp_dir/dcontainer {dcontainer_link} - curl -sSL -o $tmp_dir/checksums.txt {checksums_link} - (cd $tmp_dir ; sha256sum --check --strict --ignore-missing $tmp_dir/checksums.txt) - chmod a+x $tmp_dir/dcontainer - dcontainer_location=$tmp_dir/dcontainer + if [ "$(uname -sm)" != "Linux x86_64" ]; then + # No binaries compiled for non linux x*^ yet, therefor we fallback to install through python + + ensure_pipx + ensure_jq + pipx install dcontainer=={RELEASE_VERSION} + dcontainer_location=$(pipx list --json | jq ".venvs.dcontainer.metadata.main_package.app_paths[0].__Path__" | tr -d '"') + + else + tmp_dir=$(mktemp -d -t dcontainer-XXXXXXXXXX) + + clean_up () {{ + ARG=$? + rm -rf $tmp_dir + exit $ARG + }} + trap clean_up EXIT + curl -sSL -o $tmp_dir/dcontainer {dcontainer_link} + chmod a+x $tmp_dir/dcontainer + dcontainer_location=$tmp_dir/dcontainer + fi fi # Expose outside the resolved location @@ -168,7 +209,7 @@ def to_str(self) -> str: return HEADER.format( dependency_installation_lines="\n\n".join(installation_lines), dcontainer_link=DCONTAINER_LINK.format(RELEASE_VERSION=self.release_version), - checksums_link=CHECKSUM_LINK.format(RELEASE_VERSION=self.release_version), force_cli_installation_env=ENV_FORCE_CLI_INSTALLATION, cli_location_env=ENV_CLI_LOCATION, + RELEASE_VERSION=self.release_version )