feat(cic-eth): initial server setup
This commit is contained in:
parent
d8f51c5bdd
commit
4a1008e75e
@ -1,15 +1,11 @@
|
||||
#!/usr/bin/python
|
||||
import sys
|
||||
import os
|
||||
import logging
|
||||
import uuid
|
||||
import json
|
||||
import argparse
|
||||
|
||||
# external imports
|
||||
import redis
|
||||
from xdg.BaseDirectory import xdg_config_home
|
||||
from chainlib.chain import ChainSpec
|
||||
|
||||
# local imports
|
||||
import cic_eth.cli
|
||||
|
99
apps/cic-eth/cic_eth/runnable/daemons/server.py
Normal file
99
apps/cic-eth/cic_eth/runnable/daemons/server.py
Normal file
@ -0,0 +1,99 @@
|
||||
# standard imports
|
||||
import json
|
||||
import logging
|
||||
import os
|
||||
import sys
|
||||
import uuid
|
||||
from urllib.parse import parse_qsl, urlparse
|
||||
|
||||
import cic_eth.cli
|
||||
import redis
|
||||
from cic_eth.api.api_task import Api
|
||||
|
||||
logging.basicConfig(level=logging.WARNING)
|
||||
logg = logging.getLogger()
|
||||
|
||||
arg_flags = cic_eth.cli.argflag_std_base
|
||||
local_arg_flags = cic_eth.cli.argflag_local_taskcallback
|
||||
argparser = cic_eth.cli.ArgumentParser(arg_flags)
|
||||
|
||||
argparser.process_local_flags(local_arg_flags)
|
||||
args = argparser.parse_args()
|
||||
config = cic_eth.cli.Config.from_args(args, arg_flags, local_arg_flags)
|
||||
|
||||
celery_app = cic_eth.cli.CeleryApp.from_config(config)
|
||||
|
||||
# uwsgi application
|
||||
|
||||
|
||||
def application(env, start_response):
|
||||
parsed_url = urlparse(env['REQUEST_URI']) # /api
|
||||
path = parsed_url.path
|
||||
params = dict(parse_qsl(parsed_url.query))
|
||||
request_method = env['REQUEST_METHOD']
|
||||
chain_spec = config.get('CHAIN_SPEC')
|
||||
redis_host = config.get('REDIS_HOST')
|
||||
redis_port = config.get('REDIS_PORT')
|
||||
redis_db = config.get('REDIS_DB')
|
||||
celery_queue = config.get('CELERY_QUEUE')
|
||||
|
||||
redis_channel = str(uuid.uuid4())
|
||||
|
||||
r = redis.Redis(redis_host, redis_port, redis_db)
|
||||
|
||||
ps = r.pubsub()
|
||||
ps.subscribe(redis_channel)
|
||||
ps.get_message() # Subscription Object
|
||||
|
||||
api = Api(
|
||||
chain_spec,
|
||||
queue=celery_queue,
|
||||
callback_param='{}:{}:{}:{}'.format(
|
||||
redis_host, redis_port, redis_db, redis_channel),
|
||||
callback_task='cic_eth.callbacks.redis.redis',
|
||||
callback_queue=celery_queue,
|
||||
)
|
||||
if path == '/list':
|
||||
address = params.get('address')
|
||||
print('address', address)
|
||||
# address, limit=10, external_task=None, external_queue=None
|
||||
api.list(address)
|
||||
elif path == '/balance':
|
||||
api.balance(**params)
|
||||
elif path == '/create_account':
|
||||
api.create_account(**params)
|
||||
elif path == '/ping':
|
||||
api.ping(**params)
|
||||
elif path == '/transfer':
|
||||
api.transfer(**params)
|
||||
elif path == '/transfer_from':
|
||||
api.transfer_from(**params)
|
||||
elif path == '/token':
|
||||
api.token(**params)
|
||||
elif path == '/tokens':
|
||||
api.tokens(**params)
|
||||
elif path == '/default_token':
|
||||
api.default_token()
|
||||
|
||||
ps.get_message() # returns None !?
|
||||
try:
|
||||
o = ps.get_message(timeout=config.get('REDIS_TIMEOUT'))
|
||||
except TimeoutError as e:
|
||||
sys.stderr.write(
|
||||
'got no new address from cic-eth before timeout: {}\n'.format(e))
|
||||
sys.exit(1)
|
||||
ps.unsubscribe()
|
||||
m = json.loads(o['data'])
|
||||
print(m['result'])
|
||||
|
||||
data = {"path": path,
|
||||
"request_method": request_method, "result": m}
|
||||
json_data = json.dumps(data)
|
||||
content = json_data.encode('utf-8')
|
||||
headers = []
|
||||
headers.append(('Content-Length', str(len(content))),)
|
||||
headers.append(('Access-Control-Allow-Origin', '*',))
|
||||
headers.append(('Content-Type', 'application/json',))
|
||||
start_response('200 OK', headers)
|
||||
|
||||
return [content]
|
@ -15,8 +15,6 @@ RUN apt-get install libffi-dev
|
||||
|
||||
RUN pip install --index-url $PIP_INDEX_URL \
|
||||
--pre \
|
||||
--force-reinstall \
|
||||
--no-cache \
|
||||
--extra-index-url $EXTRA_PIP_INDEX_URL $EXTRA_PIP_ARGS \
|
||||
cic-eth-aux-erc20-demurrage-token~=0.0.2a7
|
||||
|
||||
@ -24,8 +22,6 @@ RUN pip install --index-url $PIP_INDEX_URL \
|
||||
COPY *requirements.txt ./
|
||||
RUN pip install --index-url $PIP_INDEX_URL \
|
||||
--pre \
|
||||
--force-reinstall \
|
||||
--no-cache \
|
||||
--extra-index-url $EXTRA_PIP_INDEX_URL $EXTRA_PIP_ARGS \
|
||||
-r requirements.txt \
|
||||
-r services_requirements.txt \
|
||||
|
@ -2,3 +2,4 @@ celery==4.4.7
|
||||
chainlib-eth>=0.0.10a4,<0.1.0
|
||||
semver==2.13.0
|
||||
crypto-dev-signer>=0.4.15rc2,<0.5.0
|
||||
uwsgi==2.0.19.1
|
||||
|
@ -6,7 +6,6 @@ volumes:
|
||||
bloxberg-data: {}
|
||||
contract-config: {}
|
||||
|
||||
|
||||
services:
|
||||
evm:
|
||||
image: ${DEV_DOCKER_REGISTRY:-registry.gitlab.com/grassrootseconomics/cic-internal-integration}/bloxberg-node:${TAG:-latest}
|
||||
@ -28,7 +27,7 @@ services:
|
||||
# PGDATA: /tmp/cic/postgres
|
||||
ports:
|
||||
- ${DEV_POSTGRES_PORT:-63432}:5432
|
||||
command: [ "-c", "max_connections=200" ]
|
||||
command: ["-c", "max_connections=200"]
|
||||
volumes:
|
||||
- ./scripts/initdb/create_db.sql:/docker-entrypoint-initdb.d/1-create_all_db.sql
|
||||
- postgres-db:/var/lib/postgresql/data
|
||||
@ -39,7 +38,6 @@ services:
|
||||
- ${DEV_REDIS_PORT:-63379}:6379
|
||||
command: "--loglevel verbose"
|
||||
|
||||
|
||||
bootstrap:
|
||||
image: ${DEV_DOCKER_REGISTRY:-registry.gitlab.com/grassrootseconomics/cic-internal-integration}/contract-migration:${TAG:-latest}
|
||||
build:
|
||||
@ -81,8 +79,6 @@ services:
|
||||
volumes:
|
||||
- contract-config:/tmp/cic/config
|
||||
|
||||
|
||||
|
||||
cic-signer:
|
||||
image: ${DEV_DOCKER_REGISTRY:-registry.gitlab.com/grassrootseconomics/cic-internal-integration}/funga-eth:${TAG:-latest}
|
||||
build:
|
||||
@ -145,6 +141,8 @@ services:
|
||||
SIGNER_SECRET: ${SIGNER_SECRET:-deadbeef}
|
||||
TASKS_TRACE_QUEUE_STATUS: ${TASKS_TRACE_QUEUE_STATUS:-1}
|
||||
restart: unless-stopped
|
||||
ports:
|
||||
- 8080:8000
|
||||
depends_on:
|
||||
- evm
|
||||
- postgres
|
||||
@ -162,7 +160,6 @@ services:
|
||||
set +a
|
||||
./start_tasker.sh --aux-all -q cic-eth -vv
|
||||
|
||||
|
||||
cic-eth-tracker:
|
||||
image: ${DEV_DOCKER_REGISTRY:-registry.gitlab.com/grassrootseconomics/cic-internal-integration}/cic-eth:${TAG:-latest}
|
||||
build:
|
||||
@ -210,7 +207,6 @@ services:
|
||||
set +a
|
||||
./start_tracker.sh -vv
|
||||
|
||||
|
||||
cic-eth-dispatcher:
|
||||
image: ${DEV_DOCKER_REGISTRY:-registry.gitlab.com/grassrootseconomics/cic-internal-integration}/cic-eth:${TAG:-latest}
|
||||
build:
|
||||
@ -254,7 +250,6 @@ services:
|
||||
set +a
|
||||
./start_dispatcher.sh -vv
|
||||
|
||||
|
||||
cic-eth-retrier:
|
||||
image: ${DEV_DOCKER_REGISTRY:-registry.gitlab.com/grassrootseconomics/cic-internal-integration}/cic-eth:${TAG:-latest}
|
||||
build:
|
||||
@ -300,8 +295,6 @@ services:
|
||||
set +a
|
||||
./start_retry.sh -vv
|
||||
|
||||
|
||||
|
||||
cic-cache-tracker:
|
||||
image: ${DEV_DOCKER_REGISTRY:-registry.gitlab.com/grassrootseconomics/cic-internal-integration}/cic-cache:${TAG:-latest}
|
||||
build:
|
||||
@ -349,7 +342,6 @@ services:
|
||||
set +a
|
||||
./start_tracker.sh -vv
|
||||
|
||||
|
||||
cic-cache-tasker:
|
||||
image: ${DEV_DOCKER_REGISTRY:-registry.gitlab.com/grassrootseconomics/cic-internal-integration}/cic-cache:${TAG:-latest}
|
||||
build:
|
||||
@ -392,11 +384,10 @@ services:
|
||||
if [[ -f /tmp/cic/config/env_reset ]]; then source /tmp/cic/config/env_reset; fi
|
||||
set +a
|
||||
/usr/local/bin/cic-cache-taskerd -vv
|
||||
# "/usr/local/bin/uwsgi" \
|
||||
# --wsgi-file /root/cic_cache/runnable/daemons/server.py \
|
||||
# --http :8000 \
|
||||
# --pyargv "-vv"
|
||||
|
||||
# "/usr/local/bin/uwsgi" \
|
||||
# --wsgi-file /root/cic_cache/runnable/daemons/server.py \
|
||||
# --http :8000 \
|
||||
# --pyargv "-vv"
|
||||
|
||||
cic-cache-server:
|
||||
image: ${DEV_DOCKER_REGISTRY:-registry.gitlab.com/grassrootseconomics/cic-internal-integration}/cic-cache:${TAG:-latest}
|
||||
@ -440,7 +431,6 @@ services:
|
||||
volumes:
|
||||
- contract-config:/tmp/cic/config/:ro
|
||||
|
||||
|
||||
# metadata replacement server for swarm
|
||||
cic-meta-server:
|
||||
image: ${DEV_DOCKER_REGISTRY:-registry.gitlab.com/grassrootseconomics/cic-internal-integration}/cic-meta:${TAG:-latest}
|
||||
@ -478,7 +468,6 @@ services:
|
||||
volumes:
|
||||
- ./apps/contract-migration/testdata/pgp/:/tmp/cic/pgp
|
||||
|
||||
|
||||
cic-user-tasker:
|
||||
image: ${DEV_DOCKER_REGISTRY:-registry.gitlab.com/grassrootseconomics/cic-internal-integration}/cic-user:${TAG:-latest}
|
||||
build:
|
||||
@ -514,7 +503,6 @@ services:
|
||||
- ./apps/contract-migration/testdata/pgp/:/usr/src/secrets/
|
||||
command: "/root/start_cic_user_tasker.sh -q cic-ussd -vv"
|
||||
|
||||
|
||||
cic-user-server:
|
||||
image: ${DEV_DOCKER_REGISTRY:-registry.gitlab.com/grassrootseconomics/cic-internal-integration}/cic-user:${TAG:-latest}
|
||||
build:
|
||||
@ -543,7 +531,6 @@ services:
|
||||
- redis
|
||||
command: "/root/start_cic_user_server.sh -vv"
|
||||
|
||||
|
||||
cic-user-ussd-server:
|
||||
image: ${DEV_DOCKER_REGISTRY:-registry.gitlab.com/grassrootseconomics/cic-internal-integration}/cic-user:${TAG:-latest}
|
||||
build:
|
||||
@ -581,7 +568,6 @@ services:
|
||||
- ./apps/contract-migration/testdata/pgp/:/usr/src/secrets/
|
||||
command: "/root/start_cic_user_ussd_server.sh -vv"
|
||||
|
||||
|
||||
cic-notify-tasker:
|
||||
image: ${DEV_DOCKER_REGISTRY:-registry.gitlab.com/grassrootseconomics/cic-internal-integration}/cic-notify:${TAG:-latest}
|
||||
build:
|
||||
|
Loading…
Reference in New Issue
Block a user