diff --git a/.travis.yml b/.travis.yml index d552fba28..e8c3500e8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -76,6 +76,8 @@ before_script: script: - sudo mkdir -p /harbor_storage/ca_download - sudo mv ./tests/ca.crt /harbor_storage/ca_download + - sudo mkdir -p /harbor + - sudo mv ./VERSION /harbor/VERSION - sudo service mysql stop - sudo ./tests/testprepare.sh - docker-compose -f ./make/docker-compose.test.yml up -d diff --git a/Makefile b/Makefile index 797cca15e..371918782 100644 --- a/Makefile +++ b/Makefile @@ -164,8 +164,8 @@ DOCKERCOMPOSEFILENAME=docker-compose.yml DOCKERCOMPOSENOTARYFILENAME=docker-compose.notary.yml # version prepare -VERSIONFILEPATH=$(SRCPATH)/ui/views/sections -VERSIONFILENAME=header-content.htm +VERSIONFILEPATH=$(CURDIR) +VERSIONFILENAME=VERSION GITCMD=$(shell which git) GITTAG=$(GITCMD) describe --tags ifeq ($(DEVFLAG), true) @@ -189,9 +189,7 @@ REGISTRYUSER=user REGISTRYPASSWORD=default version: - @if [ "$(DEVFLAG)" = "false" ] ; then \ - $(SEDCMD) -i 's/version=\"{{.Version}}\"/version=\"$(VERSIONTAG)\"/' -i $(VERSIONFILEPATH)/$(VERSIONFILENAME) ; \ - fi + @printf $(VERSIONTAG) > $(VERSIONFILEPATH)/$(VERSIONFILENAME); check_environment: @$(MAKEPATH)/$(CHECKENVCMD) @@ -420,7 +418,7 @@ cleandockercomposefile: cleanversiontag: @echo "cleaning version TAG" - @$(SEDCMD) -i 's/version=\"$(VERSIONTAG)\"/version=\"{{.Version}}\"/' -i $(VERSIONFILEPATH)/$(VERSIONFILENAME) + @rm -rf $(VERSIONFILEPATH)/$(VERSIONFILENAME) cleanpackage: @echo "cleaning harbor install package" diff --git a/VERSION b/VERSION new file mode 100644 index 000000000..90012116c --- /dev/null +++ b/VERSION @@ -0,0 +1 @@ +dev \ No newline at end of file diff --git a/docs/swagger.yaml b/docs/swagger.yaml index 293894750..213ad9b03 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -2028,6 +2028,9 @@ definitions: has_ca_root: type: boolean description: Indicate whether there is a ca root cert file ready for download in the file system. + harbor_version: + type: string + description: The build version of Harbor. SystemInfo: type: object properties: diff --git a/make/photon/ui/Dockerfile b/make/photon/ui/Dockerfile index 039d1603a..6b1e067c1 100644 --- a/make/photon/ui/Dockerfile +++ b/make/photon/ui/Dockerfile @@ -7,6 +7,7 @@ COPY ./make/dev/ui/harbor_ui /harbor/ COPY ./src/ui/views /harbor/views COPY ./src/ui/static /harbor/static COPY ./src/favicon.ico /harbor/favicon.ico +COPY ./VERSION /harbor/VERSION RUN chmod u+x /harbor/harbor_ui diff --git a/src/ui/api/systeminfo.go b/src/ui/api/systeminfo.go index 073dc246a..88dff92bc 100644 --- a/src/ui/api/systeminfo.go +++ b/src/ui/api/systeminfo.go @@ -1,6 +1,7 @@ package api import ( + "io/ioutil" "net/http" "os" "strings" @@ -20,6 +21,7 @@ type SystemInfoAPI struct { } const defaultRootCert = "/harbor_storage/ca_download/ca.crt" +const harborVersionFile = "/harbor/VERSION" //SystemInfo models for system info. type SystemInfo struct { @@ -42,6 +44,7 @@ type GeneralInfo struct { ProjectCreationRestrict string `json:"project_creation_restriction"` SelfRegistration bool `json:"self_registration"` HasCARoot bool `json:"has_ca_root"` + HarborVersion string `json:"harbor_version"` } // validate for validating user if an admin. @@ -113,6 +116,7 @@ func (sia *SystemInfoAPI) GetGeneralInfo() { registryURL = l[0] } _, caStatErr := os.Stat(defaultRootCert) + harborVersion := sia.getVersion() info := GeneralInfo{ AdmiralEndpoint: cfg[common.AdmiralEndpoint].(string), WithAdmiral: config.WithAdmiral(), @@ -122,7 +126,18 @@ func (sia *SystemInfoAPI) GetGeneralInfo() { SelfRegistration: cfg[common.SelfRegistration].(bool), RegistryURL: registryURL, HasCARoot: caStatErr == nil, + HarborVersion: harborVersion, } sia.Data["json"] = info sia.ServeJSON() } + +// GetVersion gets harbor version. +func (sia *SystemInfoAPI) getVersion() string { + version, err := ioutil.ReadFile(harborVersionFile) + if err != nil { + log.Errorf("Error occured getting harbor version: %v", err) + return "" + } + return string(version[:]) +} diff --git a/src/ui/api/systeminfo_test.go b/src/ui/api/systeminfo_test.go index 80892fd84..26a259ba4 100644 --- a/src/ui/api/systeminfo_test.go +++ b/src/ui/api/systeminfo_test.go @@ -3,8 +3,9 @@ package api import ( "encoding/json" "fmt" - "github.com/stretchr/testify/assert" "testing" + + "github.com/stretchr/testify/assert" ) func TestGetVolumeInfo(t *testing.T) { @@ -49,6 +50,7 @@ func TestGetGeneralInfo(t *testing.T) { assert.Nil(err, fmt.Sprintf("Unexpected Error: %v", err)) assert.Equal(false, g.WithNotary, "with notary should be false") assert.Equal(true, g.HasCARoot, "has ca root should be true") + assert.NotEmpty(g.HarborVersion, "harbor version should not be empty") } func TestGetCert(t *testing.T) {