From c5633f7ce87ab537fdd9bb35a8e270e1c529e9ee Mon Sep 17 00:00:00 2001 From: wy65701436 Date: Tue, 21 Mar 2017 04:56:59 -0700 Subject: [PATCH 1/7] add version support --- .travis.yml | 2 ++ Makefile | 10 ++++------ make/photon/ui/Dockerfile | 1 + src/ui/api/systeminfo.go | 23 +++++++++++++++++++++++ src/ui/api/systeminfo_test.go | 4 +++- 5 files changed, 33 insertions(+), 7 deletions(-) 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/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..8b144247d 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) + harbor_version := sia.getVersion() info := GeneralInfo{ AdmiralEndpoint: cfg[common.AdmiralEndpoint].(string), WithAdmiral: config.WithAdmiral(), @@ -122,7 +126,26 @@ func (sia *SystemInfoAPI) GetGeneralInfo() { SelfRegistration: cfg[common.SelfRegistration].(bool), RegistryURL: registryURL, HasCARoot: caStatErr == nil, + HarborVersion: harbor_version, } sia.Data["json"] = info sia.ServeJSON() } + +// GetVersion gets harbor version. +func (sia *SystemInfoAPI) getVersion() string { + if _, err := os.Stat(harborVersionFile); err != nil { + if os.IsNotExist(err) { + log.Errorf("Version File doesn't exist.") + return "" + } + } + + 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) { From 5baf565c00e681a09a1f49fb48fd1b4f70a365de Mon Sep 17 00:00:00 2001 From: wy65701436 Date: Tue, 21 Mar 2017 18:28:01 -0700 Subject: [PATCH 2/7] update swagger.yaml --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index e8c3500e8..e50c49e3b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -76,6 +76,7 @@ before_script: script: - sudo mkdir -p /harbor_storage/ca_download - sudo mv ./tests/ca.crt /harbor_storage/ca_download + - ls . - sudo mkdir -p /harbor - sudo mv ./VERSION /harbor/VERSION - sudo service mysql stop From e667bd7a79c2b8b6732c54c14cf444490ef9cfc1 Mon Sep 17 00:00:00 2001 From: wy65701436 Date: Tue, 21 Mar 2017 18:39:09 -0700 Subject: [PATCH 3/7] add version file --- VERSION | 1 + src/ui/api/systeminfo.go | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) create mode 100644 VERSION 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/src/ui/api/systeminfo.go b/src/ui/api/systeminfo.go index 8b144247d..de7c47303 100644 --- a/src/ui/api/systeminfo.go +++ b/src/ui/api/systeminfo.go @@ -116,7 +116,7 @@ func (sia *SystemInfoAPI) GetGeneralInfo() { registryURL = l[0] } _, caStatErr := os.Stat(defaultRootCert) - harbor_version := sia.getVersion() + harborVersion := sia.getVersion() info := GeneralInfo{ AdmiralEndpoint: cfg[common.AdmiralEndpoint].(string), WithAdmiral: config.WithAdmiral(), @@ -126,7 +126,7 @@ func (sia *SystemInfoAPI) GetGeneralInfo() { SelfRegistration: cfg[common.SelfRegistration].(bool), RegistryURL: registryURL, HasCARoot: caStatErr == nil, - HarborVersion: harbor_version, + HarborVersion: harborVersion, } sia.Data["json"] = info sia.ServeJSON() From 1a9eb09f1260462ef24d17c5c072efc419a8c9de Mon Sep 17 00:00:00 2001 From: wy65701436 Date: Tue, 21 Mar 2017 18:40:21 -0700 Subject: [PATCH 4/7] add version file, and fix go issue. --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index e50c49e3b..e8c3500e8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -76,7 +76,6 @@ before_script: script: - sudo mkdir -p /harbor_storage/ca_download - sudo mv ./tests/ca.crt /harbor_storage/ca_download - - ls . - sudo mkdir -p /harbor - sudo mv ./VERSION /harbor/VERSION - sudo service mysql stop From 8268cf66bd57fcbb0167936990db04d1fcaac493 Mon Sep 17 00:00:00 2001 From: wy65701436 Date: Tue, 21 Mar 2017 18:56:42 -0700 Subject: [PATCH 5/7] update swagger --- docs/swagger.yaml | 3 +++ 1 file changed, 3 insertions(+) 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: From 5a764d30ea269a3033990cfd2b88f0d63ded0b54 Mon Sep 17 00:00:00 2001 From: wy65701436 Date: Tue, 21 Mar 2017 22:07:12 -0700 Subject: [PATCH 6/7] remove file exist. --- src/ui/api/systeminfo.go | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/src/ui/api/systeminfo.go b/src/ui/api/systeminfo.go index de7c47303..249602144 100644 --- a/src/ui/api/systeminfo.go +++ b/src/ui/api/systeminfo.go @@ -21,7 +21,7 @@ type SystemInfoAPI struct { } const defaultRootCert = "/harbor_storage/ca_download/ca.crt" -const harborVersionFile = "/harbor/VERSION" +const harborVersionFile = "/harbor/VERSION1" //SystemInfo models for system info. type SystemInfo struct { @@ -134,18 +134,10 @@ func (sia *SystemInfoAPI) GetGeneralInfo() { // GetVersion gets harbor version. func (sia *SystemInfoAPI) getVersion() string { - if _, err := os.Stat(harborVersionFile); err != nil { - if os.IsNotExist(err) { - log.Errorf("Version File doesn't exist.") - return "" - } - } - version, err := ioutil.ReadFile(harborVersionFile) if err != nil { log.Errorf("Error occured getting harbor version: %v", err) return "" } - return string(version[:]) } From 677359b606945f94f9058a7e83ba3912b5b14df9 Mon Sep 17 00:00:00 2001 From: wy65701436 Date: Tue, 21 Mar 2017 22:20:44 -0700 Subject: [PATCH 7/7] remove file exist. --- src/ui/api/systeminfo.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ui/api/systeminfo.go b/src/ui/api/systeminfo.go index 249602144..88dff92bc 100644 --- a/src/ui/api/systeminfo.go +++ b/src/ui/api/systeminfo.go @@ -21,7 +21,7 @@ type SystemInfoAPI struct { } const defaultRootCert = "/harbor_storage/ca_download/ca.crt" -const harborVersionFile = "/harbor/VERSION1" +const harborVersionFile = "/harbor/VERSION" //SystemInfo models for system info. type SystemInfo struct {