Skip to content

Commit

Permalink
Add: Dagger integration for building and running Harbor Satellite
Browse files Browse the repository at this point in the history
Signed-off-by: bupd <bupdprasanth@gmail.com>
  • Loading branch information
bupd committed Jun 19, 2024
1 parent 6117b2b commit 55e0ba3
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
42 changes: 42 additions & 0 deletions ci/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ package main

import (
"context"
"log"
"log/slog"
"os"
"path/filepath"

"dagger.io/dagger"
)
Expand Down Expand Up @@ -38,4 +40,44 @@ func main() {
}
// print output
slog.Info("Hello from Dagger!", "version", version)

buildSatellite(client, ctx)
}

// buildSatellite builds and runs the Satellite service
func buildSatellite(client *dagger.Client, ctx context.Context) {
slog.Info("Starting the Satellite build process...")

// Get the directory of project located one level up from the current working directory
parentDir, err := getProjectDir()
if err != nil {
log.Fatalf("Error getting parent directory: %v", err)
}

// Use the parent directory path in Dagger
dir := client.Host().Directory(parentDir)

// Configure and build the container
container := client.Container().
From(imageVersion).
WithDirectory(appDir, dir).
WithWorkdir(appDir).
WithExec([]string{"go", "build", "-o", appBinary, sourceFile}).
WithExposedPort(containerPort).
WithExec([]string{"./" + appBinary})

// Start the service
_, err = container.AsService().Start(ctx)
if err != nil {
log.Fatalf("Error starting the Satellite service: %v", err)
}
}

// getProjectDir gets the directory of the project
func getProjectDir() (string, error) {
currentDir, err := os.Getwd()
if err != nil {
return "", err
}
return filepath.Dir(currentDir), nil
}
4 changes: 3 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ func run() error {
Addr: ":9090",
Handler: mux,
}

fmt.Println("program running on port 9090")

g.Go(func() error {
if err := metricsSrv.ListenAndServe(); err != nil && !errors.Is(err, http.ErrServerClosed) {
return err
Expand Down Expand Up @@ -105,7 +108,6 @@ func run() error {
cancel()
return err
}

})
}

Expand Down

0 comments on commit 55e0ba3

Please sign in to comment.