Skip to content

Commit

Permalink
Dockerized application for local development, testing and deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
oberlinstands committed Nov 13, 2024
1 parent 7fcf54e commit ad6f439
Show file tree
Hide file tree
Showing 6 changed files with 112 additions and 1 deletion.
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 [email protected]

# 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"]
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

0 comments on commit ad6f439

Please sign in to comment.