From c8c4a6e3d3904255419463ed35a31a6136e3752f Mon Sep 17 00:00:00 2001 From: Valentine Shatravenko Date: Wed, 1 Jul 2020 20:16:02 +0300 Subject: [PATCH] Feature: Implement Stellar build and deployment files --- stellar/Dockerfile | 41 ++++++++++++++ stellar/README.md | 11 ++++ stellar/VERSION | 1 + stellar/config/stellar-core-pubnet.cfg | 73 +++++++++++++++++++++++++ stellar/config/stellar-core-testnet.cfg | 38 +++++++++++++ stellar/docker-compose.yml | 38 +++++++++++++ stellar/scripts/docker-entrypoint.sh | 54 ++++++++++++++++++ 7 files changed, 256 insertions(+) create mode 100644 stellar/Dockerfile create mode 100644 stellar/README.md create mode 100644 stellar/VERSION create mode 100644 stellar/config/stellar-core-pubnet.cfg create mode 100644 stellar/config/stellar-core-testnet.cfg create mode 100644 stellar/docker-compose.yml create mode 100755 stellar/scripts/docker-entrypoint.sh diff --git a/stellar/Dockerfile b/stellar/Dockerfile new file mode 100644 index 0000000..2d32182 --- /dev/null +++ b/stellar/Dockerfile @@ -0,0 +1,41 @@ +FROM debian:stretch + +ENV STELLAR_CORE_VERSION 13.2.0-1260-e45018ea +ENV HORIZON_VERSION 1.5.0 + +EXPOSE 5432 +EXPOSE 8000 +EXPOSE 11625 +EXPOSE 11626 + +RUN apt-get update \ + && apt-get install -y wget curl git libpq-dev libsqlite3-dev libsasl2-dev postgresql-client sudo vim zlib1g-dev jq netcat \ + && apt-get clean + +# stellar-core +RUN wget -O stellar-core.deb https://s3.amazonaws.com/stellar.org/releases/stellar-core/stellar-core-${STELLAR_CORE_VERSION}_amd64.deb \ + && dpkg -i stellar-core.deb \ + && rm stellar-core.deb + +# horizon +RUN wget -O horizon.tar.gz https://github.com/stellar/go/releases/download/horizon-v${HORIZON_VERSION}/horizon-v${HORIZON_VERSION}-linux-amd64.tar.gz \ + && tar -zxvf horizon.tar.gz \ + && mv /horizon-v${HORIZON_VERSION}-linux-amd64/horizon /usr/local/bin \ + && chmod +x /usr/local/bin/horizon \ + && rm -rf horizon.tar.gz /horizon-v${HORIZON_VERSION}-linux-amd64 + +RUN ["mkdir", "-p", "/opt/stellar"] + +RUN useradd --uid 10011001 --home-dir /home/stellar --no-log-init stellar \ + && mkdir -p /home/stellar \ + && chown -R stellar:stellar /home/stellar + +RUN ["ln", "-s", "/opt/stellar", "/stellar"] +RUN ["ln", "-s", "/opt/stellar/core/etc/stellar-core.cfg", "/stellar-core.cfg"] +# RUN ["ln", "-s", "/opt/stellar/horizon/etc/horizon.env", "/horizon.env"] + +ADD scripts/docker-entrypoint.sh / + +ENTRYPOINT ["/docker-entrypoint.sh"] + +CMD ["/usr/local/bin/stellar-core", "run", "--conf", "/stellar-core.cfg"] diff --git a/stellar/README.md b/stellar/README.md new file mode 100644 index 0000000..5f96bfe --- /dev/null +++ b/stellar/README.md @@ -0,0 +1,11 @@ +# Stellar + +## Start the cryptonode + +```shell +docker-compose up -Vd *mainnet or testnet*` +``` + +## Usage + +[Stellar Horizon API reference](https://developers.stellar.org/api/introduction/) diff --git a/stellar/VERSION b/stellar/VERSION new file mode 100644 index 0000000..67aee23 --- /dev/null +++ b/stellar/VERSION @@ -0,0 +1 @@ +13.2.0 diff --git a/stellar/config/stellar-core-pubnet.cfg b/stellar/config/stellar-core-pubnet.cfg new file mode 100644 index 0000000..ca18a69 --- /dev/null +++ b/stellar/config/stellar-core-pubnet.cfg @@ -0,0 +1,73 @@ +# This is an example config for setting up a validator. +# see https://www.stellar.org/developers/stellar-core/software/admin.html +# for how to properly configure your environment + +# run `stellar-core gen-seed` to generate a public key and secret seed. +# Let us know the public key so we can add you to the validator list. +# set NODE_SEED below to the secret seed generated above. + +# uncomment those two lines if you are running a validator node +# NODE_SEED="S123456ABCDE" +# NODE_IS_VALIDATOR=true + +DATABASE="postgresql://dbname=stellar user=stellar password=changeme host=stellar-core-postgres" + +#FAILURE_SAFETY is minimum number of nodes that are allowed to fail before you no longer have quorum +FAILURE_SAFETY=1 + +# number of ledgers to synchronize (time in seconds divided by 5) +# NB: full validators should run with CATCHUP_COMPLETE=true instead +CATCHUP_RECENT=60480 + +NETWORK_PASSPHRASE="Public Global Stellar Network ; September 2015" + +# Populate NODE_NAMES, KNOW_PEERS, QUORUM and HISTORY sections with information +# on other validators +# for example https://github.com/stellar/docs/blob/master/validators.md +# or from https://dashboard.stellar.org/ +NODE_NAMES=[ +"GDIQKLQVOCD5UD6MUI5D5PTPVX7WTP5TAPP5OBMOLENBBD5KG434KYQ2 stronghold1", +"GAOO3LWBC4XF6VWRP5ESJ6IBHAISVJMSBTALHOQM2EZG7Q477UWA6L7U eno", +"GCJCSMSPIWKKPR7WEPIQG63PDF7JGGEENRC33OKVBSPUDIRL6ZZ5M7OO tempo.eu.com", +"GC5SXLNAM3C4NMGK2PXK4R34B5GNZ47FYQ24ZIBFDFOCU6D4KBN4POAE satoshipay", +"GD7FVHL2KUTUYNOJFRUUDJPDRO2MAZJ5KP6EBCU6LKXHYGZDUFBNHXQI umbrel", +"GCGB2S2KGYARPVIA37HYZXVRM2YZUEXA6S33ZU5BUDC6THSB62LZSTYH sdf_watcher1", +"GCM6QMP3DLRPTAZW2UZPCPX2LF3SXWXKPMP3GKFZBDSF3QZGV2G5QSTK sdf_watcher2", +"GABMKJM6I25XI4K7U6XWMULOUQIQ27BCTMLS6BYYSOWKTBUXVRJSXHYQ sdf_watcher3", +] + +KNOWN_PEERS=[ +"core-live-a.stellar.org:11625", +"core-live-b.stellar.org:11625", +"core-live-c.stellar.org:11625", +"validator1.stellar.stronghold.co", +"stellar.256kw.com", +"stellar1.tempo.eu.com", +"stellar.satoshipay.io" +] + +# full validators (with history archive) +[QUORUM_SET] +VALIDATORS=[ +"$sdf_watcher1", "$sdf_watcher2", "$sdf_watcher3" +] + +# other validators that you want to include +# for best result, use a number of validators +# that can be expressed as 3f+1 (4, 7, 10 ,...) +[QUORUM_SET.basic] +VALIDATORS=[ +"$stronghold1", "$eno", "$tempo.eu.com", "$satoshipay" +] + +# History archives + +# Stellar.org history store +[HISTORY.sdf1] +get="curl -sf http://history.stellar.org/prd/core-live/core_live_001/{0} -o {1}" + +[HISTORY.sdf2] +get="curl -sf http://history.stellar.org/prd/core-live/core_live_002/{0} -o {1}" + +[HISTORY.sdf3] +get="curl -sf http://history.stellar.org/prd/core-live/core_live_003/{0} -o {1}" diff --git a/stellar/config/stellar-core-testnet.cfg b/stellar/config/stellar-core-testnet.cfg new file mode 100644 index 0000000..05318da --- /dev/null +++ b/stellar/config/stellar-core-testnet.cfg @@ -0,0 +1,38 @@ +HTTP_PORT=11626 +PUBLIC_HTTP_PORT=true +LOG_FILE_PATH="" + +NETWORK_PASSPHRASE="Test SDF Network ; September 2015" +KNOWN_CURSORS=["HORIZON"] +DATABASE="postgresql://dbname=stellar user=stellar password=changeme host=stellar-core-postgres" +UNSAFE_QUORUM=true +FAILURE_SAFETY=1 +CATCHUP_RECENT=100 + +[HISTORY.cache] +get="cp /opt/stellar/history-cache/{0} {1}" + +[[HOME_DOMAINS]] +HOME_DOMAIN="testnet.stellar.org" +QUALITY="HIGH" + +[[VALIDATORS]] +NAME="sdf_testnet_1" +HOME_DOMAIN="testnet.stellar.org" +PUBLIC_KEY="GDKXE2OZMJIPOSLNA6N6F2BVCI3O777I2OOC4BV7VOYUEHYX7RTRYA7Y" +ADDRESS="core-testnet1.stellar.org" +HISTORY="curl -sf http://history.stellar.org/prd/core-testnet/core_testnet_001/{0} -o {1}" + +[[VALIDATORS]] +NAME="sdf_testnet_2" +HOME_DOMAIN="testnet.stellar.org" +PUBLIC_KEY="GCUCJTIYXSOXKBSNFGNFWW5MUQ54HKRPGJUTQFJ5RQXZXNOLNXYDHRAP" +ADDRESS="core-testnet2.stellar.org" +HISTORY="curl -sf http://history.stellar.org/prd/core-testnet/core_testnet_002/{0} -o {1}" + +[[VALIDATORS]] +NAME="sdf_testnet_3" +HOME_DOMAIN="testnet.stellar.org" +PUBLIC_KEY="GC2V2EFSXN6SQTWVYA5EPJPBWWIMSD2XQNKUOHGEKB535AQE2I6IXV2Z" +ADDRESS="core-testnet3.stellar.org" +HISTORY="curl -sf http://history.stellar.org/prd/core-testnet/core_testnet_003/{0} -o {1}" diff --git a/stellar/docker-compose.yml b/stellar/docker-compose.yml new file mode 100644 index 0000000..a1aab17 --- /dev/null +++ b/stellar/docker-compose.yml @@ -0,0 +1,38 @@ +version: '3.6' + +services: + stellar-core-postgres: + image: postgres:9 + restart: on-failure + volumes: + - postgres_data:/var/lib/postgresql/data + environment: + - POSTGRES_DB=stellar + - POSTGRES_USER=stellar + - POSTGRES_PASSWORD=changeme + + stellar-core-testnet: + image: quay.io/openware/stellar:13.2.0 + restart: always + volumes: + - ./config/stellar-core-testnet.cfg:/stellar-core.cfg + - ./data/testnet:/data + environment: + INITIALIZE_DB: "true" + INITIALIZE_HISTORY_ARCHIVES: "true" + ports: + - 127.0.0.1:11625:11625 + - 127.0.0.1:11626:11626 + + stellar-core-pubnet: + image: quay.io/openware/stellar:13.2.0 + restart: always + volumes: + - ./config/stellar-core-pubnet.cfg:/stellar-core.cfg + - ./data/pubnet:/data + ports: + - 127.0.0.1:11625:11625 + - 127.0.0.1:11626:11626 + +volumes: + postgres_data: diff --git a/stellar/scripts/docker-entrypoint.sh b/stellar/scripts/docker-entrypoint.sh new file mode 100755 index 0000000..76c6739 --- /dev/null +++ b/stellar/scripts/docker-entrypoint.sh @@ -0,0 +1,54 @@ +#!/usr/bin/env bash + +set -ue + +function stellar_core_init_db() { + if [ -z ${INITIALIZE_DB:-} ] || [ "${INITIALIZE_DB}" != "true" ]; then + echo "Not initializing DB (set INITIALIZE_DB=true if you want to initialize it)." + return 0 + fi + + local DB_INITIALIZED="/data/.db-initialized" + + if [ -f $DB_INITIALIZED ]; then + echo "Core db has already been initialized." + return 0 + fi + + echo "Initializing core db..." + + stellar-core new-db --conf /stellar-core.cfg + + echo "Finished initializing core db" + + touch $DB_INITIALIZED +} + +function stellar_core_init_history_archives() { + if [ -z ${INITIALIZE_HISTORY_ARCHIVES:-} ] || [ "${INITIALIZE_HISTORY_ARCHIVES}" != "true" ]; then + echo "Not initializing history archives (set INITIALIZE_HISTORY_ARCHIVES=true if you want to initialize them)." + return 0 + fi + + for HISTORY_ARCHIVE in $(echo $HISTORY | jq -r 'to_entries[] | select (.value.put?) | .key'); do + local HISTORY_ARCHIVE_INITIALIZED="/data/.history-archive-${HISTORY_ARCHIVE}-initialized" + + if [ -f $HISTORY_ARCHIVE_INITIALIZED ]; then + echo "History archive ${HISTORY_ARCHIVE} has already been initialized." + continue + fi + + echo "Initializing history archive ${HISTORY_ARCHIVE}..." + + stellar-core new-hist $HISTORY_ARCHIVE --conf /stellar-core.cfg + + echo "Finished initializing history archive ${HISTORY_ARCHIVE}." + + touch $HISTORY_ARCHIVE_INITIALIZED + done +} + +stellar_core_init_db +stellar_core_init_history_archives + +exec "$@"