Skip to content

Commit

Permalink
Danielbraun89/issue7 (#8)
Browse files Browse the repository at this point in the history
- A new "generate" as a python extra installation requirement in order to keeps base package requirements to the minimum
- A Pyoxidizer binary is being created from the devcontainer python page (currently without the "generate" extras)
- The binary is striped and compressed in order to keep size and footprint small
- A release with the binary is created on each package publish - alongside with matching check
  • Loading branch information
danielbraun89 authored Mar 3, 2023
1 parent b3ba4ce commit ac49b5a
Show file tree
Hide file tree
Showing 18 changed files with 448 additions and 19 deletions.
75 changes: 72 additions & 3 deletions .github/workflows/python-publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,95 @@ on:
workflow_dispatch:

permissions:
contents: read
contents: write
discussions: write

jobs:
deploy:
env:
binary_name: devcontainer-contrib

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Set up Rust
uses: actions-rs/toolchain@v1
with:
toolchain: stable
override: true

- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: '3.x'

- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install --upgrade build setuptools wheel setuptools-scm
- name: Build package
- name: Build Python Package
run: python -m build --wheel
- name: Publish package

- name: Build Binary using Pyoxidizer
id: run_pyoxidizer

run: |
python -m pip install --upgrade pip
python -m pip install pyoxidizer
oxidizer_location=$GITHUB_WORKSPACE/pyoxidizer-devcontainer-contrib
wheel_location=./dist/$(ls dist | grep .whl)
target_triple="x86_64-unknown-linux-gnu"
run_command="from devcontainer_contrib.__main__ import main; main()"
python_version="3.10"
pyoxidizer build exe \
--path $oxidizer_location \
--release \
--var wheel_location $wheel_location \
--var run_command "$run_command" \
--var python_version $python_version \
--var app_name $binary_name \
--target-triple $target_triple
mv "$oxidizer_location/build/$target_triple/release/exe/$binary_name" $GITHUB_WORKSPACE/$binary_name
echo "binary_location=$GITHUB_WORKSPACE/$binary_name" >> "$GITHUB_OUTPUT"
- name: Strip Binary
run: strip --strip-all ${{ steps.run_pyoxidizer.outputs.binary_location }}

- name: Compress Binary using UPX
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

run: |
sha256sum ${{ steps.run_pyoxidizer.outputs.binary_location }} > $GITHUB_WORKSPACE/checksums.txt
sha256sum -c $GITHUB_WORKSPACE/checksums.txt
echo "checksum_location=$GITHUB_WORKSPACE/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.create_checksum.outputs.checksum_location }}
- name: Publish Python Package
uses: pypa/gh-action-pypi-publish@27b31702a0e7fc50959f5ad993c78deac1bdfc29
with:
user: __token__
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
## Installation


`pip install devcontainer-contrib`
`pip install devcontainer-contrib[generate]`


### Feature Generation:
Expand Down
14 changes: 9 additions & 5 deletions devcontainer_contrib/cli/features.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
import typer

import logging
import pathlib
from devcontainer_contrib.models.devcontainer_feature_definition import (
FeatureDefinition,
)

from devcontainer_contrib.features.dir_modules.test_dir import TestDir
from devcontainer_contrib.features.dir_modules.src_dir import SrcDir

from easyfs import Directory
logger = logging.getLogger(__name__)

app = typer.Typer(pretty_exceptions_show_locals=False, pretty_exceptions_short=False)

Expand All @@ -18,6 +15,13 @@ def generate(
feature_definition: pathlib.Path,
output_dir: pathlib.Path,
) -> None:
try:
from devcontainer_contrib.features_generation.dir_modules.test_dir import TestDir
from devcontainer_contrib.features_generation.dir_modules.src_dir import SrcDir
from easyfs import Directory
except ImportError:
logger.error("Some imports required for feature generation are missing.\nMake sure you have included the generate extras during installation.\n eg. 'pip install devcontainer-contrib[generate]'")
raise typer.Exit(code=1)

definition_model = FeatureDefinition.parse_file(feature_definition)
feature_id = definition_model.id
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
from devcontainer_contrib.models.devcontainer_feature_definition import (
FeatureDefinition,
)
from devcontainer_contrib.features.file_models.dependencies_sh import (
from devcontainer_contrib.features_generation.file_models.dependencies_sh import (
DependenciesSH,
)
from devcontainer_contrib.features.file_models.install_command_sh import (
from devcontainer_contrib.features_generation.file_models.install_command_sh import (
InstallCommandSH,
)
from devcontainer_contrib.features.file_models.install_sh import InstallSH
from devcontainer_contrib.features.file_models.devcontainer_feature_json import (
from devcontainer_contrib.features_generation.file_models.install_sh import InstallSH
from devcontainer_contrib.features_generation.file_models.devcontainer_feature_json import (
DevcontainerFeatureJson,
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
from devcontainer_contrib.models.devcontainer_feature_definition import (
FeatureDefinition,
)
from devcontainer_contrib.features.file_models.scenarios_json import (
from devcontainer_contrib.features_generation.file_models.scenarios_json import (
ScenariosJson,
)
from devcontainer_contrib.features.file_models.test_sh import (
from devcontainer_contrib.features_generation.file_models.test_sh import (
TestSH,
)

Expand Down
Loading

0 comments on commit ac49b5a

Please sign in to comment.