Compare commits
5
Commits
06cf4d1b9e
..
v1.0.5
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
aa986a470e | ||
|
|
520fc8f81e | ||
|
|
d46e3ca247 | ||
|
|
ec0b012586 | ||
|
|
36c80458e0 |
@@ -0,0 +1,27 @@
|
||||
name: Publish Workspace Image
|
||||
|
||||
on:
|
||||
push:
|
||||
paths:
|
||||
- 'coder/workspace.Dockerfile'
|
||||
branches:
|
||||
- main
|
||||
|
||||
concurrency:
|
||||
group: publish-workspace
|
||||
cancel-in-progress: false
|
||||
|
||||
jobs:
|
||||
publish:
|
||||
runs-on: self-hosted
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Log in to registry
|
||||
run: echo "${{ secrets.REGISTRY_PASSWORD }}" | docker login registry.samson.media -u "${{ secrets.REGISTRY_USERNAME }}" --password-stdin
|
||||
|
||||
- name: Build and push
|
||||
run: |
|
||||
IMAGE=registry.samson.media/coder-workspace
|
||||
docker build -f coder/workspace.Dockerfile -t "$IMAGE:latest" .
|
||||
docker push "$IMAGE:latest"
|
||||
@@ -478,28 +478,6 @@ resource "coder_agent" "main" {
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
# --- Install Node.js 22 ---
|
||||
if ! command -v node &> /dev/null; then
|
||||
curl -fsSL https://deb.nodesource.com/setup_22.x | sudo -E bash -
|
||||
sudo apt-get install -y nodejs
|
||||
fi
|
||||
|
||||
# --- Install global tools ---
|
||||
if ! command -v wrangler &> /dev/null; then
|
||||
sudo npm install -g wrangler @anthropic-ai/claude-code
|
||||
fi
|
||||
|
||||
# --- Install Playwright system dependencies ---
|
||||
if ! dpkg -s libgbm1 &> /dev/null; then
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y libnss3 libnspr4 libatk1.0-0 libatk-bridge2.0-0 \
|
||||
libcups2t64 libdrm2 libxkbcommon0 libxcomposite1 libxdamage1 libxfixes3 \
|
||||
libxrandr2 libgbm1 libpango-1.0-0 libcairo2 libasound2t64 libatspi2.0-0 \
|
||||
|| sudo apt-get install -y libnss3 libnspr4 libatk1.0-0 libatk-bridge2.0-0 \
|
||||
libcups2 libdrm2 libxkbcommon0 libxcomposite1 libxdamage1 libxfixes3 \
|
||||
libxrandr2 libgbm1 libpango-1.0-0 libcairo2 libasound2 libatspi2.0-0
|
||||
fi
|
||||
|
||||
# --- Configure git ---
|
||||
git config --global user.name "${data.coder_workspace_owner.me.full_name}"
|
||||
git config --global user.email "${data.coder_workspace_owner.me.email}"
|
||||
@@ -535,41 +513,6 @@ resource "coder_agent" "main" {
|
||||
npm run db:migrate:local
|
||||
fi
|
||||
|
||||
# --- Start log viewer on port 13338 ---
|
||||
if [ -n "$TASK_TYPE" ]; then
|
||||
touch ~/task-output.log
|
||||
cat > ~/log-server.sh << 'LOGEOF'
|
||||
#!/bin/bash
|
||||
while true; do
|
||||
{
|
||||
echo "HTTP/1.1 200 OK"
|
||||
echo "Content-Type: text/html; charset=utf-8"
|
||||
echo "Connection: close"
|
||||
echo ""
|
||||
echo "<html><head><title>Task Log</title>"
|
||||
echo "<meta http-equiv='refresh' content='5'>"
|
||||
echo "<style>body{background:#1e1e1e;color:#d4d4d4;font-family:monospace;font-size:13px;padding:16px;white-space:pre-wrap;}"
|
||||
echo "h2{color:#569cd6;margin:0 0 8px}.meta{color:#6a9955;margin-bottom:16px;display:block}</style></head><body>"
|
||||
echo "<h2>$TASK_TYPE #$ISSUE_NUMBER — $(hostname)</h2>"
|
||||
if [ -f ~/task-output.log ]; then
|
||||
LINES=$(wc -l < ~/task-output.log)
|
||||
if grep -q "Task completed" ~/task-output.log 2>/dev/null; then
|
||||
echo "<span class='meta'>Status: ✅ Complete ($LINES lines)</span>"
|
||||
else
|
||||
echo "<span class='meta'>Status: ⏳ Running ($LINES lines) — auto-refreshing every 5s</span>"
|
||||
fi
|
||||
sed 's/&/\&/g; s/</\</g; s/>/\>/g' ~/task-output.log
|
||||
else
|
||||
echo "Waiting for task to start..."
|
||||
fi
|
||||
echo "</body></html>"
|
||||
} | nc -l -p 13338 -q 1 2>/dev/null || true
|
||||
done
|
||||
LOGEOF
|
||||
chmod +x ~/log-server.sh
|
||||
nohup bash ~/log-server.sh &>/dev/null &
|
||||
fi
|
||||
|
||||
# --- Automated task execution ---
|
||||
if [ -n "$TASK_TYPE" ] && [ -d ~/project ]; then
|
||||
cd ~/project
|
||||
@@ -579,8 +522,16 @@ LOGEOF
|
||||
ARGS="$DEPLOY_ENV"
|
||||
fi
|
||||
|
||||
# Read the slash command .md file, strip YAML frontmatter, substitute $ARGUMENTS
|
||||
CMD_FILE=".claude/commands/$TASK_TYPE.md"
|
||||
if [ ! -f "$CMD_FILE" ]; then
|
||||
echo "ERROR: Command file not found: $CMD_FILE" | tee ~/task-output.log
|
||||
exit 1
|
||||
fi
|
||||
PROMPT=$(sed '1{/^---$/!q}; 1,/^---$/d' "$CMD_FILE" | sed "s/\\\$ARGUMENTS/$ARGS/g")
|
||||
|
||||
# Run Claude Code in non-interactive mode with tool access
|
||||
claude -p --dangerously-skip-permissions --verbose "/project:$TASK_TYPE $ARGS" 2>&1 | tee ~/task-output.log
|
||||
claude -p --dangerously-skip-permissions --verbose "$PROMPT" 2>&1 | tee ~/task-output.log
|
||||
EXIT_CODE=$?
|
||||
echo "Claude exited with code: $EXIT_CODE" | tee -a ~/task-output.log
|
||||
|
||||
@@ -596,21 +547,6 @@ LOGEOF
|
||||
EOT
|
||||
}
|
||||
|
||||
resource "coder_app" "task_log" {
|
||||
agent_id = coder_agent.main.id
|
||||
slug = "task-log"
|
||||
display_name = "Task Log"
|
||||
icon = "/icon/document.svg"
|
||||
url = "http://localhost:13338"
|
||||
share = "owner"
|
||||
|
||||
healthcheck {
|
||||
url = "http://localhost:13338"
|
||||
interval = 10
|
||||
threshold = 3
|
||||
}
|
||||
}
|
||||
|
||||
# =============================================================================
|
||||
# Main Workspace Deployment
|
||||
# =============================================================================
|
||||
@@ -691,7 +627,7 @@ resource "kubernetes_deployment_v1" "workspace" {
|
||||
|
||||
container {
|
||||
name = "coder-agent"
|
||||
image = "codercom/enterprise-base:latest"
|
||||
image = "registry.samson.media/coder-workspace:latest"
|
||||
|
||||
command = ["sh", "-c", coder_agent.main.init_script]
|
||||
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
FROM codercom/enterprise-base:latest
|
||||
|
||||
USER root
|
||||
|
||||
# Node.js 22
|
||||
RUN curl -fsSL https://deb.nodesource.com/setup_22.x | bash - \
|
||||
&& apt-get install -y nodejs \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# Global npm tools
|
||||
RUN npm install -g wrangler @anthropic-ai/claude-code
|
||||
|
||||
# Playwright system dependencies (both Ubuntu 24.04 and 22.04 package names)
|
||||
RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||
libnss3 libnspr4 libatk1.0-0 libatk-bridge2.0-0 \
|
||||
libdrm2 libxkbcommon0 libxcomposite1 libxdamage1 libxfixes3 \
|
||||
libxrandr2 libgbm1 libpango-1.0-0 libcairo2 libatspi2.0-0 \
|
||||
jq netcat-openbsd \
|
||||
&& (apt-get install -y libcups2t64 libasound2t64 2>/dev/null \
|
||||
|| apt-get install -y libcups2 libasound2 2>/dev/null) \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
USER coder
|
||||
@@ -84,6 +84,11 @@ if (maintenanceRepos.length > 0) {
|
||||
// Start
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
// Reconcile queue state with Coder before accepting traffic
|
||||
queue.reconcile().catch((err) =>
|
||||
console.error("[startup] reconcile failed:", err),
|
||||
);
|
||||
|
||||
serve({ fetch: app.fetch, port: config.port }, (info) => {
|
||||
console.log(`SDLC Orchestrator listening on :${info.port} (concurrency: ${concurrency})`);
|
||||
});
|
||||
|
||||
@@ -35,6 +35,34 @@ export class TaskQueue {
|
||||
this.concurrency = concurrency;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reconcile in-memory state with Coder on startup.
|
||||
* Re-adopts any running workspaces so callbacks and dedup work correctly.
|
||||
*/
|
||||
async reconcile(): Promise<void> {
|
||||
const workspaces = await this.coder.listWorkspaces();
|
||||
const runningStatuses = ["starting", "running", "started"];
|
||||
|
||||
for (const ws of workspaces) {
|
||||
if (!runningStatuses.includes(ws.latestBuildStatus)) continue;
|
||||
|
||||
// Only adopt workspaces that match our naming pattern: {taskType}-{repo}-{issue}
|
||||
const parts = ws.name.match(/^(.+?)-(.+?)-(\d+)$/);
|
||||
if (!parts) continue;
|
||||
|
||||
this.active.set(ws.name, {
|
||||
workspaceId: ws.id,
|
||||
workspaceName: ws.name,
|
||||
startedAt: new Date(), // approximate — we don't know the real start time
|
||||
});
|
||||
console.log(`[queue] reconciled: adopted workspace "${ws.name}" (status: ${ws.latestBuildStatus})`);
|
||||
}
|
||||
|
||||
if (this.active.size > 0) {
|
||||
console.log(`[queue] reconcile complete: ${this.active.size} active workspace(s) adopted`);
|
||||
}
|
||||
}
|
||||
|
||||
/** Build a dedup key for a task. */
|
||||
static key(task: TaskRequest): string {
|
||||
return `${task.taskType}-${task.giteaRepo}-${task.issueNumber}`;
|
||||
|
||||
+72
-10
@@ -50,16 +50,30 @@ export class CoderClient {
|
||||
},
|
||||
);
|
||||
|
||||
// Handle 409 conflict — stale workspace from a previous orchestrator instance
|
||||
// Handle 409 conflict — workspace with this name already exists.
|
||||
// This can happen if the orchestrator restarted and lost in-memory state.
|
||||
if (res.status === 409) {
|
||||
console.log(`[coder] workspace "${name}" already exists — deleting stale workspace and retrying`);
|
||||
const existing = await this.findWorkspaceByName(name);
|
||||
if (existing) {
|
||||
await this.deleteWorkspace(existing.id);
|
||||
// Wait for deletion to propagate
|
||||
await new Promise((resolve) => setTimeout(resolve, 5000));
|
||||
if (!existing) {
|
||||
throw new Error(`Coder 409 but workspace "${name}" not found — possible race condition`);
|
||||
}
|
||||
return this.createWorkspace(task);
|
||||
|
||||
const stoppedStatuses = ["stopped", "failed", "canceled", "deleted"];
|
||||
if (stoppedStatuses.includes(existing.latestBuildStatus)) {
|
||||
// Workspace is done — safe to replace
|
||||
console.log(
|
||||
`[coder] workspace "${name}" exists but ${existing.latestBuildStatus} — deleting and retrying`,
|
||||
);
|
||||
await this.deleteWorkspace(existing.id);
|
||||
await new Promise((resolve) => setTimeout(resolve, 5000));
|
||||
return this.createWorkspace(task);
|
||||
}
|
||||
|
||||
// Workspace is still running — adopt it, don't kill it
|
||||
console.log(
|
||||
`[coder] workspace "${name}" is still ${existing.latestBuildStatus} — adopting existing workspace`,
|
||||
);
|
||||
return { id: existing.id, name: existing.name };
|
||||
}
|
||||
|
||||
if (!res.ok) {
|
||||
@@ -107,7 +121,42 @@ export class CoderClient {
|
||||
}
|
||||
}
|
||||
|
||||
async findWorkspaceByName(name: string): Promise<{ id: string } | null> {
|
||||
/**
|
||||
* List all workspaces owned by the authenticated user.
|
||||
* Used at startup to reconcile in-memory state with Coder.
|
||||
*/
|
||||
async listWorkspaces(): Promise<
|
||||
Array<{ id: string; name: string; latestBuildStatus: string }>
|
||||
> {
|
||||
const res = await fetch(
|
||||
`${this.baseUrl}/api/v2/workspaces?q=owner:me`,
|
||||
{
|
||||
headers: { "Coder-Session-Token": this.token },
|
||||
},
|
||||
);
|
||||
|
||||
if (!res.ok) return [];
|
||||
|
||||
const data = (await res.json()) as {
|
||||
workspaces: Array<{
|
||||
id: string;
|
||||
name: string;
|
||||
latest_build: { status: string };
|
||||
}>;
|
||||
};
|
||||
return (data.workspaces ?? []).map((w) => ({
|
||||
id: w.id,
|
||||
name: w.name,
|
||||
latestBuildStatus: w.latest_build?.status ?? "unknown",
|
||||
}));
|
||||
}
|
||||
|
||||
async findWorkspaceByName(name: string): Promise<{
|
||||
id: string;
|
||||
name: string;
|
||||
createdAt: string;
|
||||
latestBuildStatus: string;
|
||||
} | null> {
|
||||
const res = await fetch(
|
||||
`${this.baseUrl}/api/v2/workspaces?q=name:${encodeURIComponent(name)}`,
|
||||
{
|
||||
@@ -119,8 +168,21 @@ export class CoderClient {
|
||||
|
||||
if (!res.ok) return null;
|
||||
|
||||
const data = (await res.json()) as { workspaces: Array<{ id: string; name: string }> };
|
||||
const data = (await res.json()) as {
|
||||
workspaces: Array<{
|
||||
id: string;
|
||||
name: string;
|
||||
created_at: string;
|
||||
latest_build: { status: string };
|
||||
}>;
|
||||
};
|
||||
const match = data.workspaces?.find((w) => w.name === name);
|
||||
return match ? { id: match.id } : null;
|
||||
if (!match) return null;
|
||||
return {
|
||||
id: match.id,
|
||||
name: match.name,
|
||||
createdAt: match.created_at,
|
||||
latestBuildStatus: match.latest_build?.status ?? "unknown",
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user