|
| 1 | +# Evault Provisioner |
| 2 | + |
| 3 | +A TypeScript API for provisioning evault instances on Nomad. This service allows you to spin up evault instances with Neo4j backends for different tenants. |
| 4 | + |
| 5 | +## Prerequisites |
| 6 | + |
| 7 | +- Node.js 18+ |
| 8 | +- Docker |
| 9 | +- Nomad (see setup instructions below) |
| 10 | +- OrbStack (for macOS users) |
| 11 | + |
| 12 | +## Nomad Setup |
| 13 | + |
| 14 | +### macOS Setup (using OrbStack) |
| 15 | + |
| 16 | +Due to CNI bridge plugin requirements, running Nomad on macOS is best done through OrbStack: |
| 17 | + |
| 18 | +1. Install OrbStack: https://orbstack.dev/ |
| 19 | +2. Create a new VM in OrbStack |
| 20 | +3. SSH into the VM and install Nomad: |
| 21 | + |
| 22 | +```bash |
| 23 | +# Install Nomad |
| 24 | +curl -fsSL https://apt.releases.hashicorp.com/gpg | sudo apt-key add - |
| 25 | +sudo apt-add-repository "deb [arch=amd64] https://apt.releases.hashicorp.com $(lsb_release -cs) main" |
| 26 | +sudo apt-get update && sudo apt-get install nomad |
| 27 | + |
| 28 | +# Install CNI plugins |
| 29 | +sudo mkdir -p /opt/cni/bin |
| 30 | +curl -L https://github.com/containernetworking/plugins/releases/download/v1.3.0/cni-plugins-linux-amd64-v1.3.0.tgz | sudo tar -C /opt/cni/bin -xz |
| 31 | +``` |
| 32 | + |
| 33 | +4. Start Nomad in dev mode: |
| 34 | + |
| 35 | +```bash |
| 36 | +sudo nomad agent -dev -network-interface=eth0 -log-level=DEBUG -bind=0.0.0.0 |
| 37 | +``` |
| 38 | + |
| 39 | +### Linux Setup |
| 40 | + |
| 41 | +1. Install Nomad: |
| 42 | + |
| 43 | +```bash |
| 44 | +# Install Nomad |
| 45 | +curl -fsSL https://apt.releases.hashicorp.com/gpg | sudo apt-key add - |
| 46 | +sudo apt-add-repository "deb [arch=amd64] https://apt.releases.hashicorp.com $(lsb_release -cs) main" |
| 47 | +sudo apt-get update && sudo apt-get install nomad |
| 48 | + |
| 49 | +# Install CNI plugins |
| 50 | +sudo mkdir -p /opt/cni/bin |
| 51 | +curl -L https://github.com/containernetworking/plugins/releases/download/v1.3.0/cni-plugins-linux-amd64-v1.3.0.tgz | sudo tar -C /opt/cni/bin -xz |
| 52 | +``` |
| 53 | + |
| 54 | +2. Start Nomad in dev mode: |
| 55 | + |
| 56 | +```bash |
| 57 | +sudo nomad agent -dev -network-interface=eth0 -log-level=DEBUG -bind=0.0.0.0 |
| 58 | +``` |
| 59 | + |
| 60 | +## Project Setup |
| 61 | + |
| 62 | +1. Install dependencies: |
| 63 | + |
| 64 | +```bash |
| 65 | +npm install |
| 66 | +``` |
| 67 | + |
| 68 | +2. Build the project: |
| 69 | + |
| 70 | +```bash |
| 71 | +npm run build |
| 72 | +``` |
| 73 | + |
| 74 | +3. Start the server: |
| 75 | + |
| 76 | +```bash |
| 77 | +npm start |
| 78 | +``` |
| 79 | + |
| 80 | +For development with auto-reload: |
| 81 | + |
| 82 | +```bash |
| 83 | +npm run dev |
| 84 | +``` |
| 85 | + |
| 86 | +## API Endpoints |
| 87 | + |
| 88 | +### Health Check |
| 89 | + |
| 90 | +``` |
| 91 | +GET /health |
| 92 | +``` |
| 93 | + |
| 94 | +Returns the health status of the API. |
| 95 | + |
| 96 | +### Provision Evault |
| 97 | + |
| 98 | +``` |
| 99 | +POST /provision |
| 100 | +``` |
| 101 | + |
| 102 | +Provisions a new evault instance for a tenant. |
| 103 | + |
| 104 | +Request body: |
| 105 | + |
| 106 | +```json |
| 107 | +{ |
| 108 | + "tenantId": "your-tenant-id" |
| 109 | +} |
| 110 | +``` |
| 111 | + |
| 112 | +Response: |
| 113 | + |
| 114 | +```json |
| 115 | +{ |
| 116 | + "success": true, |
| 117 | + "message": "Successfully provisioned evault for tenant your-tenant-id", |
| 118 | + "jobName": "evault-your-tenant-id" |
| 119 | +} |
| 120 | +``` |
| 121 | + |
| 122 | +## Architecture |
| 123 | + |
| 124 | +The provisioner creates a Nomad job that consists of two tasks: |
| 125 | + |
| 126 | +1. **Neo4j Task**: |
| 127 | + |
| 128 | + - Runs Neo4j 5.15 |
| 129 | + - Exposes ports: 7687 (bolt) and 7474 (browser) |
| 130 | + - Uses dynamic ports for flexibility |
| 131 | + - 2GB memory allocation |
| 132 | + |
| 133 | +2. **Evault Task**: |
| 134 | + - Runs the evault application |
| 135 | + - Connects to Neo4j via localhost |
| 136 | + - Uses dynamic port allocation |
| 137 | + - 512MB memory allocation |
| 138 | + - Depends on Neo4j task |
| 139 | + |
| 140 | +## Environment Variables |
| 141 | + |
| 142 | +- `PORT` - Port to run the API on (default: 3000) |
| 143 | +- `NOMAD_ADDR` - Nomad API address (default: http://localhost:4646) |
| 144 | + |
| 145 | +## Troubleshooting |
| 146 | + |
| 147 | +### Common Issues |
| 148 | + |
| 149 | +1. **Port Allocation Issues**: |
| 150 | + |
| 151 | + - Ensure Nomad is running with CNI plugins installed |
| 152 | + - Check that the network interface is correctly specified |
| 153 | + - Verify that ports are not already in use |
| 154 | + |
| 155 | +2. **Container Networking**: |
| 156 | + |
| 157 | + - Ensure Docker is running |
| 158 | + - Check that the bridge network is properly configured |
| 159 | + - Verify container-to-container communication |
| 160 | + |
| 161 | +3. **Nomad Job Failures**: |
| 162 | + - Check Nomad logs for detailed error messages |
| 163 | + - Verify that all required images are available |
| 164 | + - Ensure resource allocations are sufficient |
| 165 | + |
| 166 | +### Debugging |
| 167 | + |
| 168 | +To debug Nomad issues: |
| 169 | + |
| 170 | +```bash |
| 171 | +# View Nomad logs |
| 172 | +journalctl -u nomad -f |
| 173 | + |
| 174 | +# Check Nomad status |
| 175 | +nomad status |
| 176 | + |
| 177 | +# View specific job details |
| 178 | +nomad job status evault-<tenant-id> |
| 179 | + |
| 180 | +# View allocation details |
| 181 | +nomad alloc status <allocation-id> |
| 182 | +``` |
| 183 | + |
| 184 | +## Development |
| 185 | + |
| 186 | +The project uses TypeScript for type safety and better development experience. The source files are in the `src` directory and are compiled to the `dist` directory. |
| 187 | + |
| 188 | +For development, you can use `npm run dev` which uses `tsx` to run the TypeScript files directly without compilation. |
0 commit comments