Skip to content

Commit

Permalink
inital commit
Browse files Browse the repository at this point in the history
  • Loading branch information
pironic committed Feb 11, 2025
0 parents commit 0d72667
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 0 deletions.
17 changes: 17 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Use the official Node.js image as the base image
FROM node:latest

# Set the working directory
WORKDIR /app

# Install pm2 globally
RUN npm install -g pm2

# Copy start.sh to the root of the container
COPY start.sh /start.sh

# Set the environment variable for the entry point of the bot, default is entry.js
ENV BOT_FILE=entry.js

# Start the application using start.sh
CMD ["sh", "/start.sh"]
41 changes: 41 additions & 0 deletions README.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Janus

## Background
Janus is a project named after the Roman god Janus, who is the god of beginnings, gates, transitions, time, duality, doorways, passages, and endings. He is usually depicted with two faces, one looking to the future and the other to the past, symbolizing watchfulness and foresight. This name embodies the essence of monitoring and maintaining order, which aligns perfectly with the functionality of this project.

## Usage
Janus is a Docker container designed to run a Node.js bot with pm2, monitoring for code changes and keeping everything in order. Below are the instructions for using Janus.

### Directory Mounting
To use Janus, you must mount your project directory to the `/app` directory in the container. This is where your bot's code will reside.
### Environment Variable
The entry point of the bot is expected to be a file named `entry.js` by default. However, you can override this default by setting an environment variable `BOT_FILE`. For example, if your bot's entry file is `discord.js`, you can set the environment variable accordingly.

### Running the Container
Here is an example of how to run the Janus container with the necessary configurations:

```sh
docker run -v /path/to/your/project:/app -e BOT_FILE=discord.js janus-container
- `/path/to/your/project` is the path to your project directory on the host machine.
- `-v /path/to/your/project:/app` mounts your project directory to the `/app` directory in the container.
- `-e BOT_FILE=discord.js` sets the environment variable to override the default entry point.
### Monitoring with pm2
Once the container is running, pm2 will monitor the bot's files for any changes and automatically restart the bot if necessary. All output from pm2 will be directed to the container's logs.
## Example
Here's a step-by-step example of how to use Janus:
1. Ensure your project directory contains `package.json` and your bot's entry file (e.g., `entry.js` or `discord.js`).
2. Run the container with the following command:
```sh
docker run -v /path/to/your/project:/app -e BOT_FILE=discord.js janus-container
```
3. pm2 will start and monitor your bot, ensuring it stays up-to-date with any code changes.
## License
This project is licensed under the MIT License.
This readme has been written by copilot.
10 changes: 10 additions & 0 deletions start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/sh

# Change to the app directory
cd /app

# Update dependencies based on the mounted package.json
npm install

# Start the bot with pm2 and monitor for changes
pm2 start $BOT_FILE --watch --no-daemon --output "/dev/stdout" --error "/dev/stderr"

0 comments on commit 0d72667

Please sign in to comment.