Commit 1ebc8829 authored by Ranadeep Biswas's avatar Ranadeep Biswas
Browse files

updated docker-compose files

parent 02e4af3b
FROM bluee/antidote
ADD connect.erl connect.erl
RUN chmod u+x connect.erl
In one console,
docker-compose up
When the nodes are ready, in another console,
docker exec antidote1 ./connect.erl 3
P.S. above setup is adapted directly from [AntidoteDB documentation](https://antidotedb.gitbook.io/documentation/#create-a-cluster).
#!/usr/bin/env run-cargo-script
//! ```cargo
//! [dependencies]
//! serde_yaml = "*"
//! clap = "*"
//! ```
extern crate clap;
extern crate serde_yaml;
use std::fs::OpenOptions;
use clap::{App, Arg};
use serde_yaml::Value;
fn main() {
let matches = App::new("compose_file")
.version("1.0")
.author("Ranadeep")
.about("Generates docker-compose.yml for a given template.")
.arg(
Arg::with_name("template")
.long("temp")
.short("t")
.takes_value(true)
.required(true),
)
.arg(
Arg::with_name("n_nodes")
.long("nodes")
.short("n")
.takes_value(true)
.required(true),
)
.get_matches();
let num: usize = matches.value_of("n_nodes").unwrap().parse().unwrap();
let template_path = matches.value_of("template").unwrap();
let mut spec: Value = {
let mut template = OpenOptions::new()
.read(true)
.open(template_path)
.expect("couldn't open");
serde_yaml::from_reader(template).unwrap()
};
{
let containers = &mut spec["services"];
let template = serde_yaml::to_string(&containers).unwrap();
match containers {
Value::Mapping(ref mut maps) => {
maps.clear();
for i_num in { 1..num + 1 } {
let container_st = template.replace("{i}", &i_num.to_string());
match serde_yaml::from_str(&container_st) {
Ok(Value::Mapping(map)) => {
maps.extend(map.iter().map(|(k, v)| (k.clone(), v.clone())))
}
_ => unreachable!(),
}
}
}
_ => unreachable!(),
}
}
{
let file = OpenOptions::new()
.write(true)
.create(true)
.truncate(true)
.open("docker-compose.yml")
.expect("couldn't create");
serde_yaml::to_writer(file, &spec).expect("failed to write docker-compose file");
}
println!("docker-compose file is ready.");
}
rpc:call(antidote@antidote1, inter_dc_manager, start_bg_processes, [stable]),
rpc:call(antidote@antidote2, inter_dc_manager, start_bg_processes, [stable]),
rpc:call(antidote@antidote3, inter_dc_manager, start_bg_processes, [stable]),
rpc:call(antidote@antidote4, inter_dc_manager, start_bg_processes, [stable]),
rpc:call(antidote@antidote5, inter_dc_manager, start_bg_processes, [stable]),
rpc:call(antidote@antidote6, inter_dc_manager, start_bg_processes, [stable]),
rpc:call(antidote@antidote7, inter_dc_manager, start_bg_processes, [stable]),
{ok, Desc1} = rpc:call(antidote@antidote1, inter_dc_manager, get_descriptor, []),
{ok, Desc2} = rpc:call(antidote@antidote2, inter_dc_manager, get_descriptor, []),
{ok, Desc3} = rpc:call(antidote@antidote3, inter_dc_manager, get_descriptor, []),
{ok, Desc4} = rpc:call(antidote@antidote4, inter_dc_manager, get_descriptor, []),
{ok, Desc5} = rpc:call(antidote@antidote5, inter_dc_manager, get_descriptor, []),
{ok, Desc6} = rpc:call(antidote@antidote6, inter_dc_manager, get_descriptor, []),
{ok, Desc7} = rpc:call(antidote@antidote7, inter_dc_manager, get_descriptor, []),
Descriptors = [
Desc1,
Desc2,
Desc3,
Desc4,
Desc5,
Desc6,
Desc7
],
rpc:call(antidote@antidote1, inter_dc_manager, observe_dcs_sync, [Descriptors]),
rpc:call(antidote@antidote2, inter_dc_manager, observe_dcs_sync, [Descriptors]),
rpc:call(antidote@antidote3, inter_dc_manager, observe_dcs_sync, [Descriptors]),
rpc:call(antidote@antidote4, inter_dc_manager, observe_dcs_sync, [Descriptors]),
rpc:call(antidote@antidote5, inter_dc_manager, observe_dcs_sync, [Descriptors]),
rpc:call(antidote@antidote6, inter_dc_manager, observe_dcs_sync, [Descriptors]),
rpc:call(antidote@antidote7, inter_dc_manager, observe_dcs_sync, [Descriptors]).
#!/usr/bin/env escript
%%! -smp enable -sname erlshell -setcookie antidote
main([St]) ->
NumDC = list_to_integer(St),
io:format("AntidoteDB: setting up cluster for ~p datacenters!~n", [NumDC]),
DCs = lists:map(fun(Num) -> list_to_atom(lists:flatten(io_lib:format("antidote@antidote~w", [Num]))) end, lists:seq(1, NumDC)),
lists:foreach(fun(DC) -> rpc:call(DC, inter_dc_manager, start_bg_processes, [stable]) end, DCs),
Descriptors = lists:map(fun(DC) -> {ok, Desc} = rpc:call(DC, inter_dc_manager, get_descriptor, []), Desc end, DCs),
lists:foreach(fun(DC) -> rpc:call(DC, inter_dc_manager, observe_dcs_sync, [Descriptors]) end, DCs),
io:format("Done.~n").
version: "3.7"
services:
antidote1:
build: .
hostname: antidote1
container_name: antidote1
environment:
SHORT_NAME: "true"
NODE_NAME: antidote@antidote1
antidote2:
build: .
hostname: antidote2
container_name: antidote2
environment:
SHORT_NAME: "true"
NODE_NAME: antidote@antidote2
antidote3:
build: .
hostname: antidote3
container_name: antidote3
environment:
SHORT_NAME: "true"
NODE_NAME: antidote@antidote3
# AntidoteDB
version: "3.7"
services:
antidote{i}:
image: antidotedb/antidote
container_name: antidote{i}
hostname: antidote{i}
environment:
SHORT_NAME: "true"
NODE_NAME: antidote@antidote{i}
volumes:
- ./script:/script
cap_add:
- NET_ADMIN
For a cluster of size 4
docker-compose up -d --scale roach0=1 --scale roach=3
version: "3.7"
services:
cockroach1:
image: cockroachdb/cockroach:v2.1.0
container_name: roach1
hostname: roach1
command:
- start
- --insecure
cockroach2:
image: cockroachdb/cockroach:v2.1.0
container_name: roach2
hostname: roach2
command:
- start
- --insecure
- --join=roach1
cockroach3:
image: cockroachdb/cockroach:v2.1.0
container_name: roach3
hostname: roach3
command:
- start
- --insecure
- --join=roach1
version: "3.7"
services:
roach_m:
image: cockroachdb/cockroach
container_name: roach_m
hostname: roach_m
command:
- start
- --insecure
roach_s:
image: cockroachdb/cockroach
command:
- start
- --insecure
- --join=roach_m
For a cluster of size 4
docker-compose up -d --scale galera0=1 --scale galera=3
FROM archlinux/base
RUN pacman -Sy --noconfirm
RUN pacman -S galera --noconfirm
RUN pacman -S xtrabackup --noconfirm
RUN pacman -S grep awk iproute2 lsof rsync --noconfirm
ADD galera.cnf /etc/mysql/my.cnf.d/galera.cnf
ADD entrypoint.sh /entrypoint.sh
ENTRYPOINT ["bash", "/entrypoint.sh"]
version: "3.7"
services:
galera0:
build: .
container_name: galera0
hostname: galera0
environment:
- MYSQL_ALLOW_EMPTY_PASSWORD=1
- CLUSTER_NAME=galera_cluster
- WSREP_SST_METHOD=xtrabackup-v2
galera:
build: .
environment:
- MYSQL_ALLOW_EMPTY_PASSWORD=1
- CLUSTER_NAME=galera_cluster
- CLUSTER_JOIN=galera0
- WSREP_SST_METHOD=xtrabackup-v2
#!/bin/bash
set -e
# if command starts with an option, prepend mysqld
if [ "${1:0:1}" = '-' ]; then
CMDARG="$@"
fi
[ -z "$TTL" ] && TTL=10
if [ -z "$CLUSTER_NAME" ]; then
echo >&2 'Error: You need to specify CLUSTER_NAME'
exit 1
fi
sed -i "s|WSREP_SST_METHOD|$WSREP_SST_METHOD|g" /etc/mysql/my.cnf.d/galera.cnf
# Get config
DATADIR="$("mysqld" --verbose --help 2>/dev/null | awk '$1 == "datadir" { print $2; exit }')"
if [ ! -s "$DATADIR/grastate.dat" ]; then
INITIALIZED=1
if [ -z "$MYSQL_ROOT_PASSWORD" -a -z "$MYSQL_ALLOW_EMPTY_PASSWORD" -a -z "$MYSQL_RANDOM_ROOT_PASSWORD" ]; then
echo >&2 'error: database is uninitialized and password option is not specified '
echo >&2 ' You need to specify one of MYSQL_ROOT_PASSWORD, MYSQL_ALLOW_EMPTY_PASSWORD and MYSQL_RANDOM_ROOT_PASSWORD'
exit 1
fi
mkdir -p "$DATADIR"
chown -R mysql:mysql "$DATADIR"
echo 'Running mysql_install_db'
mysql_install_db --user=mysql --basedir=/usr --datadir="$DATADIR" --rpm
echo 'Finished mysql_install_db'
mysqld --user=mysql --datadir="$DATADIR" --skip-networking --log-bin=mysql-bin &
pid="$!"
mysql=( mysql --protocol=socket -uroot )
for i in {30..0}; do
if echo 'SELECT 1' | "${mysql[@]}" &> /dev/null; then
break
fi
echo 'MySQL init process in progress...'
sleep 1
done
if [ "$i" = 0 ]; then
echo >&2 'MySQL init process failed.'
exit 1
fi
# sed is for https://bugs.mysql.com/bug.php?id=20545
mysql_tzinfo_to_sql /usr/share/zoneinfo | sed 's/Local time zone must be set--see zic manual page/FCTY/' | "${mysql[@]}" mysql
if [ ! -z "$MYSQL_RANDOM_ROOT_PASSWORD" ]; then
MYSQL_ROOT_PASSWORD="$(pwmake 128)"
echo "GENERATED ROOT PASSWORD: $MYSQL_ROOT_PASSWORD"
fi
"${mysql[@]}" <<-EOSQL
-- What's done in this file shouldn't be replicated
-- or products like mysql-fabric won't work
SET @@SESSION.SQL_LOG_BIN=0;
DELETE FROM mysql.user ;
CREATE USER 'root'@'%' IDENTIFIED BY '${MYSQL_ROOT_PASSWORD}' ;
GRANT ALL ON *.* TO 'root'@'%' WITH GRANT OPTION ;
CREATE USER 'xtrabackup'@'localhost' IDENTIFIED BY '$XTRABACKUP_PASSWORD';
GRANT RELOAD,LOCK TABLES,REPLICATION CLIENT ON *.* TO 'xtrabackup'@'localhost';
GRANT REPLICATION CLIENT ON *.* TO monitor@'%' IDENTIFIED BY 'monitor';
DROP DATABASE IF EXISTS test ;
FLUSH PRIVILEGES ;
EOSQL
if [ ! -z "$MYSQL_ROOT_PASSWORD" ]; then
mysql+=( -p"${MYSQL_ROOT_PASSWORD}" )
fi
if [ "$MYSQL_DATABASE" ]; then
echo "CREATE DATABASE IF NOT EXISTS \`$MYSQL_DATABASE\` ;" | "${mysql[@]}"
mysql+=( "$MYSQL_DATABASE" )
fi
if [ "$MYSQL_USER" -a "$MYSQL_PASSWORD" ]; then
echo "CREATE USER '"$MYSQL_USER"'@'%' IDENTIFIED BY '"$MYSQL_PASSWORD"' ;" | "${mysql[@]}"
if [ "$MYSQL_DATABASE" ]; then
echo "GRANT ALL ON \`"$MYSQL_DATABASE"\`.* TO '"$MYSQL_USER"'@'%' ;" | "${mysql[@]}"
fi
echo 'FLUSH PRIVILEGES ;' | "${mysql[@]}"
fi
if [ ! -z "$MYSQL_ONETIME_PASSWORD" ]; then
"${mysql[@]}" <<-EOSQL
ALTER USER 'root'@'%' PASSWORD EXPIRE;
EOSQL
fi
if ! kill -s TERM "$pid" || ! wait "$pid"; then
echo >&2 'MySQL init process failed.'
exit 1
fi
echo
echo 'MySQL init process done. Ready for start up.'
echo
fi
chown -R mysql:mysql "$DATADIR"
function join { local IFS="$1"; shift; echo "$*"; }
# set IP address based on the primary interface
# sed -i "s|WSREP_NODE_ADDRESS|$ipaddr|g" /etc/mysql/my.cnf.d/galera.cnf
echo
echo >&2 ">> Starting mysqld process"
if [ -z $CLUSTER_JOIN ]; then
export _WSREP_NEW_CLUSTER='--wsrep-new-cluster'
# set safe_to_bootstrap = 1
GRASTATE=$DATADIR/grastate.dat
[ -f $GRASTATE ] && sed -i "s|safe_to_bootstrap.*|safe_to_bootstrap: 1|g" $GRASTATE
else
export _WSREP_NEW_CLUSTER=''
fi
mysqld --user=root --wsrep_cluster_name=$CLUSTER_NAME --wsrep-cluster-address="gcomm://$CLUSTER_JOIN" $_WSREP_NEW_CLUSTER $CMDARG
[mysqld]
user = mysql
bind_address = 0.0.0.0
datadir = /var/lib/mysql
pid_file = /var/lib/mysql/mysql.pid
default_storage_engine = InnoDB
binlog_format = ROW
query_cache_size = 0
query_cache_type = 0
innodb_flush_log_at_trx_commit = 0
innodb_flush_method = O_DIRECT
innodb_file_per_table = 1
innodb_autoinc_lock_mode = 2
wsrep_on = ON
wsrep_provider = /usr/lib64/galera/libgalera_smm.so
wsrep_sst_method = WSREP_SST_METHOD
wsrep_sst_auth = "root:"
FROM centos:7
RUN echo -e "[mariadb]\nname = MariaDB\nbaseurl = http://yum.mariadb.org/10.1/centos7-amd64\nenabled = 1\ngpgkey = https://yum.mariadb.org/RPM-GPG-KEY-MariaDB\ngpgcheck = 1" > /etc/yum.repos.d/MariaDB.repo
RUN rpmkeys --import https://www.percona.com/downloads/RPM-GPG-KEY-percona && \
yum install -y http://www.percona.com/downloads/percona-release/redhat/0.1-4/percona-release-0.1-4.noarch.rpm
RUN yum install -y which MariaDB-server MariaDB-client socat percona-xtrabackup && \
yum clean all
ADD galera.cnf /etc/my.cnf.d/galera.cnf
ADD entrypoint.sh /entrypoint.sh
ENTRYPOINT ["bash", "/entrypoint.sh"]
version: "3.7"
services:
galera0:
build: .
container_name: galera0
hostname: galera0
environment:
- MYSQL_ALLOW_EMPTY_PASSWORD=1
- CLUSTER_NAME=galera_cluster
- WSREP_SST_METHOD=xtrabackup-v2
galera:
build: .
environment:
- MYSQL_ALLOW_EMPTY_PASSWORD=1
- CLUSTER_NAME=galera_cluster
- CLUSTER_JOIN=galera0
- WSREP_SST_METHOD=xtrabackup-v2
#!/bin/bash
set -e
# if command starts with an option, prepend mysqld
if [ "${1:0:1}" = '-' ]; then
CMDARG="$@"
fi
[ -z "$TTL" ] && TTL=10
if [ -z "$CLUSTER_NAME" ]; then
echo >&2 'Error: You need to specify CLUSTER_NAME'
exit 1
fi
sed -i "s|WSREP_SST_METHOD|$WSREP_SST_METHOD|g" /etc/my.cnf.d/galera.cnf
# Get config
DATADIR="$("mysqld" --verbose --help 2>/dev/null | awk '$1 == "datadir" { print $2; exit }')"
if [ ! -s "$DATADIR/grastate.dat" ]; then
INITIALIZED=1
if [ -z "$MYSQL_ROOT_PASSWORD" -a -z "$MYSQL_ALLOW_EMPTY_PASSWORD" -a -z "$MYSQL_RANDOM_ROOT_PASSWORD" ]; then
echo >&2 'error: database is uninitialized and password option is not specified '
echo >&2 ' You need to specify one of MYSQL_ROOT_PASSWORD, MYSQL_ALLOW_EMPTY_PASSWORD and MYSQL_RANDOM_ROOT_PASSWORD'
exit 1
fi
mkdir -p "$DATADIR"
chown -R mysql:mysql "$DATADIR"
echo 'Running mysql_install_db'
mysql_install_db --user=mysql --basedir=/usr --datadir="$DATADIR" --rpm
echo 'Finished mysql_install_db'
mysqld --user=mysql --datadir="$DATADIR" --skip-networking --log-bin=mysql-bin &
pid="$!"
mysql=( mysql --protocol=socket -uroot )
for i in {30..0}; do
if echo 'SELECT 1' | "${mysql[@]}" &> /dev/null; then
break
fi
echo 'MySQL init process in progress...'
sleep 1
done
if [ "$i" = 0 ]; then
echo >&2 'MySQL init process failed.'
exit 1
fi
# sed is for https://bugs.mysql.com/bug.php?id=20545
mysql_tzinfo_to_sql /usr/share/zoneinfo | sed 's/Local time zone must be set--see zic manual page/FCTY/' | "${mysql[@]}" mysql
if [ ! -z "$MYSQL_RANDOM_ROOT_PASSWORD" ]; then
MYSQL_ROOT_PASSWORD="$(pwmake 128)"
echo "GENERATED ROOT PASSWORD: $MYSQL_ROOT_PASSWORD"
fi
"${mysql[@]}" <<-EOSQL
-- What's done in this file shouldn't be replicated
-- or products like mysql-fabric won't work
SET @@SESSION.SQL_LOG_BIN=0;
DELETE FROM mysql.user ;
CREATE USER 'root'@'%' IDENTIFIED BY '${MYSQL_ROOT_PASSWORD}' ;
GRANT ALL ON *.* TO 'root'@'%' WITH GRANT OPTION ;
CREATE USER 'xtrabackup'@'localhost' IDENTIFIED BY '$XTRABACKUP_PASSWORD';
GRANT RELOAD,LOCK TABLES,REPLICATION CLIENT ON *.* TO 'xtrabackup'@'localhost';
GRANT REPLICATION CLIENT ON *.* TO monitor@'%' IDENTIFIED BY 'monitor';
DROP DATABASE IF EXISTS test ;
FLUSH PRIVILEGES ;
EOSQL
if [ ! -z "$MYSQL_ROOT_PASSWORD" ]; then
mysql+=( -p"${MYSQL_ROOT_PASSWORD}" )
fi
if [ "$MYSQL_DATABASE" ]; then
echo "CREATE DATABASE IF NOT EXISTS \`$MYSQL_DATABASE\` ;" | "${mysql[@]}"
mysql+=( "$MYSQL_DATABASE" )
fi
if [ "$MYSQL_USER" -a "$MYSQL_PASSWORD" ]; then
echo "CREATE USER '"$MYSQL_USER"'@'%' IDENTIFIED BY '"$MYSQL_PASSWORD"' ;" | "${mysql[@]}"
if [ "$MYSQL_DATABASE" ]; then
echo "GRANT ALL ON \`"$MYSQL_DATABASE"\`.* TO '"$MYSQL_USER"'@'%' ;" | "${mysql[@]}"
fi
echo 'FLUSH PRIVILEGES ;' | "${mysql[@]}"
fi
if [ ! -z "$MYSQL_ONETIME_PASSWORD" ]; then
"${mysql[@]}" <<-EOSQL
ALTER USER 'root'@'%' PASSWORD EXPIRE;
EOSQL
fi
if ! kill -s TERM "$pid" || ! wait "$pid"; then
echo >&2 'MySQL init process failed.'
exit 1
fi
echo
echo 'MySQL init process done. Ready for start up.'
echo
fi
chown -R mysql:mysql "$DATADIR"
function join { local IFS="$1"; shift; echo "$*"; }
# set IP address based on the primary interface
# sed -i "s|WSREP_NODE_ADDRESS|$ipaddr|g" /etc/mysql/my.cnf.d/galera.cnf
echo
echo >&2 ">> Starting mysqld process"
if [ -z $CLUSTER_JOIN ]; then
export _WSREP_NEW_CLUSTER='--wsrep-new-cluster'
# set safe_to_bootstrap = 1
GRASTATE=$DATADIR/grastate.dat
[ -f $GRASTATE ] && sed -i "s|safe_to_bootstrap.*|safe_to_bootstrap: 1|g" $GRASTATE
else
export _WSREP_NEW_CLUSTER=''
fi
mysqld --user=root --wsrep_cluster_name=$CLUSTER_NAME --wsrep-cluster-address="gcomm://$CLUSTER_JOIN" --wsrep_sst_auth="xtrabackup:$XTRABACKUP_PASSWORD" $_WSREP_NEW_CLUSTER $CMDARG
[mysqld]
user = mysql
bind_address = 0.0.0.0
datadir = /var/lib/mysql
pid_file = /var/lib/mysql/mysql.pid
default_storage_engine = InnoDB
binlog_format = ROW
query_cache_size = 0
query_cache_type = 0
innodb_flush_log_at_trx_commit = 0
innodb_flush_method = O_DIRECT
innodb_file_per_table = 1
innodb_autoinc_lock_mode = 2
wsrep_on = ON
wsrep_provider = /usr/lib64/galera/libgalera_smm.so
wsrep_sst_method = WSREP_SST_METHOD
wsrep_sst_auth = "root:"
version: "3.7"
services:
galera0:
image: severalnines/mariadb