fix: create /workspaces dir, clone repo before running agent
Made-with: Cursor
This commit is contained in:
@@ -16,8 +16,11 @@ RUN npm ci --omit=dev
|
|||||||
# Copy compiled output (build before docker build, or use multi-stage)
|
# Copy compiled output (build before docker build, or use multi-stage)
|
||||||
COPY dist/ ./dist/
|
COPY dist/ ./dist/
|
||||||
|
|
||||||
# Non-root user for security
|
# Create workspace dir and non-root user
|
||||||
RUN useradd -r -s /bin/false agent
|
RUN useradd -r -m -s /bin/bash agent && \
|
||||||
|
mkdir -p /workspaces && \
|
||||||
|
chown -R agent:agent /workspaces /app
|
||||||
|
|
||||||
USER agent
|
USER agent
|
||||||
|
|
||||||
EXPOSE 3333
|
EXPOSE 3333
|
||||||
|
|||||||
68
dist/server.js
vendored
68
dist/server.js
vendored
@@ -1,10 +1,46 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||||
|
if (k2 === undefined) k2 = k;
|
||||||
|
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||||
|
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||||
|
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||||
|
}
|
||||||
|
Object.defineProperty(o, k2, desc);
|
||||||
|
}) : (function(o, m, k, k2) {
|
||||||
|
if (k2 === undefined) k2 = k;
|
||||||
|
o[k2] = m[k];
|
||||||
|
}));
|
||||||
|
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||||
|
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||||
|
}) : function(o, v) {
|
||||||
|
o["default"] = v;
|
||||||
|
});
|
||||||
|
var __importStar = (this && this.__importStar) || (function () {
|
||||||
|
var ownKeys = function(o) {
|
||||||
|
ownKeys = Object.getOwnPropertyNames || function (o) {
|
||||||
|
var ar = [];
|
||||||
|
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
||||||
|
return ar;
|
||||||
|
};
|
||||||
|
return ownKeys(o);
|
||||||
|
};
|
||||||
|
return function (mod) {
|
||||||
|
if (mod && mod.__esModule) return mod;
|
||||||
|
var result = {};
|
||||||
|
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
||||||
|
__setModuleDefault(result, mod);
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
})();
|
||||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||||
};
|
};
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
const express_1 = __importDefault(require("express"));
|
const express_1 = __importDefault(require("express"));
|
||||||
const cors_1 = __importDefault(require("cors"));
|
const cors_1 = __importDefault(require("cors"));
|
||||||
|
const fs = __importStar(require("fs"));
|
||||||
|
const path = __importStar(require("path"));
|
||||||
|
const child_process_1 = require("child_process");
|
||||||
const job_store_1 = require("./job-store");
|
const job_store_1 = require("./job-store");
|
||||||
const agent_runner_1 = require("./agent-runner");
|
const agent_runner_1 = require("./agent-runner");
|
||||||
const agents_1 = require("./agents");
|
const agents_1 = require("./agents");
|
||||||
@@ -15,10 +51,36 @@ const PORT = process.env.PORT || 3333;
|
|||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
// Build ToolContext from environment variables
|
// Build ToolContext from environment variables
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
function ensureWorkspace(repo) {
|
||||||
|
const base = process.env.WORKSPACE_BASE || '/workspaces';
|
||||||
|
if (!repo) {
|
||||||
|
const dir = path.join(base, 'default');
|
||||||
|
fs.mkdirSync(dir, { recursive: true });
|
||||||
|
return dir;
|
||||||
|
}
|
||||||
|
const dir = path.join(base, repo.replace('/', '_'));
|
||||||
|
const gitea = {
|
||||||
|
apiUrl: process.env.GITEA_API_URL || '',
|
||||||
|
apiToken: process.env.GITEA_API_TOKEN || '',
|
||||||
|
username: process.env.GITEA_USERNAME || ''
|
||||||
|
};
|
||||||
|
if (!fs.existsSync(path.join(dir, '.git'))) {
|
||||||
|
fs.mkdirSync(dir, { recursive: true });
|
||||||
|
const authedUrl = `${gitea.apiUrl}/${repo}.git`
|
||||||
|
.replace('https://', `https://${gitea.username}:${gitea.apiToken}@`);
|
||||||
|
try {
|
||||||
|
(0, child_process_1.execSync)(`git clone "${authedUrl}" "${dir}"`, { stdio: 'pipe' });
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
// Repo may not exist yet — just init
|
||||||
|
(0, child_process_1.execSync)(`git init`, { cwd: dir, stdio: 'pipe' });
|
||||||
|
(0, child_process_1.execSync)(`git remote add origin "${authedUrl}"`, { cwd: dir, stdio: 'pipe' });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return dir;
|
||||||
|
}
|
||||||
function buildContext(repo) {
|
function buildContext(repo) {
|
||||||
const workspaceRoot = repo
|
const workspaceRoot = ensureWorkspace(repo);
|
||||||
? `${process.env.WORKSPACE_BASE || '/workspaces'}/${repo.replace('/', '_')}`
|
|
||||||
: (process.env.WORKSPACE_BASE || '/workspaces/default');
|
|
||||||
return {
|
return {
|
||||||
workspaceRoot,
|
workspaceRoot,
|
||||||
gitea: {
|
gitea: {
|
||||||
|
|||||||
@@ -1,5 +1,8 @@
|
|||||||
import express, { Request, Response, NextFunction } from 'express';
|
import express, { Request, Response, NextFunction } from 'express';
|
||||||
import cors from 'cors';
|
import cors from 'cors';
|
||||||
|
import * as fs from 'fs';
|
||||||
|
import * as path from 'path';
|
||||||
|
import { execSync } from 'child_process';
|
||||||
import { createJob, getJob, listJobs, updateJob } from './job-store';
|
import { createJob, getJob, listJobs, updateJob } from './job-store';
|
||||||
import { runAgent } from './agent-runner';
|
import { runAgent } from './agent-runner';
|
||||||
import { AGENTS } from './agents';
|
import { AGENTS } from './agents';
|
||||||
@@ -15,10 +18,36 @@ const PORT = process.env.PORT || 3333;
|
|||||||
// Build ToolContext from environment variables
|
// Build ToolContext from environment variables
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
function ensureWorkspace(repo?: string): string {
|
||||||
|
const base = process.env.WORKSPACE_BASE || '/workspaces';
|
||||||
|
if (!repo) {
|
||||||
|
const dir = path.join(base, 'default');
|
||||||
|
fs.mkdirSync(dir, { recursive: true });
|
||||||
|
return dir;
|
||||||
|
}
|
||||||
|
const dir = path.join(base, repo.replace('/', '_'));
|
||||||
|
const gitea = {
|
||||||
|
apiUrl: process.env.GITEA_API_URL || '',
|
||||||
|
apiToken: process.env.GITEA_API_TOKEN || '',
|
||||||
|
username: process.env.GITEA_USERNAME || ''
|
||||||
|
};
|
||||||
|
if (!fs.existsSync(path.join(dir, '.git'))) {
|
||||||
|
fs.mkdirSync(dir, { recursive: true });
|
||||||
|
const authedUrl = `${gitea.apiUrl}/${repo}.git`
|
||||||
|
.replace('https://', `https://${gitea.username}:${gitea.apiToken}@`);
|
||||||
|
try {
|
||||||
|
execSync(`git clone "${authedUrl}" "${dir}"`, { stdio: 'pipe' });
|
||||||
|
} catch {
|
||||||
|
// Repo may not exist yet — just init
|
||||||
|
execSync(`git init`, { cwd: dir, stdio: 'pipe' });
|
||||||
|
execSync(`git remote add origin "${authedUrl}"`, { cwd: dir, stdio: 'pipe' });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return dir;
|
||||||
|
}
|
||||||
|
|
||||||
function buildContext(repo?: string): ToolContext {
|
function buildContext(repo?: string): ToolContext {
|
||||||
const workspaceRoot = repo
|
const workspaceRoot = ensureWorkspace(repo);
|
||||||
? `${process.env.WORKSPACE_BASE || '/workspaces'}/${repo.replace('/', '_')}`
|
|
||||||
: (process.env.WORKSPACE_BASE || '/workspaces/default');
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
workspaceRoot,
|
workspaceRoot,
|
||||||
|
|||||||
Reference in New Issue
Block a user