Skip to content

Commit

Permalink
feat: Dockerized the TCK server, added taskfile to execute all prereq…
Browse files Browse the repository at this point in the history
…uisites for the tests to run, added README

Signed-off-by: ivaylogarnev-limechain <ivaylo.garnev@limechain.tech>
  • Loading branch information
ivaylogarnev-limechain committed Feb 14, 2025
1 parent d1651eb commit 7c4a897
Show file tree
Hide file tree
Showing 7 changed files with 218 additions and 3 deletions.
1 change: 1 addition & 0 deletions tck/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
26 changes: 26 additions & 0 deletions tck/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
FROM node:20-slim

WORKDIR /app

# Copy package files
COPY package.json pnpm-lock.yaml* ./

# Install pnpm
RUN npm install -g pnpm

# Override the local SDK dependency with the npm version and add missing dependencies
RUN pnpm add @hashgraph/sdk@^2.58.0 long@^5.2.3 @hashgraph/proto@^2.16.0-beta.8

# Install dependencies
RUN pnpm install

ENV RUNNING_IN_DOCKER=true

# Copy TCK source code
COPY . .

# Expose the port used by the server
EXPOSE 8544

# Start the server
CMD ["pnpm", "start"]
98 changes: 98 additions & 0 deletions tck/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
# TCK Server Start-Up Guide 🛠️

This guide will help you set up, start, and test the TCK server using Docker and Node.js. Follow the steps below to ensure a smooth setup.

# ⚡ TCK Server Start-Up

## Prerequisites

Before you begin, make sure you have:

- Node.js → Version 20 or higher

- npm → Version 10 or higher

## 🚀 Start the TCK Server

Run the following commands to install dependencies and start the server:

```bash
npm install
npm run start
```

Once started, your TCK server will be up and running! 🚦

# Start All TCK Tests with Docker 🐳

This guide will help you set up and start the TCK server, local node and run all TKC tests using Docker. Follow these steps to ensure all dependencies are installed and the server runs smoothly.

## Prerequisites

Before you begin, ensure you have the following installed:

- **Node.js**: Version 20 or higher
- **npm**: Version 10 or higher
- **Docker**: Latest version
- **Docker Compose**: Latest version

## 🔧 Setup Instructions

### 1. Check Node.js and npm

Verify that Node.js and npm are installed and meet the version requirements:

```bash
node -v
npm -v
```

### 2. Install Hedera Local Node CLI

If not already installed, run the following command:

```bash
npm install @hashgraph/hedera-local -g
```

### 3. Start the Local Hedera Network

Run the following command to start the local Hedera network:

```bash
task start-local-node
```

### 4. Build the Docker Image

Build the Docker image for the TCK JS server:

```bash
task build-tck-js-server
```

### 5. Start All Services

Now, let’s fire up all the services using Docker Compose:

```bash
task start-all-tests
```

This will:

- Spin up the TCK server

- Start required containers

- Run all tests automatically

Sit back and let Docker do the magic!

### 🎉 All Done!

Your TCK server is now running inside Docker! 🚀 You can now execute tests and validate the system.

Need help? Reach out to the team! 💬👨‍💻

Happy coding! 💻✨
65 changes: 65 additions & 0 deletions tck/Taskfile.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
version: "3"

tasks:
check-node:
desc: "Check if Node.js is installed and meets the version requirement"
silent: true
cmds:
- echo "Checking Node.js version..."
- |
if ! command -v node &> /dev/null || [ "$(node -v | cut -d'.' -f1)" -lt "v20" ]; then
echo "Node.js v20 or higher is required. Please install it."
exit 1
fi
check-npm:
desc: "Check if npm is installed and meets the version requirement"
silent: true
cmds:
- echo "Checking npm version..."
- |
if ! command -v npm &> /dev/null || [ "$(npm -v | cut -d'.' -f1)" -lt "10" ]; then
echo "NPM v10 or higher is required. Please install it."
exit 1
fi
install-hedera-local:
desc: "Install Hedera Local Node CLI tool if not installed"
silent: true
cmds:
- echo "Checking for Hedera Local Node CLI..."
- |
if ! command -v hedera &> /dev/null; then
echo "Hedera Local Node CLI not found, installing..."
npm install @hashgraph/hedera-local -g
else
echo "Hedera Local Node CLI is already installed."
fi
start-local-node:
desc: "Start the local Hedera network"
silent: true
deps: [check-node, check-npm, install-hedera-local]
cmds:
- echo "Starting local Hedera network..."
- hedera start

build-tck-js-server:
desc: "Build the Docker image for tck-js-server"
silent: true
cmds:
- echo "Building Docker image for tck-js-server..."
- docker build -t tck-js-server .

start-all-tests:
desc: "Start Docker Compose services"
silent: true
deps: [start-local-node, build-tck-js-server]
cmds:
- echo "Starting Docker Compose services..."
- docker compose up

default:
desc: "Start local node and Docker Compose"
silent: true
deps: [start-all-tests]
18 changes: 18 additions & 0 deletions tck/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
services:
tck-server:
image: tck-js-server
build:
context: .
ports:
- "8544:8544"
networks:
- tck-network
tck-client:
image: ivaylogarnev/tck-client
depends_on:
- tck-server
networks:
- tck-network
networks:
tck-network:
driver: bridge
9 changes: 8 additions & 1 deletion tck/sdk_data.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
import { Client } from "../lib";
import { Client, AccountId } from "@hashgraph/sdk";

export const sdk = {
client: null,
getClient(): Client {
if (this.client == null) {
throw new Error("Client not set up");
}

if (process.env.RUNNING_IN_DOCKER) {
this.client.setNetwork({
"host.docker.internal:50211": new AccountId(3),
});
}

return this.client;
},
};
4 changes: 2 additions & 2 deletions tck/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,13 +132,13 @@ app.post("/", (req, res) => {
});
});

let port = 80; // Default port
let port = 8544; // Default port
const args = process.argv.slice(2);
if (args.length > 0) {
try {
port = parseInt(args[0]);
} catch (err) {
console.warn("Port args error! Defaulting to port 80");
console.warn("Port args error! Defaulting to port 8544");
}
}

Expand Down

0 comments on commit 7c4a897

Please sign in to comment.