dockerize it

This commit is contained in:
alexcos20 2020-12-10 02:28:12 -08:00
parent fccf8bc2bc
commit 38a6d09679
4 changed files with 34 additions and 5 deletions

7
.dockerignore Normal file
View File

@ -0,0 +1,7 @@
node_modules
contracts
.env.local
.env
build
coverage
__mocks__

20
Dockerfile Normal file
View File

@ -0,0 +1,20 @@
FROM node:12
COPY package*.json /usr/src/app/
WORKDIR /usr/src/app
RUN npm install
COPY . /usr/src/app
ENV DB_PASSWORD='pass'
ENV DB_USER='user'
ENV DB_HOST='localhost'
ENV DB_PORT='27017'
ENV DB_NAME='faucet'
ENV RPC='xxx'
ENV SEED_PHRASE='xxx'
ENV TOKEN_AMOUNT=200
ENV TOKEN_CONTRACT_ADDRESS=0x
ENV PORT=4000
ENV COOLING_PERIOD_IN_HOURS=24
ENTRYPOINT ["/usr/src/app/docker-entrypoint.sh"]

2
docker-entrypoint.sh Executable file
View File

@ -0,0 +1,2 @@
#!/bin/sh
npm start

View File

@ -11,14 +11,14 @@ var client = null;
require("dotenv").config();
var tokenInstance = null;
const infura_apikey = process.env.INFURA_NODE_ID;
const rpc = process.env.RPC;
const provider = new HDWalletProvider(
process.env.SEED_PHRASE,
"https://rinkeby.infura.io/v3/" + infura_apikey
rpc
);
const web3 = new Web3(provider);
const account = provider.getAddress(0)
const app = express();
app.use(bodyParser.urlencoded({ extended: false }));
@ -36,7 +36,7 @@ app.get("/send", async (req, res) => {
const url_parts = url.parse(req.url, true);
const query = url_parts.query;
const from = process.env.FROM;
const from = account;
const to = query.address;
const value = web3.utils.toWei(process.env.TOKEN_AMOUNT, "ether");
//check if its valid ETH address
@ -98,7 +98,7 @@ app.get("/send", async (req, res) => {
async function getBalance() {
let tokenInst = getTokenInstance();
let bal = await tokenInst.methods.balanceOf(process.env.FROM).call();
let bal = await tokenInst.methods.balanceOf(account).call();
let balance = web3.utils.fromWei(bal, "ether");
return Math.floor(balance);
}