Skip to content

Commit

Permalink
Merge pull request #78 from ethpandaops/feat/health-check
Browse files Browse the repository at this point in the history
feat(docker): exposes health check port via compose if set
  • Loading branch information
mattevans authored Jan 22, 2025
2 parents 1d28dd0 + 786a922 commit 43965d5
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 17 deletions.
3 changes: 2 additions & 1 deletion .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ archives:
- LICENSE*
- install.sh
- docker-compose.yml
- docker-compose.ports.yml
- docker-compose.metrics.yml
- docker-compose.health.yml
- docker-compose.network.yml

changelog:
Expand Down
4 changes: 4 additions & 0 deletions docker-compose.health.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
services:
sentry:
ports:
- "${CONTRIBUTOOR_HEALTH_ADDRESS:-127.0.0.1}:${CONTRIBUTOOR_HEALTH_PORT:-9191}:${CONTRIBUTOOR_HEALTH_PORT:-9191}"
File renamed without changes.
9 changes: 6 additions & 3 deletions install.bats
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,8 @@ EOF

# Create compose files
touch "$CONTRIBUTOOR_PATH/releases/installer-${CONTRIBUTOOR_VERSION}/docker-compose.yml"
touch "$CONTRIBUTOOR_PATH/releases/installer-${CONTRIBUTOOR_VERSION}/docker-compose.ports.yml"
touch "$CONTRIBUTOOR_PATH/releases/installer-${CONTRIBUTOOR_VERSION}/docker-compose.metrics.yml"
touch "$CONTRIBUTOOR_PATH/releases/installer-${CONTRIBUTOOR_VERSION}/docker-compose.health.yml"
touch "$CONTRIBUTOOR_PATH/releases/installer-${CONTRIBUTOOR_VERSION}/docker-compose.network.yml"

return 0
Expand All @@ -412,7 +413,8 @@ EOF
# Also create compose files in the same directory if it's the binary symlink
if [[ "$3" == *"/bin/contributoor" ]]; then
cp "$CONTRIBUTOOR_PATH/releases/installer-${CONTRIBUTOOR_VERSION}/docker-compose.yml" "$(dirname "$3")/docker-compose.yml"
cp "$CONTRIBUTOOR_PATH/releases/installer-${CONTRIBUTOOR_VERSION}/docker-compose.ports.yml" "$(dirname "$3")/docker-compose.ports.yml"
cp "$CONTRIBUTOOR_PATH/releases/installer-${CONTRIBUTOOR_VERSION}/docker-compose.metrics.yml" "$(dirname "$3")/docker-compose.metrics.yml"
cp "$CONTRIBUTOOR_PATH/releases/installer-${CONTRIBUTOOR_VERSION}/docker-compose.health.yml" "$(dirname "$3")/docker-compose.health.yml"
cp "$CONTRIBUTOOR_PATH/releases/installer-${CONTRIBUTOOR_VERSION}/docker-compose.network.yml" "$(dirname "$3")/docker-compose.network.yml"
fi
fi
Expand All @@ -432,7 +434,8 @@ EOF
[ -f "$CONTRIBUTOOR_PATH/bin/contributoor" ]
[ -x "$CONTRIBUTOOR_PATH/bin/contributoor" ]
[ -f "$CONTRIBUTOOR_PATH/releases/installer-${CONTRIBUTOOR_VERSION}/docker-compose.yml" ]
[ -f "$CONTRIBUTOOR_PATH/releases/installer-${CONTRIBUTOOR_VERSION}/docker-compose.ports.yml" ]
[ -f "$CONTRIBUTOOR_PATH/releases/installer-${CONTRIBUTOOR_VERSION}/docker-compose.metrics.yml" ]
[ -f "$CONTRIBUTOOR_PATH/releases/installer-${CONTRIBUTOOR_VERSION}/docker-compose.health.yml" ]
[ -f "$CONTRIBUTOOR_PATH/releases/installer-${CONTRIBUTOOR_VERSION}/docker-compose.network.yml" ]
}

Expand Down
11 changes: 8 additions & 3 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -215,10 +215,15 @@ setup_installer() {
chmod 755 "$release_dir"
} || fail "docker-compose.yml not found after extraction"

[ -f "$release_dir/docker-compose.ports.yml" ] && {
chmod 644 "$release_dir/docker-compose.ports.yml"
[ -f "$release_dir/docker-compose.metrics.yml" ] && {
chmod 644 "$release_dir/docker-compose.metrics.yml"
chmod 755 "$release_dir"
} || fail "docker-compose.ports.yml not found after extraction"
} || fail "docker-compose.metrics.yml not found after extraction"

[ -f "$release_dir/docker-compose.health.yml" ] && {
chmod 644 "$release_dir/docker-compose.health.yml"
chmod 755 "$release_dir"
} || fail "docker-compose.health.yml not found after extraction"

[ -f "$release_dir/docker-compose.network.yml" ] && {
chmod 644 "$release_dir/docker-compose.network.yml"
Expand Down
41 changes: 33 additions & 8 deletions internal/sidecar/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ type DockerSidecar interface {
type dockerSidecar struct {
logger *logrus.Logger
composePath string
composePortsPath string
composeMetricsPath string
composeHealthPath string
composeNetworkPath string
configPath string
sidecarCfg ConfigManager
Expand All @@ -35,7 +36,8 @@ type dockerSidecar struct {
func NewDockerSidecar(logger *logrus.Logger, sidecarCfg ConfigManager, installerCfg *installer.Config) (DockerSidecar, error) {
var (
composeFilename = "docker-compose.yml"
composePortsFilename = "docker-compose.ports.yml"
composeMetricsFilename = "docker-compose.metrics.yml"
composeHealthFilename = "docker-compose.health.yml"
composeNetworkFilename = "docker-compose.network.yml"
)

Expand All @@ -44,9 +46,14 @@ func NewDockerSidecar(logger *logrus.Logger, sidecarCfg ConfigManager, installer
return nil, fmt.Errorf("failed to find %s: %w", composeFilename, err)
}

composePortsPath, err := findComposeFile(composePortsFilename)
composeMetricsPath, err := findComposeFile(composeMetricsFilename)
if err != nil {
return nil, fmt.Errorf("failed to find %s: %w", composePortsFilename, err)
return nil, fmt.Errorf("failed to find %s: %w", composeMetricsFilename, err)
}

composeHealthPath, err := findComposeFile(composeHealthFilename)
if err != nil {
return nil, fmt.Errorf("failed to find %s: %w", composeHealthFilename, err)
}

composeNetworkPath, err := findComposeFile(composeNetworkFilename)
Expand All @@ -58,8 +65,12 @@ func NewDockerSidecar(logger *logrus.Logger, sidecarCfg ConfigManager, installer
return nil, fmt.Errorf("invalid %s file: %w", composeFilename, err)
}

if err := validateComposePath(composePortsPath); err != nil {
return nil, fmt.Errorf("invalid %s file: %w", composePortsFilename, err)
if err := validateComposePath(composeMetricsPath); err != nil {
return nil, fmt.Errorf("invalid %s file: %w", composeMetricsPath, err)
}

if err := validateComposePath(composeHealthPath); err != nil {
return nil, fmt.Errorf("invalid %s file: %w", composeHealthPath, err)
}

if err := validateComposePath(composeNetworkPath); err != nil {
Expand All @@ -69,8 +80,9 @@ func NewDockerSidecar(logger *logrus.Logger, sidecarCfg ConfigManager, installer
return &dockerSidecar{
logger: logger,
composePath: filepath.Clean(composePath),
composePortsPath: filepath.Clean(composePortsPath),
composeMetricsPath: filepath.Clean(composeMetricsPath),
composeNetworkPath: filepath.Clean(composeNetworkPath),
composeHealthPath: filepath.Clean(composeHealthPath),
configPath: sidecarCfg.GetConfigPath(),
sidecarCfg: sidecarCfg,
installerCfg: installerCfg,
Expand Down Expand Up @@ -258,6 +270,15 @@ func (s *dockerSidecar) GetComposeEnv() []string {
)
}

// Handle health address (only added if set).
if healthHost, healthPort := cfg.GetHealthCheckHostPort(); healthHost != "" {
env = append(
env,
fmt.Sprintf("CONTRIBUTOOR_HEALTH_ADDRESS=%s", healthHost),
fmt.Sprintf("CONTRIBUTOOR_HEALTH_PORT=%s", healthPort),
)
}

// Handle pprof address (only added if set).
if pprofHost, pprofPort := cfg.GetPprofHostPort(); pprofHost != "" {
env = append(
Expand Down Expand Up @@ -296,7 +317,11 @@ func (s *dockerSidecar) getComposeArgs() []string {
var additionalArgs []string

if metricsHost, _ := s.sidecarCfg.Get().GetMetricsHostPort(); metricsHost != "" {
additionalArgs = append(additionalArgs, "-f", s.composePortsPath)
additionalArgs = append(additionalArgs, "-f", s.composeMetricsPath)
}

if healthHost, _ := s.sidecarCfg.Get().GetHealthCheckHostPort(); healthHost != "" {
additionalArgs = append(additionalArgs, "-f", s.composeHealthPath)
}

if s.sidecarCfg.Get().RunMethod == config.RunMethod_RUN_METHOD_DOCKER && s.sidecarCfg.Get().DockerNetwork != "" {
Expand Down
6 changes: 4 additions & 2 deletions internal/sidecar/docker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ func TestDockerService_Integration(t *testing.T) {

// Write out compose files first.
require.NoError(t, os.WriteFile(filepath.Join(tmpDir, "docker-compose.yml"), []byte(composeFile), 0644))
require.NoError(t, os.WriteFile(filepath.Join(tmpDir, "docker-compose.ports.yml"), []byte(composePortsFile), 0644))
require.NoError(t, os.WriteFile(filepath.Join(tmpDir, "docker-compose.metrics.yml"), []byte(composePortsFile), 0644))
require.NoError(t, os.WriteFile(filepath.Join(tmpDir, "docker-compose.health.yml"), []byte(composePortsFile), 0644))
require.NoError(t, os.WriteFile(filepath.Join(tmpDir, "docker-compose.network.yml"), []byte(composeNetworkFile), 0644))

// Change working directory to our test directory before creating DockerSidecar.
Expand Down Expand Up @@ -306,7 +307,8 @@ func TestGetComposeEnv(t *testing.T) {

// Write out compose files first
require.NoError(t, os.WriteFile(filepath.Join(tt.config.ContributoorDirectory, "docker-compose.yml"), []byte(composeFile), 0644))
require.NoError(t, os.WriteFile(filepath.Join(tt.config.ContributoorDirectory, "docker-compose.ports.yml"), []byte(composePortsFile), 0644))
require.NoError(t, os.WriteFile(filepath.Join(tt.config.ContributoorDirectory, "docker-compose.metrics.yml"), []byte(composePortsFile), 0644))
require.NoError(t, os.WriteFile(filepath.Join(tt.config.ContributoorDirectory, "docker-compose.health.yml"), []byte(composePortsFile), 0644))
require.NoError(t, os.WriteFile(filepath.Join(tt.config.ContributoorDirectory, "docker-compose.network.yml"), []byte(composeNetworkFile), 0644))

// Change working directory to test directory
Expand Down

0 comments on commit 43965d5

Please sign in to comment.