Skip to content

Commit

Permalink
Merge pull request #61 from tolak/game-tee
Browse files Browse the repository at this point in the history
Add TEE support for GAME agents
  • Loading branch information
Ang-dot authored Feb 25, 2025
2 parents 3d16d91 + ad7512a commit 35e3fe9
Show file tree
Hide file tree
Showing 6 changed files with 129 additions and 2 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,9 @@ Function
- Used to control which functions are called by the workers, based on each worker's low-level plan
- This can be any executable

## Run agent in TEE

Head to the [game-starter README](./game-starter/README.md#to-run-project-in-phala-tee) for more detailed instructions.

## License

Expand Down
22 changes: 22 additions & 0 deletions game-starter/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# .dockerignore

# Ignore node_modules from the build context
node_modules

# Ignore logs and temporary files
*.log
*.tmp
.DS_Store

# Ignore Git files and metadata
.git
.gitignore

# Ignore IDE and editor config files
.vscode
.idea
*.swp

# Ignore build artifacts from the host
dist
build
73 changes: 73 additions & 0 deletions game-starter/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# Use a specific Node.js version for better reproducibility
FROM node:23.3.0-slim AS builder

# Install necessary build tools
RUN apt-get update && \
apt-get upgrade -y && \
apt-get install -y \
git \
python3 \
python3-pip \
curl \
node-gyp \
ffmpeg \
libtool-bin \
autoconf \
automake \
libopus-dev \
make \
g++ \
build-essential \
libcairo2-dev \
libjpeg-dev \
libpango1.0-dev \
libgif-dev \
openssl \
libssl-dev libsecret-1-dev && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*

# Set Python 3 as the default python
RUN ln -sf /usr/bin/python3 /usr/bin/python

# Set the working directory
WORKDIR /app

# Copy application code
COPY . .

# Install dependencies
RUN npm install --no-frozen-lockfile

# Install TypeScript globally
RUN npm install -g typescript

# Build the project
RUN npm run build && npm prune --production

# Final runtime image
FROM node:23.3.0-slim

# Install runtime dependencies
RUN apt-get update && \
apt-get install -y \
git \
python3 \
ffmpeg && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*

# Set the working directory
WORKDIR /app

# Copy built artifacts and production dependencies from the builder stage
COPY --from=builder /app/package.json ./
COPY --from=builder /app/package-lock.json ./
COPY --from=builder /app/node_modules ./node_modules
COPY --from=builder /app/dist ./dist

# Expose necessary ports
# EXPOSE 3000

# Command to start the application
CMD ["npm", "start"]
10 changes: 9 additions & 1 deletion game-starter/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,17 @@ NPM: https://www.npmjs.com/package/@virtuals-protocol/game
`cp .env.example .env`
3. Place your API key in the ".env" file
4. Start the project with `npm install && npm run build && npm start`

5. Or run with docker compose
`docker compose up -d`
**Note** We recommend using nvm version 23 `nvm use 23`

## To run project in Phala TEE

1. Build the docker image and publish it to the docker hub
`docker compose build -t <your-dockerhub-username>/virtuals-game-starter`
`docker push <your-dockerhub-username>/virtuals-game-starter`
2. Deploy to Phala cloud using [tee-cloud-cli](https://github.com/Phala-Network/tee-cloud-cli) or manually with the [Cloud dashboard](https://cloud.phala.network/).
3. Check your agent's TEE proof and verify it on the [TEE Attestation Explorer](https://proof.t16z.com/).



20 changes: 20 additions & 0 deletions game-starter/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
services:
game-starter:
image: virtuals-game-starter
build:
context: .
dockerfile: Dockerfile
platform: linux/amd64
environment:
- API_KEY=
- WEATHER_API_KEY=
- OPENAI_API_KEY=
- OPENAI_BASE_URL=
- botToken=
volumes:
- /var/run/tappd.sock:/var/run/tappd.sock
- virtuals:/app
restart: always

volumes:
virtuals:
3 changes: 2 additions & 1 deletion game-starter/src/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ import OpenAI from 'openai';

// Initialize OpenAI
const openai = new OpenAI({
apiKey: process.env.OPENAI_API_KEY
apiKey: process.env.OPENAI_API_KEY,
baseURL: process.env.OPENAI_BASE_URL || 'https://api.openai.com/v1' // Default to OpenAI's standard URL
});

// Example function that shows current state
Expand Down

0 comments on commit 35e3fe9

Please sign in to comment.