mirror of
https://github.com/goharbor/harbor
synced 2025-04-19 18:35:50 +00:00
add version support
This commit is contained in:
parent
7f099ebe50
commit
c5633f7ce8
|
@ -76,6 +76,8 @@ before_script:
|
||||||
script:
|
script:
|
||||||
- sudo mkdir -p /harbor_storage/ca_download
|
- sudo mkdir -p /harbor_storage/ca_download
|
||||||
- sudo mv ./tests/ca.crt /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 service mysql stop
|
||||||
- sudo ./tests/testprepare.sh
|
- sudo ./tests/testprepare.sh
|
||||||
- docker-compose -f ./make/docker-compose.test.yml up -d
|
- docker-compose -f ./make/docker-compose.test.yml up -d
|
||||||
|
|
10
Makefile
10
Makefile
|
@ -164,8 +164,8 @@ DOCKERCOMPOSEFILENAME=docker-compose.yml
|
||||||
DOCKERCOMPOSENOTARYFILENAME=docker-compose.notary.yml
|
DOCKERCOMPOSENOTARYFILENAME=docker-compose.notary.yml
|
||||||
|
|
||||||
# version prepare
|
# version prepare
|
||||||
VERSIONFILEPATH=$(SRCPATH)/ui/views/sections
|
VERSIONFILEPATH=$(CURDIR)
|
||||||
VERSIONFILENAME=header-content.htm
|
VERSIONFILENAME=VERSION
|
||||||
GITCMD=$(shell which git)
|
GITCMD=$(shell which git)
|
||||||
GITTAG=$(GITCMD) describe --tags
|
GITTAG=$(GITCMD) describe --tags
|
||||||
ifeq ($(DEVFLAG), true)
|
ifeq ($(DEVFLAG), true)
|
||||||
|
@ -189,9 +189,7 @@ REGISTRYUSER=user
|
||||||
REGISTRYPASSWORD=default
|
REGISTRYPASSWORD=default
|
||||||
|
|
||||||
version:
|
version:
|
||||||
@if [ "$(DEVFLAG)" = "false" ] ; then \
|
@printf $(VERSIONTAG) > $(VERSIONFILEPATH)/$(VERSIONFILENAME);
|
||||||
$(SEDCMD) -i 's/version=\"{{.Version}}\"/version=\"$(VERSIONTAG)\"/' -i $(VERSIONFILEPATH)/$(VERSIONFILENAME) ; \
|
|
||||||
fi
|
|
||||||
|
|
||||||
check_environment:
|
check_environment:
|
||||||
@$(MAKEPATH)/$(CHECKENVCMD)
|
@$(MAKEPATH)/$(CHECKENVCMD)
|
||||||
|
@ -420,7 +418,7 @@ cleandockercomposefile:
|
||||||
|
|
||||||
cleanversiontag:
|
cleanversiontag:
|
||||||
@echo "cleaning version TAG"
|
@echo "cleaning version TAG"
|
||||||
@$(SEDCMD) -i 's/version=\"$(VERSIONTAG)\"/version=\"{{.Version}}\"/' -i $(VERSIONFILEPATH)/$(VERSIONFILENAME)
|
@rm -rf $(VERSIONFILEPATH)/$(VERSIONFILENAME)
|
||||||
|
|
||||||
cleanpackage:
|
cleanpackage:
|
||||||
@echo "cleaning harbor install package"
|
@echo "cleaning harbor install package"
|
||||||
|
|
|
@ -7,6 +7,7 @@ COPY ./make/dev/ui/harbor_ui /harbor/
|
||||||
COPY ./src/ui/views /harbor/views
|
COPY ./src/ui/views /harbor/views
|
||||||
COPY ./src/ui/static /harbor/static
|
COPY ./src/ui/static /harbor/static
|
||||||
COPY ./src/favicon.ico /harbor/favicon.ico
|
COPY ./src/favicon.ico /harbor/favicon.ico
|
||||||
|
COPY ./VERSION /harbor/VERSION
|
||||||
|
|
||||||
RUN chmod u+x /harbor/harbor_ui
|
RUN chmod u+x /harbor/harbor_ui
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package api
|
package api
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -20,6 +21,7 @@ type SystemInfoAPI struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
const defaultRootCert = "/harbor_storage/ca_download/ca.crt"
|
const defaultRootCert = "/harbor_storage/ca_download/ca.crt"
|
||||||
|
const harborVersionFile = "/harbor/VERSION"
|
||||||
|
|
||||||
//SystemInfo models for system info.
|
//SystemInfo models for system info.
|
||||||
type SystemInfo struct {
|
type SystemInfo struct {
|
||||||
|
@ -42,6 +44,7 @@ type GeneralInfo struct {
|
||||||
ProjectCreationRestrict string `json:"project_creation_restriction"`
|
ProjectCreationRestrict string `json:"project_creation_restriction"`
|
||||||
SelfRegistration bool `json:"self_registration"`
|
SelfRegistration bool `json:"self_registration"`
|
||||||
HasCARoot bool `json:"has_ca_root"`
|
HasCARoot bool `json:"has_ca_root"`
|
||||||
|
HarborVersion string `json:"harbor_version"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// validate for validating user if an admin.
|
// validate for validating user if an admin.
|
||||||
|
@ -113,6 +116,7 @@ func (sia *SystemInfoAPI) GetGeneralInfo() {
|
||||||
registryURL = l[0]
|
registryURL = l[0]
|
||||||
}
|
}
|
||||||
_, caStatErr := os.Stat(defaultRootCert)
|
_, caStatErr := os.Stat(defaultRootCert)
|
||||||
|
harbor_version := sia.getVersion()
|
||||||
info := GeneralInfo{
|
info := GeneralInfo{
|
||||||
AdmiralEndpoint: cfg[common.AdmiralEndpoint].(string),
|
AdmiralEndpoint: cfg[common.AdmiralEndpoint].(string),
|
||||||
WithAdmiral: config.WithAdmiral(),
|
WithAdmiral: config.WithAdmiral(),
|
||||||
|
@ -122,7 +126,26 @@ func (sia *SystemInfoAPI) GetGeneralInfo() {
|
||||||
SelfRegistration: cfg[common.SelfRegistration].(bool),
|
SelfRegistration: cfg[common.SelfRegistration].(bool),
|
||||||
RegistryURL: registryURL,
|
RegistryURL: registryURL,
|
||||||
HasCARoot: caStatErr == nil,
|
HasCARoot: caStatErr == nil,
|
||||||
|
HarborVersion: harbor_version,
|
||||||
}
|
}
|
||||||
sia.Data["json"] = info
|
sia.Data["json"] = info
|
||||||
sia.ServeJSON()
|
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[:])
|
||||||
|
}
|
||||||
|
|
|
@ -3,8 +3,9 @@ package api
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestGetVolumeInfo(t *testing.T) {
|
func TestGetVolumeInfo(t *testing.T) {
|
||||||
|
@ -49,6 +50,7 @@ func TestGetGeneralInfo(t *testing.T) {
|
||||||
assert.Nil(err, fmt.Sprintf("Unexpected Error: %v", err))
|
assert.Nil(err, fmt.Sprintf("Unexpected Error: %v", err))
|
||||||
assert.Equal(false, g.WithNotary, "with notary should be false")
|
assert.Equal(false, g.WithNotary, "with notary should be false")
|
||||||
assert.Equal(true, g.HasCARoot, "has ca root should be true")
|
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) {
|
func TestGetCert(t *testing.T) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user