Skip to content

Commit

Permalink
Install pip invoke in a custom location during npm installation and k…
Browse files Browse the repository at this point in the history
…eep Makefile as a proxy to invoke (WIP)
  • Loading branch information
ibc committed Nov 24, 2023
1 parent 8ccfb27 commit 36a5e90
Show file tree
Hide file tree
Showing 7 changed files with 112 additions and 232 deletions.
4 changes: 0 additions & 4 deletions .github/workflows/mediasoup-node.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,6 @@ jobs:
restore-keys: |
${{ matrix.ci.os }}-node-
# TODO: Temporal until we decide how to deal with pip invoke requirement.
- name: pip install invoke
run: python3 -m pip install invoke

# NOTE: Add --force since otherwise `npm ci` fails in Node 16 because
# @octokit/auth-token dev dependency requires Node >= 16.
- name: npm ci
Expand Down
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@
# Flatc generated files.
/worker/include/FBS
/worker/prebuild
# Vistual Studio generated Stuff.
# Python invoke.
/worker/pip_invoke
# Build artifacts.
/worker/**/Debug
/worker/**/Release
/worker/.vs
# clang-fuzzer stuff is too big.
/worker/deps/clang-fuzzer
# Ignore all fuzzer generated test inputs.
Expand Down
47 changes: 46 additions & 1 deletion npm-scripts.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ import tar from 'tar';
const PKG = JSON.parse(fs.readFileSync('./package.json').toString());
const IS_WINDOWS = os.platform() === 'win32';
const MAYOR_VERSION = PKG.version.split('.')[0];
const INVOKE = process.env.INVOKE || 'invoke';
const PIP_INVOKE_DIR = 'worker/pip_invoke';
const INVOKE = `${PIP_INVOKE_DIR}/bin/invoke`;
const INVOKE_VERSION = process.env.INVOKE_VERSION ?? '2.0.0';
const FLATBUFFERS_VERSION = '23.3.3';
const WORKER_RELEASE_DIR = 'worker/out/Release';
const WORKER_RELEASE_BIN = IS_WINDOWS ? 'mediasoup-worker.exe' : 'mediasoup-worker';
Expand All @@ -22,6 +24,17 @@ const GH_REPO = 'mediasoup';

const task = process.argv.slice(2).join(' ');

// PYTHONPATH env must be updated now so all invoke calls below will find the
// pip invoke module.
if (IS_WINDOWS)
{
process.env.PYTHONPATH = `${PIP_INVOKE_DIR};${process.env.PYTHONPATH}`;
}
else
{
process.env.PYTHONPATH = `${PIP_INVOKE_DIR}:${process.env.PYTHONPATH}`;
}

run();

async function run()
Expand Down Expand Up @@ -273,6 +286,37 @@ async function run()
}
}

function installInvoke()
{
if (fs.existsSync(PIP_INVOKE_DIR))
{
return;
}

logInfo('installInvoke()');

let python = process.env.PYTHON;

if (!python)
{
try
{
execSync('python3 -version', { stdio: [ 'ignore', 'ignore', 'ignore' ] });
python = 'python3';
}
catch (error)
{
python = 'python';
}
}

// Install `invoke` into custom location, so we don't depend on system-wide
// installation.
executeCmd(
`${python} -m pip install --upgrade --target=${PIP_INVOKE_DIR} invoke==${INVOKE_VERSION}`, /* exitOnError */ true
);
}

function deleteNodeLib()
{
if (!fs.existsSync('node/lib'))
Expand Down Expand Up @@ -310,6 +354,7 @@ function buildWorker()
{
logInfo('buildWorker()');

installInvoke();
executeCmd(`${INVOKE} -r worker`);
}

Expand Down
5 changes: 0 additions & 5 deletions worker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,6 @@ ENV LANG="C.UTF-8"
ENV CC="clang"
ENV CXX="clang++"

# Install pip invoke package.
# TODO: Temporal.
RUN set -x \
&& pip3 install invoke

WORKDIR /mediasoup

CMD ["bash"]
5 changes: 0 additions & 5 deletions worker/Dockerfile.alpine
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@ ENV LANG="C.UTF-8"
ENV CC="gcc"
ENV CXX="g++"

# Install pip invoke package.
# TODO: Temporal.
RUN set -x \
&& pip3 install invoke

WORKDIR /mediasoup

CMD ["ash"]
Loading

0 comments on commit 36a5e90

Please sign in to comment.