Building a package from a port
These instructions have been tested on a 4GB RAM, 2 vCPUs atlantic.net VPS - nope I don't work for them, but I'm quickly becoming a huge fan
1. Update pkg:
env ASSUME_ALWAYS_YES=YES pkg upgrade
2. Get the ports tree
time portsnap fetch extract
Took about 5 minutes:
110.871u 165.742s 5:03.28 91.2% 62+167k 7361+5099io 32pf+0w
3. Make sure SSL and SASL are added
We want to install Mongo and make sure it compiles with both SSL and SASL enabled - let's check what the default port options are , shall we?
cd /usr/ports/databases/mongodb
make showconfig
Output:
===> The following configuration options are available for mongodb-2.6.6:
SASL=off: SASL authentication support
SSL=on: SSL protocol support
TEST=off: Add support for running regression test
===> Use 'make config' to modify these settings
4. How do we enable SASL so we don't get the prompts?
grep OPTIONS_ Makefile
OPTIONS_DEFINE= SSL SASL TEST
OPTIONS_DEFAULT=SSL
^ That's how - we add 'SASL' next to 'SSL' in 'OPTIONS_DEFAULT'
5. Use AWK to modify the file in a single command:
awk '{ gsub("OPTIONS_DEFAULT=SSL","OPTIONS_DEFAULT=SSL SASL" ) ; print }' Makefile > Makefile2
Backup the original Makefile
mv Makefile Makefile.backup
Rename Makefile2 to Makefile
mv Makefile2 Makefile
6. Check that it worked:
make showconfig
===> The following configuration options are available for mongodb-2.6.6:
SASL=on: SASL authentication support
SSL=on: SSL protocol support
TEST=off: Add support for running regression test
===> Use 'make config' to modify these settings
Looks like it worked.
7. Now prefetch all source files for Mongo and all dependencies:
time make fetch-recursive
8. Get a list of ports that Mongo depends on
We'll install some of the port dependencies using packages to make things faster (in this case we won't get any benefit from installing perl/python from ports!)
make all-depends-list
Output:
/usr/ports/ports-mgmt/pkg
/usr/ports/devel/scons
/usr/ports/devel/pcre
/usr/ports/archivers/snappy
/usr/ports/lang/v8
/usr/ports/security/cyrus-sasl2
/usr/ports/devel/py-setuptools27
/usr/ports/lang/python27
/usr/ports/lang/python2
/usr/ports/devel/m4
/usr/ports/devel/gmake
/usr/ports/lang/perl5.18
/usr/ports/devel/pkgconf
/usr/ports/devel/gettext-tools
/usr/ports/devel/libffi
/usr/ports/devel/gettext-runtime
/usr/ports/print/indexinfo
/usr/ports/textproc/expat2
9. Let's try installing some of those with pkg:
env ASSUME_ALWAYS_YES=YES pkg install scons pcre snappy v8 python27 m4 gmake perl5 gettext-tools libffi
10. Now to compile with no prompts/interruptions:
setenv BATCH yes; time make install clean
We got no prompts and the following output (took 29 minutes and 31 seconds to compile)
===> Cleaning for cyrus-sasl-2.1.26_9
===> Cleaning for mongodb-2.6.6
2466.164u 257.914s 29:31.00 153.8% 25917+543k 3527+394210io 1246pf+28w
11. Now create a pkg out of the port:
pkg create mongodb-2.6.6
Output:
Creating package for mongodb-2.6.6
12. And here's our package:
ls -alh mongodb-2.6.6.txz
-rw-r--r-- 1 root wheel 46M Dec 28 03:24 mongodb-2.6.6.txz
13. Now let's copy the mongodb-2.6.6.txz package to a brand new system that has nothing installed:
scp mongodb-2.6.6.txz root@104.245.33.186:~
The authenticity of host '104.245.33.186 (104.245.33.186)' can't be established.
ECDSA key fingerprint is 48:8f:84:f1:78:e3:ab:c3:3d:e0:17:b0:86:4c:a1:4b.
No matching host key fingerprint found in DNS.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '104.245.33.186' (ECDSA) to the list of known hosts.
Password for root@mongotest2:
mongodb-2.6.6.txz 100% 46MB 15.5MB/s 00:03
14. Install the package on the brand new system:
env ASSUME_ALWAYS_YES=YES pkg install mongodb-2.6.6.txz
The output is too long to copy paste here, so instead let's take a look at the installed packages:
pkg info
cyrus-sasl-2.1.26_9 RFC 2222 SASL (Simple Authentication and Security Layer)
gettext-runtime-0.19.3 GNU gettext runtime libraries and programs
indexinfo-0.2 Utility to regenerate the GNU info page index
libffi-3.0.13_3 Foreign Function Interface
mongodb-2.6.6 NOSQL distributed document-oriented database
pcre-8.35_2 Perl Compatible Regular Expressions library
pkg-1.4.1 Package manager
python2-2_3 The "meta-port" for version 2 of the Python interpreter
python27-2.7.9 Interpreted object-oriented programming language
snappy-1.1.1_1 Fast compressor/decompressor library
v8-3.18.5 Open source JavaScript engine by Google
As you can see pkg installed the mongo package we built plus all of it's dependencies - over 25 minutes saved in compiling time :)