|
| 1 | +# Self-Hosting TensorBlock Forge |
| 2 | + |
| 3 | +This guide provides a simple and reliable method for self-hosting TensorBlock Forge and all its components using Docker. |
| 4 | + |
| 5 | +## Prerequisites |
| 6 | + |
| 7 | +- [Docker](https://docs.docker.com/get-docker/) and [Docker Compose](https://docs.docker.com/compose/install/) must be installed. |
| 8 | +- `git` must be installed to clone the repository. |
| 9 | +- You will need API keys for any AI providers you wish to use with Forge. |
| 10 | + |
| 11 | +## How It Works |
| 12 | + |
| 13 | +This setup uses Docker Compose to run three separate services in their own containers: |
| 14 | + |
| 15 | +1. **The Forge Application**: The core API gateway. |
| 16 | +2. **PostgreSQL Database**: Used for storing all user and key information. |
| 17 | +3. **Redis**: Provides a high-speed cache to improve performance. |
| 18 | + |
| 19 | +Using Docker Compose is the recommended way to get started, as it handles the setup and networking of all three components for you. |
| 20 | + |
| 21 | +## Installation Steps |
| 22 | + |
| 23 | +### 1. Clone the Repository |
| 24 | + |
| 25 | +First, get the source code from GitHub. |
| 26 | + |
| 27 | +```bash |
| 28 | +git clone https://github.com/tensorblockai/forge.git |
| 29 | +cd forge |
| 30 | +``` |
| 31 | + |
| 32 | +### 2. Configure Your Environment |
| 33 | + |
| 34 | +Forge is configured using environment variables. An example file is provided, which you should copy to create your own configuration. |
| 35 | + |
| 36 | +```bash |
| 37 | +cp .env.example .env |
| 38 | +``` |
| 39 | + |
| 40 | +Now, open the new `.env` file in an editor and configure the following required variables: |
| 41 | + |
| 42 | +- `API_KEY_ENCRYPTION_KEY`: A secret key used to encrypt provider API keys in the database. |
| 43 | +- `JWT_SECRET_KEY`: A secret key for signing user session tokens. |
| 44 | + |
| 45 | +You can generate secure values for these keys by running the following commands: |
| 46 | + |
| 47 | +```bash |
| 48 | +echo "API_KEY_ENCRYPTION_KEY=$(openssl rand -base64 32)" >> .env |
| 49 | +echo "JWT_SECRET_KEY=$(openssl rand -base64 32)" >> .env |
| 50 | +``` |
| 51 | + |
| 52 | +### 3. Start the Services |
| 53 | + |
| 54 | +With the configuration in place, you can start all the services using Docker Compose. |
| 55 | + |
| 56 | +```bash |
| 57 | +docker-compose up -d |
| 58 | +``` |
| 59 | + |
| 60 | +This command will download the necessary images, build the Forge application container, and start everything in the background (`-d`). The first time you run this, it may take a few minutes. |
| 61 | + |
| 62 | +## Accessing Your Forge Instance |
| 63 | + |
| 64 | +Once the startup is complete, you can access the services: |
| 65 | + |
| 66 | +- **API Endpoint**: `http://localhost:8000` |
| 67 | +- **Interactive API Docs (Swagger UI)**: `http://localhost:8000/docs` |
| 68 | + |
| 69 | +The database will be running on port `5432`, but it is only accessible to the other containers, not to your host machine by default. |
| 70 | + |
| 71 | +## Basic Management |
| 72 | + |
| 73 | +Here are the essential commands for managing your self-hosted instance: |
| 74 | + |
| 75 | +- **View Logs**: See the real-time output from all services. |
| 76 | + ```bash |
| 77 | + docker-compose logs -f |
| 78 | + ``` |
| 79 | +- **Restart Services**: |
| 80 | + ```bash |
| 81 | + docker-compose restart |
| 82 | + ``` |
| 83 | +- **Stop Services**: Stop and remove the containers. Your database data will be preserved in a Docker volume. |
| 84 | + ```bash |
| 85 | + docker-compose down |
| 86 | + ``` |
| 87 | + |
| 88 | +## Managing Your Instance with the CLI |
| 89 | + |
| 90 | +Once your Forge instance is running, you use the command-line interface (CLI) to create users and manage provider keys. To run the CLI, you execute commands inside the running `app` container. |
| 91 | + |
| 92 | +The basic format is `docker-compose exec app python forge-cli.py [COMMAND]`. |
| 93 | + |
| 94 | +### Create Your First User |
| 95 | + |
| 96 | +This is the very first thing you should do. This command will create your admin user and generate your first Forge API key. |
| 97 | + |
| 98 | +```bash |
| 99 | +docker-compose exec app python forge-cli.py register |
| 100 | +``` |
| 101 | + |
| 102 | +Follow the prompts to set your username, email, and password. **Save the Forge API key that is printed at the end.** |
| 103 | + |
| 104 | +### Add a Provider Key |
| 105 | + |
| 106 | +Next, add the API key for a provider like OpenAI or Anthropic. |
| 107 | + |
| 108 | +```bash |
| 109 | +docker-compose exec app python forge-cli.py add-key |
| 110 | +``` |
| 111 | + |
| 112 | +This will launch an interactive prompt where you can select the provider and paste in your key. |
| 113 | + |
| 114 | +### List Your Provider Keys |
| 115 | + |
| 116 | +To see which providers you have successfully connected, run: |
| 117 | + |
| 118 | +```bash |
| 119 | +docker-compose exec app python forge-cli.py list-keys |
| 120 | +``` |
| 121 | + |
| 122 | +### Explore All Commands |
| 123 | + |
| 124 | +The Forge CLI has many other features. To see a full list of commands and options, use the `--help` flag: |
| 125 | + |
| 126 | +```bash |
| 127 | +docker-compose exec app python forge-cli.py --help |
| 128 | +``` |
0 commit comments