Async deploy pipeline + port recycling + central config#43
Open
atharv10032 wants to merge 1 commit into
Open
Conversation
- Submit returns 202 with deploymentID; client polls GET /projects/:id. Bounded goroutine pool (8) with panic recovery so build/run can take minutes without HTTP timeouts. - Port allocator: reuses pooled Mongo client (was open-per-call), atomic InsertOne with unique index (was racy upsert), recycle pool via db.ReleasePort on delete (was permanently watermarked). - Fix DeleteProjectByContainerName field name: containername -> container_name (was silently no-op, leaving orphan project docs). - New internal/config package loads .env once at startup via sync.Once. Removed duplicate godotenv.Load from utils/jwt.go and utils/port_manager.go's init(). - FUTURE comments added for follow-up items (docker bind cleanup, double AuthorizePort, clone-path race, GH callback nil panic, hardcoded localhost redirect, Go Dockerfile template, containerName collision, signup validation). Co-Authored-By: Claude Opus 4.7 <[email protected]>
Ashmit-Kumar
approved these changes
Jun 6, 2026
Ashmit-Kumar
approved these changes
Jun 6, 2026
Ashmit-Kumar
left a comment
Owner
There was a problem hiding this comment.
LGTM. Next: Fix the auth module
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Three related changes to make the deploy flow correct under real-world conditions:
POST /projects/submitreturns202 {deploymentID, status: "pending"}immediately; the build runs in a detached goroutine with a bounded worker pool (8 concurrent) and panic recovery. Clients pollGET /projects/:id(auth-scoped) for state. Running the build inline was timing out browsers / proxies on real repos (docker build + Azure NSG poll runs into minutes).db.GetCollection's pooled Mongo client (was opening + tearing down a freshmongo.Connect/Disconnectper allocation).InsertOneagainst a unique index onports.port(replaces the upsert-with-$setOnInsertthat could silently let two concurrent claims both think they won).DELETE /projects/:containerNamenow actually frees the port viadb.ReleasePort, and allocation tries the recycle pool (lowest available first) before the watermark scan.DeleteProjectByContainerNamequery:containername→container_nameto match theProjectstruct's bson tag (the old form never matched, silently orphaning project docs).internal/configpackage loads.envexactly once at startup viasync.Once. Removed the duplicategodotenv.Loadcalls fromutils/jwt.goandutils/port_manager.go'sinit()(which ran beforemain.go's load and read empty env vars).Breaking change for the client
POST /projects/submitblocked for minutes, returned200 {url}.POST /projects/submitreturns202 {deploymentID, status: "pending"}. Client pollsGET /projects/:iduntilstatusissucceeded(readhosted_url) orfailed(readdeploy_error).autoship-clientside is intentionally out of scope here; will follow in a separate PR.Operator notes (one-time, before bringing this build up)
db.EnsurePortsIndexwill fail at startup if the existing ports collection has duplicateportvalues (a remnant of the prior buggy upsert). Either drop the collection (loses existing reservations) or dedupe in place before deploying.Test plan
go build ./...andgo vet ./...green locallysucceeded, hit Blob URLdeploying → succeeded, hit hosted URLstatus: "available"and Project doc is goneCLOUD_PROVIDER=awsKnown follow-ups (FUTURE comments in code)
Pointers for the next pass:
services/dynamic.gonearfinalCmd.Run()— docker bind failure leaves a phantom port reservation; needsbound bool+ deferdb.ReleasePort.services/dynamic.goline ~227 —cloud.Get().AuthorizePort(hostPort)redundant afterGetOrReserveValidFreePortalready authorized internally (Azure NSG poll wastes ~10-30s).services/clone.go— clone pathstatic/<user>/<repo>has no deploy id; concurrent same-repo deploys race on the same dir.api/auth.goGitHubCallback —userInfo["login"].(string)panics if login is missing/non-string.api/auth.goGitHubCallback — hardcodedhttp://localhost:3000/dashboardredirect; needsFRONTEND_URLenv var for prod.services/dynamic.goGo branch ofGenerateDockerfile—installCmdbuildsappthenCMDruns whatever startCommand says; incoherent for Go projects.services/dynamic.gocontainerName—time.Now().Unix()is seconds-resolution; same-repo deploys landing in same second collide.api/auth.goSignup — no input validation; empty email/password create unusable user.🤖 Generated with Claude Code