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

Avoid build commands when MEDIASOUP_WORKER_BIN is set #695

Merged
merged 1 commit into from
Oct 27, 2021
Merged

Avoid build commands when MEDIASOUP_WORKER_BIN is set #695

merged 1 commit into from
Oct 27, 2021

Conversation

j1elo
Copy link
Contributor

@j1elo j1elo commented Oct 27, 2021

Small fix that prevents needing to even install build tools when MEDIASOUP_WORKER_BIN env var is set.

Fixes #694

This also prevents needing to even install build tools when
MEDIASOUP_WORKER_BIN env var is set.
Copy link
Member

@ibc ibc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. Tested?

@j1elo
Copy link
Contributor Author

j1elo commented Oct 27, 2021

Tests were done manually for this feature. Here are some commands that show the complete test:

First, a Stage 1 (Docker image: node:16 which is Debian with Node and extra tools preinstalled) is prepared with all build deps and used to build the mediasoup-worker file, then that's used on a minimal system in Stage 2 (node:16-slim, which comes with minimal requirements just to run Node stuff):

docker run -ti --rm --name stage1 \
    --entrypoint /bin/bash \
    -v /path/to/mediasoup:/host/mediasoup \
    node:16

apt-get update && apt-get install --no-install-recommends --yes \
    build-essential \
    python3 python3-pip

su node

cd /host/mediasoup/
npm install

Now, a clean Stage 2 is used to test installing with and without this PR's change.

Before the change

docker run -ti --rm --name stage2 \
    --entrypoint /bin/bash \
    -v /path/to/mediasoup:/host/mediasoup \
    node:16-slim

export NODE_ENV="production"
export MEDIASOUP_WORKER_BIN="/host/mediasoup/worker/out/Release/mediasoup-worker"

su node

cd /host/mediasoup/
rm -rf node_modules/
npm install

This renders the following error:

/bin/sh: 1: make: not found
npm ERR! code 1
npm ERR! path /host/mediasoup
npm ERR! command failed
npm ERR! command sh -c node npm-scripts.js postinstall

And installing Make would then complain about missing Python:

exit # Exit `su node`

apt-get update && apt-get install --no-install-recommends --yes \
    make

su node

cd /host/mediasoup/
rm -rf node_modules/
npm install

/bin/sh: 2: python: not found
make: python: Command not found
make: *** [Makefile:56: meson-ninja] Error 127
make: Leaving directory '/host/mediasoup/worker'
npm ERR! code 1
npm ERR! path /host/mediasoup
npm ERR! command failed
npm ERR! command sh -c node npm-scripts.js postinstall

After the change

Stage 2 runs without errors:

docker run -ti --rm --name stage2 \
    --entrypoint /bin/bash \
    -v /path/to/mediasoup:/host/mediasoup \
    node:16-slim

export NODE_ENV="production"
export MEDIASOUP_WORKER_BIN="/host/mediasoup/worker/out/Release/mediasoup-worker"

su node

cd /host/mediasoup/
rm -rf node_modules/
npm install
# OK

Is this enough? I thought how to easily make an automated test from this but it's a bit contrived thing to make because it requires modifying what is installed or not in the system (hence why I used Docker for clean baseline on each stage)

@ibc
Copy link
Member

ibc commented Oct 27, 2021

Honestly I don't know if that's enough, probably it's but it's too Docker dependent.

Something easier:

  • No Docker at all.
  • Build mediasoup normally.
  • Then move the binary somewhere else to /tmp.
  • Set the env variable before running "npm run postinstall", it should NOT compile anything nor require python/pip/meson.
  • Set the env again and run node interactive terminal, require("mediasoup") and create a Worker. It should work normally.

Copy link
Collaborator

@nazar-pc nazar-pc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is correct, thanks!

When I was refactoring it I moved check into worker:build, but then when I added cleanup into postinstall it became incorrect.

@j1elo
Copy link
Contributor Author

j1elo commented Oct 27, 2021

Honestly I don't know if that's enough, probably it's but it's too Docker dependent.

Something easier:

* No Docker at all.
* Build mediasoup normally.
* Then move the binary somewhere else to /tmp.
* Set the env variable before running "npm run postinstall", it should NOT compile anything nor require python/pip/meson.
* Set the env again and run node interactive terminal, require("mediasoup") and create a Worker. It should work normally.

All done and yes, without the change npm run postinstall does run some make and pip install commands; after the change, it does nothing.

Note that my test was actually better by using Docker, and it's not really dependent on Docker itself at all, it's just the tool that I happen to use to ensure a clean (and repeatable) system, and the errors are more obvious because there is nothing installed. In your step 4,

  • Set the env variable before running "npm run postinstall", it should NOT compile anything nor require python/pip/meson.

running without Docker does actually work in my system, because I have lots of customization, tools and packages installed, included Meson. So for a true, isolated test, I would need to install a clean Debian system or maybe make a virtual machine... but at that point, a clean Docker container is already equivalent to those (and faster)

@ibc
Copy link
Member

ibc commented Oct 27, 2021

Thanks. Merging.

@ibc ibc merged commit f100e0f into versatica:v3 Oct 27, 2021
@j1elo j1elo deleted the postinstall-skip branch October 27, 2021 14:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

MEDIASOUP_WORKER_BIN still requires Make and Python in v3.9
3 participants