remove manifests directory from init (close #254) (#258)

This commit is contained in:
Shahidh K Muhammed 2018-08-06 17:03:17 +05:30 committed by GitHub
parent 60f15c654b
commit 0ed3ff6418
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
19 changed files with 46 additions and 226 deletions

View File

@ -51,7 +51,7 @@ send_pr_to_repo() {
git clone https://github.com/hasura/$1.git ~/$1
cd ~/$1
git checkout -b ${LATEST_TAG}
find . -type f -exec sed -i "s/\(hasura\/graphql-engine:\).*$/\1${LATEST_TAG}/" {} \;
find . -type f -exec sed -i -E 's#(hasura/graphql-engine:)v(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(\-[0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*)?(\+[0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*)?( \\)*$#\1'"${LATEST_TAG}"'\9#' {} \;
git add .
git commit -m "update image version to ${LATEST_TAG}"
git push -q https://${GITHUB_TOKEN}@github.com/hasura/$1.git ${LATEST_TAG}

View File

@ -1,16 +1,3 @@
## Quickstart
[![Deploy to heroku](https://www.herokucdn.com/deploy/button.svg)](https://heroku.com/deploy?template=https://github.com/hasura/graphql-engine-heroku)
Docker image for server: \`hasura/graphql-engine:${LATEST_TAG}\` [[docs]](https://docs.hasura.io/1.0/graphql/manual/getting-started/docker-simple.html)
CLI installation (for migrations):
- Mac/Linux: \`curl -L https://cli.hasura.io/install.sh | bash\`
- Windows: [installer](https://cli.hasura.io/install/windows-amd64)
(*The GraphQL Engine CLI is bundled with Hasura platform CLI which includes commands for managing Hasura platform.*)
## Changelog
${CHANGELOG_TEXT}

View File

@ -8,17 +8,14 @@
package cli
import (
"bytes"
"net/url"
"os"
"path/filepath"
"regexp"
"strings"
"text/template"
"time"
"github.com/briandowns/spinner"
"github.com/hasura/graphql-engine/cli/util"
"github.com/hasura/graphql-engine/cli/version"
colorable "github.com/mattn/go-colorable"
homedir "github.com/mitchellh/go-homedir"
@ -99,10 +96,6 @@ type ExecutionContext struct {
// stored.
GlobalConfigFile string
// InstallManifestsRepo is the object referring to the github repo where
// installation scripts/manifests for Hasura GraphQL Engine are located.
InstallManifestsRepo *util.InstallManifestsRepo
// IsStableRelease indicates if the CLI release is stable or not.
IsStableRelease bool
// Version indicates the version object
@ -126,14 +119,6 @@ func (ec *ExecutionContext) Prepare() error {
}
ec.CMDName = cmdName
// set the install manifests repo
if ec.InstallManifestsRepo == nil {
ec.InstallManifestsRepo = &util.InstallManifestsRepo{
Name: "graphql-engine-install-manifests",
Namespace: "hasura",
}
}
// set spinner
ec.setupSpinner()
@ -378,19 +363,3 @@ func (ec *ExecutionContext) setVersion() {
ec.Version = version.New()
}
}
// RenderTextWithContext renders the template text passed as 'in' with the
// ExecutionContext as the template context and returns 'out'.
func (ec *ExecutionContext) RenderTextWithContext(in string) (out string) {
t, err := template.New("r").Parse(in)
if err != nil {
ec.Logger.Debug(errors.Wrap(err, "failed parsing template"))
return ""
}
b := &bytes.Buffer{}
if err := t.Execute(b, ec); err != nil {
ec.Logger.Debug(errors.Wrap(err, "failed rendering template"))
return ""
}
return b.String()
}

View File

@ -9,7 +9,6 @@ import (
"github.com/ghodss/yaml"
"github.com/hasura/graphql-engine/cli"
"github.com/hasura/graphql-engine/cli/util"
"github.com/manifoldco/promptui"
"github.com/pkg/errors"
"github.com/spf13/cobra"
@ -27,15 +26,17 @@ func NewInitCmd(ec *cli.ExecutionContext) *cobra.Command {
}
initCmd := &cobra.Command{
Use: "init",
Short: "Initialize directory for Hasura GraphQL Engine",
Long: "Create directories and files required for Hasura GraphQL Engine",
Example: ` # Create a directory with installation manifests:
hasura init --directory <my-directory>
Short: "Initialize directory for Hasura GraphQL Engine migrations",
Long: "Create directories and files required for enabling migrations on Hasura GraphQL Engine",
Example: ` # Create a directory to store migrations
hasura init
# Create a directory with an endpoint configured:
hasura --directory <my-directory> --endpoint <graphql-engine-endpoint>
# Now, edit <my-directory>/config.yaml to add endpoint and access key
# See https://docs.hasura.io/0.15/graphql/manual/getting-started for more details`,
# Create a directory with endpoint and access key configured:
hasura init --directory <my-project> --endpoint https://my-graphql-engine.com --access-key secretaccesskey
# See https://docs.hasura.io/1.0/graphql/manual/migrations/index.html for more details`,
SilenceUsage: true,
PreRunE: func(cmd *cobra.Command, args []string) error {
return ec.Prepare()
@ -83,59 +84,23 @@ func (o *initOptions) run() error {
}
var infoMsg string
// If endpoint is not provided, download installation manifests
if len(o.Endpoint) == 0 {
o.EC.Spin("Downloading install manifests... ")
defer o.EC.Spinner.Stop()
src, err := o.EC.InstallManifestsRepo.Download()
if err != nil {
return errors.Wrap(err, "getting manifests failed")
}
defer os.RemoveAll(src)
o.EC.Spinner.Stop()
o.EC.Logger.Info("Manifests downloaded")
dst := filepath.Join(o.EC.ExecutionDirectory, MANIFESTS_DIR)
if _, err := os.Stat(dst); err == nil {
return errors.Errorf("directory '%s' already exist", dst)
}
o.EC.Spin("Creating manifests in current directory... ")
defer o.EC.Spinner.Stop()
err = os.MkdirAll(filepath.Dir(dst), os.ModePerm)
if err != nil {
return errors.Wrap(err, "error creating setup directories")
}
// copy manifests to manifests directory (dst)
err = util.CopyDir(src, dst)
if err != nil {
return errors.Wrap(err, "error copying files")
}
o.EC.Spinner.Stop()
infoMsg = fmt.Sprintf("manifests created at [%s]", dst)
} else {
// if endpoint is set, just create the execution directory
if _, err := os.Stat(o.EC.ExecutionDirectory); err == nil {
return errors.Errorf("directory '%s' already exist", o.EC.ExecutionDirectory)
}
err := os.MkdirAll(o.EC.ExecutionDirectory, os.ModePerm)
if err != nil {
return errors.Wrap(err, "error creating setup directories")
}
infoMsg = fmt.Sprintf(`directory created. execute the following commands to continue:
// create the execution directory
if _, err := os.Stat(o.EC.ExecutionDirectory); err == nil {
return errors.Errorf("directory '%s' already exist", o.EC.ExecutionDirectory)
}
err := os.MkdirAll(o.EC.ExecutionDirectory, os.ModePerm)
if err != nil {
return errors.Wrap(err, "error creating setup directories")
}
infoMsg = fmt.Sprintf(`directory created. execute the following commands to continue:
cd %s
%s console
`, o.EC.ExecutionDirectory, o.EC.CMDName)
}
hasura console
`, o.EC.ExecutionDirectory)
// create other required files, like config.yaml, migrations directory
err := o.createFiles()
err = o.createFiles()
if err != nil {
return err
}

View File

@ -1,3 +1,3 @@
# Hasura GraphQL Engine CLI Docs
Follow [hasura](hasura.md).
See [hasura](hasura.md).

View File

@ -16,9 +16,9 @@ Hasura GraphQL Engine command line tool
### SEE ALSO
* [hasura console](hasura_console.md) - Open console to manage database and try out APIs
* [hasura init](hasura_init.md) - Initialize directory for Hasura GraphQL Engine
* [hasura init](hasura_init.md) - Initialize directory for Hasura GraphQL Engine migrations
* [hasura metadata](hasura_metadata.md) - Manage Hausra GraphQL Engine metdata saved in the database
* [hasura migrate](hasura_migrate.md) - Manage migrations on the database
* [hasura version](hasura_version.md) - Print the CLI version
###### Auto generated by spf13/cobra on 28-Jun-2018
###### Auto generated by spf13/cobra on 6-Aug-2018

View File

@ -30,6 +30,7 @@ hasura console [flags]
--endpoint string http(s) endpoint for Hasura GraphQL Engine
-h, --help help for console
--no-browser do not automatically open console in browser
--static-dir string directory where static assets mentioned in the console html template can be served from
```
### Options inherited from parent commands
@ -42,4 +43,4 @@ hasura console [flags]
* [hasura](hasura.md) - Hasura GraphQL Engine command line tool
###### Auto generated by spf13/cobra on 28-Jun-2018
###### Auto generated by spf13/cobra on 6-Aug-2018

View File

@ -1,10 +1,10 @@
## hasura init
Initialize directory for Hasura GraphQL Engine
Initialize directory for Hasura GraphQL Engine migrations
### Synopsis
Create directories and files required for Hasura GraphQL Engine
Create directories and files required for enabling migrations on Hasura GraphQL Engine
```
hasura init [flags]
@ -13,13 +13,15 @@ hasura init [flags]
### Examples
```
# Create a directory with installation manifests:
hasura init --directory <my-directory>
# Create a directory to store migrations
hasura init
# Create a directory with an endpoint configured:
hasura --directory <my-directory> --endpoint <graphql-engine-endpoint>
# Now, edit <my-directory>/config.yaml to add endpoint and access key
# See https://docs.hasura.io/0.15/graphql/manual/getting-started for more details
# Create a directory with endpoint and access key configured:
hasura init --directory <my-project> --endpoint https://my-graphql-engine.com --access-key secretaccesskey
# See https://docs.hasura.io/1.0/graphql/manual/migrations/index.html for more details
```
### Options
@ -41,4 +43,4 @@ hasura init [flags]
* [hasura](hasura.md) - Hasura GraphQL Engine command line tool
###### Auto generated by spf13/cobra on 28-Jun-2018
###### Auto generated by spf13/cobra on 6-Aug-2018

View File

@ -27,4 +27,4 @@ Manage Hausra GraphQL Engine metdata saved in the database
* [hasura metadata export](hasura_metadata_export.md) - Export Hasura GraphQL Engine metadata from the database
* [hasura metadata reset](hasura_metadata_reset.md) - Reset or clean Hasura GraphQL Engine metadata on the database
###### Auto generated by spf13/cobra on 28-Jun-2018
###### Auto generated by spf13/cobra on 6-Aug-2018

View File

@ -35,4 +35,4 @@ hasura metadata apply [flags]
* [hasura metadata](hasura_metadata.md) - Manage Hausra GraphQL Engine metdata saved in the database
###### Auto generated by spf13/cobra on 28-Jun-2018
###### Auto generated by spf13/cobra on 6-Aug-2018

View File

@ -35,4 +35,4 @@ hasura metadata export [flags]
* [hasura metadata](hasura_metadata.md) - Manage Hausra GraphQL Engine metdata saved in the database
###### Auto generated by spf13/cobra on 28-Jun-2018
###### Auto generated by spf13/cobra on 6-Aug-2018

View File

@ -35,4 +35,4 @@ hasura metadata reset [flags]
* [hasura metadata](hasura_metadata.md) - Manage Hausra GraphQL Engine metdata saved in the database
###### Auto generated by spf13/cobra on 28-Jun-2018
###### Auto generated by spf13/cobra on 6-Aug-2018

View File

@ -27,4 +27,4 @@ Manage migrations on the database
* [hasura migrate create](hasura_migrate_create.md) - Create files required for a migration
* [hasura migrate status](hasura_migrate_status.md) - Display current status of migrations on a database
###### Auto generated by spf13/cobra on 28-Jun-2018
###### Auto generated by spf13/cobra on 6-Aug-2018

View File

@ -32,4 +32,4 @@ hasura migrate apply [flags]
* [hasura migrate](hasura_migrate.md) - Manage migrations on the database
###### Auto generated by spf13/cobra on 28-Jun-2018
###### Auto generated by spf13/cobra on 6-Aug-2018

View File

@ -28,4 +28,4 @@ hasura migrate create [migration-name] [flags]
* [hasura migrate](hasura_migrate.md) - Manage migrations on the database
###### Auto generated by spf13/cobra on 28-Jun-2018
###### Auto generated by spf13/cobra on 6-Aug-2018

View File

@ -28,4 +28,4 @@ hasura migrate status [flags]
* [hasura migrate](hasura_migrate.md) - Manage migrations on the database
###### Auto generated by spf13/cobra on 28-Jun-2018
###### Auto generated by spf13/cobra on 6-Aug-2018

View File

@ -26,4 +26,4 @@ hasura version [flags]
* [hasura](hasura.md) - Hasura GraphQL Engine command line tool
###### Auto generated by spf13/cobra on 28-Jun-2018
###### Auto generated by spf13/cobra on 6-Aug-2018

View File

@ -1,69 +0,0 @@
package util
import (
"fmt"
"io/ioutil"
"net/url"
"os"
"path/filepath"
"strconv"
"time"
"github.com/pkg/errors"
)
// InstallManifestsRepo is the GitHub repo where GraphQL Engine installation
// manifests are kept.
type InstallManifestsRepo struct {
// Namespace of the repo (e.g. hasura from github.com/hasura).
Namespace string
// Name of the repo (e.g. graphql-engine-install-manifests from
// github.com/hasura/graphql-engine-install-manifests).
Name string
}
// ZipURL returns the URL to download the repo from GitHub in ZIP format.
func (i *InstallManifestsRepo) ZipURL() string {
u := url.URL{
Scheme: "https",
Host: "github.com",
Path: fmt.Sprintf("%s/%s/archive/master.zip", i.Namespace, i.Name),
}
return u.String()
}
// Download downloads the repo contents into a temporary directory and returns
// the directory path. It is the caller's responsibility to remove the directory
// after handling the contents.
func (i *InstallManifestsRepo) Download() (dir string, err error) {
target, err := ioutil.TempDir("", "h-gql-temp")
if err != nil {
return "", errors.Wrap(err, "failed to create a temp dir")
}
err = Download(i.ZipURL(), filepath.Join(target, "manifests.zip"))
if err != nil {
return "", errors.Wrap(err, "failed downloading manifests")
}
err = Unzip(filepath.Join(target, "manifests.zip"),
filepath.Join(target, "manifests"))
if err != nil {
return "", errors.Wrap(err, "failed extracting manifests")
}
timestamp := strconv.Itoa(int(time.Now().Unix()))
dir = filepath.Join(os.TempDir(), "hasuragraphqlinstall"+timestamp)
if err != nil {
return "", errors.Wrap(err, "failed creating temp dir")
}
err = CopyDir(filepath.Join(target, "manifests", i.ZipExtractedDirectory()), dir)
if err != nil {
return "", errors.Wrap(err, "failed copying files to temp dir")
}
os.RemoveAll(target)
return dir, nil
}
// ZipExtractedDirectory returns the name of directory obtained after extracting
// the ZIP file downloaded from GitHub.
func (i *InstallManifestsRepo) ZipExtractedDirectory() string {
return fmt.Sprintf("%s-master", i.Name)
}

View File

@ -1,35 +0,0 @@
package util
import (
"os"
"testing"
)
var i = &InstallManifestsRepo{
Namespace: "hasura",
Name: "graphql-engine-install-manifests",
}
func TestZipURL(t *testing.T) {
expected := "https://github.com/hasura/graphql-engine-install-manifests/archive/master.zip"
u := i.ZipURL()
if u != expected {
t.Fatalf("expected: %s, got %s", expected, u)
}
}
func TestZipExtractedDirectory(t *testing.T) {
expected := "graphql-engine-install-manifests-master"
got := i.ZipExtractedDirectory()
if got != expected {
t.Fatalf("expected: %s, got %s", expected, got)
}
}
func TestDownload(t *testing.T) {
dir, err := i.Download()
if err != nil {
t.Fatalf("download failed: %v", err)
}
os.RemoveAll(dir)
}