From 1eec352b4ed867e34fe0e342bea44656837316d6 Mon Sep 17 00:00:00 2001 From: David Pangerl Date: Mon, 20 Sep 2021 15:17:05 +0200 Subject: [PATCH] docker fixes --- .dockerignore | 1 + Dockerfile | 1 + README.md | 18 ++++++++++++++++++ lib/DataProvider.ts | 21 +++++++++------------ lib/utils.ts | 2 +- scripts/docker-compose.yml | 11 +++++++++++ scripts/docker-deploy.sh | 1 + 7 files changed, 42 insertions(+), 13 deletions(-) diff --git a/.dockerignore b/.dockerignore index 2ab20731..bd65ff07 100644 --- a/.dockerignore +++ b/.dockerignore @@ -19,5 +19,6 @@ le**/.classpath **/obj **/secrets.dev.yaml **/values.dev.yaml +/logs README.md node_modules \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 496b1319..e1b64561 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,6 +10,7 @@ COPY . . RUN yarn RUN yarn build +RUN mkdir logs EXPOSE 3000 diff --git a/README.md b/README.md index 29439db2..80a61b82 100644 --- a/README.md +++ b/README.md @@ -75,3 +75,21 @@ We currently use WsLimitedPriceProvider class that implements IPriceProvider and - mode: it can either be 'first' or 'avg'. In the first case it means it returns the price from the first tuple in the list that is possible (if first fails, tries with the second, etc.); in the second case - avg - it retrieves prices from all tuples in the list (some may fail and are thus skipped) and then calculates the average of their prices to be fed to *Flare Networks* Note that this provider is retrieving prices by subscribing to websockets of the exchanges passed in the list of tuples. If no price can be retrieved from websockets, then it fallbacks to retrieving prices via REST API calls - again prioritized with list of tuples. + +Dockerization +------------- + +Docker build is issued with command: +*yarn docker-build* +it runs script `scripts/docker-build.sh` + +You can get error on build start: +`Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?` +in this case start the docker service with command: +`sudo service docker start` + +Docker deploy is issued with command: +*yarn docker-deploy* +it runs script `scripts/docker-build.sh` + +ATM the deploy address is set to data-provider-4 and can be changed by setting SERVER variable in the script. diff --git a/lib/DataProvider.ts b/lib/DataProvider.ts index 04f5142e..8fad6c2b 100644 --- a/lib/DataProvider.ts +++ b/lib/DataProvider.ts @@ -1,6 +1,6 @@ import { BigNumber, Contract } from 'ethers'; import * as fs from 'fs'; -import Web3 from 'web3'; +//import Web3 from 'web3'; import { FtsoManager } from '../typechain-web3-v1/FtsoManager'; import { FtsoRegistry } from '../typechain-web3-v1/FtsoRegistry'; import { PriceSubmitter } from '../typechain-web3-v1/PriceSubmitter'; @@ -134,22 +134,17 @@ function preparePrice(price: number, decimals: number) { }; async function signAndFinalize3(label: string, toAddress: string, fnToEncode: any, gas: string = "2500000"): Promise { - // tle posilja transakcijo let nonce = await getNonce(); var tx = { from: account.address, to: toAddress, - gas: gas, // koliko dovolis 21000 Gas - gasPrice: conf.gasPrice, // koliko stane gas 225G vai - data: fnToEncode.encodeABI(), // posljes kr neki 0x0 + gas: gas, + gasPrice: conf.gasPrice, + data: fnToEncode.encodeABI(), nonce: nonce }; var signedTx = await account.signTransaction(tx); - // samo - web3.eth.sendSignedTransaction(signedTx.rawTransaction!); - - try { await recordBalance(tx, null); let receipt = await waitFinalize3(account.address, () => web3.eth.sendSignedTransaction(signedTx.rawTransaction!)); @@ -377,6 +372,8 @@ function setupEvents() { async function runDataProvider() { + let version = 1003 + DotEnvExt() const configData : string = "" @@ -384,7 +381,7 @@ async function runDataProvider() if( process.env.NODE_ENV === "production") { - logger.info(`Starting Flare Price Provider`) + logger.info(`Starting Flare Price Provider v${version}`) if( process.env.PROJECT_SECRET===undefined ) { @@ -399,7 +396,7 @@ async function runDataProvider() } else { - logger.info(`Starting Flare Price Provider [developer mode]`) + logger.info(`Starting Flare Price Provider v${version} [developer mode]`) logger.info(` * account read from .env`) accountPrivateKey = (conf.accountPrivateKey as string) @@ -420,7 +417,7 @@ async function runDataProvider() } - web3 = getWeb3(rpcUrl) as Web3; + web3 = getWeb3(rpcUrl); account = getWeb3Wallet(web3, accountPrivateKey ); diff --git a/lib/utils.ts b/lib/utils.ts index 71ff9dbd..500218f4 100644 --- a/lib/utils.ts +++ b/lib/utils.ts @@ -117,7 +117,7 @@ export function getLogger(label: string | undefined = undefined) { new winston.transports.Console(), new winston.transports.File({ level: 'info', - filename: './dataprovider.log' + filename: './logs/flare-price-provider.log' }) ] }); diff --git a/scripts/docker-compose.yml b/scripts/docker-compose.yml index f3b3b41b..72890b08 100644 --- a/scripts/docker-compose.yml +++ b/scripts/docker-compose.yml @@ -8,5 +8,16 @@ services: env_file: .deploy.env + volumes: + - type: volume + source: mydata + target: /data + - type: bind + source: /home/ubuntu/logs + target: /usr/app/logs + ports: - 3000:3000 + +volumes: + mydata: \ No newline at end of file diff --git a/scripts/docker-deploy.sh b/scripts/docker-deploy.sh index 2c6a0ef3..7da1df35 100644 --- a/scripts/docker-deploy.sh +++ b/scripts/docker-deploy.sh @@ -26,6 +26,7 @@ echo -e "${GREENBOLD}[1/3] Setup server $SERVER${NC}" # Create install folder if they do not exist (on server) ssh -n $USER@$SERVER "mkdir -p $WORKDIR" +ssh -n $USER@$SERVER "mkdir -p /home/ubuntu/logs" # Copy files to server echo -e "${GREENBOLD}[2/3] Copying files on server $SERVER${NC}"