Skip to content

Commit

Permalink
Danielbraun89/issue14 (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielbraun89 authored Mar 14, 2023
1 parent 6d1dd98 commit 99f0ba6
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 39 deletions.
52 changes: 32 additions & 20 deletions .github/workflows/release-publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand All @@ -60,39 +70,41 @@ 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/[email protected]
with:
files: |
${{ steps.run_pyoxidizer.outputs.binary_location }}
${{ steps.run_pyoxidizer.outputs.binary_location_nonupx }}
${{ steps.create_checksum.outputs.checksum_location }}
79 changes: 60 additions & 19 deletions dcontainer/cli/generate/file_models/dependencies_sh.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
)

0 comments on commit 99f0ba6

Please sign in to comment.