diff --git a/README.md b/README.md index dac9a36..c22367d 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/game-starter/.dockerignore b/game-starter/.dockerignore new file mode 100644 index 0000000..5dccde9 --- /dev/null +++ b/game-starter/.dockerignore @@ -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 diff --git a/game-starter/Dockerfile b/game-starter/Dockerfile new file mode 100644 index 0000000..91b6504 --- /dev/null +++ b/game-starter/Dockerfile @@ -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"] diff --git a/game-starter/README.md b/game-starter/README.md index fa69873..0ec7a15 100644 --- a/game-starter/README.md +++ b/game-starter/README.md @@ -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 /virtuals-game-starter` + `docker push /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/). diff --git a/game-starter/docker-compose.yml b/game-starter/docker-compose.yml new file mode 100644 index 0000000..eccdaf2 --- /dev/null +++ b/game-starter/docker-compose.yml @@ -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: diff --git a/game-starter/src/functions.ts b/game-starter/src/functions.ts index 11791c4..1876932 100644 --- a/game-starter/src/functions.ts +++ b/game-starter/src/functions.ts @@ -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