Skip to content

Instantly share code, notes, and snippets.

@christiankakesa
Created November 24, 2017 21:16
Show Gist options
  • Save christiankakesa/8bb995bc89fdea0fe2d241ea7cab9d23 to your computer and use it in GitHub Desktop.
Save christiankakesa/8bb995bc89fdea0fe2d241ea7cab9d23 to your computer and use it in GitHub Desktop.
If you want to play with Faktory on Ubuntu 16.04, this bash script could help you.
#!/bin/sh
#
# Faktory build on Ubuntu 16.04
#
# Christian Kakesa <[email protected]>
# 2017-11-23
set -eu
BASEDIR=${HOME}/src/faktory
if [ ! -d ${BASEDIR} ]
then
echo "create directory: ${BASEDIR}"
mkdir -p ${BASEDIR}
fi
cd ${BASEDIR}
SHA256_CMD=sha256sum
# ZLIB_VER=1.2.11
# ZLIB_SHA256=c3e5e9fdd5004dcb542feda5ee4f0ff0744628baf8ed2dd5d66f8ca1197cb1a1
# ZLIB_DOWNLOAD_BASE=http://zlib.net
# BZIP2_VER=1.0.6
# BZIP2_SHA256=a2848f34fcd5d6cf47def00461fcb528a0484d8edef8208d6d2e2909dc61d9cd
# BZIP2_DOWNLOAD_BASE=http://www.bzip.org
# SNAPPY_VER=1.1.4
# SNAPPY_SHA256=134bfe122fd25599bb807bb8130e7ba6d9bdb851e0b16efcb83ac4f5d0b70057
# SNAPPY_DOWNLOAD_BASE=https://github.com/google/snappy/releases/download
# LZ4_VER=1.7.5
# LZ4_SHA256=0190cacd63022ccb86f44fa5041dc6c3804407ad61550ca21c382827319e7e7e
# LZ4_DOWNLOAD_BASE=https://github.com/lz4/lz4/archive
# ZSTD_VER=1.2.0
# ZSTD_SHA256=4a7e4593a3638276ca7f2a09dc4f38e674d8317bbea51626393ca73fc047cbfb
# ZSTD_DOWNLOAD_BASE=https://github.com/facebook/zstd/archive
ZLIB_VER=1.2.11
ZLIB_SHA256=c3e5e9fdd5004dcb542feda5ee4f0ff0744628baf8ed2dd5d66f8ca1197cb1a1
ZLIB_DOWNLOAD_BASE=http://zlib.net
BZIP2_VER=1.0.6
BZIP2_SHA256=a2848f34fcd5d6cf47def00461fcb528a0484d8edef8208d6d2e2909dc61d9cd
BZIP2_DOWNLOAD_BASE=http://www.bzip.org
SNAPPY_VER=1.1.7
SNAPPY_SHA256=3dfa02e873ff51a11ee02b9ca391807f0c8ea0529a4924afa645fbf97163f9d4
SNAPPY_DOWNLOAD_BASE=https://github.com/google/snappy/archive
LZ4_VER=1.8.0
LZ4_SHA256=2ca482ea7a9bb103603108b5a7510b7592b90158c151ff50a28f1ca8389fccf6
LZ4_DOWNLOAD_BASE=https://github.com/lz4/lz4/archive
ZSTD_VER=1.3.2
ZSTD_SHA256=ac5054a3c64e6510bc1ae890d05e3d271cc33ceebc9d06ac9f08105766d2798a
ZSTD_DOWNLOAD_BASE=https://github.com/facebook/zstd/archive
ROCKSDB_VER=5.8.6
ROCKSDB_SHA256=d6fe7596d195447749ee5cd9d34d340cd1fb6fa62a04ea07b0aaeeda110e3a49
ROCKSDB_DOWNLOAD_BASE=https://github.com/facebook/rocksdb/archive/
GO_VER=1.9.2
GO_SHA256=de874549d9a8d8d8062be05808509c09a88a248e77ec14eb77453530829ac02b
GO_DOWNLOAD_BASE=https://storage.googleapis.com/golang
FAKTORY_VER=v0.6.1-1
# ZLIB
cd ${BASEDIR}
curl -O -L ${ZLIB_DOWNLOAD_BASE}/zlib-${ZLIB_VER}.tar.gz
ZLIB_SHA256_ACTUAL=`${SHA256_CMD} zlib-${ZLIB_VER}.tar.gz | cut -d ' ' -f 1`; \
if [ "${ZLIB_SHA256}" != "${ZLIB_SHA256_ACTUAL}" ]; then \
echo zlib-${ZLIB_VER}.tar.gz checksum mismatch, expected=\"${ZLIB_SHA256}\" actual=\"${ZLIB_SHA256_ACTUAL}\"; \
exit 1; \
fi
tar xvzf zlib-${ZLIB_VER}.tar.gz
cd zlib-${ZLIB_VER} && CFLAGS="-fPIC ${EXTRA_CFLAGS:-""}" LDFLAGS="${EXTRA_LDFLAGS:-""}" ./configure --static && make
cp ${BASEDIR}/zlib-${ZLIB_VER}/libz.a ${BASEDIR}/
# BZIP2
cd ${BASEDIR}
curl -O -L ${BZIP2_DOWNLOAD_BASE}/${BZIP2_VER}/bzip2-${BZIP2_VER}.tar.gz
BZIP2_SHA256_ACTUAL=`${SHA256_CMD} bzip2-${BZIP2_VER}.tar.gz | cut -d ' ' -f 1`; \
if [ "${BZIP2_SHA256}" != "${BZIP2_SHA256_ACTUAL}" ]; then \
echo bzip2-${BZIP2_VER}.tar.gz checksum mismatch, expected=\"${BZIP2_SHA256}\" actual=\"${BZIP2_SHA256_ACTUAL}\"; \
exit 1; \
fi
tar xvzf bzip2-${BZIP2_VER}.tar.gz
cd bzip2-${BZIP2_VER} && make CFLAGS="-fPIC -O2 -g -D_FILE_OFFSET_BITS=64 ${EXTRA_CFLAGS:-""}" AR="ar ${EXTRA_ARFLAGS:-""}"
cp ${BASEDIR}/bzip2-${BZIP2_VER}/libbz2.a ${BASEDIR}/
# SNAPPY
cd ${BASEDIR}
curl -O -L ${SNAPPY_DOWNLOAD_BASE}/${SNAPPY_VER}/snappy-${SNAPPY_VER}.tar.gz
SNAPPY_SHA256_ACTUAL=`${SHA256_CMD} snappy-${SNAPPY_VER}.tar.gz | cut -d ' ' -f 1`; \
if [ "${SNAPPY_SHA256}" != "${SNAPPY_SHA256_ACTUAL}" ]; then \
echo snappy-${SNAPPY_VER}.tar.gz checksum mismatch, expected=\"${SNAPPY_SHA256}\" actual=\"${SNAPPY_SHA256_ACTUAL}\"; \
exit 1; \
fi
tar xvzf snappy-${SNAPPY_VER}.tar.gz
cd snappy-${SNAPPY_VER}
if [ ! -d build ]; then
mkdir build
fi
cd build && cmake ../ && make
cp ${BASEDIR}/snappy-${SNAPPY_VER}/build/libsnappy.a ${BASEDIR}/
# LZ4
cd ${BASEDIR}
curl -O -L ${LZ4_DOWNLOAD_BASE}/v${LZ4_VER}.tar.gz
mv v${LZ4_VER}.tar.gz lz4-${LZ4_VER}.tar.gz
LZ4_SHA256_ACTUAL=`${SHA256_CMD} lz4-${LZ4_VER}.tar.gz | cut -d ' ' -f 1`; \
if [ "${LZ4_SHA256}" != "${LZ4_SHA256_ACTUAL}" ]; then \
echo lz4-${LZ4_VER}.tar.gz checksum mismatch, expected=\"${LZ4_SHA256}\" actual=\"${LZ4_SHA256_ACTUAL}\"; \
exit 1; \
fi
tar xvzf lz4-${LZ4_VER}.tar.gz
cd lz4-${LZ4_VER}/lib && make CFLAGS="-fPIC -O2 ${EXTRA_CFLAGS:-""}" all
cp ${BASEDIR}/lz4-${LZ4_VER}/lib/liblz4.a ${BASEDIR}/
# ZSTD
cd ${BASEDIR}
curl -O -L ${ZSTD_DOWNLOAD_BASE}/v${ZSTD_VER}.tar.gz
mv v${ZSTD_VER}.tar.gz zstd-${ZSTD_VER}.tar.gz
ZSTD_SHA256_ACTUAL=`${SHA256_CMD} zstd-${ZSTD_VER}.tar.gz | cut -d ' ' -f 1`; \
if [ "${ZSTD_SHA256}" != "${ZSTD_SHA256_ACTUAL}" ]; then \
echo zstd-${ZSTD_VER}.tar.gz checksum mismatch, expected=\"${ZSTD_SHA256}\" actual=\"${ZSTD_SHA256_ACTUAL}\"; \
exit 1; \
fi
tar xvzf zstd-${ZSTD_VER}.tar.gz
cd zstd-${ZSTD_VER}/lib && make CFLAGS="-fPIC -O2 ${EXTRA_CFLAGS:-""}" all
cp ${BASEDIR}/zstd-${ZSTD_VER}/lib/libzstd.a ${BASEDIR}/
# ROCKSDB
cd ${BASEDIR}
curl -O -L ${ROCKSDB_DOWNLOAD_BASE}/v${ROCKSDB_VER}.tar.gz
mv v${ROCKSDB_VER}.tar.gz rocksdb-${ROCKSDB_VER}.tar.gz
ROCKSDB_SHA256_ACTUAL=`${SHA256_CMD} rocksdb-${ROCKSDB_VER}.tar.gz | cut -d ' ' -f 1`; \
if [ "${ROCKSDB_SHA256}" != "${ROCKSDB_SHA256_ACTUAL}" ]; then \
echo rocksdb-${ROCKSDB_VER}.tar.gz checksum mismatch, expected=\"${ROCKSDB_SHA256}\" actual=\"${ROCKSDB_SHA256_ACTUAL}\"; \
exit 1; \
fi
tar xvzf rocksdb-${ROCKSDB_VER}.tar.gz
cd rocksdb-${ROCKSDB_VER}
export EXTRA_CFLAGS=" -I${BASEDIR}/zlib-${ZLIB_VER}/ -DZLIB -I${BASEDIR}/bzip2-${BZIP2_VER}/ -DBZIP2 -I${BASEDIR}/snappy-${SNAPPY_VER}/ -DSNAPPY -I${BASEDIR}/lz4-${LZ4_VER}/lib/ -DLZ4 -I${BASEDIR}/zstd-${ZSTD_VER}/lib/ -DZSTD"
export EXEC_LDFLAGS=" ${BASEDIR}/zlib-${ZLIB_VER}/libz.a ${BASEDIR}/bzip2-${BZIP2_VER}/libbz2.a ${BASEDIR}/snappy-${SNAPPY_VER}/build/libsnappy.a ${BASEDIR}/lz4-${LZ4_VER}/lib/liblz4.a ${BASEDIR}/zstd-${ZSTD_VER}/lib/libzstd.a"
export EXTRA_CXXFLAGS=" ${EXTRA_CFLAGS}"
DEBUG_LEVEL=0 PORTABLE=1 make -j8 static_lib
strip -g librocksdb.a
cp ${BASEDIR}/rocksdb-${ROCKSDB_VER}/librocksdb.a ${BASEDIR}/
# FAKTORY
## Golang
cd ${BASEDIR}
curl -O -L "${GO_DOWNLOAD_BASE}/go${GO_VER}.linux-amd64.tar.gz"
GO_SHA256_ACTUAL=`${SHA256_CMD} go${GO_VER}.linux-amd64.tar.gz | cut -d ' ' -f 1`; \
if [ "${GO_SHA256}" != "${GO_SHA256_ACTUAL}" ]; then \
echo go${GO_VER}.linux-amd64.tar.gz checksum mismatch, expected=\"${GO_SHA256}\" actual=\"${GO_SHA256_ACTUAL}\"; \
exit 1; \
fi
tar xvzf go${GO_VER}.linux-amd64.tar.gz
export GOROOT=${BASEDIR}/go
export GOPATH=${BASEDIR}/goworkspace
mkdir -p ${GOPATH}
export GOBIN=${GOPATH}/bin
export PATH=${GOROOT}/bin:${GOBIN}:${PATH}
which go
go version
## Faktory
rm -f ${BASEDIR}/faktory-${FAKTORY_VER}.linux-amd64.tar.gz \
${BASEDIR}/faktory \
${BASEDIR}/faktory-cli
rm -rf ${GOPATH}/src/github.com/contribsys/faktory
mkdir -p ${GOPATH}/src/github.com/contribsys/faktory
cd ${GOPATH}/src/github.com/contribsys/faktory
git clone https://github.com/contribsys/faktory.git .
git checkout ${FAKTORY_VER}
export ROCKSDB_HOME="${BASEDIR}/rocksdb-${ROCKSDB_VER}"
echo "ROCKSDB_HOME: ${ROCKSDB_HOME}"
export CGO_CFLAGS=" -I${ROCKSDB_HOME}/include ${EXTRA_CFLAGS}"
echo "CGO_CFLAGS: ${CGO_CFLAGS}"
export CGO_LDFLAGS=" -L${BASEDIR} -lrocksdb -lstdc++ -lm -lz -lbz2 -lsnappy -llz4 -lzstd"
echo "CGO_LDFLAGS: ${CGO_LDFLAGS}"
make prepare
make test
make build
cp ${GOPATH}/src/github.com/contribsys/faktory/faktory ${BASEDIR}/
cp ${GOPATH}/src/github.com/contribsys/faktory/faktory-cli ${BASEDIR}/
tar zcvf ${BASEDIR}/faktory-${FAKTORY_VER}.linux-amd64.tar.gz faktory faktory-cli
# Remove files
cd ${BASEDIR}
rm -rf ${BASEDIR}/zlib-${ZLIB_VER}.tar.gz ${BASEDIR}/zlib-${ZLIB_VER}
rm -rf ${BASEDIR}/bzip2-${BZIP2_VER}.tar.gz ${BASEDIR}/bzip2-${BZIP2_VER}
rm -rf ${BASEDIR}/snappy-${SNAPPY_VER}.tar.gz ${BASEDIR}/snappy-${SNAPPY_VER}
rm -rf ${BASEDIR}/lz4-${LZ4_VER}.tar.gz ${BASEDIR}/lz4-${LZ4_VER}
rm -rf ${BASEDIR}/zstd-${ZSTD_VER}.tar.gz ${BASEDIR}/zstd-${ZSTD_VER}
rm -rf ${BASEDIR}/rocksdb-${ROCKSDB_VER}.tar.gz ${BASEDIR}/rocksdb-${ROCKSDB_VER}
rm -f ${BASEDIR}/libbz2.a
rm -f ${BASEDIR}/liblz4.a
rm -f ${BASEDIR}/librocksdb.a
rm -f ${BASEDIR}/libsnappy.a
rm -f ${BASEDIR}/libz.a
rm -f ${BASEDIR}/libzstd.a
rm -rf ${BASEDIR}/go${GO_VER}.linux-amd64.tar.gz ${BASEDIR}/go ${BASEDIR}/goworkspace
# Result
echo [Build of FAKTORY ${FAKTORY_VER}]
ls -l ${BASEDIR}/
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment