feat: enhance workspace setup and service management with improved port forwarding and installation scripts

- Added support for Claude Code CLI, Cursor IDE, and Windsurf IDE in workspace setup.
- Refactored port forwarding command to check for existing processes and provide feedback.
- Implemented direct access for Qdrant and added test commands for connectivity checks.
- Improved package installation logic to handle locked APT processes and retries.
- Updated startup scripts to log output for better debugging and monitoring.
- Added installation scripts for additional development tools and utilities.
This commit is contained in:
2025-09-09 01:43:22 +00:00
parent d7fd50d7a3
commit 70347afa97
7 changed files with 589 additions and 44 deletions

372
task.md Normal file
View File

@@ -0,0 +1,372 @@
🤖 Installing Claude Code CLI...
📝 Setting up Git hooks and metadata capture...
bash: line 23: syntax error near unexpected token `('
bash: line 23: ` LOCKWAIT=$$((LOCKWAIT + 2))'
Starting workspace with services enabled...
🎯 Setting up Cursor IDE support...
🌊 Setting up Windsurf IDE support...
🚀 Initializing development environment as user: root
🔍 Running as user: root (actual: root, $USER env: coder)
📁 Creating user directories...
🔄 Setting up environment context...
⚙️ Configuring Git...
🔧 Installing development extensions and tools...
📦 Installing additional CLI tools...
📝 Capturing Git metadata...
✅ Found npm at: /home/codespace/nvm/current/bin/npm
📥 Installing Claude Code CLI...
📦 Installing system packages...
📦 Waiting for other package managers to finish...
⚠️ Could not set ownership - you may need to run with appropriate permissions
✅ Git hooks and metadata capture configured
📝 Git metadata will be automatically captured on commits
🔍 Pre-push quality checks will run before each push
💡 Run '.git/hooks/show-metadata' to view captured git metadata
💡 Metadata is stored in: /tmp/git-metadata/
📦 Updating package lists...
⚠️ Could not set ownership - you may need to run with appropriate permissions
✅ Cursor IDE support configured
🎯 Cursor will use optimized settings for this development environment
⚠️ Could not set ownership - you may need to run with appropriate permissions
✅ Windsurf IDE support configured
🌊 Windsurf AI features enabled with optimized settings
⌨️ Keyboard shortcuts: Ctrl+Shift+A (chat), Ctrl+Shift+C (generate), Ctrl+Shift+R (refactor)
📁 Configuration stored in: /home/coder/.windsurf/
💡 Run '/home/coder/.windsurf/windsurf-help' for quick reference
🛠️ Installing development utilities...
🌿 Installing lazygit...
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
added 3 packages in 1s
2 packages are looking for funding
run `npm fund` for details
✅ Claude Code installed successfully!
🔧 Run 'claude auth login' to authenticate
💡 Use 'claude chat' for interactive assistance
💡 Use 'claude edit <file>' to edit files with AI
💡 Run 'claude-help' for quick reference
51 7742k 51 4013k 0 0 3699k 0 0:00:02 0:00:01 0:00:01 3699k
100 7742k 100 7742k 0 0 5627k 0 0:00:01 0:00:01 --:--:-- 12.5M
📊 Installing btop...
Fetched 36.2 MB in 2s (23.8 MB/s)
Reading package lists...
Reading package lists...
Building dependency tree...
📦 Installing core packages...
E: Could not get lock /var/lib/dpkg/lock-frontend. It is held by process 3695 (apt-get)
E: Unable to acquire the dpkg frontend lock (/var/lib/dpkg/lock-frontend), is another process using it?
⚠️ Some packages failed to install
📦 Installing ranger file manager...
E: Could not get lock /var/lib/dpkg/lock-frontend. It is held by process 3695 (apt-get)
E: Unable to acquire the dpkg frontend lock (/var/lib/dpkg/lock-frontend), is another process using it?
⚠️ ranger not available in this repository
🟢 Setting up Node.js and npm...
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
100 14984 100 14984 0 0 281k 0 --:--:-- --:--:-- --:--:-- 281k
=> nvm is already installed in /usr/local/share/nvm, trying to update using git
=> => Compressing and cleaning up git repository
=> nvm source string already in /home/coder/.bashrc
=> bash_completion source string already in /home/coder/.bashrc
=> You currently have modules installed globally with `npm`. These will no
=> longer be linked to the active version of Node when you install a new node
=> with `nvm`; and they may (depending on how you construct your `$PATH`)
=> override the binaries of modules installed with `nvm`:
/usr/local/share/nvm/versions/node/v22.15.0/lib
├── @anthropic-ai/claude-code@1.0.108
Reading state information...
btop not available in repos, htop is installed as alternative
Reading package lists...
Building dependency tree...
├── corepack@0.32.0
└── pnpm@10.10.0
=> If you wish to uninstall them at a later point (or re-install them under your
=> `nvm` Nodes), you can remove them from the system Node as follows:
$ nvm use system
$ npm uninstall -g a_module
=> Installing Node.js version 20
Downloading and installing node v20.19.5...
Reading state information...
htop is already the newest version (2.2.0-2build1).
0 upgraded, 0 newly installed, 0 to remove and 54 not upgraded.
🔍 Installing fd-find...
Reading package lists...
Building dependency tree...
Reading state information...
The following NEW packages will be installed:
fd-find
0 upgraded, 1 newly installed, 0 to remove and 54 not upgraded.
Need to get 699 kB of archives.
After this operation, 2391 kB of additional disk space will be used.
Get:1 http://archive.ubuntu.com/ubuntu focal-updates/universe amd64 fd-find amd64 7.4.0-2ubuntu0.1 [699 kB]
Fetched 699 kB in 0s (7510 kB/s)
Selecting previously unselected package fd-find.
(Reading database ...
(Reading database ... 5%
(Reading database ... 10%
(Reading database ... 15%
(Reading database ... 20%
(Reading database ... 25%
(Reading database ... 30%
(Reading database ... 35%
(Reading database ... 40%
(Reading database ... 45%
(Reading database ... 50%
(Reading database ... 55%
(Reading database ... 60%
(Reading database ... 65%
(Reading database ... 70%
(Reading database ... 75%
(Reading database ... 80%
(Reading database ... 85%
(Reading database ... 90%
(Reading database ... 95%
(Reading database ... 100%
(Reading database ... 70100 files and directories currently installed.)
Preparing to unpack .../fd-find_7.4.0-2ubuntu0.1_amd64.deb ...
Unpacking fd-find (7.4.0-2ubuntu0.1) ...
Setting up fd-find (7.4.0-2ubuntu0.1) ...
Processing triggers for man-db (2.9.1-1) ...
Now using node v20.19.5 (npm v9.8.1)
🔎 Installing ripgrep...
=> Close and reopen your terminal to start using nvm or run the following to use it now:
export NVM_DIR="/usr/local/share/nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
Reading package lists...
⚠️ Failed to install Node.js 20
📦 Installing npm packages...
Building dependency tree...
Reading state information...
The following NEW packages will be installed:
ripgrep
0 upgraded, 1 newly installed, 0 to remove and 54 not upgraded.
Need to get 1173 kB of archives.
After this operation, 4293 kB of additional disk space will be used.
Get:1 http://archive.ubuntu.com/ubuntu focal-updates/universe amd64 ripgrep amd64 11.0.2-1ubuntu0.1 [1173 kB]
Fetched 1173 kB in 1s (1773 kB/s)
Selecting previously unselected package ripgrep.
(Reading database ...
(Reading database ... 5%
(Reading database ... 10%
(Reading database ... 15%
(Reading database ... 20%
(Reading database ... 25%
(Reading database ... 30%
(Reading database ... 35%
(Reading database ... 40%
(Reading database ... 45%
(Reading database ... 50%
(Reading database ... 55%
(Reading database ... 60%
(Reading database ... 65%
(Reading database ... 70%
(Reading database ... 75%
(Reading database ... 80%
(Reading database ... 85%
(Reading database ... 90%
(Reading database ... 95%
(Reading database ... 100%
(Reading database ... 70115 files and directories currently installed.)
Preparing to unpack .../ripgrep_11.0.2-1ubuntu0.1_amd64.deb ...
Unpacking ripgrep (11.0.2-1ubuntu0.1) ...
Setting up ripgrep (11.0.2-1ubuntu0.1) ...
Processing triggers for man-db (2.9.1-1) ...
🦇 Installing bat...
Reading package lists...
Building dependency tree...
added 189 packages in 4s
66 packages are looking for funding
run `npm fund` for details
Reading state information...
The following additional packages will be installed:
libgit2-28 libhttp-parser2.9 libmbedcrypto3 libmbedtls12 libmbedx509-0
libssh2-1
The following NEW packages will be installed:
bat libgit2-28 libhttp-parser2.9 libmbedcrypto3 libmbedtls12 libmbedx509-0
libssh2-1
0 upgraded, 7 newly installed, 0 to remove and 54 not upgraded.
Need to get 2298 kB of archives.
After this operation, 6441 kB of additional disk space will be used.
Get:1 http://archive.ubuntu.com/ubuntu focal/universe amd64 libhttp-parser2.9 amd64 2.9.2-2 [21.8 kB]
added 1 package in 373ms
Get:2 http://archive.ubuntu.com/ubuntu focal/universe amd64 libmbedcrypto3 amd64 2.16.4-1ubuntu2 [150 kB]
Get:3 http://archive.ubuntu.com/ubuntu focal/universe amd64 libmbedx509-0 amd64 2.16.4-1ubuntu2 [42.3 kB]
added 29 packages in 609ms
4 packages are looking for funding
run `npm fund` for details
Get:4 http://archive.ubuntu.com/ubuntu focal/universe amd64 libmbedtls12 amd64 2.16.4-1ubuntu2 [71.8 kB]
Get:5 http://archive.ubuntu.com/ubuntu focal-updates/universe amd64 libssh2-1 amd64 1.8.0-2.1ubuntu0.1 [75.5 kB]
Get:6 http://archive.ubuntu.com/ubuntu focal-updates/universe amd64 libgit2-28 amd64 0.28.4+dfsg.1-2ubuntu0.1 [403 kB]
Get:7 http://archive.ubuntu.com/ubuntu focal-updates/universe amd64 bat amd64 0.12.1-1ubuntu0.2 [1533 kB]
Fetched 2298 kB in 3s (789 kB/s)
added 25 packages in 1s
6 packages are looking for funding
run `npm fund` for details
Selecting previously unselected package libhttp-parser2.9:amd64.
(Reading database ...
(Reading database ... 5%
(Reading database ... 10%
(Reading database ... 15%
(Reading database ... 20%
(Reading database ... 25%
(Reading database ... 30%
(Reading database ... 35%
(Reading database ... 40%
(Reading database ... 45%
(Reading database ... 50%
(Reading database ... 55%
(Reading database ... 60%
(Reading database ... 65%
(Reading database ... 70%
(Reading database ... 75%
(Reading database ... 80%
(Reading database ... 85%
(Reading database ... 90%
(Reading database ... 95%
(Reading database ... 100%
(Reading database ... 70124 files and directories currently installed.)
added 2 packages in 383ms
added 1 package in 441ms
Preparing to unpack .../0-libhttp-parser2.9_2.9.2-2_amd64.deb ...
Unpacking libhttp-parser2.9:amd64 (2.9.2-2) ...
Selecting previously unselected package libmbedcrypto3:amd64.
Preparing to unpack .../1-libmbedcrypto3_2.16.4-1ubuntu2_amd64.deb ...
Unpacking libmbedcrypto3:amd64 (2.16.4-1ubuntu2) ...
Selecting previously unselected package libmbedx509-0:amd64.
Preparing to unpack .../2-libmbedx509-0_2.16.4-1ubuntu2_amd64.deb ...
Unpacking libmbedx509-0:amd64 (2.16.4-1ubuntu2) ...
Selecting previously unselected package libmbedtls12:amd64.
Preparing to unpack .../3-libmbedtls12_2.16.4-1ubuntu2_amd64.deb ...
Unpacking libmbedtls12:amd64 (2.16.4-1ubuntu2) ...
Selecting previously unselected package libssh2-1:amd64.
Preparing to unpack .../4-libssh2-1_1.8.0-2.1ubuntu0.1_amd64.deb ...
Unpacking libssh2-1:amd64 (1.8.0-2.1ubuntu0.1) ...
Selecting previously unselected package libgit2-28:amd64.
Preparing to unpack .../5-libgit2-28_0.28.4+dfsg.1-2ubuntu0.1_amd64.deb ...
Unpacking libgit2-28:amd64 (0.28.4+dfsg.1-2ubuntu0.1) ...
Selecting previously unselected package bat.
Preparing to unpack .../6-bat_0.12.1-1ubuntu0.2_amd64.deb ...
Unpacking bat (0.12.1-1ubuntu0.2) ...
Setting up libmbedcrypto3:amd64 (2.16.4-1ubuntu2) ...
Setting up libssh2-1:amd64 (1.8.0-2.1ubuntu0.1) ...
Setting up libhttp-parser2.9:amd64 (2.9.2-2) ...
Setting up libmbedx509-0:amd64 (2.16.4-1ubuntu2) ...
Setting up libmbedtls12:amd64 (2.16.4-1ubuntu2) ...
Setting up libgit2-28:amd64 (0.28.4+dfsg.1-2ubuntu0.1) ...
Setting up bat (0.12.1-1ubuntu0.2) ...
Processing triggers for man-db (2.9.1-1) ...
Processing triggers for libc-bin (2.31-0ubuntu9.17) ...
📁 Installing eza...
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
40 1026k 40 410k 0 0 949k 0 0:00:01 --:--:-- 0:00:01 949k
100 1026k 100 1026k 0 0 1216k 0 --:--:-- --:--:-- --:--:-- 1498k
added 85 packages in 1s
22 packages are looking for funding
run `npm fund` for details
👤 Setting up user-specific tools...
⚠️ Could not switch to user coder, running as current user
added 1 package in 353ms
1 package is looking for funding
run `npm fund` for details
🐍 Setting up Python and uv...
Reading package lists...
added 90 packages in 2s
27 packages are looking for funding
run `npm fund` for details
Building dependency tree...
Reading state information...
⚠️ Failed to install Python 3.12
no checksums to verify
installing to /home/coder/.local/bin
uv
added 108 packages in 2s
51 packages are looking for funding
run `npm fund` for details
✅ Development tools installed and configured!
uvx
everything's installed!
📦 Installing Python developer tools...
🦀 Installing Rust and Cargo...
🎉 All development tools installed successfully!
💡 Available tools: gh, docker-compose, lazygit, htop/btop, fd, rg, bat, eza, tldr, fkill
💡 Aliases configured: cat→bat, ls→eza, find→fd, grep→rg, git-ui→lazygit, top→htop/btop
💡 Restart your shell or run 'source ~/.bashrc' (or ~/.zshrc) to use the new aliases
stable-x86_64-unknown-linux-gnu unchanged - rustc 1.89.0 (29483883e 2025-08-04)
Rust is installed now. Great!
To get started you may need to restart your current shell.
This would reload your PATH environment variable to include
Cargo's bin directory ($HOME/.cargo/bin).
To configure your current shell, you need to source
the corresponding env file under $HOME/.cargo.
This is usually done by running one of the following (note the leading DOT):
. "$HOME/.cargo/env" # For sh/bash/zsh/ash/dash/pdksh
source "$HOME/.cargo/env.fish" # For fish
source $"($nu.home-path)/.cargo/env.nu" # For nushell
📁 Installing repomix...
changed 189 packages in 2s
66 packages are looking for funding
run `npm fund` for details
🐚 Setting up shell environment...
✅ Development environment initialization complete!
🎉 Available tools:
- Node.js 20 with npm packages
- Python 3.12 with uv package manager
- Rust with Cargo
- repomix for repository packaging
- make, tree, and other build tools
- PostgreSQL, Redis, Qdrant databases
🔧 Run 'devinfo' for detailed environment information
🚀 Ready for development!
💡 Restart your shell or source your shell config to use new aliases

79
tf/.terraform.lock.hcl generated Normal file
View File

@@ -0,0 +1,79 @@
# This file is maintained automatically by "terraform init".
# Manual edits may be lost in future updates.
provider "registry.terraform.io/coder/coder" {
version = "2.10.1"
constraints = ">= 0.17.0, ~> 2.0"
hashes = [
"h1:X/5i3/1fFLc/WbWHRhJERBVGUd1oGCrXPKjIwP4qMFY=",
"zh:037ef9d6b5dfebb2aa1f81ab87d07946ba2bb8fe4819ae02b1046b70c42bed38",
"zh:17125eb205a4341eedbea00e53a9c2c9e3396799e1b5d7865dd4d3261369707b",
"zh:1c482c03c47817a02b3829caeb7f3c757d82aedbd0f200c71b946a23d14b3bb0",
"zh:1de27897786d81528ed321ba84ec4cde05b381ba192613b78aefc39019c1adca",
"zh:4667e4c64961fe03b502b27b9f15c2360b1f0f213626b6b473f49f2ef65070ea",
"zh:4788fd6930f7ea984daaf244f8206faabf4caede21a05701802bfabf73cf4298",
"zh:6572294a08a3bc9b12294b406173f63e9927252cb2795f43ece8dd9e9cfefe2c",
"zh:70f33963c020ebe571354a40f33332c904faa5c3452eeb6a2794b8012ec558cc",
"zh:7bf3587a24bddce84d619a111583a728cf35f0d792459f3051a1ec71d9bf8f0f",
"zh:a42c73f2e21e935cd95430ae1eb770c6b3a17e2f4dce1379d7e2ca98b099c2fa",
"zh:a82a6899f425ab5196f2a7732044f3b05ffafc6c26a03e6c4899d1caef56f9dd",
"zh:d3f0e48d5dc7a415cb6a355f8ff985ed126a490690ced29bdb54fc0eab3d7bea",
"zh:e45312311dd7371d2ebb3d7113016fa6e00e94877bbcef34bab53db94b49937d",
"zh:f3b64f9c840e92c3950d31e7b34a5aa27d10b65e39185da17b268928047426f7",
"zh:f569b65999264a9416862bca5cd2a6177d94ccb0424f3a4ef424428912b9cb3c",
]
}
provider "registry.terraform.io/coder/envbuilder" {
version = "1.0.0"
constraints = "~> 1.0"
hashes = [
"h1:EijMsTkZ+GM+0gSaTR2Rw9FO9vJE7i6w3U5/Z76zBsQ=",
"zh:638f85855a86dd9f783ac667d302a2fe072ff6570e866dabed8082d74a246c09",
"zh:8316dd29b5015d178cb6f8ecd4b10e4df766a82496d06883ba4c91ef410ce719",
"zh:890df766e9b839623b1f0437355032a3c006226a6c200cd911e15ee1a9014e9f",
"zh:d91bc816e66c01ef552b04413bd0d83f35a217eb578148da31ba54c0fe0aca31",
]
}
provider "registry.terraform.io/hashicorp/http" {
version = "3.5.0"
constraints = ">= 3.0.0"
hashes = [
"h1:8bUoPwS4hahOvzCBj6b04ObLVFXCEmEN8T/5eOHmWOM=",
"zh:047c5b4920751b13425efe0d011b3a23a3be97d02d9c0e3c60985521c9c456b7",
"zh:157866f700470207561f6d032d344916b82268ecd0cf8174fb11c0674c8d0736",
"zh:1973eb9383b0d83dd4fd5e662f0f16de837d072b64a6b7cd703410d730499476",
"zh:212f833a4e6d020840672f6f88273d62a564f44acb0c857b5961cdb3bbc14c90",
"zh:2c8034bc039fffaa1d4965ca02a8c6d57301e5fa9fff4773e684b46e3f78e76a",
"zh:5df353fc5b2dd31577def9cc1a4ebf0c9a9c2699d223c6b02087a3089c74a1c6",
"zh:672083810d4185076c81b16ad13d1224b9e6ea7f4850951d2ab8d30fa6e41f08",
"zh:78d5eefdd9e494defcb3c68d282b8f96630502cac21d1ea161f53cfe9bb483b3",
"zh:7b4200f18abdbe39904b03537e1a78f21ebafe60f1c861a44387d314fda69da6",
"zh:843feacacd86baed820f81a6c9f7bd32cf302db3d7a0f39e87976ebc7a7cc2ee",
"zh:a9ea5096ab91aab260b22e4251c05f08dad2ed77e43e5e4fadcdfd87f2c78926",
"zh:d02b288922811739059e90184c7f76d45d07d3a77cc48d0b15fd3db14e928623",
]
}
provider "registry.terraform.io/kreuzwerker/docker" {
version = "2.25.0"
constraints = "~> 2.25"
hashes = [
"h1:nB2atWOMNrq3tfVH216oFFCQ/TNjAXXno6ZyZhlGdQs=",
"zh:02ca00d987b2e56195d2e97d82349f680d4b94a6a0d514dc6c0031317aec4f11",
"zh:432d333412f01b7547b3b264ec85a2627869fdf5f75df9d237b0dc6a6848b292",
"zh:4709e81fea2b9132020d6c786a1d1d02c77254fc0e299ea1bb636892b6cadac6",
"zh:53c4a4ab59a1e0671d2292d74f14e060489482d430ad811016bf7cb95503c5de",
"zh:6c0865e514ceffbf19ace806fb4595bf05d0a165dd9c8664f8768da385ccc091",
"zh:6d72716d58b8c18cd0b223265b2a190648a14973223cc198a019b300ede07570",
"zh:a710ce90557c54396dfc27b282452a8f5373eb112a10e9fd77043ca05d30e72f",
"zh:e0868c7ac58af596edfa578473013bd550e40c0a1f6adc2c717445ebf9fd694e",
"zh:e2ab2c40631f100130e7b525e07be7a9b8d8fcb8f57f21dca235a3e15818636b",
"zh:e40c93b1d99660f92dd0c75611bcb9e68ae706d4c0bc6fac32f672e19e6f05bf",
"zh:e480501b2dd1399135ec7eb820e1be88f9381d32c4df093f2f4645863f8c48f4",
"zh:f1a71e90aa388d34691595883f6526543063f8e338792b7c2c003b2c8c63d108",
"zh:f346cd5d25a31991487ca5dc7a05e104776c3917482bc2a24ec6a90bb697b22e",
"zh:fa822a4eb4e6385e88fbb133fd63d3a953693712a7adeb371913a2d477c0148c",
]
}

View File

@@ -69,9 +69,9 @@ resource "coder_app" "qdrant" {
agent_id = coder_agent.main.id
slug = "qdrant-dashboard"
display_name = "Qdrant Dashboard"
url = "http://localhost:6333/dashboard"
url = "http://localhost:6333"
icon = "/icon/database.svg"
subdomain = true
subdomain = false # Changed from true to false
share = "owner"
order = 11
@@ -226,7 +226,30 @@ resource "coder_app" "port_forward" {
slug = "port-forward"
display_name = "Start Port Forwarding"
icon = "/icon/terminal.svg"
command = "CODER_WORKSPACE_ID=${local.workspace_id} echo '${base64encode(file("${path.module}/scripts/port-forward.sh"))}' | base64 -d | tr -d '\\r' | bash"
command = "bash -c 'echo \"Checking port forwarding status...\"; ps aux | grep -E \"socat.*6333\" | grep -v grep || echo \"No Qdrant forwarding active\"; echo; echo \"Starting port forwarding...\"; killall socat 2>/dev/null || true; if command -v socat >/dev/null 2>&1; then nohup socat TCP6-LISTEN:6333,reuseaddr,fork TCP:qdrant-${local.workspace_id}:6333 >/tmp/socat-qdrant.log 2>&1 & echo \"Port forwarding started\"; else echo \"ERROR: socat not installed\"; fi; sleep 2; echo; echo \"Testing Qdrant connection...\"; curl -f http://localhost:6333 2>/dev/null && echo \"SUCCESS: Qdrant accessible\" || echo \"FAILED: Cannot reach Qdrant\"; echo; read -p \"Press Enter to exit...\"'"
}
# Qdrant Direct Access (Alternative)
resource "coder_app" "qdrant_direct" {
count = data.coder_parameter.enable_services.value ? 1 : 0
agent_id = coder_agent.main.id
slug = "qdrant"
display_name = "Qdrant (Direct)"
url = "http://localhost:6333"
icon = "/icon/database.svg"
subdomain = false
share = "owner"
order = 12
}
# Qdrant Direct Test
resource "coder_app" "qdrant_test" {
count = data.coder_parameter.enable_services.value ? 1 : 0
agent_id = coder_agent.main.id
slug = "qdrant-test"
display_name = "Test Qdrant Access"
icon = "/icon/terminal.svg"
command = "bash -c 'echo \"Testing Qdrant access...\"; echo; echo \"1. Direct container access:\"; curl -f http://qdrant-${local.workspace_id}:6333 2>&1 | head -20; echo; echo \"2. Localhost forwarded access:\"; curl -f http://localhost:6333 2>&1 | head -20; echo; echo \"3. Socat process status:\"; ps aux | grep socat | grep -v grep || echo \"No socat processes running\"; echo; echo \"4. Socat logs:\"; tail -20 /tmp/socat-qdrant.log 2>/dev/null || echo \"No socat logs found\"; echo; read -p \"Press Enter to exit...\"'"
}
# Development Logs Viewer
@@ -238,6 +261,25 @@ resource "coder_app" "dev_logs" {
command = "bash -c 'echo \"=== Coder Agent Logs ===\"; tail -f /tmp/coder-*.log 2>/dev/null || (echo \"No Coder agent logs found in /tmp\"; echo \"Press Ctrl+C to exit log viewer\"; sleep infinity)'"
}
# Install Socat Manually
resource "coder_app" "install_socat" {
count = data.coder_parameter.enable_services.value ? 1 : 0
agent_id = coder_agent.main.id
slug = "install-socat"
display_name = "Install Socat"
icon = "/icon/terminal.svg"
command = "bash -c 'echo \"Installing socat for port forwarding...\"; if command -v apt-get >/dev/null 2>&1; then apt-get update && apt-get install -y socat && echo \"Socat installed successfully!\"; elif command -v apk >/dev/null 2>&1; then apk add --no-cache socat && echo \"Socat installed successfully!\"; else echo \"Cannot determine package manager\"; fi; echo; echo \"Starting port forwarding...\"; nohup socat TCP6-LISTEN:6333,reuseaddr,fork TCP:qdrant-${local.workspace_id}:6333 >/tmp/socat-qdrant.log 2>&1 & nohup socat TCP6-LISTEN:5050,reuseaddr,fork TCP:pgadmin-${local.workspace_id}:80 >/tmp/socat-pgadmin.log 2>&1 & echo \"Port forwarding started!\"; echo; read -p \"Press Enter to exit...\"'"
}
# Check Startup Script Logs
resource "coder_app" "startup_logs" {
agent_id = coder_agent.main.id
slug = "startup-logs"
display_name = "Startup Script Logs"
icon = "/icon/terminal.svg"
command = "bash -c 'echo \"=== Startup Script Logs ===\"; cat /tmp/startup-script.log 2>/dev/null || echo \"No startup script logs found\"; echo; echo \"=== Checking installed packages ===\"; which socat || echo \"socat: not found\"; which curl || echo \"curl: not found\"; which apt-get || echo \"apt-get: not found\"; echo; read -p \"Press Enter to exit...\"'"
}
# Git Repository Manager
resource "coder_app" "git_manager" {
agent_id = coder_agent.main.id

View File

@@ -203,43 +203,63 @@ echo 'Starting workspace with services enabled...'
# Ensure tools are in PATH
export PATH=/usr/bin:/usr/local/bin:$$PATH
# Install essential tools in background if needed
(
if command -v apt-get >/dev/null 2>&1; then
# Always update package lists first
echo "Updating package lists..."
apt-get update -qq 2>/dev/null || true
# Install all needed tools
echo "Installing essential tools..."
apt-get install -y socat ranger postgresql-client redis-tools 2>/dev/null || {
# If group install fails, try individually
apt-get install -y socat 2>/dev/null || true
apt-get install -y ranger 2>/dev/null || true
apt-get install -y postgresql-client 2>/dev/null || true
apt-get install -y redis-tools 2>/dev/null || true
}
elif command -v apk >/dev/null 2>&1; then
# Alpine Linux
apk add --no-cache socat ranger postgresql-client redis 2>/dev/null || true
fi
) &
# Install essential tools - run synchronously to avoid conflicts
echo "Installing essential tools for port forwarding..."
# Start port forwarding after a delay to ensure socat is installed
(sleep 10 && {
if command -v socat >/dev/null 2>&1; then
echo "Starting port forwarding..."
if [ "${data.coder_parameter.enable_pgadmin.value}" = "true" ]; then
echo 'Forwarding pgAdmin (localhost:5050 -> pgadmin-${local.workspace_id}:80)...'
nohup socat TCP-LISTEN:5050,reuseaddr,fork TCP:pgadmin-${local.workspace_id}:80 >/tmp/socat-pgadmin.log 2>&1 &
if command -v apt-get >/dev/null 2>&1; then
# Wait for any existing APT operations to complete
echo "Checking APT availability..."
# Try up to 12 times with 5 second delays (60 seconds total)
for i in 1 2 3 4 5 6 7 8 9 10 11 12; do
if ! fuser /var/lib/dpkg/lock-frontend >/dev/null 2>&1; then
echo "APT is available"
break
fi
echo 'Forwarding Qdrant (localhost:6333 -> qdrant-${local.workspace_id}:6333)...'
nohup socat TCP-LISTEN:6333,reuseaddr,fork TCP:qdrant-${local.workspace_id}:6333 >/tmp/socat-qdrant.log 2>&1 &
echo "Port forwarding started"
else
echo "Socat not available yet, port forwarding skipped"
echo "Waiting for APT to become available... attempt $$i of 12"
sleep 5
done
# Now install our tools
echo "Updating package lists..."
apt-get update -qq || true
echo "Installing socat for port forwarding..."
# Retry socat installation if it fails
for attempt in 1 2 3; do
if apt-get install -y socat 2>/dev/null; then
echo "Socat installed successfully"
break
else
echo "Failed to install socat (attempt $$attempt), retrying..."
sleep 5
fi
done
echo "Installing other tools..."
apt-get install -y ranger postgresql-client redis-tools || echo "Some tools failed to install"
elif command -v apk >/dev/null 2>&1; then
# Alpine Linux
apk add --no-cache socat ranger postgresql-client redis || true
fi
# Start port forwarding only after tools are installed
echo "Setting up port forwarding..."
if command -v socat >/dev/null 2>&1; then
echo "Starting port forwarding..."
if [ "${data.coder_parameter.enable_pgadmin.value}" = "true" ]; then
echo 'Forwarding pgAdmin (localhost:5050 -> pgadmin-${local.workspace_id}:80)...'
nohup socat TCP-LISTEN:5050,reuseaddr,fork TCP:pgadmin-${local.workspace_id}:80 >/tmp/socat-pgadmin.log 2>&1 &
fi
}) &
echo 'Forwarding Qdrant (localhost:6333 -> qdrant-${local.workspace_id}:6333)...'
nohup socat TCP6-LISTEN:6333,reuseaddr,fork TCP:qdrant-${local.workspace_id}:6333 >/tmp/socat-qdrant.log 2>&1 &
echo "Port forwarding started"
else
echo "Warning: socat not available, port forwarding cannot start"
echo "You may need to manually install socat and restart port forwarding"
fi
echo 'Workspace startup initiated.'
SCRIPT

View File

@@ -33,8 +33,13 @@ install_package() {
local package="$1"
case "$SYSTEM" in
"debian")
apt-get update >/dev/null 2>&1 || true
apt-get install -y "$package"
# Check if APT is locked before attempting
if fuser /var/lib/dpkg/lock-frontend >/dev/null 2>&1; then
echo "⚠️ APT is locked by another process, skipping $package installation"
else
apt-get update >/dev/null 2>&1 || true
apt-get install -y "$package" 2>&1 || echo "⚠️ Failed to install $package"
fi
;;
"rhel")
yum install -y "$package" || dnf install -y "$package"
@@ -190,10 +195,15 @@ install_development_tools() {
echo "📊 Installing btop..."
case "$SYSTEM" in
"debian")
# Try to install btop, fallback to htop if not available
if ! $SUDO_CMD apt-get install -y btop 2>/dev/null; then
echo " btop not available in repos, htop is installed as alternative"
$SUDO_CMD apt-get install -y htop 2>/dev/null || true
# Check if APT is locked
if fuser /var/lib/dpkg/lock-frontend >/dev/null 2>&1; then
echo " APT is locked, skipping btop/htop installation"
else
# Try to install btop, fallback to htop if not available
if ! $SUDO_CMD apt-get install -y btop 2>/dev/null; then
echo " btop not available in repos, installing htop as alternative"
$SUDO_CMD apt-get install -y htop 2>/dev/null || true
fi
fi
;;
"macos") install_package btop ;;

View File

@@ -185,11 +185,33 @@ install_system_packages() {
# Install packages based on privileges
echo "📦 Installing system packages..."
# Add initial delay to let port forwarding script run first
if [[ "$SYSTEM" == "debian" ]]; then
echo "📦 Waiting for initial system setup to complete..."
sleep 30
fi
if [[ "$EUID" -eq 0 ]]; then
# Running as root, no sudo needed
case "$SYSTEM" in
"debian")
export DEBIAN_FRONTEND=noninteractive
# Simple wait for APT to be available
echo "📦 Waiting for other package managers to finish..."
retries=0
max_retries=30
while [ $retries -lt $max_retries ]; do
if ! (fuser /var/lib/apt/lists/lock >/dev/null 2>&1 || fuser /var/lib/dpkg/lock >/dev/null 2>&1 || fuser /var/lib/dpkg/lock-frontend >/dev/null 2>&1); then
break
fi
echo "APT is locked, waiting... ($retries/$max_retries)"
sleep 2
retries=$((retries + 1))
done
echo "📦 Updating package lists..."
apt-get update 2>&1 | grep -v "^Get:" | grep -v "^Hit:" || true
echo "📦 Installing core packages..."

View File

@@ -40,7 +40,7 @@ resource "coder_agent" "main" {
}
# Reference bind-mounted startup script plus service port forwarding
startup_script = data.coder_parameter.enable_services.value ? "echo '${base64encode(local.port_forward_script)}' | base64 -d | tr -d '\\r' | bash" : "echo 'Starting workspace...'"
startup_script = data.coder_parameter.enable_services.value ? "echo '${base64encode(local.port_forward_script)}' | base64 -d | tr -d '\\r' | bash 2>&1 | tee /tmp/startup-script.log" : "echo 'Starting workspace...'"
# Performance and resource monitoring
metadata {