Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: containerize faucet #9

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions .github/workflows/faucet.yml
Original file line number Diff line number Diff line change
@@ -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
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
```
17 changes: 17 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -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
11 changes: 11 additions & 0 deletions faucet/Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
8 changes: 0 additions & 8 deletions faucet/config.json

This file was deleted.

11 changes: 5 additions & 6 deletions faucet/main.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
const config = require('./config.json');
const bip39 = require("bip39");
const bip32 = require("bip32");
const {bech32} = require("bech32");
Expand Down Expand Up @@ -88,15 +87,15 @@ 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);
let broadcastReq = {
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'
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down