Skip to content

Commit

Permalink
Remove unused docker buildargs. Improve error handling when parsing c…
Browse files Browse the repository at this point in the history
…ore version
  • Loading branch information
urvisavla committed May 31, 2024
1 parent eb8f17b commit c3dcc27
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
1 change: 0 additions & 1 deletion exp/services/ledgerexporter/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ docker-build:
cd ../../../ && \
$(SUDO) docker build --platform linux/amd64 --pull --label org.opencontainers.image.created="$(BUILD_DATE)" \
--build-arg GOFLAGS="-ldflags=-X=github.com/stellar/go/exp/services/ledgerexporter/internal.version=$(VERSION)" \
--build-arg VERSION=$(VERSION) \
$(if $(STELLAR_CORE_VERSION), --build-arg STELLAR_CORE_VERSION=$(STELLAR_CORE_VERSION)) \
-f exp/services/ledgerexporter/docker/Dockerfile \
-t $(DOCKER_IMAGE):$(VERSION) \
Expand Down
10 changes: 7 additions & 3 deletions exp/services/ledgerexporter/internal/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,10 @@ func (config *Config) generateCaptiveCoreConfig() (ledgerbackend.CaptiveCoreConf
return ledgerbackend.CaptiveCoreConfig{}, errors.Wrap(err, "Failed to find stellar-core binary")
}
}
config.setCoreVersionInfo()

if err := config.setCoreVersionInfo(); err != nil {
return ledgerbackend.CaptiveCoreConfig{}, fmt.Errorf("failed to set stellar-core version info: %w", err)
}

var captiveCoreConfig []byte
// Default network config
Expand Down Expand Up @@ -178,10 +181,11 @@ func (c *Config) setCoreVersionInfo() (err error) {

// Validate and set the core version
coreVersionPattern := `^v\d+\.\d+\.\d+`
if match, _ := regexp.MatchString(coreVersionPattern, rows[0]); !match {
return fmt.Errorf("core version not found in stellar-core version output")
if match, err := regexp.MatchString(coreVersionPattern, rows[0]); !match || err != nil {
return fmt.Errorf("stellar-core version not found")
}
c.CoreVersion = rows[0]
logger.Infof("stellar-core version: %s", c.CoreVersion)
return nil
}

Expand Down
4 changes: 2 additions & 2 deletions exp/services/ledgerexporter/internal/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -308,13 +308,13 @@ func TestSetCoreVersionInfo(t *testing.T) {
{
name: "core version invalid format",
commandOutput: "ledger protocol version: 20\\n\" +",
expectedError: errors.New("core version not found in stellar-core version output"),
expectedError: errors.New("stellar-core version not found"),
expectedCoreVer: "",
},
{
name: "core version not found",
commandOutput: "",
expectedError: errors.New("core version not found in stellar-core version output"),
expectedError: errors.New("stellar-core version not found"),
expectedCoreVer: "",
},
}
Expand Down

0 comments on commit c3dcc27

Please sign in to comment.