Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pkg/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
21 changes: 5 additions & 16 deletions pkg/services/git_livereload_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -53,38 +53,27 @@ 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),
"GIT_PASSWORD": ptrString(gitPassword),
"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(),
Expand Down
16 changes: 9 additions & 7 deletions pkg/services/git_livereload_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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'")
}
})
}
Loading