Begin to disentangle the api

This commit is contained in:
Jack Zampolin
2018-01-16 14:40:49 -08:00
parent f901aa8c8f
commit d6bfd83fc9
12 changed files with 238 additions and 30 deletions

36
api/Dockerfile Normal file
View File

@@ -0,0 +1,36 @@
FROM ubuntu:xenial
WORKDIR /src/blockstack
# Install dependancies from apt
RUN apt-get -y update
RUN apt-get install -y python-pip python-dev libssl-dev libffi-dev rng-tools libgmp3-dev lsof curl
# Copy all files from the repo into the container
COPY . .
# Upgrade pip and install pyparsing
RUN pip install --upgrade pip && pip install pyparsing uwsgi
RUN pip install -r api/requirements.txt
# Install Blockstack from source
RUN pip install .
# Install Node
RUN curl -sL https://deb.nodesource.com/setup_8.x | bash -
RUN apt-get install -y nodejs
# Install aglio to build docs
RUN npm -g install aglio --unsafe
# Create data dir
RUN mkdir /var/blockstack-search
# Build Documentation
RUN ./build_docs.sh public_api
# Work out of the /api dir
WORKDIR /src/blockstack/api
# Start the uwsgi server
CMD ["/usr/local/bin/uwsgi", "--ini", "deployment/blockstack_api.ini"]

View File

@@ -1 +0,0 @@
web: python runserver.py

View File

@@ -1,9 +0,0 @@
machine:
python:
version: 2.7.9
test:
pre:
- python manage.py init_db
override:
- python unit_tests.py

View File

@@ -35,14 +35,14 @@ MAX_PROFILE_LIMIT = (8 * 1024) - 50 # roughly 8kb max limit
EMAIL_REGREX = r'[^@]+@[^@]+\.[^@]+'
DEFAULT_NAMESPACE = "id"
PUBLIC_NODE = True
BASE_API_URL = "http://localhost:6270"
PUBLIC_NODE_URL = 'https://core.blockstack.org'
SEARCH_NODE_URL = 'https://search.blockstack.org'
BLOCKSTACKD_IP = 'localhost'
MONGODB_URI = "mongodb://mongodb"
BASE_API_URL = "http://blockstack-api:6270"
PUBLIC_NODE_URL = 'https://core.example.org'
SEARCH_NODE_URL = 'https://search.example.org'
BLOCKSTACKD_IP = 'node.technofractal.com'
BLOCKSTACKD_PORT = 6264
DHT_MIRROR_IP = '52.20.98.85'
DHT_MIRROR_PORT = 6266
@@ -71,19 +71,6 @@ SEARCH_DEFAULT_LIMIT = 50
SEARCH_LUCENE_ENABLED = False
SEARCH_SUPPORTED_PROOFS = ['twitter', 'facebook', 'github', 'domain']
# Memcache settings
MEMCACHED_USERNAME = None
MEMCACHED_PASSWORD = None
MEMCACHED_TIMEOUT = 12 * 60 * 60
USERSTATS_TIMEOUT = 60 * 60
MEMCACHED_ENABLED = False
MEMCACHED_PORT = 11211
MEMCACHED_SERVER = '127.0.0.1'
MEMCACHED_SERVERS = ['127.0.0.1:11211']
if 'DYNO' in os.environ:
DEBUG = False
# heroku configs go here

View File

@@ -0,0 +1,14 @@
[bitcoind]
p2p_port = 8333
regtest = False
spv_path = /root/.virtualchain-spv-headers.dat
server = bitcoin.blockstack.com
passwd = blockstacksystem
user = blockstack
timeout = 300
port = 8332
use_https = False
[blockstack]
email = foo@bar.com
server_version = 0.14.5.1

View File

@@ -0,0 +1,17 @@
[uwsgi]
plugins = python
module = api.server:app
master = true
processes = 4
pcre-jit = true
manage-script-name = true
thunder-lock = on
enable-threads = true
listen = 128
http = 0.0.0.0:3000
vacuum = true
die-on-term = true
close-on-exec = true

39
api/deployment/client.ini Normal file
View File

@@ -0,0 +1,39 @@
[blockstack-client]
protocol = https
api_endpoint_host = 0.0.0.0
poll_interval = 300
api_endpoint_port = 6270
api_password = dummywalletpassword
metadata = metadata
server = node.technofractal.com
email =
api_endpoint_bind = 0.0.0.0
blockchain_writer = blockstack_utxo
queue_path = /root/.blockstack/queues.db
storage_drivers = disk,http,dht
blockchain_reader = blockstack_utxo
client_version = 0.17.0.16
storage_drivers_required_write = disk,dropbox
port = 6263
anonymous_statistics = True
[blockchain-reader]
url = https://utxo.blockstack.org
utxo_provider = blockstack_utxo
[subdomain-resolution]
subdomains_db = /root/.blockstack/subdomains.db
[bitcoind]
passwd = blockstacksystem
regtest = False
spv_path = /root/.virtualchain-spv-headers.dat
server = bitcoin.blockstack.com
p2p_port = 8333
user = blockstack
timeout = 300
port = 8332
[blockchain-writer]
url = https://utxo.blockstack.org
utxo_provider = blockstack_utxo

3
api/deployment/crontab Normal file
View File

@@ -0,0 +1,3 @@
0 12 * * * /usr/bin/docker run -d --network api_api -v /home/ubuntu/blockstack-core/api/data/search-api/:/var/blockstack-search/ api_search-api:latest ./ops search-reindex
0 0 * * * /usr/bin/docker run -d --network api_api -v /home/ubuntu/blockstack-core/api/data/search-api/:/var/blockstack-search/ api_search-api:latest ./ops search-reindex
0,12,24,36,48 * * * * /usr/bin/docker run -d --network api_api -v /home/ubuntu/blockstack-core/api/data/search-api/:/var/blockstack-search/ api_search-api:latest ./ops search-update

42
api/deployment/nginx.cfg Normal file
View File

@@ -0,0 +1,42 @@
uwsgi_cache_path /tmp/blockstack_uwsgi_cache levels=1:2 keys_zone=api:50m inactive=180m;
server {
listen 80 default_server;
server_name core.example.com;
return 301 https://core.example.com$request_uri;
location / {
include uwsgi_params;
uwsgi_pass localhost:3000;
}
}
server {
listen 443 default_server;
server_name core.example.com;
ssl on;
ssl_certificate /etc/letsencrypt/live/core.example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/core.example.com/privkey.pem;
location / {
if ($request_method = OPTIONS ) {
add_header Access-Control-Allow-Origin "*";
add_header Access-Control-Allow-Methods "GET, HEAD, POST, OPTIONS";
add_header Access-Control-Max-Age "21600";
add_header Content-Length 0;
add_header Content-Type text/plain;
return 200;
}
include uwsgi_params;
uwsgi_pass localhost:3000;
expires 180m;
uwsgi_cache api; uwsgi_cache_key $uri$args;
add_header X-Cache-Status $upstream_cache_status;
uwsgi_cache_methods GET HEAD;
uwsgi_cache_valid 200 12h; uwsgi_cache_valid 404 12h;
}
}

40
api/docker-compose.yaml Normal file
View File

@@ -0,0 +1,40 @@
version: '2'
services:
mongodb:
image: mongo:3.4
volumes:
- './data/mongodb/:/data/db'
networks:
- api
restart: always
blockstack-api:
image: 'quay.io/blockstack/blockstack-core:master'
command: blockstack api start-foreground --debug --password dummywalletpassword
volumes:
- './data/blockstack-api/:/root/.blockstack'
# - '/tmp/:/data/blockstack-api/tmp/'
networks:
- api
restart: always
search-api:
build:
context: ../
dockerfile: api/Dockerfile
environment:
- BLOCKSTACK_DEBUG=1
networks:
- api
ports:
- 3000:3000
restart: always
links:
- mongodb
- blockstack-api
volumes:
- "./data/search-api/:/var/blockstack-search"
networks:
api: null

40
api/ops Executable file
View File

@@ -0,0 +1,40 @@
#!/bin/bash
ops () {
local python=/usr/bin/python
local initCore=blockstack-core-init
local storageBucket=https://blockstack.blob.core.windows.net/index
local image=quay.io/blockstack/blockstack-core
local tag=master
init-api () {
local apiData=data/blockstack-api
echo "Initializing Blockstack Core API server with dummy wallet..."
mkdir -p $apiData
docker run -it --rm \
-v $(pwd)/$apiData:/root/.blockstack \
$image:$tag \
blockstack setup -y --password dummywalletpassword
sudo cp deployment/client.ini $apiData/client.ini
}
commands () {
cat <<-EOF
ops commands:
init-api -> Set up the dummy wallet for the core api
EOF
}
case $1 in
init-api)
init-api
;;
*)
commands
;;
esac
}
ops $1 $2

View File

@@ -101,7 +101,7 @@ def search_people():
if SEARCH_API_ENDPOINT_ENABLED:
client = app.test_client()
return client.get('/search?query={}'.format(query),
return client.get('/search?query={}'.format(query),
headers=list(request.headers))
search_url = SEARCH_NODE_URL + '/search'