This commit is contained in:
TeadRIM 2023-01-24 16:36:18 +04:00
commit 3c264e2e4c
9 changed files with 288 additions and 0 deletions

52
.github/workflows/docker-publish.yml vendored Normal file
View File

@ -0,0 +1,52 @@
name: Docker
on:
push:
branches: [ master ]
workflow_dispatch:
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
RIAK_VERSION: 3.0.12
jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
id-token: write
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Setup Docker buildx
uses: docker/setup-buildx-action@79abd3f86f79a9d68a23c75a09a9a85889262adf
- name: Log into registry ${{ env.REGISTRY }}
if: github.event_name != 'pull_request'
uses: docker/login-action@28218f9b04b4f3f62068d7b6ce6ca5b26e35336c
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@v3
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=raw,value=${{ env.RIAK_VERSION }}
- name: Build and push Docker image
id: build-and-push
uses: docker/build-push-action@v3
with:
context: .
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: RIAK_VERSION=${{ env.RIAK_VERSION }}

64
Dockerfile Normal file
View File

@ -0,0 +1,64 @@
FROM erlang:22 as build
RUN DEBIAN_FRONTEND=noninteractive TZ=Etc/UTC apt-get update && apt-get -y install tzdata
ENV DEBIAN_FRONTEND teletype \
TERM=xterm \
LANG en_US.UTF-8
RUN apt-get update && apt-get install -y --no-install-recommends apt-utils && \
apt-get -y --no-install-recommends dist-upgrade && \
apt-get install -y --no-install-recommends curl apt-transport-https ca-certificates git && \
apt-get install -y --no-install-recommends openjdk-11-jdk-headless locales logrotate sudo && \
apt-get install -y patch make wget cmake g++ build-essential libpam0g-dev
ARG RIAK_VERSION
COPY files/install-riak.sh /
COPY files/vars.config /
RUN /install-riak.sh
# Install custom hooks
COPY files/prestart.d /tmp/portage-root/etc/riak/prestart.d
COPY files/poststart.d /tmp/portage-root/etc/riak/poststart.d
# Install custom start script
COPY files/riak-cluster.sh /tmp/portage-root/riak-cluster.sh
#####################################################################
# Riak image
FROM erlang:22-slim
COPY --from=build /tmp/portage-root/ /
# Prepare directrories
RUN mkdir -p /etc/riak/prestart.d /etc/riak/poststart.d \
/usr/lib/riak/ /var/lib/riak /var/log/riak /var/run/riak
#
# Copy riak sources
COPY --from=build /opt/riak/_build/deb/rel/riak/lib /usr/lib/riak/lib
COPY --from=build /opt/riak/_build/deb/rel/riak/share /usr/lib/riak/share
COPY --from=build /opt/riak/_build/deb/rel/riak/releases /usr/lib/riak/releases
COPY --from=build /opt/riak/_build/deb/rel/riak/erts-10.7.2.18 /usr/lib/riak/erts-10.7.2.18
COPY --from=build /opt/riak/_build/deb/rel/riak/bin /usr/lib/riak/bin
COPY --from=build /opt/riak/_build/deb/rel/riak/etc/* /etc/riak/
COPY --from=build /opt/riak/_build/deb/rel/riak/data/* /var/lib/riak/data/
COPY --from=build /opt/riak/_build/deb/rel/riak/usr/bin/* /usr/sbin/
#
#RUN busybox --install
# Expose default ports
EXPOSE 8087 8098
# Create riak user/group
RUN adduser --disabled-login --home /var/lib/riak riak; \
chown -R riak:riak /var/lib/riak /var/log/riak /var/run/riak /etc/riak
RUN echo "riak hard nofile 1000000\n" >> /etc/security/limits.conf && \
echo "riak soft nofile 65536" >> /etc/security/limits.conf
# Expose volumes for data and logs
VOLUME /var/log/riak
VOLUME /var/lib/riak
ENV RIAK_HOME /usr/lib/riak
WORKDIR /var/lib/riak
RUN chmod a+x /riak-cluster.sh
CMD ["/riak-cluster.sh"]

9
files/install-riak.sh Executable file
View File

@ -0,0 +1,9 @@
#!/bin/bash
set -e eu
# Build riak
mkdir -p /opt/riak && cd /opt/riak
curl -L https://github.com/basho/riak/archive/refs/tags/riak-${RIAK_VERSION}.tar.gz -o /opt/riak.tar.gz
tar zxf /opt/riak.tar.gz --strip-components 1
make all
./rebar3 as deb release --overlay_vars /vars.config

View File

@ -0,0 +1,9 @@
#!/bin/bash
# Maybe join to a cluster
if [[ -z "$($RIAK_ADMIN cluster status | egrep $COORDINATOR_NODE)" && "$COORDINATOR_NODE" != "$HOST" ]]; then
# Not already in this cluster, so join
echo "Connecting to cluster coordinator $COORDINATOR_NODE"
$RIAK_ADMIN cluster join $CLUSTER_NAME@$COORDINATOR_NODE
$RIAK_ADMIN cluster plan
$RIAK_ADMIN cluster commit
fi

View File

@ -0,0 +1,12 @@
#!/bin/sh
# Riak is sensitive to permissions on the erlang distribution cooke file.
# The ERTS requires that the cookie permissions are always 0600.
# In some environments, file permissions may change. For example, this
# can happen in kubernetes if the `fsGroup` option is used.
COOKIE_PATH="/var/lib/riak/.erlang.cookie"
if [ -e "$COOKIE_PATH" ]; then
chmod 0400 "$COOKIE_PATH"
fi

View File

@ -0,0 +1,14 @@
#!/bin/bash
# Add standard config items
cat <<END >>$RIAK_CONF
nodename = $CLUSTER_NAME@$HOST
distributed_cookie = $CLUSTER_NAME
listener.protobuf.internal = $HOSTIP:$PB_PORT
listener.http.internal = $HOSTIP:$HTTP_PORT
END
# Maybe add user config items
if [ -s $USER_CONF ]; then
cat $USER_CONF >>$RIAK_CONF
fi

View File

@ -0,0 +1,16 @@
#!/bin/bash
RING_SIZE=$(awk -F'=' '/ring_size/{print $2}' $RIAK_CONF | sed 's/[ ]//')
CLUSTER_CONVERGENCE=${CLUSTER_CONVERGENCE:-standard}
if [[ "fast" == "$CLUSTER_CONVERGENCE" && ! -e $RIAK_ADVANCED_CONF ]]; then
cat <<END >$RIAK_ADVANCED_CONF
[
{riak_core, [
{vnode_parallel_start, $RING_SIZE},
{forced_ownership_handoff, $RING_SIZE},
{handoff_concurrency, $RING_SIZE}
]}
].
END
fi

52
files/riak-cluster.sh Executable file
View File

@ -0,0 +1,52 @@
#!/bin/bash
#
# Cluster start script to bootstrap a Riak cluster.
#
sleep 10
set -x
if [[ -x /usr/sbin/riak ]]; then
export RIAK=/usr/sbin/riak
else
export RIAK=$RIAK_HOME/bin/riak
fi
export RIAK_CONF=/etc/riak/riak.conf
export USER_CONF=/etc/riak/user.conf
export RIAK_ADVANCED_CONF=/etc/riak/advanced.config
export SCHEMAS_DIR=/usr/lib/riak/share/schema/
export RIAK_ADMIN="$RIAK admin"
# Set ports for PB and HTTP
export PB_PORT=${PB_PORT:-8087}
export HTTP_PORT=${HTTP_PORT:-8098}
# Use ping to discover our HOSTNAME because it's easier and more reliable than other methods
export HOST=${NODENAME:-$(hostname -f)}
export HOSTIP=$(hostname -i)
# CLUSTER_NAME is used to name the nodes and is the value used in the distributed cookie
export CLUSTER_NAME=${CLUSTER_NAME:-riak}
# The COORDINATOR_NODE is the first node in a cluster to which other nodes will eventually join
export COORDINATOR_NODE=${COORDINATOR_NODE:-$HOSTNAME}
export COORDINATOR_NODE_HOST=$(ping -c1 $COORDINATOR_NODE | awk '/^PING/ {print $3}' | sed -e 's/[()]//g' -e 's/:$//') || '127.0.0.1'
sleep 10
# Run all prestart scripts
PRESTART=$(find /etc/riak/prestart.d -name *.sh -print | sort)
for s in $PRESTART; do
. $s
done
sleep 10
$RIAK start &
sleep 40
# join cluster if needed
if [[ -z "$($RIAK_ADMIN cluster status | egrep $COORDINATOR_NODE)" && "$COORDINATOR_NODE" != "$HOST" ]]; then
echo "Connecting to cluster coordinator $COORDINATOR_NODE"
riak admin cluster join $CLUSTER_NAME@$COORDINATOR_NODE
riak admin cluster plan
riak admin cluster commit
fi

60
files/vars.config Normal file
View File

@ -0,0 +1,60 @@
%% -*- mode: erlang;erlang-indent-level: 4;indent-tabs-mode: nil -*-
%% ex: ft=erlang ts=4 sw=4 et
%% Platform-specific installation paths
{platform_bin_dir, "/usr/lib/riak/bin"}.
{platform_data_dir, "/var/lib/riak"}.
{platform_etc_dir, "/etc/riak"}.
{platform_base_dir, "/usr/lib/riak"}.
{platform_lib_dir, "/usr/lib/riak/lib"}.
{platform_log_dir, "/var/log/riak"}.
{platform_gen_dir, "/var/lib/riak"}.
{runner_script_dir, "/usr/lib/riak/bin"}.
{runner_base_dir, "/usr/lib/riak"}.
{runner_etc_dir, "/etc/riak"}.
{runner_log_dir, "/var/log/riak"}.
{runner_user, "riak"}.
{runner_lib_dir, "/usr/lib/riak/lib"}.
{runner_patch_dir, "/usr/lib/riak/lib/patches"}.
{pipe_dir, "/tmp/riak/"}.
{pid_dir, "/run/riak/"}.
{package_replacement_line, ""}.
{package_conflicts_line, ""}.
{cluster_manager_ip, "127.0.0.1"}.
{cluster_manager_port, 9080}.
{web_ip, "127.0.0.1"}.
{web_port, 8098}.
{handoff_ip, "0.0.0.0"}.
{handoff_port, 8099}.
{pb_ip, "127.0.0.1"}.
{pb_port, 8087}.
{storage_backend, "leveldb"}.
{sasl_error_log, "{{platform_log_dir}}/sasl-error.log"}.
{sasl_log_dir, "{{platform_log_dir}}/sasl"}.
{repl_data_root, "{{platform_data_dir}}/riak_repl/"}.
{crash_dump, "{{platform_log_dir}}/erl_crash.dump"}.
%%
%% cuttlefish
%%
{cuttlefish, "on"}.
{cuttlefish_conf, "riak.conf"}.
%%
%% yokozuna
%%
{yz_solr_port, 8093}.
{yz_solr_jmx_port, 8985}.
%% lager
{console_log_default, file}.
%%
%% etc/vm.args
%%
{node, "riak@127.0.0.1"}.