diff --git a/.gitignore b/.gitignore index 3e8ec232c80..18eb1dea66e 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ node_modules /out .env +.env.production concatenated-output.ts embedding-cache.json diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000000..d7bfcd15143 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,30 @@ +FROM node:23.1.0 +# Install pnpm globally +RUN npm install -g pnpm@9.4.0 + +# Set the working directory +WORKDIR /app + +# Add configuration files and install dependencies +ADD pnpm-workspace.yaml /app/pnpm-workspace.yaml +ADD package.json /app/package.json +ADD .npmrc /app/.npmrc +ADD tsconfig.json /app/tsconfig.json +ADD pnpm-lock.yaml /app/pnpm-lock.yaml +RUN pnpm i + +# Add the documentation +ADD docs /app/docs +RUN pnpm i + +# Add the rest of the application code +ADD packages /app/packages +RUN pnpm i + +# Add the environment variables +ADD scripts /app/scripts +ADD characters /app/characters +ADD .env /app/.env + +# Command to run the container +CMD ["tail", "-f", "/dev/null"] \ No newline at end of file diff --git a/README.md b/README.md index 046ad41a52f..3f10a0a36d7 100644 --- a/README.md +++ b/README.md @@ -178,3 +178,11 @@ Tests are written using Jest and can be found in `src/**/*.test.ts` files. The t - Run tests in sequence (--runInBand) To create new tests, add a `.test.ts` file adjacent to the code you're testing. + +## Docker + +For development purposes, you can run the docker container with the following command: + +``` +pnpm docker +``` diff --git a/package.json b/package.json index 282297c4c2c..1d971e65588 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,12 @@ "lint": "pnpm --dir packages/core lint && pnpm --dir packages/agent lint", "prettier-check": "npx prettier --check .", "prettier": "npx prettier --write .", - "clean": "bash ./scripts/clean.sh" + "clean": "bash ./scripts/clean.sh", + "docker:build": "bash ./scripts/docker.sh build", + "docker:run": "bash ./scripts/docker.sh run", + "docker:bash": "bash ./scripts/docker.sh bash", + "docker:start": "bash ./scripts/docker.sh start", + "docker": "pnpm docker:build && pnpm docker:run && pnpm docker:bash" }, "devDependencies": { "concurrently": "^9.1.0", diff --git a/packages/client-direct/package.json b/packages/client-direct/package.json index 506bd8a83cf..f776d0e205b 100644 --- a/packages/client-direct/package.json +++ b/packages/client-direct/package.json @@ -12,6 +12,7 @@ "@types/express": "5.0.0", "body-parser": "1.20.3", "cors": "2.8.5", + "express": "^4.21.1", "multer": "1.4.5-lts.1" }, "devDependencies": { diff --git a/scripts/docker.sh b/scripts/docker.sh new file mode 100755 index 00000000000..3736eaf8a20 --- /dev/null +++ b/scripts/docker.sh @@ -0,0 +1,66 @@ +#!/bin/bash + +# Check if an argument is provided +if [ -z "$1" ]; then + echo "Usage: $0 {build|run|start|bash}" + exit 1 +fi + +# Execute the corresponding command based on the argument +case "$1" in + build) + docker build --platform linux/amd64 -t eliza . + ;; + run) + # Ensure the container is not already running + if [ "$(docker ps -q -f name=eliza)" ]; then + echo "Container 'eliza' is already running. Stopping it first." + docker stop eliza + docker rm eliza + fi + + docker run \ + --platform linux/amd64 \ + -p 3000:3000 \ + -d \ + -v "$(pwd)/characters:/app/characters" \ + -v "$(pwd)/.env:/app/.env" \ + -v "$(pwd)/docs:/app/docs" \ + -v "$(pwd)/scripts:/app/scripts" \ + -v "$(pwd)/packages/adapter-postgres/src:/app/packages/adapter-postgres/src" \ + -v "$(pwd)/packages/adapter-sqlite/src:/app/packages/adapter-sqlite/src" \ + -v "$(pwd)/packages/adapter-sqljs/src:/app/packages/adapter-sqljs/src" \ + -v "$(pwd)/packages/adapter-supabase/src:/app/packages/adapter-supabase/src" \ + -v "$(pwd)/packages/agent/src:/app/packages/agent/src" \ + -v "$(pwd)/packages/client-auto/src:/app/packages/client-auto/src" \ + -v "$(pwd)/packages/client-direct/src:/app/packages/client-direct/src" \ + -v "$(pwd)/packages/client-discord/src:/app/packages/client-discord/src" \ + -v "$(pwd)/packages/client-telegram/src:/app/packages/client-telegram/src" \ + -v "$(pwd)/packages/client-twitter/src:/app/packages/client-twitter/src" \ + -v "$(pwd)/packages/core/src:/app/packages/core/src" \ + -v "$(pwd)/packages/core/types:/app/packages/core/types" \ + -v "$(pwd)/packages/plugin-bootstrap/src:/app/packages/plugin-bootstrap/src" \ + -v "$(pwd)/packages/plugin-image-generation/src:/app/packages/plugin-image-generation/src" \ + -v "$(pwd)/packages/plugin-node/src:/app/packages/plugin-node/src" \ + -v "$(pwd)/packages/plugin-solana/src:/app/packages/plugin-solana/src" \ + --name eliza \ + eliza + ;; + start) + docker start eliza + ;; + bash) + # Check if the container is running before executing bash + if [ "$(docker ps -q -f name=eliza)" ]; then + docker exec -it eliza bash + else + echo "Container 'eliza' is not running. Please start it first." + exit 1 + fi + ;; + *) + echo "Invalid option: $1" + echo "Usage: $0 {build|run|start|bash}" + exit 1 + ;; +esac