Skip to content

Commit 021b63d

Browse files
authored
Feat/registry and evault provisioning (#106)
* feat: evault provisioning * chore: fianlly fixed provisioner * feat: add logic for metadata in consul * feat: registry * chore: format
1 parent a4a3900 commit 021b63d

File tree

19 files changed

+4304
-78
lines changed

19 files changed

+4304
-78
lines changed

docker/Dockerfile.evault

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,5 @@ WORKDIR /app
1919
RUN npm i -g corepack@latest
2020
COPY --from=deps /out/ /app
2121
EXPOSE 4000
22-
workdir /app/infrastructure/evault-core
22+
WORKDIR /app/infrastructure/evault-core
2323
CMD ["pnpm", "dev"]

docker/Dockerfile.evault-prod

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
FROM node:22-slim AS deps
2+
ENV PNPM_HOME="/pnpm"
3+
ENV PATH="$PNPM_HOME:$PATH"
4+
RUN corepack enable
5+
COPY . /app
6+
WORKDIR /app
7+
RUN npm i -g corepack@latest
8+
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --frozen-lockfile
9+
RUN pnpm turbo prune evault-core --docker --use-gitignore=false
10+
RUN mkdir /out
11+
RUN cp -R ./out/full/* /out/
12+
RUN cp -R ./out/json/* /out/
13+
RUN cp ./out/pnpm-lock.yaml /out/pnpm-lock.yaml
14+
RUN cp -R node_modules/ /out/
15+
16+
17+
FROM node:22-slim AS core-api
18+
WORKDIR /app
19+
RUN npm i -g corepack@latest
20+
COPY --from=deps /out/ /app
21+
RUN pnpm -F=evault-core build
22+
EXPOSE 4000
23+
WORKDIR /app/infrastructure/evault-core
24+
CMD ["echo \'hi'\"]

infrastructure/evault-core/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
"scripts": {
77
"test": "vitest --config vitest.config.ts",
88
"build": "tsc",
9-
"dev": "node --watch --import tsx src/evault.ts"
9+
"dev": "node --watch --import tsx src/evault.ts",
10+
"start": "node ./dist/evault.js"
1011
},
1112
"packageManager": "[email protected]",
1213
"keywords": [],

infrastructure/evault-core/src/evault.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ class EVault {
3232
}
3333

3434
start() {
35-
const port = process.env.PORT ?? 4000;
36-
this.server.listen(port, () => {
37-
console.log(`GraphQL Server started on http://localhost:${port}`);
38-
console.log(`Voyager started on http://localhost:${port}`);
35+
const port = process.env.NOMAD_PORT_http || process.env.PORT || 4000;
36+
this.server.listen(Number(port), "0.0.0.0", () => {
37+
console.log(`GraphQL Server started on http://0.0.0.0:${port}`);
38+
console.log(`Voyager started on http://0.0.0.0:${port}`);
3939
});
4040
}
4141
}
Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,27 @@
11
{
2-
"compilerOptions": {
3-
"target": "ES2017",
4-
"module": "ESNext",
5-
"lib": ["ESNext", "DOM"],
6-
"declaration": true,
7-
"declarationDir": "./dist/types",
8-
"outDir": "./dist",
9-
"rootDir": "./src",
10-
"strict": true,
11-
"esModuleInterop": true,
12-
"forceConsistentCasingInFileNames": true,
13-
"moduleResolution": "Node",
14-
"skipLibCheck": true
15-
},
16-
"include": ["src/**/*"],
17-
"exclude": ["node_modules", "dist"]
2+
"compilerOptions": {
3+
"target": "ES2021",
4+
"module": "CommonJS",
5+
"lib": [
6+
"ESNext",
7+
"DOM"
8+
],
9+
"declaration": true,
10+
"declarationDir": "./dist/types",
11+
"outDir": "./dist",
12+
"rootDir": "./src",
13+
"strict": true,
14+
"esModuleInterop": true,
15+
"forceConsistentCasingInFileNames": true,
16+
"moduleResolution": "Node",
17+
"skipLibCheck": true
18+
},
19+
"include": [
20+
"src/**/*"
21+
],
22+
"exclude": [
23+
"node_modules",
24+
"dist",
25+
"*/**/*.spec.ts"
26+
]
1827
}
Lines changed: 188 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,188 @@
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.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"name": "evault-provisioner",
3+
"version": "1.0.0",
4+
"description": "API for provisioning evault instances on Nomad",
5+
"main": "dist/index.js",
6+
"type": "module",
7+
"scripts": {
8+
"start": "node dist/index.js",
9+
"dev": "tsx watch src/index.ts",
10+
"build": "tsc",
11+
"test": "vitest"
12+
},
13+
"dependencies": {
14+
"express": "^4.18.2",
15+
"axios": "^1.6.7",
16+
"dotenv": "^16.4.5",
17+
"w3id": "workspace:*"
18+
},
19+
"devDependencies": {
20+
"@types/express": "^4.17.21",
21+
"@types/node": "^20.11.24",
22+
"nodemon": "^3.0.3",
23+
"tsx": "^4.7.1",
24+
"typescript": "^5.3.3",
25+
"vitest": "^1.3.1"
26+
}
27+
}

0 commit comments

Comments
 (0)