generated from TBD54566975/tbd-project-template
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b02c014
commit e52b793
Showing
5 changed files
with
71 additions
and
13 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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,50 @@ | ||
package dev | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/alecthomas/types/optional" | ||
|
||
"github.com/TBD54566975/ftl/internal/container" | ||
"github.com/TBD54566975/ftl/internal/log" | ||
) | ||
|
||
const ftlGrafanaName = "ftl-grafana-1" | ||
|
||
func SetupGrafana(ctx context.Context, image string) error { | ||
logger := log.FromContext(ctx) | ||
|
||
exists, err := container.DoesExist(ctx, ftlGrafanaName, optional.Some(image)) | ||
if err != nil { | ||
return fmt.Errorf("failed to check if container exists: %w", err) | ||
} | ||
// check if port is already in use | ||
ports := []int{3000, 9090, 4317, 4318} | ||
|
||
if !exists { | ||
logger.Debugf("Creating docker container '%s' for grafana", ftlGrafanaName) | ||
|
||
err = container.Run(ctx, image, ftlGrafanaName, map[int]int{3000: 3000, 9090: 9090, 4317: 4317, 4318: 4318}, optional.None[string]()) | ||
if err != nil { | ||
return fmt.Errorf("failed to run grafana container: %w", err) | ||
} | ||
|
||
} else { | ||
// Start the existing container | ||
err = container.Start(ctx, ftlGrafanaName) | ||
if err != nil { | ||
return fmt.Errorf("failed to start existing registry container: %w", err) | ||
} | ||
|
||
logger.Debugf("Reusing existing docker container %s for grafana", ftlGrafanaName) | ||
} | ||
|
||
for _, port := range ports { | ||
err = WaitForPortReady(ctx, port) | ||
if err != nil { | ||
return fmt.Errorf("registry container failed to be healthy: %w", err) | ||
} | ||
} | ||
return nil | ||
} |
This file contains 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