From ab0a82d8c4e58f0b97dd4a20f531233584bd7073 Mon Sep 17 00:00:00 2001
From: duanhongyi <duanhongyi@doopai.com>
Date: Wed, 16 Feb 2022 14:26:45 +0800
Subject: [PATCH 1/2] chore(stacks): add fluentd

---
 stacks/fluentd/build.sh | 22 ++++++++++++++++++++++
 stacks/fluentd/make.sh  | 27 +++++++++++++++++++++++++++
 2 files changed, 49 insertions(+)
 create mode 100755 stacks/fluentd/build.sh
 create mode 100755 stacks/fluentd/make.sh

diff --git a/stacks/fluentd/build.sh b/stacks/fluentd/build.sh
new file mode 100755
index 0000000..7addd9b
--- /dev/null
+++ b/stacks/fluentd/build.sh
@@ -0,0 +1,22 @@
+#!/bin/bash
+
+# Load stack utils
+. /usr/bin/stack-utils
+
+# Implement build function
+function build() {
+  export STACK_DOWNLOAD_URL="http://47.75.184.187:8000" 
+  cat  << EOF > ${PROFILE_DIR}/${STACK_NAME}.sh
+export GEM_HOME=/opt/drycc/fluentd
+export BUNDLE_SILENCE_ROOT_WARNING=1
+export BUNDLE_APP_CONFIG="$GEM_HOME"
+export PATH=$GEM_HOME/bin:$PATH
+EOF
+  . ${PROFILE_DIR}/${STACK_NAME}.sh
+  ./make.sh
+  echo "export LD_PRELOAD=/usr/lib/libjemalloc.so.2" >> ${PROFILE_DIR}/${STACK_NAME}.sh
+  cp -rf /opt/drycc/fluentd/* "${DATA_DIR}"
+}
+
+# call build stack
+build-stack "${1}"
diff --git a/stacks/fluentd/make.sh b/stacks/fluentd/make.sh
new file mode 100755
index 0000000..ffef0b7
--- /dev/null
+++ b/stacks/fluentd/make.sh
@@ -0,0 +1,27 @@
+install-stack ruby 3.1.0
+. /opt/drycc/ruby/profile.d/*.sh
+
+
+apt-get update \
+ && apt-get install -y --no-install-recommends \
+            ca-certificates \
+ && buildDeps=" \
+      make gcc g++ libc-dev \
+      wget bzip2 gnupg dirmngr \
+    " \
+ && apt-get install -y --no-install-recommends $buildDeps \
+ && echo 'gem: --no-document' >> /etc/gemrc \
+ && gem install oj -v 3.10.18 \
+ && gem install json -v 2.4.1 \
+ && gem install async-http -v 0.54.0 \
+ && gem install fluentd -v 1.14.5 \
+ && wget -O /tmp/jemalloc-4.5.0.tar.bz2 https://github.com/jemalloc/jemalloc/releases/download/4.5.0/jemalloc-4.5.0.tar.bz2 \
+ && cd /tmp && tar -xjf jemalloc-4.5.0.tar.bz2 && cd jemalloc-4.5.0/ \
+ && ./configure && make \
+ && mkdir -p /opt/drycc/fluentd/lib \
+ && mv lib/libjemalloc.so.2 /opt/drycc/fluentd/lib \
+ && apt-get purge -y --auto-remove \
+                  -o APT::AutoRemove::RecommendsImportant=false \
+                  $buildDeps \
+ && rm -rf /var/lib/apt/lists/* \
+ && rm -rf /tmp/* /var/tmp/*
\ No newline at end of file

From de30f2c860358c0fce8e04d621451b21d011d143 Mon Sep 17 00:00:00 2001
From: lijianguo <lijianguo@zhumengyuan.com>
Date: Wed, 16 Feb 2022 14:48:46 +0800
Subject: [PATCH 2/2] feat(stacks): add mariadb postgis postgresql redis

---
 stacks/mariadb/build.sh    | 44 ++++++++++++++++++++
 stacks/postgis/build.sh    | 34 ++++++++++++++++
 stacks/postgresql/build.sh | 83 ++++++++++++++++++++++++++++++++++++++
 stacks/redis/build.sh      | 72 +++++++++++++++++++++++++++++++++
 4 files changed, 233 insertions(+)
 create mode 100755 stacks/mariadb/build.sh
 create mode 100755 stacks/postgis/build.sh
 create mode 100755 stacks/postgresql/build.sh
 create mode 100755 stacks/redis/build.sh

diff --git a/stacks/mariadb/build.sh b/stacks/mariadb/build.sh
new file mode 100755
index 0000000..9320bbc
--- /dev/null
+++ b/stacks/mariadb/build.sh
@@ -0,0 +1,44 @@
+#!/bin/bash
+
+# Load stack utils
+. /usr/bin/stack-utils
+
+# Implement build function
+function build() {
+  cat << EOF > /workspace/"${TARNAME}"/meta/dependencies
+libncurses6
+EOF
+
+  install-packages \
+  	cmake \
+
+  # Generate binary
+  curl -sSL "https://downloads.mariadb.org/interstitial/mariadb-${STACK_VERSION}/source/mariadb-${STACK_VERSION}.tar.gz" | tar -xz && \
+  cd mariadb-"${STACK_VERSION}" && \
+  pcre_version=$(< cmake/pcre.cmake grep 'ftp.pcre.org' |awk -F 'pcre2-' '{print $2}' | awk -F '.zip' '{print $1}')
+  sed -i -e "s|http://ftp.pcre.org/pub/pcre|https://github.com/PhilipHazel/pcre2/releases/download/pcre2-${pcre_version}|g" cmake/pcre.cmake
+  cmake . -DCMAKE_INSTALL_PREFIX=/opt/drycc/mariadb \
+  -DMYSQL_DATADIR=/opt/drycc/mariadb/data \
+  -DWITH_INNOBASE_STORAGE_ENGINE=1 \
+  -DWITH_ARCHIVE_STORAGE_ENGINE=1 \
+  -DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
+  -DWITH_READLINE=1 \
+  -DWITH_SSL=system \
+  -DWITH_ZLIB=system \
+  -DWITH_LIBWRAP=0 \
+  -DMYSQL_UNIX_ADDR=/tmp/mariadb.sock \
+  -DDEFAULT_CHARSET=utf8 \
+  -DDEFAULT_COLLATION=utf8_general_ci \
+  && \
+  make install
+
+  mkdir -p "${PROFILE_DIR}"
+  cat  << EOF > "${PROFILE_DIR}/${STACK_NAME}.sh"
+export PATH="/opt/drycc/mariadb/bin:\$PATH"
+EOF
+
+  cp -rf /opt/drycc/mariadb/* "${DATA_DIR}"
+}
+
+# call build stack
+build-stack "${1}"
\ No newline at end of file
diff --git a/stacks/postgis/build.sh b/stacks/postgis/build.sh
new file mode 100755
index 0000000..3e909ad
--- /dev/null
+++ b/stacks/postgis/build.sh
@@ -0,0 +1,34 @@
+#!/bin/bash
+
+# Load stack utils
+. /usr/bin/stack-utils
+
+# Implement build function
+function build() {
+  # Generate binary
+  POSTGIS_VER=${STACK_VERSION} # 3.1.4
+
+  install-packages \
+    libgdal-dev \
+		libgeos-dev \
+		libjson-c-dev \
+		libmysqlclient-dev \
+		libproj-dev \
+		libprotobuf-c-dev \
+		libxml2-dev \
+		protobuf-c-compiler
+
+  curl -sSL "https://download.osgeo.org/postgis/source/postgis-"${POSTGIS_VER}".tar.gz" | tar -xz && \
+	cd postgis-"${POSTGIS_VER}" && \
+	./configure \
+	--prefix=/opt/drycc/postgis/"${POSTGIS_VER}" \
+	--with-pgconfig=/opt/drycc/postgresql/"${PG_MAJOR}"/bin/pg_config \
+	&& \
+	make && \
+	make install
+
+  cp -rf /opt/drycc/postgresql "${DATA_DIR}"
+}
+
+# call build stack
+build-stack "${1}"
diff --git a/stacks/postgresql/build.sh b/stacks/postgresql/build.sh
new file mode 100755
index 0000000..76ea172
--- /dev/null
+++ b/stacks/postgresql/build.sh
@@ -0,0 +1,83 @@
+#!/bin/bash
+
+# Load stack utils
+. /usr/bin/stack-utils
+
+# Implement build function
+function build() {
+  # Generate binary
+  PG_VER=${STACK_VERSION}
+  PG_MAJOR=$(echo "${STACK_VERSION}"|cut -d"." -f1)
+
+  cat << EOF > /workspace/"${TARNAME}"/meta/dependencies
+binutils \
+gdal-bin \
+libproj-dev
+EOF
+
+  install-packages \
+  	clang \
+		dirmngr \
+		gnupg \
+		libclang-dev \
+		libicu-dev \
+		libipc-run-perl \
+		libkrb5-dev \
+		libldap2-dev \
+		liblz4-dev \
+		libpam-dev \
+		libperl-dev \
+		libpython3-dev \
+		libreadline-dev \
+		libssl-dev \
+		libxml2-dev \
+		libxslt1-dev \
+		llvm \
+		llvm-dev \
+		locales \
+		python3-dev \
+		tcl-dev \
+		uuid-dev \
+		pkg-config
+
+  curl -sSL "https://ftp.postgresql.org/pub/source/v${PG_VER}/postgresql-${PG_VER}.tar.gz" | tar -xz && \
+	cd postgresql-"${PG_VER}" && \
+	./configure \
+		--prefix=/opt/drycc/postgresql/"${PG_MAJOR}" \
+		--enable-integer-datetimes \
+		--enable-thread-safety \
+		--enable-tap-tests \
+		--with-uuid=e2fs \
+		--with-gnu-ld \
+		--with-pgport=5432 \
+		--with-system-tzdata=/usr/share/zoneinfo \
+		--with-includes=/usr/local/include \
+		--with-libraries=/usr/local/lib \
+		--with-krb5 \
+		--with-gssapi \
+		--with-ldap \
+		--with-pam \
+		--with-tcl \
+		--with-perl \
+		--with-python \
+		--with-openssl \
+		--with-libxml \
+		--with-libxslt \
+		--with-icu \
+		--with-llvm \
+		--with-lz4 \
+	&& \
+	# we can change from world to world-bin in newer releases
+	make world && \
+	make install-world
+
+  mkdir -p "${PROFILE_DIR}"
+  cat  << EOF > "${PROFILE_DIR}/${STACK_NAME}.sh"
+export PATH="/opt/drycc/postgresql/$PG_MAJOR/bin:\$PATH"
+EOF
+
+  cp -rf /opt/drycc/postgresql/* "${DATA_DIR}"
+}
+
+# call build stack
+build-stack "${1}"
\ No newline at end of file
diff --git a/stacks/redis/build.sh b/stacks/redis/build.sh
new file mode 100755
index 0000000..4006b17
--- /dev/null
+++ b/stacks/redis/build.sh
@@ -0,0 +1,72 @@
+#!/bin/bash
+
+# Load stack utils
+. /usr/bin/stack-utils
+
+# Implement build function
+function build() {
+  # Generate binary
+  REDIS_DOWNLOAD_URL="http://download.redis.io/releases/redis-${STACK_VERSION}.tar.gz"
+  savedAptMark="$(apt-mark showmanual)"; \
+  curl -fsSL -o redis.tar.gz "$REDIS_DOWNLOAD_URL"; \
+  mkdir -p /usr/src/redis; \
+  tar -xzf redis.tar.gz -C /usr/src/redis --strip-components=1; \
+  rm redis.tar.gz; \
+  grep -E '^ *createBoolConfig[(]"protected-mode",.*, *1 *,.*[)],$' /usr/src/redis/src/config.c; \
+  sed -ri 's!^( *createBoolConfig[(]"protected-mode",.*, *)1( *,.*[)],)$!\10\2!' /usr/src/redis/src/config.c; \
+  grep -E '^ *createBoolConfig[(]"protected-mode",.*, *0 *,.*[)],$' /usr/src/redis/src/config.c; \
+  gnuArch="$(dpkg-architecture --query DEB_BUILD_GNU_TYPE)"; \
+  extraJemallocConfigureFlags="--build=$gnuArch"; \
+  # https://salsa.debian.org/debian/jemalloc/-/blob/c0a88c37a551be7d12e4863435365c9a6a51525f/debian/rules#L8-23
+  dpkgArch="$(dpkg --print-architecture)"; \
+  case "${dpkgArch##*-}" in \
+    amd64 | i386 | x32) extraJemallocConfigureFlags="$extraJemallocConfigureFlags --with-lg-page=12" ;; \
+    *) extraJemallocConfigureFlags="$extraJemallocConfigureFlags --with-lg-page=16" ;; \
+  esac; \
+  extraJemallocConfigureFlags="$extraJemallocConfigureFlags --with-lg-hugepage=21"; \
+  grep -F 'cd jemalloc && ./configure ' /usr/src/redis/deps/Makefile; \
+  sed -ri 's!cd jemalloc && ./configure !&'"$extraJemallocConfigureFlags"' !' /usr/src/redis/deps/Makefile; \
+  grep -F "cd jemalloc && ./configure $extraJemallocConfigureFlags " /usr/src/redis/deps/Makefile; \
+  \
+  export BUILD_TLS=yes; \
+  make -C /usr/src/redis -j "$(nproc)" all; \
+  make -C /usr/src/redis PREFIX=/opt/drycc/redis install; \
+  \
+  # TODO https://github.com/redis/redis/pull/3494 (deduplicate "redis-server" copies)
+  serverMd5="$(md5sum /opt/drycc/redis/bin/redis-server | cut -d' ' -f1)"; export serverMd5; \
+  find /opt/drycc/redis/bin/redis* -maxdepth 0 \
+    -type f -not -name redis-server \
+    -exec sh -eux -c ' \
+      md5="$(md5sum "$1" | cut -d" " -f1)"; \
+      test "$md5" = "$serverMd5"; \
+    ' -- '{}' ';' \
+    -exec ln -svfT 'redis-server' '{}' ';' \
+  ; \
+  \
+  rm -r /usr/src/redis; \
+  \
+  apt-mark auto '.*' > /dev/null; \
+  [ -z "$savedAptMark" ] || apt-mark manual $savedAptMark > /dev/null; \
+  find /opt/drycc/redis/bin -type f -executable -exec ldd '{}' ';' \
+    | awk '/=>/ { print $(NF-1) }' \
+    | sort -u \
+    | xargs -r dpkg-query --search \
+    | cut -d: -f1 \
+    | sort -u \
+    | xargs -r apt-mark manual \
+  ; \
+  apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false; \
+  \
+  /opt/drycc/redis/bin/redis-cli --version; \
+  /opt/drycc/redis/bin/redis-server --version
+
+  chmod +x /opt/drycc/redis/bin/redis*
+  mkdir -p "${PROFILE_DIR}"
+  cat  << EOF > "${PROFILE_DIR}/${STACK_NAME}.sh"
+export PATH="/opt/drycc/redis/bin:\$PATH"
+EOF
+  cp -rf /opt/drycc/redis/* "${DATA_DIR}"
+}
+
+# call build stack
+build-stack "${1}"
\ No newline at end of file
