Compare commits

...

4 Commits

Author SHA1 Message Date
Foysal Iqbal
dabaed4c07 fix uninstall (#15) 2020-01-09 14:36:46 -05:00
Foysal Iqbal
54d0972e85 uprev mixin (#13) 2020-01-08 13:20:51 -05:00
renovate[bot]
2839e5b77b Add renovate.json (#1)
Co-authored-by: Renovate Bot <renovatebot@gmail.com>
2020-01-03 10:45:33 -05:00
Jacob Martin
3608f9693c reconfigure auth to work (#3)
* reconfigure auth to work
2020-01-03 10:44:25 -05:00
5 changed files with 136 additions and 64 deletions

View File

@@ -16,6 +16,7 @@ func buildAliasCommands(porterCmd *cobra.Command, q *qliksense.Qliksense) []*cob
buildInstallAlias(porterCmd, q),
buildAboutAlias(porterCmd),
buildPreflightAlias(porterCmd, q),
buildUninstallAlias(porterCmd, q),
}
}
@@ -84,7 +85,7 @@ For example, the 'debug' driver may be specified, which simply logs the info giv
RunE: func(cmd *cobra.Command, args []string) error {
// Push images here.
// TODO: Need to get the private reg from params
args = append(os.Args[1:], opts.getTagDefaults(args)...)
args = append(os.Args[2:], opts.getTagValue(args)...)
if registry = opts.findKey("dockerRegistry"); registry != nil {
if len(*registry) > 0 {
q.TagAndPushImages(*registry)
@@ -121,17 +122,78 @@ For example, the 'debug' driver may be specified, which simply logs the info giv
"Force a fresh pull of the bundle and all dependencies")
return c
}
func buildUninstallAlias(porterCmd *cobra.Command, q *qliksense.Qliksense) *cobra.Command {
var (
c *cobra.Command
opts *paramOptions
)
opts = &paramOptions{}
c = &cobra.Command{
Use: "uninstall [INSTANCE]",
Short: "Uninstall a bundle instance",
Long: `Uninstall a bundle instance
The first argument is the bundle instance name to uninstall. This defaults to the name of the bundle.
Porter uses the Docker driver as the default runtime for executing a bundle's invocation image, but an alternate driver may be supplied via '--driver/-d'.
For example, the 'debug' driver may be specified, which simply logs the info given to it and then exits.`,
Example: ` qliksense uninstall
qliksense uninstall --insecure
qliksense uninstall MyAppInDev --file myapp/bundle.json
qliksense uninstall --param-file base-values.txt --param-file dev-values.txt --param test-mode=true --param header-color=blue
qliksense uninstall --cred azure --cred kubernetes
qliksense uninstall --driver debug
qliksense uninstall MyAppFromTag --tag deislabs/porter-kube-bundle:v1.0
`,
RunE: func(cmd *cobra.Command, args []string) error {
return porterCmd.RunE(porterCmd, append([]string{"uninstall"}, os.Args[2:]...))
},
Annotations: map[string]string{
"group": "alias",
},
}
f := c.Flags()
f.BoolVar(&opts.Insecure, "insecure", true,
"Allow working with untrusted bundles")
f.StringVarP(&opts.File, "file", "f", "",
"Path to the porter manifest file. Defaults to the bundle in the current directory. Optional unless a newer version of the bundle should be used to uninstall the bundle.")
f.StringVar(&opts.CNABFile, "cnab-file", "",
"Path to the CNAB bundle.json file.")
f.StringSliceVar(&opts.ParamFiles, "param-file", nil,
"Path to a parameters definition file for the bundle, each line in the form of NAME=VALUE. May be specified multiple times.")
f.StringSliceVar(&opts.Params, "param", nil,
"Define an individual parameter in the form NAME=VALUE. Overrides parameters set with the same name using --param-file. May be specified multiple times.")
f.StringSliceVarP(&opts.CredentialIdentifiers, "cred", "c", nil,
"Credential to use when uninstalling the bundle. May be either a named set of credentials or a filepath, and specified multiple times.")
f.StringVarP(&opts.Driver, "driver", "d", "docker",
"Specify a driver to use. Allowed values: docker, debug")
f.StringVarP(&opts.Tag, "tag", "t", "",
"Use a bundle in an OCI registry specified by the given tag")
f.BoolVar(&opts.InsecureRegistry, "insecure-registry", false,
"Don't require TLS for the registry")
f.BoolVar(&opts.Force, "force", false,
"Force a fresh pull of the bundle and all dependencies")
return c
}
func (o *aboutOptions) getTagDefaults(args []string) []string {
var err error
args = append(args, o.getTagValue(args)...)
return args
}
func (o *aboutOptions) getTagValue(args []string) []string {
tagArr := []string{}
if len(o.Tag) > 1 {
args = append(args, []string{"--tag", o.Tag}...)
tagArr = []string{"--tag", o.Tag}
}
if len(o.Tag) <= 0 && len(o.File) <= 0 && len(o.CNABFile) <= 0 {
if _, err = os.Stat("porter.yaml"); err != nil {
args = append(args, []string{"--tag", "qlik/qliksense-cnab-bundle:" + o.Version}...)
if _, err := os.Stat("porter.yaml"); err != nil {
tagArr = []string{"--tag", "qlik/qliksense-cnab-bundle:" + o.Version}
}
}
return args
return tagArr
}
type aboutOptions struct {

View File

@@ -49,7 +49,7 @@ func installPorter() (string, error) {
destination, homeDir, mixin, mixinOpts, qlikSenseHome, porterExe, ext string
mixinsVar = map[string]string{
"kustomize": "-v 0.2-beta-3-0e19ca4 --url https://github.com/donmstewart/porter-kustomize/releases/download",
"qliksense": "-v v0.11.0 --url https://github.com/qlik-oss/porter-qliksense/releases/download",
"qliksense": "-v v0.14.0 --url https://github.com/qlik-oss/porter-qliksense/releases/download",
"exec": "-v latest",
"kubernetes": "-v latest",
"helm": "-v latest",

View File

@@ -8,10 +8,12 @@ import (
"github.com/docker/cli/cli/command"
cliflags "github.com/docker/cli/cli/flags"
"github.com/docker/distribution/reference"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/filters"
"github.com/docker/docker/pkg/jsonmessage"
"github.com/docker/docker/pkg/term"
"github.com/docker/docker/registry"
"strings"
@@ -53,7 +55,6 @@ func (p *Qliksense) PullImages() error {
if err = yaml.Unmarshal([]byte(yamlVersion), &images); err != nil {
return err
}
for _, image = range images.Images {
if err = p.PullImage(image); err != nil {
fmt.Print(err)
@@ -72,12 +73,12 @@ func (p *Qliksense) PullImage(imageName string) error {
response io.ReadCloser
pullOptions types.ImagePullOptions
ctx context.Context
// ref reference.Named
// repoInfo *registry.RepositoryInfo
// authConfig types.AuthConfig
// encodedAuth string
termFd uintptr
err error
ref reference.Named
repoInfo *registry.RepositoryInfo
authConfig types.AuthConfig
encodedAuth string
termFd uintptr
err error
)
// TODO: Create a real cli config context
ctx = context.Background()
@@ -85,24 +86,26 @@ func (p *Qliksense) PullImage(imageName string) error {
return err
}
// if ref, err = reference.ParseNormalizedNamed(imageName); err != nil {
// return err
// }
// if repoInfo, err = registry.ParseRepositoryInfo(ref); err != nil {
// return err
// }
// authConfig = command.ResolveAuthConfig(ctx, cli, repoInfo.Index)
// if encodedAuth, err = command.EncodeAuthToBase64(authConfig); err != nil {
// return err
// }
pullOptions = types.ImagePullOptions{
// RegistryAuth: encodedAuth,
}
if err = cli.Initialize(cliflags.NewClientOptions()); err != nil {
return err
}
if ref, err = reference.ParseNormalizedNamed(imageName); err != nil {
return err
}
if repoInfo, err = registry.ParseRepositoryInfo(ref); err != nil {
return err
}
authConfig = command.ResolveAuthConfig(ctx, cli, repoInfo.Index)
if encodedAuth, err = command.EncodeAuthToBase64(authConfig); err != nil {
return err
}
pullOptions = types.ImagePullOptions{
RegistryAuth: encodedAuth,
}
if response, err = cli.Client().ImagePull(ctx, imageName, pullOptions); err != nil {
return err
}
@@ -164,7 +167,7 @@ func (p *Qliksense) TagAndPushImages(registry string) error {
}
// PullImage ...
func (p *Qliksense) TagAndPush(image string, registry string) error {
func (p *Qliksense) TagAndPush(image string, registryName string) error {
var (
cli *command.DockerCli
dockerOutput io.Writer
@@ -176,11 +179,12 @@ func (p *Qliksense) TagAndPush(image string, registry string) error {
imageList []types.ImageSummary
imageListOptions types.ImageListOptions
filterArgs filters.Args
// repoInfo *registry.RepositoryInfo
// authConfig types.AuthConfig
// encodedAuth string
termFd uintptr
err error
ref reference.Named
repoInfo *registry.RepositoryInfo
authConfig types.AuthConfig
encodedAuth string
termFd uintptr
err error
)
// TODO: Create a real cli config context
ctx = context.Background()
@@ -194,7 +198,7 @@ func (p *Qliksense) TagAndPush(image string, registry string) error {
if segments[0] == "docker.io" {
image = strings.Join(segments[1:], "/")
}
newName = registry + "/" + segments[len(segments)-1]
newName = registryName + "/" + segments[len(segments)-1]
filterArgs = filters.NewArgs()
filterArgs.Add("reference", image)
@@ -213,20 +217,19 @@ func (p *Qliksense) TagAndPush(image string, registry string) error {
return err
}
// if ref, err = reference.ParseNormalizedNamed(imageName); err != nil {
// return err
// }
// if repoInfo, err = registry.ParseRepositoryInfo(ref); err != nil {
// return err
// }
// authConfig = command.ResolveAuthConfig(ctx, cli, repoInfo.Index)
// if encodedAuth, err = command.EncodeAuthToBase64(authConfig); err != nil {
// return err
// }
if ref, err = reference.ParseNormalizedNamed(image); err != nil {
return err
}
if repoInfo, err = registry.ParseRepositoryInfo(ref); err != nil {
return err
}
authConfig = command.ResolveAuthConfig(ctx, cli, repoInfo.Index)
if encodedAuth, err = command.EncodeAuthToBase64(authConfig); err != nil {
return err
}
pushOptions = types.ImagePushOptions{
All: true,
RegistryAuth: "temp",
// RegistryAuth: encodedAuth,
RegistryAuth: encodedAuth,
}
if response, err = cli.Client().ImagePush(ctx, newName, pushOptions); err != nil {

View File

@@ -1,30 +1,33 @@
package qliksense
import (
"io"
"fmt"
"bufio"
"fmt"
"io"
"os"
"os/exec"
)
// ProcessLine ...
type ProcessLine func(string) *string
// CallPorter ...
func (p *Qliksense) CallPorter(args []string, processor ProcessLine) (string,error) {
func (p *Qliksense) CallPorter(args []string, processor ProcessLine) (string, error) {
var (
outText string
cmd *exec.Cmd
err error
output io.ReadCloser
scanner *bufio.Scanner
done chan struct{}
output io.ReadCloser
scanner *bufio.Scanner
done chan struct{}
)
cmd = exec.Command(p.porterExe,args[:]...)
if output,err = cmd.StdoutPipe(); err !=nil {
return "",err
cmd = exec.Command(p.porterExe, args[:]...)
if output, err = cmd.StdoutPipe(); err != nil {
return "", err
}
cmd.Stderr = os.Stderr
done = make(chan struct{})
scanner = bufio.NewScanner(output)
go func() {
@@ -35,24 +38,23 @@ func (p *Qliksense) CallPorter(args []string, processor ProcessLine) (string,err
if processor != nil {
newText = processor(text)
if newText != nil {
outText = outText + fmt.Sprintln(*newText)
outText = outText + fmt.Sprintln(*newText)
}
} else {
outText = outText + fmt.Sprintln(text)
outText = outText + fmt.Sprintln(text)
}
}
done <- struct{}{}
}()
if err = cmd.Start(); err != nil {
return "",err
return "", err
}
<-done
if err = cmd.Wait(); err != nil {
return "",err
return "", err
}
if err = scanner.Err(); err != nil {
return "",err
return "", err
}
return outText,nil
return outText, nil
}

5
renovate.json Normal file
View File

@@ -0,0 +1,5 @@
{
"extends": [
"config:base"
]
}