Merge pull request #1705 from wy65701436/dev

add version support
This commit is contained in:
Daniel Jiang 2017-03-22 15:50:08 +08:00 committed by GitHub
commit 872a01b342
7 changed files with 29 additions and 7 deletions

View File

@ -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

View File

@ -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"

1
VERSION Normal file
View File

@ -0,0 +1 @@
dev

View File

@ -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:

View File

@ -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

View File

@ -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[:])
}

View File

@ -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) {