diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..ba231c9 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,8 @@ +node_modules +npm-debug.log +.git +.gitignore +.env +config.env +*.md +!README.md \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..56b5b32 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,18 @@ +FROM node:20-slim + +# Install ffmpeg and other deps +RUN apt-get update && apt-get install -y ffmpeg && apt-get clean && rm -rf /var/lib/apt/lists/* + +WORKDIR /usr/src/app + +COPY package*.json ./ + +RUN npm install + +COPY . . + +RUN chmod +x /usr/src/app/src/plugins/yt-dlp/yt-dlp + +VOLUME /usr/src/app/config.env + +CMD ["npm", "start"] \ No newline at end of file diff --git a/README.md b/README.md index e2e35ff..6b4fe46 100644 --- a/README.md +++ b/README.md @@ -9,10 +9,10 @@ Kowalski is a a simple Telegram bot made in Node.js. ## Self-host requirements -- Node.js 20 or newer (you can also use Bun) +- Node.js 20 or newer (you can also use [Bun](https://bun.sh)) - A Telegram bot (create one at [@BotFather](https://t.me/botfather)) -- Latest version of Node.js - FFmpeg (only for the `/yt` command) +- Docker and Docker Compose (only required for Docker setup) ## Run it yourself, develop or contribute with Kowalski @@ -36,6 +36,47 @@ After editing the file, save all changes and run the bot with ``npm start``. > [!TIP] > To deal with dependencies, just run ``npm install`` or ``npm i`` at any moment to install all of them. +## Running with Docker + +> [!IMPORTANT] +> Please complete the above steps to prepare your local copy for building. You do not need to install FFmpeg on your host system. + +You can also run Kowalski using Docker, which simplifies the setup process. Make sure you have Docker and Docker Compose installed. + +### Using Docker Compose + +1. **Make sure to setup your `config.env` file first!** + +2. **Run the container** + + ```bash + docker compose up -d + ``` + + > [!NOTE] + > The `-d` flag causes the bot to run in the background. If you're just playing around, you may not want to use this flag. + +### Using Docker Run + +If you prefer to use Docker directly, you can use these instructions instead. + +1. **Make sure to setup your `config.env` file first!** + +2. **Build the image** + + ```bash + docker build -t kowalski . + ``` + +3. **Run the container** + + ```bash + docker run -d --name kowalski --restart unless-stopped -v $(pwd)/config.env:/usr/src/app/config.env:ro kowalski + ``` + + > [!NOTE] + > The `-d` flag causes Kowalski to run in the background. If you're just playing around, you may not want to use this flag. + ## config.env Functions - **botSource**: Put the link to your bot source code. diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..981d90a --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,9 @@ +services: + kowalski: + build: . + container_name: kowalski + restart: unless-stopped + volumes: + - ./config.env:/usr/src/app/config.env:ro + environment: + - NODE_ENV=production \ No newline at end of file