From 9dcfc664b42ef59a5879cc8a8882e49be6137654 Mon Sep 17 00:00:00 2001 From: bupd Date: Mon, 4 Nov 2024 19:14:58 +0530 Subject: [PATCH] add build-dev function to dagger - 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 (https://github.com/dagger/dagger/issues/6990) Signed-off-by: bupd --- .air.toml | 13 +++++++++++++ ci/main.go | 36 ++++++++++++++++++++++++++++++++++++ ground-control/.air.toml | 13 +++++++++++++ 3 files changed, 62 insertions(+) create mode 100644 .air.toml create mode 100644 ground-control/.air.toml diff --git a/.air.toml b/.air.toml new file mode 100644 index 0000000..e03ed91 --- /dev/null +++ b/.air.toml @@ -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" diff --git a/ci/main.go b/ci/main.go index fd6ca31..21add26 100644 --- a/ci/main.go +++ b/ci/main.go @@ -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, diff --git a/ground-control/.air.toml b/ground-control/.air.toml new file mode 100644 index 0000000..e03ed91 --- /dev/null +++ b/ground-control/.air.toml @@ -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"