Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dockerized application for local development, testing and deployment #293

Merged
merged 2 commits into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ node_modules
/out

.env
.env.production
concatenated-output.ts
embedding-cache.json

Expand Down
30 changes: 30 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

docs needed in the docker?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, would be great if Elizas can read their own 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"]
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions packages/client-direct/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
66 changes: 66 additions & 0 deletions scripts/docker.sh
Original file line number Diff line number Diff line change
@@ -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
Loading