Skip to content

Commit

Permalink
Updates and Improvements
Browse files Browse the repository at this point in the history
- Update Dockerfile
- Update Caching Engine
- Add Support for Hive.one
- Update Dependencies
  • Loading branch information
anudit committed Jan 11, 2022
1 parent ba6df4e commit 2179d20
Show file tree
Hide file tree
Showing 11 changed files with 1,606 additions and 1,392 deletions.
6 changes: 6 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Dockerfile
.dockerignore
node_modules
npm-debug.log
README.md
.next
5 changes: 4 additions & 1 deletion .github/workflows/CacheTrustScores.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
name: "Cache Trust Scores"
on:
push:
branches: [ main ]
schedule:
- cron: "0 0,12 * * *" # Every 12 hrs.

Expand Down Expand Up @@ -29,4 +31,5 @@ jobs:
CNVSEC_ID: ${{ secrets.CNVSEC_ID }}
MONGODB_URI: ${{ secrets.MONGODB_URI }}
ETHERSCAN_API_KEY: ${{ secrets.ETHERSCAN_API_KEY }}
run: yarn cron:cache
POLYGONSCAN_API_KEY: ${{ secrets.POLYGONSCAN_API_KEY }}
run: yarn cron:cacheV2
27 changes: 17 additions & 10 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
# Official Dockerfile from https://nextjs.org/docs/deployment#docker-image
# https://github.com/vercel/next.js/blob/canary/examples/with-docker/Dockerfile

# Install dependencies only when needed
FROM node:alpine AS deps
FROM node:16-alpine AS deps
# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
RUN apk add --no-cache libc6-compat
WORKDIR /app
COPY package.json yarn.lock ./
RUN yarn install --frozen-lockfile

# Rebuild the source code only when needed
FROM node:alpine AS builder
FROM node:16-alpine AS builder
WORKDIR /app
COPY . .
COPY --from=deps /app/node_modules ./node_modules
RUN yarn build && yarn install --production --ignore-scripts --prefer-offline
COPY . .
RUN yarn build

# Production image, copy all the files and run next
FROM node:alpine AS runner
FROM node:16-alpine AS runner
WORKDIR /app

ENV NODE_ENV production
Expand All @@ -24,7 +26,6 @@ RUN addgroup -g 1001 -S nodejs
RUN adduser -S nextjs -u 1001

# You only need to copy next.config.js if you are NOT using the default configuration
COPY --from=builder /app/next.config.js ./
COPY --from=builder /app/components ./components
COPY --from=builder /app/contexts ./contexts
COPY --from=builder /app/hooks ./hooks
Expand All @@ -34,20 +35,26 @@ COPY --from=builder /app/pages ./pages
COPY --from=builder /app/public ./public
COPY --from=builder /app/styles ./styles
COPY --from=builder /app/utils ./utils
COPY --from=builder /app/.dockerignore ./
COPY --from=builder /app/.eslintrc.json ./
COPY --from=builder /app/.prettierignore ./
COPY --from=builder /app/.prettierrc ./
COPY --from=builder /app/.jsconfig.json ./
COPY --from=builder /app/.next-sitemap-config.js ./
COPY --from=builder /app/.next.config.js ./
COPY --from=builder /app/next-sitemap-config.js ./
COPY --from=builder /app/next.config.js ./
COPY --from=builder /app/package.json ./package.json
COPY --from=builder /app/vercel.json ./
COPY --from=builder --chown=nextjs:nodejs /app/.next ./.next
COPY --from=builder /app/node_modules ./node_modules
COPY --from=builder /app/package.json ./package.json

# Automatically leverage output traces to reduce image size
# https://nextjs.org/docs/advanced-features/output-file-tracing
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static

USER nextjs

EXPOSE 3000
ENV PORT 3000

# Next.js collects completely anonymous telemetry data about general usage.
# Learn more here: https://nextjs.org/telemetry
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,8 @@
The Decentralized Conversation Layer of Internet.

👉 [theconvo.space](https://theconvo.space)

### Using Docker
- Install Docker on your machine.
- Build your container: `docker build -t nextjs-docker .`.
- Run your container: `docker run -p 3000:3000 nextjs-docker`.
26 changes: 20 additions & 6 deletions cron/cacheTrustScore.js
Original file line number Diff line number Diff line change
Expand Up @@ -290,16 +290,30 @@ async function getCyberconnectData(address){
}

async function getAge(address){
let data = await fetch(`https://api.etherscan.io/api?module=account&action=txlist&address=${address}&startblock=0&endblock=99999999&page=1&offset=10&sort=asc&apikey=${ETHERSCAN_API_KEY}`).then(r=>{return r.json()});
let etherscanReq = fetch(`https://api.etherscan.io/api?module=account&action=txlist&address=${address}&startblock=0&endblock=99999999&page=1&offset=10&sort=asc&apikey=${ETHERSCAN_API_KEY}`).then(r=>{return r.json()});
let polygonscanReq = fetch(`https://api.polygonscan.com/api?module=account&action=txlist&address=${address}&startblock=0&endblock=99999999&page=1&offset=10&sort=asc&apikey=${POLYGONSCAN_API_KEY}`).then(r=>{return r.json()});

if (data['result'].length > 0){
let data = await Promise.allSettled([etherscanReq, polygonscanReq]);

let polygonAge = 0;
let ethereumAge = 0;
let now = new Date();

if (Boolean(data[0]?.value) === true && data[0]?.value['result'].length > 0){
let past = new Date(parseInt(data['result'][0].timeStamp)*1000);
let now = new Date();
let days = parseInt(parseInt((now - past)/1000)/(3600*24));
return days;
ethereumAge = days;
}
else {
return 0

if (Boolean(data[1]?.value) === true && data[1]?.value['result'].length > 0){
let past2 = new Date(parseInt(data['result'][0].timeStamp)*1000);
let days2 = parseInt(parseInt((now - past2)/1000)/(3600*24));
polygonAge = days2;
}

return {
polygon: polygonAge,
ethereum: ethereumAge,
}
}

Expand Down
Loading

1 comment on commit 2179d20

@vercel
Copy link

@vercel vercel bot commented on 2179d20 Jan 11, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.