How do I install pip packages to an image as part of the build process

450 views
Skip to first unread message

ba...@rtbrick.com

unread,
Nov 23, 2017, 12:08:23 PM11/23/17
to opennetworklinux
Hi All,

How do I add python pip packages like python-iptables(that we install using pip for eg. pip install python-iptables) to the prebuilt image for ONL?

Regards
Basil

Jeffrey Townsend

unread,
Nov 28, 2017, 2:56:46 PM11/28/17
to ba...@rtbrick.com, opennetworklinux
Basil, 

You can perform any post-setup steps you like using the Configure:commands and Configure:scripts sections in the yaml file for your root filesystem. 

In the case of the commands section it just runs the command you specify. You can refer to the root filesystem directory as $(__rfs__)s in your command. 

For example, if you added python-pip as a debian package and then wanted to run a pip install command you would add the following under Configure:

commands:
    - 'sudo chroot %(__rfs__)s pip install python-iptables'

For your particular use case you will run into other issues which will also need to be resolved or accepted:

1. The chroot into the root filesystem does not have a resolv.conf at the time your command is executed so pip transactions (really general network transactions) won't be successful. You can probably fix this by added a 'sudo cp /etc/resolv.conf %(__rfs__)s/etc/' command before the pip command. 
2. PIP install will likely need to compile things within the chroot and those dependencies will get added to the packages installed in the RFS. If you don't want these in the final image you will want to clean it up afterwards. 

If the commands you need to execute get too complicated you can put them all in a script and execute that instead by adding to the scripts section:

scripts:
    - myscript.py

The script is executed under sudo and the first and only argument is the root filesystem directory. From there you can do as much or as little as you want. 

I'd be happy to help your further once you try these out. 

Jeff

--
You received this message because you are subscribed to the Google Groups "opennetworklinux" group.
To unsubscribe from this group and stop receiving emails from it, send an email to opennetworklinux+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages