Skip to content

Commit

Permalink
Merge pull request #14 from koinos/ci
Browse files Browse the repository at this point in the history
CI
  • Loading branch information
sgerbino authored May 9, 2024
2 parents fcf3149 + 3248532 commit a3cc930
Show file tree
Hide file tree
Showing 14 changed files with 113 additions and 33 deletions.
40 changes: 40 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
language: generic

os: linux

addons:
apt:
update: true

jobs:
include:
- name: "Docker and Integration Tests"
os: linux
dist: jammy
services:
- docker
env:
- TAG=`if [ $TRAVIS_BRANCH == "master" ]; then echo -n latest; else echo -n $TRAVIS_BRANCH; fi`
- REST_TAG=$TAG
before_install:
- sudo systemctl stop docker.service && sudo systemctl stop docker.socket
- sudo apt-get install ca-certificates curl
- sudo install -m 0755 -d /etc/apt/keyrings
- sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
- sudo chmod a+r /etc/apt/keyrings/docker.asc
- |
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
$(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
- sudo apt-get update
install:
- sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
before_script:
- echo $DOCKER_PASSWORD | docker login -u $DOCKER_USERNAME --password-stdin
- docker build . -t $TRAVIS_REPO_SLUG:$TAG
after_success:
- |
if [ "$TRAVIS_PULL_REQUEST" = "false" ]; then
docker push $TRAVIS_REPO_SLUG:$TAG
fi
38 changes: 38 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# https://towardsserverless.com/articles/dockerize-nextjs-app

FROM node:18-alpine AS build
# Install dependencies only when needed
# 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 python3
WORKDIR /app
# Copy and install the dependencies for the project
COPY package.json yarn.lock ./
RUN yarn install
# Copy all other project files to working directory
COPY . .
# Run the next build process and generate the artifacts
RUN yarn build

# we are using multi stage build process to keep the image size as small as possible
FROM node:18-alpine
# update and install latest dependencies, add dumb-init package
# add a non root user
RUN apk update && apk upgrade && apk add dumb-init python3

# set work dir as app
WORKDIR /app
# copy the public folder from the project as this is not included in the build process
COPY --from=build /app/public ./public
# copy the standalone folder inside the .next folder generated from the build process
COPY --from=build /app/.next/standalone ./
# copy the static folder inside the .next folder generated from the build process
COPY --from=build /app/.next/static ./.next/static

# expose 3000 on container
EXPOSE 3000

# set app host ,port and node env
ENV HOST=0.0.0.0 PORT=3000 NODE_ENV=production
# start the app with dumb init to spawn the Node.js runtime process
# with signal support
CMD ["dumb-init","node","server.js"]
12 changes: 6 additions & 6 deletions app/v1/account/[account]/history/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { AppError, getErrorMessage, handleError } from '@/utils/errors'
import { decodeEvents } from '@/utils/events'
import { decodeOperations } from '@/utils/operations'
import { getProvider } from '@/utils/providers'
import { interfaces } from 'koilib'
import { BlockHeaderJson, EventData, TransactionJson, TransactionReceipt } from 'koilib'
import { NextRequest, NextResponse } from 'next/server'

/**
Expand Down Expand Up @@ -126,9 +126,9 @@ export type BlockReceiptJson = {
network_bandwidth_used?: string
compute_bandwidth_used?: string
state_merkle_root?: string
events?: interfaces.EventData[]
events?: EventData[]
token_events: string[]
transaction_receipts?: interfaces.TransactionReceipt[]
transaction_receipts?: TransactionReceipt[]
logs?: string[]
disk_storage_charged?: string
network_bandwidth_charged?: string
Expand All @@ -147,20 +147,20 @@ export type TransactionReceiptJson = {
network_bandwidth_used: string
compute_bandwidth_used: string
reverted: boolean
events: interfaces.EventData[]
events: EventData[]
token_events: string[]
logs: string[]
amount?: string
}

export type HistoryRecord = {
trx?: {
transaction: interfaces.TransactionJson
transaction: TransactionJson
receipt: TransactionReceiptJson
}

block?: {
header: interfaces.BlockHeaderJson
header: BlockHeaderJson
receipt: BlockReceiptJson
}

Expand Down
14 changes: 7 additions & 7 deletions app/v1/block/[block_id]/route.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { interfaces } from 'koilib'
import { BlockJson, EventData, TransactionReceipt } from 'koilib'
import { AppError, handleError } from '@/utils/errors'
import { getProvider } from '@/utils/providers'
import { decodeEvents } from '@/utils/events'
Expand Down Expand Up @@ -127,10 +127,10 @@ export async function GET(request: Request, { params }: { params: { block_id: st
block_items: {
block_id: string
block_height: string
block: interfaces.BlockJson
block: BlockJson
receipt: {
events: interfaces.EventData[]
transaction_receipts: interfaces.TransactionReceipt[]
events: EventData[]
transaction_receipts: TransactionReceipt[]
}
}[]
}>('block_store.get_blocks_by_id', {
Expand All @@ -143,10 +143,10 @@ export async function GET(request: Request, { params }: { params: { block_id: st
block_items: {
block_id: string
block_height: string
block: interfaces.BlockJson
block: BlockJson
receipt: {
events: interfaces.EventData[]
transaction_receipts: interfaces.TransactionReceipt[]
events: EventData[]
transaction_receipts: TransactionReceipt[]
}
}[]
}>('block_store.get_blocks_by_height', {
Expand Down
4 changes: 2 additions & 2 deletions app/v1/contract/[contract_id]/abi/route.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { getContractId } from '@/utils/contracts'
import { AppError, handleError } from '@/utils/errors'
import { getProvider } from '@/utils/providers'
import { interfaces } from 'koilib'
import { Abi } from 'koilib'
import { convert } from '@roamin/koinos-pb-to-proto'
import protobufjs from 'protobufjs'

Expand Down Expand Up @@ -70,7 +70,7 @@ export async function GET(request: Request, { params }: { params: { contract_id:
throw new AppError(`abi not available for contract ${contract_id}`)
}

const abi: interfaces.Abi = {
const abi: Abi = {
...JSON.parse(response.meta.abi)
}

Expand Down
4 changes: 2 additions & 2 deletions app/v1/decode/events/route.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AppError, getErrorMessage, handleError } from '@/utils/errors'
import { interfaces } from 'koilib'
import { EventData } from 'koilib'
import { NextRequest, NextResponse } from 'next/server'
import { decodeEvents } from '@/utils/events'

Expand Down Expand Up @@ -92,7 +92,7 @@ import { decodeEvents } from '@/utils/events'
export async function POST(request: NextRequest) {
try {
try {
const events = (await request.json()) as interfaces.EventData[]
const events = (await request.json()) as EventData[]
const result = await decodeEvents(events)

return NextResponse.json(result)
Expand Down
4 changes: 2 additions & 2 deletions app/v1/decode/operations/route.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AppError, getErrorMessage, handleError } from '@/utils/errors'
import { interfaces } from 'koilib'
import { OperationJson } from 'koilib'
import { NextRequest, NextResponse } from 'next/server'
import { decodeOperations } from '@/utils/operations'

Expand Down Expand Up @@ -55,7 +55,7 @@ import { decodeOperations } from '@/utils/operations'
export async function POST(request: NextRequest) {
try {
try {
const operations = (await request.json()) as interfaces.OperationJson[]
const operations = (await request.json()) as OperationJson[]
const result = await decodeOperations(operations)

return NextResponse.json(result)
Expand Down
6 changes: 3 additions & 3 deletions app/v1/transaction/[transaction_id]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { AppError, handleError } from '@/utils/errors'
import { decodeEvents } from '@/utils/events'
import { decodeOperations } from '@/utils/operations'
import { getProvider } from '@/utils/providers'
import { interfaces } from 'koilib'
import { BlockJson, TransactionReceipt } from 'koilib'

/**
* @swagger
Expand Down Expand Up @@ -173,9 +173,9 @@ export async function GET(request: Request, { params }: { params: { transaction_
block_items: {
block_id: string
block_height: string
block: interfaces.BlockJson
block: BlockJson
receipt: {
transaction_receipts: interfaces.TransactionReceipt[]
transaction_receipts: TransactionReceipt[]
}
}[]
}>('block_store.get_blocks_by_id', {
Expand Down
4 changes: 2 additions & 2 deletions app/v1/transaction/prepare/route.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AppError, getErrorMessage, handleError } from '@/utils/errors'
import { interfaces, Transaction } from 'koilib'
import { Transaction, TransactionJson } from 'koilib'
import { getProvider } from '@/utils/providers'
import { NextRequest, NextResponse } from 'next/server'

Expand Down Expand Up @@ -106,7 +106,7 @@ export async function POST(request: NextRequest) {
try {
try {
const provider = getProvider()
const transaction = (await request.json()) as interfaces.TransactionJson
const transaction = (await request.json()) as TransactionJson

const preparedTransaction = await Transaction.prepareTransaction(transaction, provider)

Expand Down
4 changes: 2 additions & 2 deletions app/v1/transaction/submit/route.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AppError, getErrorMessage, handleError } from '@/utils/errors'
import { interfaces } from 'koilib'
import { TransactionJson } from 'koilib'
import { getProvider } from '@/utils/providers'
import { NextRequest, NextResponse } from 'next/server'
import { revalidatePath } from 'next/cache'
Expand Down Expand Up @@ -39,7 +39,7 @@ export async function POST(request: NextRequest) {
// Get the JSON RPC provider
const provider = getProvider()

const transaction = (await request.json()) as interfaces.TransactionJson
const transaction = (await request.json()) as TransactionJson

const { searchParams } = new URL(request.url)
const broadcast = searchParams.get('broadcast') !== 'false'
Expand Down
4 changes: 3 additions & 1 deletion next.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
/** @type {import('next').NextConfig} */
const nextConfig = {}
const nextConfig = {
output: 'standalone'
}

module.exports = nextConfig
4 changes: 2 additions & 2 deletions utils/contracts.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ProtoDescriptor, convert } from '@roamin/koinos-pb-to-proto'
import { Contract, interfaces, utils } from 'koilib'
import { Abi, Contract, utils } from 'koilib'
import { Root, Type, parse } from 'protobufjs'
import { AppError } from './errors'
import { getAddress } from './addresses'
Expand Down Expand Up @@ -31,7 +31,7 @@ export async function getContractId(str: string) {
return contract_id
}

export function fixAbi(abi: interfaces.Abi): interfaces.Abi {
export function fixAbi(abi: Abi): Abi {
Object.keys(abi.methods).forEach((name) => {
abi.methods[name] = {
...abi!.methods[name]
Expand Down
4 changes: 2 additions & 2 deletions utils/events.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Serializer, interfaces, utils } from 'koilib'
import { EventData, Serializer } from 'koilib'
import { getContract } from './contracts'
import koinosJson from '@koinos/proto-js/index.json'
// @ts-ignore
const serializer = new Serializer(koinosJson)

export async function decodeEvents(events: interfaces.EventData[]) {
export async function decodeEvents(events: EventData[]) {
for (let index = 0; index < events.length; index++) {
const event = events[index]

Expand Down
4 changes: 2 additions & 2 deletions utils/operations.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { interfaces } from 'koilib'
import { OperationJson } from 'koilib'
import { getContract } from './contracts'

export async function decodeOperations(operations: interfaces.OperationJson[]) {
export async function decodeOperations(operations: OperationJson[]) {
for (let index = 0; index < operations.length; index++) {
const operation = operations[index]
if (operation.call_contract) {
Expand Down

0 comments on commit a3cc930

Please sign in to comment.