Repository navigation
chore: Init executor service #292
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
SuvabrataChowdhury
wants to merge
43
commits into
main
Choose a base branch
from
init-executor-service
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
43 commits
Select commit
Hold shift + click to select a range
0bb9231
init http based execution
SuvabrataChowdhury 59cf0d6
updated executor service doc
SuvabrataChowdhury 53ef008
service taking inputs and little refactoring
SuvabrataChowdhury 568bd0f
working pipeline execution
SuvabrataChowdhury 6d0b16d
init state transition
SuvabrataChowdhury cd974e5
correct state transitions
SuvabrataChowdhury 8b2f93f
Merge branch 'main' into init-executor-service
SuvabrataChowdhury 396b2ba
refactorings
SuvabrataChowdhury 430bd81
profile based startup
SuvabrataChowdhury 0538ae3
refactoring main.go
SuvabrataChowdhury f9bcf3c
Merge branch 'main' into init-executor-service
SuvabrataChowdhury 9c4f4a8
refactoring handlers
SuvabrataChowdhury 673b8b7
valid handler reorg
SuvabrataChowdhury 084a732
correct state transitions
SuvabrataChowdhury 5c015ae
Valid uuid per builds
SuvabrataChowdhury f8cc53f
Build entities introduction
SuvabrataChowdhury b58700c
persisting builds
SuvabrataChowdhury 6904fbb
added .gitignore for go service
SuvabrataChowdhury 81d5b21
added all build read endpoints in go service
SuvabrataChowdhury 9503780
Merge branch 'main' into init-executor-service
SuvabrataChowdhury 5635b68
Refactored DB config
SuvabrataChowdhury 0f0dc6c
refactoring handlers for better dependency injection
SuvabrataChowdhury e2ea8fb
service extraction and correct schema
SuvabrataChowdhury 4ee26b9
refactoring the existing executor
SuvabrataChowdhury 3af8000
Merge branch 'main' into init-executor-service
SuvabrataChowdhury bd1231c
refactorings and formattings
SuvabrataChowdhury 71cb567
refactored the runner into it's own type
SuvabrataChowdhury b39878e
formattings
SuvabrataChowdhury 20dd695
rename of daggerRunner
SuvabrataChowdhury 46e29f1
logs to files per stage completions
SuvabrataChowdhury 4e7d7cf
Error logs to log file
SuvabrataChowdhury 5acad2e
added stage logs endpoint
SuvabrataChowdhury 47d7f47
binding to localhost
SuvabrataChowdhury e14a3bf
getting rid of magic numbers with proper comments
SuvabrataChowdhury f0f5a97
json error writer
SuvabrataChowdhury 363f696
json body writer
SuvabrataChowdhury 3e1560d
removed log field from dto
SuvabrataChowdhury 6d9b029
validations and exit on failure
SuvabrataChowdhury e3d5a4b
empty logs for failed stage
SuvabrataChowdhury edc43a0
logging log write errors
SuvabrataChowdhury ef66b5d
don't delete in progress builds
SuvabrataChowdhury 7e7b400
added future todos
SuvabrataChowdhury 2504e54
doc strings and claude skills to generate such doc strings
SuvabrataChowdhury File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| --- | ||
| name: add-go-docstrings | ||
| description: Add Go doc comments to exported Go symbols. Use when creating or updating exported types, functions, methods, or constant blocks in the AutoBuild executor Go module that lack doc comments. | ||
| metadata: | ||
| version: "1.0" | ||
| language: go | ||
| --- | ||
|
|
||
| # Add Go Doc Comments | ||
|
|
||
| Prepend a Go-style doc comment (`// SymbolName ...`) directly above any exported Go symbol (type, function, method, or constant block) that lacks one. | ||
|
|
||
| ## Rules | ||
| - **Format:** Start the comment with the exact symbol name (`// SymbolName ...`). | ||
| - **Length:** Keep it to one or two sentences covering what the symbol does, plus any notable preconditions or return values. | ||
| - **Scope:** Apply to all `.go` files under the AutoBuild executor module. | ||
|
|
||
| ## Do Not Comment | ||
| - Unexported symbols, unless the logic is non-obvious. | ||
| - Struct fields (document them in the type-level doc comment instead). | ||
| - Generated files. |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ../.agents/skills |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| TestRequests/* |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| EXECUTOR_PORT=8080 | ||
|
|
||
| EXECUTOR_DB_DSN="autobuild.db" |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| autobuild.db |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| # Executor Go Module | ||
|
|
||
| ## Prod like execution | ||
| Script to startup dagger | ||
|
|
||
| ```sh | ||
| docker run \ | ||
| --name dagger-engine \ | ||
| --privileged \ | ||
| -p 8081:8081 \ | ||
| -e DAGGER_ENGINE_PORT=8081 \ | ||
| -v dagger-engine-cache:/var/lib/dagger \ | ||
| --restart unless-stopped \ | ||
| registry.dagger.io/engine:v0.21.11 | ||
| ``` | ||
|
|
||
| Script to start go service | ||
|
|
||
| ```sh | ||
| _EXPERIMENTAL_DAGGER_RUNNER_HOST=tcp://localhost:8081 EXECUTOR_PROFILE=local go run main.go | ||
| ``` | ||
|
|
||
| ## Local Execution | ||
|
|
||
| ```sh | ||
| EXECUTOR_PROFILE=local go run main.go | ||
| ``` | ||
|
|
||
| No separate dagger service is required as it will fallback to starting it's own container. | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| package config | ||
|
|
||
| import ( | ||
| "log" | ||
| "os" | ||
| "slices" | ||
|
|
||
| "github.com/joho/godotenv" | ||
| ) | ||
|
|
||
| var validProfiles = [1]string{"local"} | ||
|
|
||
| // LoadProfile loads the environment variables for the given application profile. | ||
| // The profile is read from the EXECUTOR_PROFILE environment variable. | ||
| // Valid profiles are defined in validProfiles. The corresponding .env.<profile> file is loaded via godotenv. | ||
| func LoadProfile() { | ||
| appProfile := os.Getenv("EXECUTOR_PROFILE") | ||
|
|
||
| if appProfile == "" || !slices.Contains(validProfiles[:], appProfile) { | ||
| log.Fatal("Please pass along a valid application profile") | ||
| } | ||
|
|
||
| envFile := ".env." + appProfile | ||
| err := godotenv.Load(envFile) | ||
| if err != nil { | ||
| log.Fatal("Error ocurred while loading env file: ", envFile) | ||
| } | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| package config | ||
|
|
||
| import ( | ||
| "net/http" | ||
| "os" | ||
| "time" | ||
| ) | ||
|
|
||
| // InitServer creates and returns an HTTP server bound to localhost on the port | ||
| // specified by the EXECUTOR_PORT environment variable. | ||
| func InitServer(mux *http.ServeMux) (string, *http.Server) { | ||
| // Configure server settings explicitly | ||
| serverAddr := "127.0.0.1:" + os.Getenv("EXECUTOR_PORT") | ||
| // 10s: GitHub webhook spec requires a 2XX response within 10s or the delivery is marked failed | ||
| const maxOpsTime = 10 * time.Second | ||
|
|
||
| server := &http.Server{ | ||
| Addr: serverAddr, | ||
| Handler: mux, | ||
| ReadTimeout: maxOpsTime, | ||
| WriteTimeout: maxOpsTime, | ||
| MaxHeaderBytes: 1 << 20, // 1 MB: matches Go's http.DefaultMaxHeaderBytes | ||
| } | ||
| return serverAddr, server | ||
| } |
|
SuvabrataChowdhury marked this conversation as resolved.
Resolved
|
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| package dto | ||
|
|
||
| import "github.com/google/uuid" | ||
|
|
||
| // StageBuildDTO represents the execution state of a single stage within a pipeline build. | ||
| type StageBuildDTO struct { | ||
| Id uuid.UUID `json:"id"` | ||
|
|
||
| StageId uuid.UUID `json:"stageId"` | ||
|
|
||
| StageName string `json:"stageName"` | ||
|
|
||
| StageOrder int `json:"stageOrder"` | ||
|
|
||
| CurrentState StageExecutionState `json:"stageExecutionState"` | ||
| } | ||
|
|
||
| // PipelineBuildDTO represents the execution state of a full pipeline run, including all its stage builds. | ||
| type PipelineBuildDTO struct { | ||
| Id uuid.UUID `json:"id"` | ||
|
|
||
| PipelineId uuid.UUID `json:"pipelineId"` | ||
|
|
||
| PipelineName string `json:"pipelineName"` | ||
|
|
||
| CurrentState PipelineExecutionState `json:"currentState"` | ||
|
|
||
| StageBuilds []StageBuildDTO `json:"stageBuilds"` | ||
| } | ||
|
|
||
| // StageDTO carries the definition of a single pipeline stage as received from the caller. | ||
| type StageDTO struct { | ||
| Id uuid.UUID `json:"id"` | ||
|
|
||
| Name string `json:"name"` | ||
|
|
||
| ScriptType string `json:"scriptType"` | ||
|
|
||
| Command string `json:"command"` | ||
|
|
||
| StageOrder int `json:"stageOrder"` | ||
| } | ||
|
|
||
| // PipelineDTO carries the definition of a pipeline and its ordered stages as received from the caller. | ||
| type PipelineDTO struct { | ||
| Id uuid.UUID `json:"id"` | ||
|
|
||
| Name string `json:"name"` | ||
|
|
||
| Stages []StageDTO `json:"stages"` | ||
| } |
|
SuvabrataChowdhury marked this conversation as resolved.
Resolved
|
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| package dto | ||
|
|
||
| // StageExecutionState represents the lifecycle state of an individual stage build. | ||
| type StageExecutionState string | ||
|
|
||
| const ( | ||
| StageWaiting StageExecutionState = "WAITING" | ||
| StageRunning StageExecutionState = "RUNNING" | ||
| StageSuccess StageExecutionState = "SUCCESS" | ||
| StageFailed StageExecutionState = "FAILED" | ||
| StageStopped StageExecutionState = "STOPPED" | ||
| ) | ||
|
|
||
|
|
||
| // PipelineExecutionState represents the lifecycle state of a pipeline build. | ||
| type PipelineExecutionState string | ||
|
|
||
| const ( | ||
| PipelineWaiting PipelineExecutionState = "WAITING" | ||
| PipelineRunning PipelineExecutionState = "RUNNING" | ||
| PipelineSuccess PipelineExecutionState = "SUCCESS" | ||
| PipelineFailed PipelineExecutionState = "FAILED" | ||
| ) | ||
|
|
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| package entity | ||
|
|
||
| import ( | ||
| "github.com/google/uuid" | ||
| "gorm.io/gorm" | ||
| ) | ||
|
|
||
| // PipelineExecutionState represents the lifecycle state of a pipeline build record. | ||
| type PipelineExecutionState string | ||
|
|
||
| const ( | ||
|
SuvabrataChowdhury marked this conversation as resolved.
Resolved
|
||
| PipelineWaiting PipelineExecutionState = "WAITING" | ||
| PipelineRunning PipelineExecutionState = "RUNNING" | ||
| PipelineSuccess PipelineExecutionState = "SUCCESS" | ||
| PipelineFailed PipelineExecutionState = "FAILED" | ||
| ) | ||
|
|
||
| // StageExecutionState represents the lifecycle state of an individual stage build record. | ||
| type StageExecutionState string | ||
|
|
||
| const ( | ||
| StageWaiting StageExecutionState = "WAITING" | ||
| StageRunning StageExecutionState = "RUNNING" | ||
| StageSuccess StageExecutionState = "SUCCESS" | ||
| StageFailed StageExecutionState = "FAILED" | ||
| StageStopped StageExecutionState = "STOPPED" | ||
| ) | ||
|
|
||
| // StageBuild is the GORM entity that persists the execution record of a single pipeline stage. | ||
| type StageBuild struct { | ||
| ID uuid.UUID `gorm:"type:uuid;primaryKey"` | ||
| StageID uuid.UUID `gorm:"type:uuid;not null;column:stage_id"` | ||
| StageName string `gorm:"type:varchar(255);not null;column:stage_name"` | ||
| CurrentState StageExecutionState `gorm:"type:varchar(20);not null;column:stage_build_current_state;default:WAITING"` | ||
| StageOrder int `gorm:"not null;column:stage_order"` | ||
| LogPath string `gorm:"not null;column:log_path"` | ||
| } | ||
|
|
||
| func (s *StageBuild) BeforeCreate(tx *gorm.DB) error { | ||
| if s.ID == uuid.Nil { | ||
| s.ID = uuid.New() | ||
| } | ||
| if s.CurrentState == "" { | ||
| s.CurrentState = StageWaiting | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| // PipelineStageBuild is the join-table entity that links a PipelineBuild to its StageBuild records. | ||
| type PipelineStageBuild struct { | ||
| PipelineBuildID uuid.UUID `gorm:"type:uuid;primaryKey;column:pipeline_build_id;constraint:OnDelete:CASCADE;"` | ||
| StageBuildID uuid.UUID `gorm:"type:uuid;primaryKey;column:stage_build_id;constraint:OnDelete:CASCADE;"` | ||
| } | ||
|
|
||
| // PipelineBuild is the GORM entity that persists the execution record of a full pipeline run. | ||
| type PipelineBuild struct { | ||
| ID uuid.UUID `gorm:"type:uuid;primaryKey"` | ||
| PipelineID uuid.UUID `gorm:"type:uuid;not null;column:pipeline_id"` | ||
| PipelineName string `gorm:"type:varchar(255);not null;column:pipeline_name"` | ||
| StageBuilds []StageBuild `gorm:"many2many:pipeline_stage_builds;joinForeignKey:PipelineBuildID;joinReferences:StageBuildID"` | ||
| CurrentState PipelineExecutionState `gorm:"type:varchar(20);not null;column:pipeline_build_current_state;default:WAITING"` | ||
| } | ||
|
|
||
| func (p *PipelineBuild) BeforeCreate(tx *gorm.DB) error { | ||
| if p.ID == uuid.Nil { | ||
| p.ID = uuid.New() | ||
| } | ||
| if p.CurrentState == "" { | ||
| p.CurrentState = PipelineWaiting | ||
| } | ||
| return nil | ||
| } | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| package customerror | ||
|
|
||
| // InvalidOperationError is returned when an operation is not permitted given the current state of a resource. | ||
| type InvalidOperationError struct { | ||
| Message string | ||
| } | ||
|
|
||
| func (e *InvalidOperationError) Error() string { | ||
| return e.Message | ||
| } | ||
|
|
||
| // NewInvalidOperationError creates an InvalidOperationError with the given message. | ||
| func NewInvalidOperationError(msg string) *InvalidOperationError { | ||
| return &InvalidOperationError{Message: msg} | ||
| } | ||
|
|
||
| func (e *InvalidOperationError) Is(target error) bool { | ||
| _, ok := target.(*InvalidOperationError) | ||
| return ok | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| package customerror | ||
|
|
||
| // NotFoundError is returned when a requested resource does not exist. | ||
| type NotFoundError struct { | ||
| Message string | ||
| } | ||
|
|
||
| func (e *NotFoundError) Error() string { | ||
| return e.Message | ||
| } | ||
|
|
||
| // NewNotFoundError creates a NotFoundError with the given message. | ||
| func NewNotFoundError(msg string) *NotFoundError { | ||
| return &NotFoundError{Message: msg} | ||
| } | ||
|
|
||
| // Is allows errors.Is() to match any *NotFoundError regardless of Message value. | ||
| func (e *NotFoundError) Is(target error) bool { | ||
| _, ok := target.(*NotFoundError) | ||
| return ok | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| module github.com/AutoBuilders/AutoBuild/executor | ||
|
|
||
| go 1.27.3 | ||
|
|
||
| require ( | ||
| dagger.io/dagger v0.21.11 | ||
| github.com/google/uuid v1.6.0 | ||
| github.com/joho/godotenv v1.5.1 | ||
| gorm.io/driver/sqlite v1.6.0 | ||
| gorm.io/gorm v1.31.2 | ||
| ) | ||
|
|
||
| require ( | ||
| github.com/99designs/gqlgen v0.17.89 // indirect | ||
| github.com/Khan/genqlient v0.8.1 // indirect | ||
| github.com/adrg/xdg v0.5.3 // indirect | ||
| github.com/cespare/xxhash/v2 v2.3.0 // indirect | ||
| github.com/dagger/querybuilder v0.0.0-20260402040506-574a5e81cb59 // indirect | ||
| github.com/go-logr/logr v1.4.3 // indirect | ||
| github.com/go-logr/stdr v1.2.2 // indirect | ||
| github.com/jinzhu/inflection v1.0.0 // indirect | ||
| github.com/jinzhu/now v1.1.5 // indirect | ||
| github.com/mattn/go-sqlite3 v1.14.22 // indirect | ||
| github.com/mitchellh/go-homedir v1.1.0 // indirect | ||
| github.com/sosodev/duration v1.4.0 // indirect | ||
| github.com/vektah/gqlparser/v2 v2.5.32 // indirect | ||
| go.opentelemetry.io/auto/sdk v1.2.1 // indirect | ||
| go.opentelemetry.io/otel v1.43.0 // indirect | ||
| go.opentelemetry.io/otel/metric v1.43.0 // indirect | ||
| go.opentelemetry.io/otel/trace v1.43.0 // indirect | ||
| golang.org/x/sync v0.20.0 // indirect | ||
| golang.org/x/sys v0.42.0 // indirect | ||
| golang.org/x/text v0.34.0 // indirect | ||
| ) |
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The documented engine command does not open the TCP port used on line 20.
DAGGER_ENGINE_PORT=8081does not set the engine listener. The engine entrypoint does not read that variable. The command passes no--addrargument. The service therefore connects totcp://localhost:8081with no listener behind it, and the prod-like startup path can fail to connect. Pass the listener address after the image name:Add the listener address to the engine command
The local-execution command on line 26 does not use this container and is unaffected.