diff --git a/.github/workflows/faucet.yml b/.github/workflows/faucet.yml new file mode 100644 index 0000000..1b794cd --- /dev/null +++ b/.github/workflows/faucet.yml @@ -0,0 +1,42 @@ +name: Faucet - CI + +on: + push: + branches: + - "master" + workflow_dispatch: + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Setup docker builder + uses: docker/setup-buildx-action@v1 + with: { install: true } + + - name: Prepare production release tags + id: meta + uses: docker/metadata-action@v3 + with: + images: | + assetmantle/faucet + tags: | + type=raw,value=latest-{{sha}}-{{date 'X'}} + type=raw,value=latest + + - name: Login to docker registry + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Build production container image + uses: docker/build-push-action@v2 + with: + push: true + tags: ${{ steps.meta.outputs.tags }} + cache-from: type=local,src=/tmp/buildx-cache + cache-to: type=gha,mode=max diff --git a/README.md b/README.md index 4673433..a1620ca 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,15 @@ # assetDApp + A decentralised web app for assetMantle. + +## Run faucet in container + +> Make sure [docker]((https://docs.docker.com/desktop/mac/install/)) and [docker-compose](https://docs.docker.com/compose/install/) is installed in your system +> +> Building container image with docker in macos will be slower as there is no native docker support + +Edit `services.faucet.environment` in `docker-compose.yaml` as per your need + +```shell +docker-compose up +``` diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 0000000..3a29e96 --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,17 @@ +--- +version: "3" +services: + faucet: + image: assetmantle/faucet:edge + build: + context: ./faucet/ + environment: + - CHAINID=test + - LCDURL=http://127.0.0.1:1317 + - HOST=0.0.0.0 + - PORT=3001 + - MNEMONICS=wage thunder live sense resemble foil apple course spin horse glass mansion midnight laundry acoustic rhythm loan scale talent push green direct brick please + - MODE=block + ports: + - 3001:3001 + restart: unless-stopped diff --git a/faucet/Dockerfile b/faucet/Dockerfile new file mode 100644 index 0000000..f389efe --- /dev/null +++ b/faucet/Dockerfile @@ -0,0 +1,11 @@ +FROM node:16 AS build-env +COPY . /app +WORKDIR /app +RUN --mount=type=cache,target=/root/.cache \ + --mount=type=cache,target=/root/.npm \ + npm i + +FROM gcr.io/distroless/nodejs:16 +COPY --from=build-env /app /app +WORKDIR /app +CMD ["main.js"] diff --git a/faucet/config.json b/faucet/config.json deleted file mode 100644 index c63d178..0000000 --- a/faucet/config.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "chainID": "test", - "lcdURL": "http://127.0.0.1:1317", - "host": "0.0.0.0", - "port": "3001", - "mnemonics": "wage thunder live sense resemble foil apple course spin horse glass mansion midnight laundry acoustic rhythm loan scale talent push green direct brick please", - "mode": "block" -} diff --git a/faucet/main.js b/faucet/main.js index 660050d..88ead8a 100644 --- a/faucet/main.js +++ b/faucet/main.js @@ -1,4 +1,3 @@ -const config = require('./config.json'); const bip39 = require("bip39"); const bip32 = require("bip32"); const {bech32} = require("bech32"); @@ -88,7 +87,7 @@ async function broadcastTx(wallet, tx, mode) { } const signMeta = { account_number: accountNum, - chain_id: config.chainID, + chain_id: process.env.CHAINID, sequence: seq }; let stdTx = tmSig.signTx(tx, signMeta, wallet); @@ -96,7 +95,7 @@ async function broadcastTx(wallet, tx, mode) { tx: stdTx, mode: mode }; - let broadcastResponse = await fetch(config.lcdURL + "/txs", { + let broadcastResponse = await fetch(process.env.LCDURL + "/txs", { method: 'POST', headers: { 'Content-Type': 'application/json' @@ -120,7 +119,7 @@ async function getAccount(address) { result.success = false; result.account = {}; try { - let response = await fetch(config.lcdURL + "/auth/accounts/" + address); + let response = await fetch(process.env.LCDURL + "/auth/accounts/" + address); let json = await response.json(); result.success = true; result.account = json; @@ -166,7 +165,7 @@ app.get("/faucet/:address", async function (req, res) { const toAddress = getMantleAddress(req.params.address); let result = {}; if (toAddress !== "") { - let txResult = await sendCoin(config.mnemonics, toAddress, faucetAmount, 3000, gas, config.mode); + let txResult = await sendCoin(process.env.MNEMONICS, toAddress, faucetAmount, 3000, gas, process.env.MODE); result.success = txResult.success; result.message = txResult.message; console.log(result.message); @@ -185,7 +184,7 @@ app.get("/faucet/:address", async function (req, res) { } }); -let server = app.listen(config.port, config.host, function () { +let server = app.listen(process.env.PORT, process.env.HOST, function () { let host = server.address().address; let port = server.address().port; console.log("App listening at http://%s:%s", host, port);