Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix various version-related issues with cli (close #3706) #3709

Merged
merged 1 commit into from
Jan 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 28 additions & 3 deletions cli/assets/assets.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

75 changes: 75 additions & 0 deletions cli/assets/latest/console.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<html lang="en-us">
<head>
<link rel="icon" type="image/png" href="https://graphql-engine-cdn.hasura.io/console/assets/common/img/favicon_green.png" />
<script>
window.__env = {
apiHost: {{.apiHost}},
apiPort: "{{.apiPort}}",
cliVersion: {{.cliVersion}},
dataApiUrl: {{.dataApiUrl}},
dataApiVersion: {{.dataApiVersion}},
{{- if .hasAccessKey }}
accessKey: {{.adminSecret}},
{{ else }}
adminSecret: {{.adminSecret}},
{{ end -}}
urlPrefix: "/",
consoleMode: "cli",
cliUUID: {{.cliUUID}},
enableTelemetry: {{.enableTelemetry}},
assetsPath: "https://graphql-engine-cdn.hasura.io/console/assets",
serverVersion: "{{.serverVersion}}",
};
</script>
</head>
<body>
<style>
.mainContent {
display: 'none';
opacity: 0;
transition: opacity .20s linear;
}
.mainContent.show {
display: 'block';
opacity: 1;
transition: opacity .20s linear;
}
</style>

<div id="loading">
<div class="page-loading" style="
min-height: 100vh;
width: 100%;
display: flex;
align-items: center;
font-family: sans-serif;
justify-content: center;
">
<span class="" style="
font-size: 2em;
margin-top: -3em;
color: #848484;
">
Loading...
</span>
</div>
</div>
<div id="content" class="mainContent"></div>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css"/>

{{ if .cliStaticDir }}

<link rel="stylesheet" href="/static/main.css" charset="UTF-8"/>
<script src="/static/vendor.js" charset="UTF-8"></script>
<script src="/static/main.js" charset="UTF-8"></script>

{{ else }}

<link rel="stylesheet" href="https://graphql-engine-cdn.hasura.io/console/assets/{{.assetsVersion}}/main.css.gz" charset="UTF-8"/>
<script src="https://graphql-engine-cdn.hasura.io/console/assets/{{.assetsVersion}}/vendor.js.gz" charset="UTF-8"></script>
<script src="https://graphql-engine-cdn.hasura.io/console/assets/{{.assetsVersion}}/main.js.gz" charset="UTF-8"></script>

{{ end }}

</body>
</html>
2 changes: 1 addition & 1 deletion cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ func (ec *ExecutionContext) checkServerVersion() error {
ec.Logger.Debugf("versions: cli: [%s] server: [%s]", ec.Version.GetCLIVersion(), ec.Version.GetServerVersion())
ec.Logger.Debugf("compatibility check: [%v] %v", isCompatible, reason)
if !isCompatible {
return errors.Errorf("[cli: %s] [server: %s] versions incompatible: %s", ec.Version.GetCLIVersion(), ec.Version.GetServerVersion(), reason)
ec.Logger.Warnf("[cli: %s] [server: %s] version mismatch: %s", ec.Version.GetCLIVersion(), ec.Version.GetServerVersion(), reason)
}
return nil
}
Expand Down
4 changes: 4 additions & 0 deletions cli/commands/console.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,10 @@ func serveConsole(assetsVersion, staticDir string, opts gin.H) (*gin.Engine, err
// An Engine instance with the Logger and Recovery middleware already attached.
r := gin.New()

if !util.DoAssetExist("assets/" + assetsVersion + "/console.html") {
assetsVersion = "latest"
}

// Template console.html
templateRender, err := util.LoadTemplates("assets/"+assetsVersion+"/", "console.html")
if err != nil {
Expand Down
2 changes: 2 additions & 0 deletions cli/commands/update-cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ func (o *updateOptions) run(showPrompt bool) error {
return errors.Wrap(err, "command: check update")
}

ec.Logger.Debugln("hasUpdate: ", hasUpdate, "latestVersion: ", latestVersion, "currentVersion:", currentVersion)

if !hasUpdate {
o.EC.Logger.WithField("version", currentVersion).Info("hasura cli is up to date")
return nil
Expand Down
2 changes: 1 addition & 1 deletion cli/update/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func HasUpdate(currentVersion *semver.Version, timeFile string) (bool, *semver.V
return false, nil, errors.Wrap(err, "get latest version")
}

c, err := semver.NewConstraint(fmt.Sprintf("> %s", currentVersion.String()))
c, err := semver.NewConstraint(fmt.Sprintf("> %s-0", currentVersion.String()))
if err != nil {
return false, nil, errors.Wrap(err, "semver constraint build")
}
Expand Down
11 changes: 11 additions & 0 deletions cli/util/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,15 @@ func (b *binaryFileSystem) Exists(prefix string, filepath string) bool {
return false
}

// BinaryFileSystem creates a binary file system at root from the assets
func BinaryFileSystem(root string) *binaryFileSystem {
fs := &assetfs.AssetFS{assets.Asset, assets.AssetDir, assets.AssetInfo, root}
return &binaryFileSystem{
fs,
}
}

// LoadTemplates loads templates from path for the given list
func LoadTemplates(path string, list ...string) (multitemplate.Render, error) {
r := multitemplate.New()

Expand All @@ -55,3 +57,12 @@ func LoadTemplates(path string, list ...string) (multitemplate.Render, error) {

return r, nil
}

// DoAssetExist returns true if an asset exists at pathk
func DoAssetExist(path string) bool {
_, err := assets.AssetInfo(path)
if err != nil {
return false
}
return true
}
6 changes: 3 additions & 3 deletions cli/version/compatibility.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package version

const (
untaggedBuild = "for untagged builds, server and cli versions should match"
taggedBuild = "cli version (major.minor) should be equal or ahead of server version, please update cli"
untaggedBuild = "untagged build, there could be inconsistencies"
taggedBuild = "older cli version might not be compatible with latest server apis, please update cli"
noServerVersion = "server with no version treated as pre-release build"
noCLIVersion = "cli version is empty, indicates a broken build"
untaggedCLI = "untagged cli build can work with tagged server build"
devCLI = "dev version of cli, compatible with all servers"
devCLI = "dev version of cli, there could be inconsistencies"
)

// CheckCLIServerCompatibility compares server and cli for compatibility,
Expand Down