Skip to content

Commit

Permalink
docker fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
David Pangerl committed Sep 20, 2021
1 parent ed97c87 commit 1eec352
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 13 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@ le**/.classpath
**/obj
**/secrets.dev.yaml
**/values.dev.yaml
/logs
README.md
node_modules
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ COPY . .

RUN yarn
RUN yarn build
RUN mkdir logs

EXPOSE 3000

Expand Down
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
21 changes: 9 additions & 12 deletions lib/DataProvider.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -134,22 +134,17 @@ function preparePrice(price: number, decimals: number) {
};

async function signAndFinalize3(label: string, toAddress: string, fnToEncode: any, gas: string = "2500000"): Promise<boolean> {
// 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!));
Expand Down Expand Up @@ -377,14 +372,16 @@ function setupEvents() {

async function runDataProvider()
{
let version = 1003

DotEnvExt()

const configData : string = ""
let accountPrivateKey : string =""

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 )
{
Expand All @@ -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)
Expand All @@ -420,7 +417,7 @@ async function runDataProvider()
}


web3 = getWeb3(rpcUrl) as Web3;
web3 = getWeb3(rpcUrl);
account = getWeb3Wallet(web3, accountPrivateKey );


Expand Down
2 changes: 1 addition & 1 deletion lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
})
]
});
Expand Down
11 changes: 11 additions & 0 deletions scripts/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
1 change: 1 addition & 0 deletions scripts/docker-deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down

0 comments on commit 1eec352

Please sign in to comment.