diff --git a/pkg/constants/constants.go b/pkg/constants/constants.go index b81635e70..fd6a6d6b0 100644 --- a/pkg/constants/constants.go +++ b/pkg/constants/constants.go @@ -6,8 +6,8 @@ import "time" const ( // renovate: datasource=docker depName=ghcr.io/windsorcli/git-livereload-server DEFAULT_GIT_LIVE_RELOAD_IMAGE = "ghcr.io/windsorcli/git-livereload:v0.2.0" - DEFAULT_GIT_LIVE_RELOAD_RSYNC_INCLUDE = "" - DEFAULT_GIT_LIVE_RELOAD_RSYNC_EXCLUDE = ".windsor,.terraform,data,.volumes,.venv" + DEFAULT_GIT_LIVE_RELOAD_RSYNC_INCLUDE = "kustomize" + DEFAULT_GIT_LIVE_RELOAD_RSYNC_EXCLUDE = ".windsor,.terraform,.volumes,.venv" DEFAULT_GIT_LIVE_RELOAD_RSYNC_PROTECT = "flux-system" DEFAULT_GIT_LIVE_RELOAD_USERNAME = "local" DEFAULT_GIT_LIVE_RELOAD_PASSWORD = "local" diff --git a/pkg/services/git_livereload_service.go b/pkg/services/git_livereload_service.go index c5ac1a389..99201338a 100644 --- a/pkg/services/git_livereload_service.go +++ b/pkg/services/git_livereload_service.go @@ -38,12 +38,12 @@ func NewGitLivereloadService(injector di.Injector) *GitLivereloadService { // Public Methods // ============================================================================= -// GetComposeConfig returns the top-level compose configuration including a list of container data for docker-compose. +// GetComposeConfig constructs and returns a docker-compose configuration for the GitLivereloadService. +// It retrieves configuration values for environment variables, image, and service metadata from the config handler. +// The method builds the environment variable map, sets up service labels, and binds the project root as a volume. +// Returns a types.Config pointer containing the service definition, or an error if the project root cannot be determined. func (s *GitLivereloadService) GetComposeConfig() (*types.Config, error) { - // Get the context name contextName := s.configHandler.GetContext() - - // Retrieve environment variables from config with defaults using Get* functions rsyncInclude := s.configHandler.GetString("git.livereload.rsync_include", constants.DEFAULT_GIT_LIVE_RELOAD_RSYNC_INCLUDE) rsyncExclude := s.configHandler.GetString("git.livereload.rsync_exclude", constants.DEFAULT_GIT_LIVE_RELOAD_RSYNC_EXCLUDE) rsyncProtect := s.configHandler.GetString("git.livereload.rsync_protect", constants.DEFAULT_GIT_LIVE_RELOAD_RSYNC_PROTECT) @@ -53,8 +53,8 @@ func (s *GitLivereloadService) GetComposeConfig() (*types.Config, error) { verifySsl := s.configHandler.GetBool("git.livereload.verify_ssl", false) image := s.configHandler.GetString("git.livereload.image", constants.DEFAULT_GIT_LIVE_RELOAD_IMAGE) - // Prepare environment variables map envVars := map[string]*string{ + "RSYNC_INCLUDE": ptrString(rsyncInclude), "RSYNC_EXCLUDE": ptrString(rsyncExclude), "RSYNC_PROTECT": ptrString(rsyncProtect), "GIT_USERNAME": ptrString(gitUsername), @@ -62,29 +62,18 @@ func (s *GitLivereloadService) GetComposeConfig() (*types.Config, error) { "VERIFY_SSL": ptrString(fmt.Sprintf("%t", verifySsl)), } - // Add RSYNC_INCLUDE if it's not empty - if rsyncInclude != "" { - envVars["RSYNC_INCLUDE"] = ptrString(rsyncInclude) - } - - // Add webhook URL if provided if webhookUrl != "" { envVars["WEBHOOK_URL"] = ptrString(webhookUrl) } - // Get the project root using the shell projectRoot, err := s.shell.GetProjectRoot() if err != nil { return nil, fmt.Errorf("error retrieving project root: %w", err) } - // Get the git folder name gitFolderName := filepath.Base(projectRoot) - - // Get the service name serviceName := s.name - // Create the service config serviceConfig := types.ServiceConfig{ Name: serviceName, ContainerName: s.GetContainerName(), diff --git a/pkg/services/git_livereload_service_test.go b/pkg/services/git_livereload_service_test.go index 1eb8f7c07..c90dcb7ef 100644 --- a/pkg/services/git_livereload_service_test.go +++ b/pkg/services/git_livereload_service_test.go @@ -164,17 +164,19 @@ func TestGitLivereloadService_GetComposeConfig(t *testing.T) { t.Fatalf("GetComposeConfig() error = %v", err) } - // Then verify the configuration doesn't contain RSYNC_INCLUDE when it's empty + // Then verify the configuration contains the expected service with default RSYNC_INCLUDE expectedName := "git" serviceFound := false - rsyncIncludePresent := false + rsyncIncludeFound := false for _, service := range composeConfig.Services { if service.Name == expectedName { serviceFound = true - // Check if RSYNC_INCLUDE environment variable is NOT set when empty - if _, exists := service.Environment["RSYNC_INCLUDE"]; exists { - rsyncIncludePresent = true + // Check if RSYNC_INCLUDE environment variable is set to default value + if rsyncInclude, exists := service.Environment["RSYNC_INCLUDE"]; exists && rsyncInclude != nil { + if *rsyncInclude == "kustomize" { + rsyncIncludeFound = true + } } break } @@ -183,8 +185,8 @@ func TestGitLivereloadService_GetComposeConfig(t *testing.T) { if !serviceFound { t.Errorf("expected service with name %q to be in the list of configurations", expectedName) } - if rsyncIncludePresent { - t.Errorf("expected RSYNC_INCLUDE environment variable to NOT be set when rsync_include is empty") + if !rsyncIncludeFound { + t.Errorf("expected RSYNC_INCLUDE environment variable to be set to default value 'kustomize'") } }) }