Skip to content

Commit

Permalink
add build-dev function to dagger
Browse files Browse the repository at this point in the history
- This adds development server for ground control
- This commit only focuses on setting the dev server for ground-control
- Dagger has a known limitation for hot reloading dev servers.
- limitation issue in dagger
(dagger/dagger#6990)

Signed-off-by: bupd <[email protected]>
  • Loading branch information
bupd committed Nov 4, 2024
1 parent 8e168aa commit 9dcfc66
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 0 deletions.
13 changes: 13 additions & 0 deletions .air.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[build]
bin = "main"
dir = "."
cmd = "go build -o main ."
exclude_dir = ["assets", "tmp", "vendor", "testdata"]
exclude_regex = ["_test.go"]
exclude_unchanged = false
follow_symlink = false
run_after_build = "chmod +x main"
include_ext = ["go"]

[log]
level = "debug"
36 changes: 36 additions & 0 deletions ci/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,42 @@ const (

type HarborSatellite struct{}

// build-dev function would start the dev server for the component provided.
func (m *HarborSatellite) BuildDev(
ctx context.Context,
// +optional
// +defaultPath="./ground-control"
source *dagger.Directory,
component string,
) (*dagger.Service, error) {
if component == "satellite" || component == "ground-control" {
golang := dag.Container().
From("golang:latest").
WithMountedCache("/go/pkg/mod", dag.CacheVolume("go-mod")).
WithEnvVariable("GOMODCACHE", "/go/pkg/mod").
WithMountedCache("/go/build-cache", dag.CacheVolume("go-build")).
WithEnvVariable("GOCACHE", "/go/build-cache").
WithMountedDirectory(PROJ_MOUNT, source).
WithWorkdir(PROJ_MOUNT).
WithExec([]string{"go", "install", "github.com/air-verse/air@latest"})

if component == "ground-control" {
golang = golang.
WithExec([]string{"ls", "-la"}).
// WithWorkdir("./ground-control/").
// WithExec([]string{"go", "mod", "download"}).
WithExec([]string{"ls", "-la"}).
WithExec([]string{"air", "-c", ".air.toml"}).
WithExposedPort(8080)
}
// to-do: build else part for the satellite

return golang.AsService(), nil
}

return nil, fmt.Errorf("error: please provide component as either satellite or ground-control")
}

// Build function would start the build process for the name provided. Source should be the path to the main.go file.
func (m *HarborSatellite) Build(
ctx context.Context,
Expand Down
13 changes: 13 additions & 0 deletions ground-control/.air.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[build]
bin = "main"
dir = "."
cmd = "go build -o main ."
exclude_dir = ["assets", "tmp", "vendor", "testdata"]
exclude_regex = ["_test.go"]
exclude_unchanged = false
follow_symlink = false
run_after_build = "chmod +x main"
include_ext = ["go"]

[log]
level = "debug"

0 comments on commit 9dcfc66

Please sign in to comment.