|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# Load stack utils |
| 4 | +. /usr/bin/stack-utils |
| 5 | + |
| 6 | +# Implement build function |
| 7 | +function build() { |
| 8 | + # Generate binary |
| 9 | + REDIS_DOWNLOAD_URL="http://download.redis.io/releases/redis-${STACK_VERSION}.tar.gz" |
| 10 | + savedAptMark="$(apt-mark showmanual)"; \ |
| 11 | + curl -fsSL -o redis.tar.gz "$REDIS_DOWNLOAD_URL"; \ |
| 12 | + mkdir -p /usr/src/redis; \ |
| 13 | + tar -xzf redis.tar.gz -C /usr/src/redis --strip-components=1; \ |
| 14 | + rm redis.tar.gz; \ |
| 15 | + grep -E '^ *createBoolConfig[(]"protected-mode",.*, *1 *,.*[)],$' /usr/src/redis/src/config.c; \ |
| 16 | + sed -ri 's!^( *createBoolConfig[(]"protected-mode",.*, *)1( *,.*[)],)$!\10\2!' /usr/src/redis/src/config.c; \ |
| 17 | + grep -E '^ *createBoolConfig[(]"protected-mode",.*, *0 *,.*[)],$' /usr/src/redis/src/config.c; \ |
| 18 | + gnuArch="$(dpkg-architecture --query DEB_BUILD_GNU_TYPE)"; \ |
| 19 | + extraJemallocConfigureFlags="--build=$gnuArch"; \ |
| 20 | + # https://salsa.debian.org/debian/jemalloc/-/blob/c0a88c37a551be7d12e4863435365c9a6a51525f/debian/rules#L8-23 |
| 21 | + dpkgArch="$(dpkg --print-architecture)"; \ |
| 22 | + case "${dpkgArch##*-}" in \ |
| 23 | + amd64 | i386 | x32) extraJemallocConfigureFlags="$extraJemallocConfigureFlags --with-lg-page=12" ;; \ |
| 24 | + *) extraJemallocConfigureFlags="$extraJemallocConfigureFlags --with-lg-page=16" ;; \ |
| 25 | + esac; \ |
| 26 | + extraJemallocConfigureFlags="$extraJemallocConfigureFlags --with-lg-hugepage=21"; \ |
| 27 | + grep -F 'cd jemalloc && ./configure ' /usr/src/redis/deps/Makefile; \ |
| 28 | + sed -ri 's!cd jemalloc && ./configure !&'"$extraJemallocConfigureFlags"' !' /usr/src/redis/deps/Makefile; \ |
| 29 | + grep -F "cd jemalloc && ./configure $extraJemallocConfigureFlags " /usr/src/redis/deps/Makefile; \ |
| 30 | + \ |
| 31 | + export BUILD_TLS=yes; \ |
| 32 | + make -C /usr/src/redis -j "$(nproc)" all; \ |
| 33 | + make -C /usr/src/redis PREFIX=/opt/drycc/redis-sentinel install; \ |
| 34 | + \ |
| 35 | + # TODO https://github.com/redis/redis/pull/3494 (deduplicate "redis-server" copies) |
| 36 | + serverMd5="$(md5sum /opt/drycc/redis-sentinel/bin/redis-server | cut -d' ' -f1)"; export serverMd5; \ |
| 37 | + find /opt/drycc/redis-sentinel/bin/redis* -maxdepth 0 \ |
| 38 | + -type f -not -name redis-server \ |
| 39 | + -exec sh -eux -c ' \ |
| 40 | + md5="$(md5sum "$1" | cut -d" " -f1)"; \ |
| 41 | + test "$md5" = "$serverMd5"; \ |
| 42 | + ' -- '{}' ';' \ |
| 43 | + -exec ln -svfT 'redis-server' '{}' ';' \ |
| 44 | + ; \ |
| 45 | + \ |
| 46 | + rm -r /usr/src/redis; \ |
| 47 | + \ |
| 48 | + apt-mark auto '.*' > /dev/null; \ |
| 49 | + [ -z "$savedAptMark" ] || apt-mark manual $savedAptMark > /dev/null; \ |
| 50 | + find /opt/drycc/redis-sentinel/bin -type f -executable -exec ldd '{}' ';' \ |
| 51 | + | awk '/=>/ { print $(NF-1) }' \ |
| 52 | + | sort -u \ |
| 53 | + | xargs -r dpkg-query --search \ |
| 54 | + | cut -d: -f1 \ |
| 55 | + | sort -u \ |
| 56 | + | xargs -r apt-mark manual \ |
| 57 | + ; \ |
| 58 | + apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false; \ |
| 59 | + \ |
| 60 | + /opt/drycc/redis-sentinel/bin/redis-cli --version; \ |
| 61 | + /opt/drycc/redis-sentinel/bin/redis-server --version |
| 62 | + |
| 63 | + chmod +x /opt/drycc/redis-sentinel/bin/redis* |
| 64 | + mkdir -p "${PROFILE_DIR}" |
| 65 | + cat << EOF > "${PROFILE_DIR}/${STACK_NAME}.sh" |
| 66 | +export PATH="/opt/drycc/redis-sentinel/bin:\$PATH" |
| 67 | +EOF |
| 68 | + cp -rf /opt/drycc/redis-sentinel/* "${DATA_DIR}" |
| 69 | + REDIS_MAJOR_VERSION=$(echo "${STACK_VERSION}" | awk -F "." '{print ""$1"."$2""}') |
| 70 | + mkdir -p "${DATA_DIR}"/etc && \ |
| 71 | + curl -fsSL -o "${DATA_DIR}"/etc/sentinel.conf https://raw.githubusercontent.com/redis/redis/"${REDIS_MAJOR_VERSION}"/sentinel.conf |
| 72 | +} |
| 73 | + |
| 74 | +# call build stack |
| 75 | +build-stack "${1}" |
0 commit comments