Skip to content

Commit

Permalink
Initial release
Browse files Browse the repository at this point in the history
  • Loading branch information
dragonsmith committed Jun 1, 2018
0 parents commit 1346d0c
Show file tree
Hide file tree
Showing 11 changed files with 213 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
data/
log/
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
data/
log/

.vscode
boto.cfg
docker-compose.yml
gcloud-service-account-key.json
stellar-core.cfg
47 changes: 47 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
FROM debian:stretch-slim

LABEL maintainer="Evil Martians <[email protected]>"

ARG STELLAR_VERSION="9.2.0-9"

# hack to make postgresql-client install work on slim
RUN mkdir -p /usr/share/man/man1 \
&& mkdir -p /usr/share/man/man7

# prerequisites for stellar-core
RUN apt-get update \
&& DEBIAN_FRONTEND=noninteractive apt-get -y dist-upgrade \
&& DEBIAN_FRONTEND=noninteractive apt-get -y install curl gnupg2 apt-transport-https man-db \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

# Stellar core installation
RUN curl -q https://apt.stellar.org/SDF.asc | apt-key add - \
&& echo "deb https://apt.stellar.org/public stable/" | tee -a /etc/apt/sources.list.d/SDF.list \
&& apt-get update \
&& DEBIAN_FRONTEND=noninteractive apt-get -y install stellar-core=$STELLAR_VERSION \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

# Additional packages
RUN apt-get update \
&& DEBIAN_FRONTEND=noninteractive apt-get -y install postgresql-client s3cmd python-pip \
&& pip install "pyasn1>=0.4.3" \
&& pip install gsutil \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*


ADD init_db.sh /usr/local/bin/stellar_init_db.sh
ADD init_cache.sh /usr/local/bin/stellar_init_cache.sh
ADD entrypoint.sh /entrypoint.sh
ADD wait_for_postgres.sh /usr/local/bin/wait_for_postgres.sh

# USER stellar

EXPOSE 11625
EXPOSE 11626

WORKDIR /var/lib/stellar

ENTRYPOINT [ "/entrypoint.sh" ]
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Stellar Core Docker Image

This repository is used to build a [Docker image](https://quay.io/repository/evilmartians/docker-stellar-core?tab=info) containing Stellar Core package with some tools to bootstrap Stellar Core installation and manage remote history uploading.

Currently, only `gsutil` and Google Cloud Storage are supported as a remote backend. s3cmd & AWS S3 implementation is planned for the future release. There is an option to store history locally for test purposes.

This image does not support a multiple Stellar Core history backend yet. It's a big downside, sorry.

There is **no** `confd` or other template or configuration engines included as it is intended to be used in a Helm Chart which has its own templating capabilities.

## Example

See included `docker-compose-example.yml` for clues how to hack it.
5 changes: 5 additions & 0 deletions boto-example.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[Credentials]
gs_service_key_file = /etc/mobius-service-account.json

[GSUtil]
default_project_id = YOURPROJECTID
31 changes: 31 additions & 0 deletions docker-compose-example.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
version: "3"
services:
postgres:
image: postgres:9.6-alpine
ports:
- "5432"
networks:
- stellar
environment:
- POSTGRES_PASSWORD=password
stellar-core:
image: stellar-core:latest
command:
- "--conf /etc/stellar/stellar-core.cfg"
environment:
- STELLAR_CORE_DATABASE_URL=postgresql://dbname=stellarcore host=postgres user=postgres password=password
- STELLAR_CORE_HISTORY_CACHE_TYPE=gcloud
- STELLAR_CORE_HISTORY_CACHE_PATH=gs://YOURBUCKETNAME/
networks:
- stellar
volumes:
- ./stellar-core-testnet-example.cfg:/etc/stellar/stellar-core.cfg
- ./boto-example.cfg:/etc/boto.cfg
- ./gcloud-service-account-key.json:/etc/mobius-service-account.json
- ./data:/var/lib/stellar/
- ./logs:/var/log/stellar
depends_on:
- postgres

networks:
stellar:
9 changes: 9 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash

set -ue

/usr/local/bin/wait_for_postgres.sh
/usr/local/bin/stellar_init_db.sh
/usr/local/bin/stellar_init_cache.sh

exec /usr/bin/stellar-core $@
34 changes: 34 additions & 0 deletions init_cache.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/bin/bash

set -ue

_init_cache=false

case $STELLAR_CORE_HISTORY_CACHE_TYPE in
gcloud)
echo "Stellar core cache will be stored on GCloud Storage."
if ! gsutil -q stat ${STELLAR_CORE_HISTORY_CACHE_PATH%/}/.well-known/stellar-history.json
then
_init_cache=true
fi
;;
local)
echo "Stellar core cache will be sored locally."

if [ ! -e ${STELLAR_CORE_HISTORY_CACHE_PATH%/}/.well-known/stellar-history.json ]
then
_init_cache=true
fi
;;
*)
echo "Unknown storage type for Stellar Core"
;;
esac

# Stellar core checks history archive cache before initializing one.
if [ "X$_init_cache" == "Xtrue" ]
then
stellar-core --newhist cache --conf /etc/stellar/stellar-core.cfg
else
echo "Skipping Stellar core cache creation."
fi
12 changes: 12 additions & 0 deletions init_db.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash

set -ue

if psql "${STELLAR_CORE_DATABASE_URL#postgresql://}" -c "\dt" | grep -q "No relations" ; then
echo -n "Database is not initialized. Initializing... "
stellar-core --newdb --conf /etc/stellar/stellar-core.cfg && echo "done!"

exit $?
fi

echo "Database was already initialized. Skipping."
41 changes: 41 additions & 0 deletions stellar-core-testnet-example.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@

HTTP_PORT=11626
PUBLIC_HTTP_PORT=true
LOG_FILE_PATH=""

NETWORK_PASSPHRASE="Test SDF Network ; September 2015"

KNOWN_PEERS=[
"core-testnet1.stellar.org",
"core-testnet2.stellar.org",
"core-testnet3.stellar.org"]

DATABASE="postgresql://dbname=stellarcore host=postgres user=postgres password=password"
UNSAFE_QUORUM=true
FAILURE_SAFETY=1
CATCHUP_RECENT=8640

#The public keys of the Stellar testnet servers
[QUORUM_SET]
THRESHOLD_PERCENT=51 # rounded up -> 2 nodes out of 3
VALIDATORS=[
"GDKXE2OZMJIPOSLNA6N6F2BVCI3O777I2OOC4BV7VOYUEHYX7RTRYA7Y sdf1",
"GCUCJTIYXSOXKBSNFGNFWW5MUQ54HKRPGJUTQFJ5RQXZXNOLNXYDHRAP sdf2",
"GC2V2EFSXN6SQTWVYA5EPJPBWWIMSD2XQNKUOHGEKB535AQE2I6IXV2Z sdf3"]

# [HISTORY.cache]
# get="cp /var/lib/stellar/history-cache/{0} {1}"
# put="cp {0} /var/lib/stellar/history-cache/{1}"
# mkdir="mkdir -p /var/lib/stellar/history-cache/{0}"
[HISTORY.cache]
get="gsutil cp gs://YOURBUCKETNAME/{0} {1}"
put="gsutil cp {0} gs://YOURBUCKETNAME/{1}"

[HISTORY.h1]
get="curl -sf http://s3-eu-west-1.amazonaws.com/history.stellar.org/prd/core-testnet/core_testnet_001/{0} -o {1}"

[HISTORY.h2]
get="curl -sf http://s3-eu-west-1.amazonaws.com/history.stellar.org/prd/core-testnet/core_testnet_002/{0} -o {1}"

[HISTORY.h3]
get="curl -sf http://s3-eu-west-1.amazonaws.com/history.stellar.org/prd/core-testnet/core_testnet_003/{0} -o {1}"
11 changes: 11 additions & 0 deletions wait_for_postgres.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash
# wait-for-postgres.sh

set -eu

until psql "${STELLAR_CORE_DATABASE_URL#postgresql://}" -c '\q'; do
>&2 echo "Postgres is unavailable - sleeping"
sleep 1
done

>&2 echo "Postgres is up - continuing"

0 comments on commit 1346d0c

Please sign in to comment.