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

feat! Create a script to build adaptor package artifacts #85

Merged
merged 1 commit into from
Feb 14, 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
6 changes: 3 additions & 3 deletions DEVELOPMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,12 @@ You can run the adaptor on your local workstation. This approach does not contai

```bash
# Path mapping disabled
NukeAdaptor run --init-data file://init-data.yaml --run-data file://run-data.yaml
nuke-openjd run --init-data file://init-data.yaml --run-data file://run-data.yaml

#path mapping enabled
NukeAdaptor run --init-data file://init-data.yaml --run-data file://run-data.yaml --path-mapping-rules file://path-mapping.yaml
nuke-openjd run --init-data file://init-data.yaml --run-data file://run-data.yaml --path-mapping-rules file://path-mapping.yaml
```

NOTE: The NukeAdaptor expects that the Nuke executable is named `nuke` and is set on the PATH. If this is not the case, you can set the `NUKE_ADAPTOR_NUKE_EXECUTABLE` environment variable to the path to the Nuke executable.
NOTE: The nuke-openjd binary expects that the Nuke executable is named `nuke` and is set on the PATH. If this is not the case, you can set the `NUKE_ADAPTOR_NUKE_EXECUTABLE` environment variable to the path to the Nuke executable.

4. The result will be written based on the output specified on the write node, taking any path mapping into account.
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ parameterValues:
value: /normalized/job/bundle/dir/cwd-path.nk
- name: ProxyMode
value: 'false'
- name: TelemetryOptOut
value: 'false'
- name: deadline:targetTaskRunStatus
value: READY
- name: deadline:maxFailedTasksCount
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,6 @@ parameterDefinitions:
allowedValues:
- 'true'
- 'false'
- name: TelemetryOptOut
type: STRING
default: 'false'
allowedValues:
- 'true'
- 'false'
steps:
- name: Render
parameterSpace:
Expand All @@ -84,7 +78,6 @@ steps:
continue_on_error: {{Param.ContinueOnError}}
proxy: {{Param.ProxyMode}}
script_file: '{{Param.NukeScriptFile}}'
telemetry_opt_out: {{Param.TelemetryOptOut}}
write_nodes:
- '{{Param.WriteNode}}'
views:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ parameterValues:
value: /normalized/job/bundle/dir/group-read.nk
- name: ProxyMode
value: 'false'
- name: TelemetryOptOut
value: 'false'
- name: deadline:targetTaskRunStatus
value: READY
- name: deadline:maxFailedTasksCount
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,6 @@ parameterDefinitions:
allowedValues:
- 'true'
- 'false'
- name: TelemetryOptOut
type: STRING
default: 'false'
allowedValues:
- 'true'
- 'false'
steps:
- name: Render
parameterSpace:
Expand All @@ -83,7 +77,6 @@ steps:
continue_on_error: {{Param.ContinueOnError}}
proxy: {{Param.ProxyMode}}
script_file: '{{Param.NukeScriptFile}}'
telemetry_opt_out: {{Param.TelemetryOptOut}}
write_nodes:
- '{{Param.WriteNode}}'
views:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ parameterValues:
value: /normalized/job/bundle/dir/multi-load-save.nk
- name: ProxyMode
value: 'false'
- name: TelemetryOptOut
value: 'false'
- name: deadline:targetTaskRunStatus
value: READY
- name: deadline:maxFailedTasksCount
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,6 @@ parameterDefinitions:
allowedValues:
- 'true'
- 'false'
- name: TelemetryOptOut
type: STRING
default: 'false'
allowedValues:
- 'true'
- 'false'
steps:
- name: Render
parameterSpace:
Expand All @@ -86,7 +80,6 @@ steps:
continue_on_error: {{Param.ContinueOnError}}
proxy: {{Param.ProxyMode}}
script_file: '{{Param.NukeScriptFile}}'
telemetry_opt_out: {{Param.TelemetryOptOut}}
write_nodes:
- '{{Param.WriteNode}}'
views:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ parameterValues:
value: /normalized/job/bundle/dir/noise-saver.nk
- name: ProxyMode
value: 'false'
- name: TelemetryOptOut
value: 'false'
- name: deadline:targetTaskRunStatus
value: READY
- name: deadline:maxFailedTasksCount
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,6 @@ parameterDefinitions:
allowedValues:
- 'true'
- 'false'
- name: TelemetryOptOut
type: STRING
default: 'false'
allowedValues:
- 'true'
- 'false'
steps:
- name: Render
parameterSpace:
Expand All @@ -84,7 +78,6 @@ steps:
continue_on_error: {{Param.ContinueOnError}}
proxy: {{Param.ProxyMode}}
script_file: '{{Param.NukeScriptFile}}'
telemetry_opt_out: {{Param.TelemetryOptOut}}
write_nodes:
- '{{Param.WriteNode}}'
views:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ parameterValues:
value: /normalized/job/bundle/dir/ocio.nk
- name: ProxyMode
value: 'false'
- name: TelemetryOptOut
value: 'false'
- name: deadline:targetTaskRunStatus
value: READY
- name: deadline:maxFailedTasksCount
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,6 @@ parameterDefinitions:
allowedValues:
- 'true'
- 'false'
- name: TelemetryOptOut
type: STRING
default: 'false'
allowedValues:
- 'true'
- 'false'
steps:
- name: Render
parameterSpace:
Expand All @@ -84,7 +78,6 @@ steps:
continue_on_error: {{Param.ContinueOnError}}
proxy: {{Param.ProxyMode}}
script_file: '{{Param.NukeScriptFile}}'
telemetry_opt_out: {{Param.TelemetryOptOut}}
write_nodes:
- '{{Param.WriteNode}}'
views:
Expand Down
6 changes: 4 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ requires-python = ">=3.7"

dependencies = [
"deadline == 0.37.*",
"openjd-adaptor-runtime == 0.3.*",
"openjd-adaptor-runtime == 0.4.*",
]

[project.scripts]
nuke-openjd = "deadline.nuke_adaptor.NukeAdaptor:main"
# The binary name 'NukeAdaptor' is deprecated.
NukeAdaptor = "deadline.nuke_adaptor.NukeAdaptor:main"

[tool.hatch.build]
Expand Down Expand Up @@ -126,7 +128,7 @@ source = [

[tool.coverage.report]
show_missing = true
fail_under = 73
fail_under = 72

[tool.semantic_release]
# Can be removed or set to true once we are v1
Expand Down
181 changes: 181 additions & 0 deletions scripts/create_adaptor_packaging_artifact.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
#!/usr/bin/env bash
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
set -xeou pipefail

APP=nuke
ADAPTOR_NAME=deadline-cloud-for-$APP

# This script generates an tar.gz artifact from $ADAPTOR_NAME and its dependencies
# that can be used to create a package for running the adaptor.

SCRIPTDIR=$(realpath $(dirname $0))

SOURCE=0
# Python 3.11 is for https://vfxplatform.com/ CY2024
PYTHON_VERSION=3.11
CONDA_PLATFORM=linux-64
TAR_BASE=

while [ $# -gt 0 ]; do
case "${1}" in
--source) SOURCE=1 ; shift ;;
--platform) CONDA_PLATFORM="$2" ; shift 2 ;;
--python) PYTHON_VERSION="$2" ; shift 2 ;;
--tar-base) TAR_BASE="$2" ; shift 2 ;;
*) echo "Unexpected option: $1"; exit 1 ;;
esac
done

if [ "$CONDA_PLATFORM" = "linux-64" ]; then
PYPI_PLATFORM=manylinux2014_x86_64
elif [ "$CONDA_PLATFORM" = "win-64" ]; then
PYPI_PLATFORM=win_amd64
elif [ "$CONDA_PLATFORM" = "osx-64" ]; then
PYPI_PLATFORM=macosx_10_9_x86_64
else
echo "Unknown Conda operating system option --platform $CONDA_PLATFORM"
exit 1
fi

if [ "$TAR_BASE" = "" ]; then
TAR_BASE=$SCRIPTDIR/../$APP-openjd-py$PYTHON_VERSION-$CONDA_PLATFORM
fi

# Create a temporary prefix
WORKDIR=$(mktemp -d adaptor-pkg.XXXXXXXXXX)
function cleanup_workdir {
echo "Cleaning up $WORKDIR"
rm -rf $WORKDIR
}
trap cleanup_workdir EXIT

PREFIX=$WORKDIR/prefix

if [ "$CONDA_PLATFORM" = "win-64" ]; then
BINDIR=$PREFIX/Library/bin
PACKAGEDIR=$PREFIX/Library/opt/$ADAPTOR_NAME
else
BINDIR=$PREFIX/bin
PACKAGEDIR=$PREFIX/opt/$ADAPTOR_NAME
fi


mkdir -p $PREFIX
mkdir -p $PACKAGEDIR
mkdir -p $BINDIR

# Install the adaptor into the virtual env
if [ $SOURCE = 1 ]; then
# In source mode, openjd-adaptor-runtime-for-python must be alongside this adaptor source
RUNTIME_INSTALLABLE=$SCRIPTDIR/../../openjd-adaptor-runtime-for-python
ADAPTOR_INSTALLABLE=$SCRIPTDIR/..

if [ "$CONDA_PLATFORM" = "win-64" ]; then
DEPS="pyyaml jsonschema pywin32"
else
DEPS="pyyaml jsonschema"
fi

pip install \
--target $PACKAGEDIR \
--platform $PYPI_PLATFORM \
--python-version $PYTHON_VERSION \
--ignore-installed \
--only-binary=:all: \
$DEPS
pip install \
--target $PACKAGEDIR \
--platform $PYPI_PLATFORM \
--python-version $PYTHON_VERSION \
--ignore-installed \
--no-deps \
$RUNTIME_INSTALLABLE \
$ADAPTOR_INSTALLABLE
else
# In PyPI mode, PyPI and/or a CodeArtifact must have these packages
RUNTIME_INSTALLABLE=openjd-adaptor-runtime-for-python
ADAPTOR_INSTALLABLE=$ADAPTOR_NAME

pip install \
--target $PACKAGEDIR \
--platform $PYPI_PLATFORM \
--python-version $PYTHON_VERSION \
--ignore-installed \
--only-binary=:all: \
$RUNTIME_INSTALLABLE
pip install \
--target $PACKAGEDIR \
--platform $PYPI_PLATFORM \
--python-version $PYTHON_VERSION \
--ignore-installed \
--no-deps \
$ADAPTOR_INSTALLABLE
fi


# Remove the submitter code
rm -r $PACKAGEDIR/deadline/*_submitter

# Remove the bin dir if there is one
if [ -d $PACKAGEDIR/bin ]; then
rm -r $PACKAGEDIR/bin
fi

PYSCRIPT="from pathlib import Path
import sys
reentry_exe = Path(sys.argv[0]).absolute()
sys.path.append(str(reentry_exe.parent.parent / \"opt\" / \"$ADAPTOR_NAME\"))
from deadline.${APP}_adaptor.${APP^}Adaptor.__main__ import main
sys.exit(main(reentry_exe=reentry_exe))
"

cat <<EOF > $BINDIR/$APP-openjd
#!/usr/bin/env python3.11
$PYSCRIPT
EOF

# Temporary
cp $BINDIR/$APP-openjd $BINDIR/${APP^}Adaptor

chmod u+x $BINDIR/$APP-openjd $BINDIR/${APP^}Adaptor

if [ $CONDA_PLATFORM = "win-64" ]; then
# Install setuptools to get cli-64.exe
mkdir -p $WORKDIR/tmp
pip install \
--target $WORKDIR/tmp \
--platform $PYPI_PLATFORM \
--python-version $PYTHON_VERSION \
--ignore-installed \
--no-deps \
setuptools

# Use setuptools' cli-64.exe to define the entry point
cat <<EOF > $BINDIR/$APP-openjd-script.py
#!C:\\Path\\To\\Python.exe
$PYSCRIPT
EOF
cp $WORKDIR/tmp/setuptools/cli-64.exe $BINDIR/$APP-openjd.exe
fi

# Everything between the first "-" and the next "+" is the package version number
PACKAGEVER=$(cd $PACKAGEDIR; echo deadline_cloud_for*)
PACKAGEVER=${PACKAGEVER#*-}
PACKAGEVER=${PACKAGEVER%+*}
echo "Package version number is $PACKAGEVER"

# Create the tar artifact
GIT_TIMESTAMP="$(env TZ=UTC git log -1 --date=iso-strict-local --format="%ad")"
pushd $PREFIX
# See https://reproducible-builds.org/docs/archives/ for information about
# these options
#tar --mtime=$GIT_TIMESTAMP \
# --sort=name \
# --pax-option=exthdr.name=%d/PaxHeaders/%f,delete=atime,delete=ctime \
# --owner=0 --group=0 --numeric-owner \
# -cf $TAR_BASE .
# TODO Switch to the above command once the build environment has tar version > 1.28
tar --owner=0 --group=0 --numeric-owner \
-cf $TAR_BASE-$PACKAGEVER.tar.gz .
sha256sum $TAR_BASE-$PACKAGEVER.tar.gz
popd
Loading