Compare commits
30 Commits
v0.1.0
...
readme_doc
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
35bd8835df | ||
|
|
c1799deeef | ||
|
|
837b88f3c8 | ||
|
|
880f7cb29c | ||
|
|
c7d93e2652 | ||
|
|
87ebd74daf | ||
|
|
39d02db187 | ||
|
|
0393a431fb | ||
|
|
d1088e2635 | ||
|
|
dabaed4c07 | ||
|
|
54d0972e85 | ||
|
|
2839e5b77b | ||
|
|
3608f9693c | ||
|
|
60a328d69f | ||
|
|
ee02016f16 | ||
|
|
e5024b7f0a | ||
|
|
d408d33971 | ||
|
|
cff29ed862 | ||
|
|
e5108e0040 | ||
|
|
0372b82b49 | ||
|
|
48ca84f5f8 | ||
|
|
97a137ff23 | ||
|
|
776c91d300 | ||
|
|
c37f5338dc | ||
|
|
0cf8a9b4c9 | ||
|
|
75fcb93c33 | ||
|
|
465095e4ee | ||
|
|
3ffd167ae7 | ||
|
|
51bc8fda68 | ||
|
|
0623ebd603 |
@@ -17,12 +17,23 @@ jobs:
|
||||
steps:
|
||||
- checkout
|
||||
- run: make xbuild-all
|
||||
- run:
|
||||
name: "Build latest master from porter repo"
|
||||
command: |
|
||||
export GO111MODULE=off
|
||||
go get -u get.porter.sh/porter || true
|
||||
cd /go/src/get.porter.sh/porter
|
||||
# store porter master commit
|
||||
git rev-parse HEAD > /go/porter-master-commit.txt
|
||||
make xbuild-all VERSION=latest
|
||||
cp -r bin/latest/* /go/src/github.com/${CIRCLE_PROJECT_USERNAME}/${CIRCLE_PROJECT_REPONAME}/bin/${CIRCLE_TAG}/
|
||||
- run:
|
||||
name: "Publish Release on GitHub"
|
||||
command: |
|
||||
go get github.com/tcnksm/ghr
|
||||
# VERSION=v$(./artifacts/qliksense-linux-amd64 version | sed -nre 's/^[^0-9]*(([0-9]+\.)*[0-9]+).*/\1/p')
|
||||
ghr -t ${GITHUB_TOKEN} -u ${CIRCLE_PROJECT_USERNAME} -r ${CIRCLE_PROJECT_REPONAME} -c ${CIRCLE_SHA1} -delete ${CIRCLE_TAG} /go/src/github.com/${CIRCLE_PROJECT_USERNAME}/${CIRCLE_PROJECT_REPONAME}/bin/${CIRCLE_TAG}/
|
||||
PORTER_REPO_COMMIT=$(cat /go/porter-master-commit.txt)
|
||||
ghr -t ${GITHUB_TOKEN} -u ${CIRCLE_PROJECT_USERNAME} -r ${CIRCLE_PROJECT_REPONAME} -c ${CIRCLE_SHA1} -b "porter build based on commit: https://github.com/deislabs/porter/commit/${PORTER_REPO_COMMIT}" -delete ${CIRCLE_TAG} /go/src/github.com/${CIRCLE_PROJECT_USERNAME}/${CIRCLE_PROJECT_REPONAME}/bin/${CIRCLE_TAG}/
|
||||
workflows:
|
||||
version: 2
|
||||
commit:
|
||||
|
||||
628
.qliksense/porter-runtime
Normal file
628
.qliksense/porter-runtime
Normal file
File diff suppressed because one or more lines are too long
628
.qliksense/porter.exe
Normal file
628
.qliksense/porter.exe
Normal file
File diff suppressed because one or more lines are too long
6
Makefile
6
Makefile
@@ -1,13 +1,14 @@
|
||||
PKG = qlik-oss/sense-installer
|
||||
PKG = github.com/qlik-oss/sense-installer
|
||||
|
||||
# --no-print-directory avoids verbose logging when invoking targets that utilize sub-makes
|
||||
MAKE_OPTS ?= --no-print-directory
|
||||
|
||||
LDFLAGS = -w -X $(PKG)/pkg.Version=$(VERSION) -X $(PKG)/pkg.Commit=$(COMMIT)
|
||||
LDFLAGS = -w -X $(PKG)/pkg.Version=$(VERSION) -X $(PKG)/pkg.Commit=$(COMMIT) -X "$(PKG)/pkg.CommitDate=$(COMMIT_DATE)"
|
||||
XBUILD = CGO_ENABLED=0 go build -a -tags netgo -ldflags '$(LDFLAGS)'
|
||||
BINDIR = bin
|
||||
|
||||
COMMIT ?= $(shell git rev-parse --short HEAD)
|
||||
COMMIT_DATE ?= $(shell git show --no-patch --no-notes --pretty='%cd' $(COMMIT) --date=iso)
|
||||
VERSION ?= $(shell git describe --tags 2> /dev/null || echo v0)
|
||||
PERMALINK ?= $(shell git describe --tags --exact-match &> /dev/null && echo latest || echo canary)
|
||||
|
||||
@@ -44,3 +45,4 @@ xbuild: $(BINDIR)/$(VERSION)/$(MIXIN)-$(CLIENT_PLATFORM)-$(CLIENT_ARCH)$(FILE_EX
|
||||
$(BINDIR)/$(VERSION)/$(MIXIN)-$(CLIENT_PLATFORM)-$(CLIENT_ARCH)$(FILE_EXT):
|
||||
mkdir -p $(dir $@)
|
||||
GOOS=$(CLIENT_PLATFORM) GOARCH=$(CLIENT_ARCH) $(XBUILD) -o $@ ./cmd/$(MIXIN)
|
||||
|
||||
|
||||
124
README.md
124
README.md
@@ -1 +1,123 @@
|
||||
# sense-installer
|
||||
# Qlik Sense installation and operations CLI
|
||||
|
||||
- [Qlik Sense installation and operations CLI](#qlik-sense-installation-and-operations-cli)
|
||||
- [About](#about)
|
||||
- [Future Direction](#future-direction)
|
||||
- [Getting Started](#getting-started)
|
||||
- [Requirements](#requirements)
|
||||
- [Download](#download)
|
||||
- [Generate Credentials from published bundle](#generate-credentials-from-published-bundle)
|
||||
- [Qlik Sense version and image list](#qliksense-version-and-image-list)
|
||||
- [Optional: Pulling images in manifest locally, "air gap"](#optional-pulling-images-in-manifest-locally-%22air-gap%22)
|
||||
- [Running Preflight checks](#running-preflight-checks)
|
||||
- [Installation](#installation)
|
||||
- [Supported Parameters during install](#supported-parameters-during-install)
|
||||
- [How To Add Identity Provider Config](#how-to-add-identity-provider-config)
|
||||
- [Packaging a Custom bundle](#packaging-a-custom-bundle)
|
||||
|
||||
## About
|
||||
|
||||
The Qlik Sense installer CLI (sense-installer) provides an imperitive interface to many of the configurations that need to be applied against the declaritive structure described in (https://github.com/qlik-oss/qliksense-k8s)[https://github.com/qlik-oss/qliksense-k8s].
|
||||
|
||||
This is a technology preview that uses (porter)[https://porter.sh] to execute "actions" (operations) and bundle versions of the (qliksense-k8s)[https://github.com/qlik-oss/qliksense-k8s] repository.
|
||||
|
||||
These bundles are posted to (docker hub)[https://hub.docker.com/] at the following location: (https://hub.docker.com/r/qlik/qliksense-cnab-bundle)[https://hub.docker.com/r/qlik/qliksense-cnab-bundle/tags].
|
||||
|
||||
For each version of a qliksense sense edge build there should be a corresponding release current posted on docker hub. ex. `qlik/qliksense-cnab-bundle:v1.21.23-edge` for `v1.21.23` edge release of qliksense. The latest version posted will also be labelled as `latest`
|
||||
|
||||
### Future Direction
|
||||
|
||||
- Porter is currently used as a core technology for the CLI. In the future Porter will be moved "up the stack" to allow the CLI to perform the current and expanded operations independently and encapsulate core functionality currently provided by Porter and other dependent tooling.
|
||||
- More operations:
|
||||
- Expanded preflight checks
|
||||
- backup/restore operations
|
||||
|
||||
## Getting Started
|
||||
|
||||
### Requirements
|
||||
|
||||
- Docker Client connected to a docker engine into which images can built, pulled and pushed.
|
||||
- (Docker Desktop setup tested for these instructions)
|
||||
|
||||
### Download
|
||||
|
||||
- Download the appropriate executable for your platform from the [releases page](https://github.com/qlik-oss/sense-installer/releases).
|
||||
- Two environment variables will need to be set so as not to conflict with an existing porter installation:
|
||||
- _Bash_
|
||||
```shell
|
||||
bash# export PORTER_HOME="$HOME\.qliksense"
|
||||
bash# export PATH="$HOME\.qliksense;$PATH"
|
||||
```
|
||||
- _PowerShell_
|
||||
```shell
|
||||
PS> $Env:PORTER_HOME="$Env:USERPROFILE\.qliksense"
|
||||
PS> $Env:PATH="$Env:USERPROFILE\.qliksense;$Env:PATH"
|
||||
```
|
||||
- To allow the CLI to download and initialize dependencies (including porter and it's associated mixins), simply execute `qliksense` with no arguments
|
||||
- `qliksense`
|
||||
|
||||
### Generate Credentials from published bundle
|
||||
|
||||
- Ensure connectivity to the target cluster create a kubeconfig credential for a target bundle run ex.
|
||||
- `porter cred generate <credential_name> --tag qlik/qliksense-cnab-bundle:v1.21.23-edge`
|
||||
, replace `<credential_name>` with a name of your choosing.
|
||||
- Select `file path` and specify full path to a kube config file ex. _Bash_:
|
||||
- `/home/user/.kube/config` or _PowerShell_ `C:\Users\user\.kube\config `
|
||||
|
||||
### Qlik Sense version and image list
|
||||
|
||||
It is possible verify the version of the (qliksense-k8s)[https://github.com/qlik-oss/qliksense-k8s] repository bundled into the `qlik/qliksense-cnab-bundle` image and retreive the list of images included in that release. (This operation can take a minute or so)<https://github.com/qlik-oss/kustomize/issues/13> as the entire manifests needs to be rendered:
|
||||
- `qliksense about --tag qlik/qliksense-cnab-bundle:<qliksense_version>`
|
||||
|
||||
### Optional: Pulling images in manifest locally, "air gap"
|
||||
|
||||
If the `dockerRegistry` parameter is specified as the private docker registry to be used by the kubernetes cluster hosting qliksense, it is possible to pull images to the local docker engine for an eventual push during a `qliksense install` or `qliksense upgrade`
|
||||
|
||||
### Running Preflight checks
|
||||
You can run preflight checks to ensure that the cluster is in a healthy state before installing Qliksense.
|
||||
- `qliksense preflight -c <credential_name> --tag qlik/qliksense-cnab-bundle:<qliksense_version>`
|
||||
|
||||
The above command runs the checks in the default namespace. If you want to specify the namespace to run preflight checks on:
|
||||
- `qliksense preflight --param namespace=<value> -c <credential_name> --tag qlik/qliksense-cnab-bundle:<qliksense_version>`
|
||||
|
||||
### Installation
|
||||
- Install the bundle : `qliksense install --param acceptEULA=yes -c <credential_name> --tag qlik/qliksense-cnab-bundle:<qliksense_version>`
|
||||
|
||||
#### Supported Parameters during install
|
||||
|
||||
| Name | Descriptions | Default |
|
||||
| ------------- |:-------------:| -----:|
|
||||
| profile | select a profile i.e docker-desktop, aws-eks, gke | docker-desktop |
|
||||
| acceptEULA | yes | has to be yes |
|
||||
| namespace | any kubernetes namespace | default |
|
||||
| dockerRegistry | A private docker image regitry for pods | not specified (public) |
|
||||
| rotateKeys | regenerate application PKI keys on upgrade (yes/no) | no |
|
||||
| mongoDbUri | the mongodb URI to use | URI of development mongodb |
|
||||
| scName | storage class name | none |
|
||||
|
||||
#### How To Add Identity Provider Config
|
||||
|
||||
Since idp configs are usually multiline configs it is not conventional to pass to porter during install as a `param`. Rather put the configs in a file and refer to that file during `porter install` command. For example to add `keycloak` IDP create file named `idpconfigs.txt` and put
|
||||
|
||||
```shell
|
||||
idpConfigs=[{"discoveryUrl":"http://keycloak-insecure:8089/keycloak/realms/master22/.well-known/openid-configuration","clientId":"edge-auth","clientSecret":"e15b5075-9399-4b20-a95e-023022aa4aed","realm":"master","hostname":"elastic.example","claimsMapping":{"sub":["sub","client_id"],"name":["name","given_name","family_name","preferred_username"]}}]
|
||||
|
||||
```
|
||||
|
||||
Then pass that file during install command like this
|
||||
|
||||
```shell
|
||||
porter install --param acceptEULA=yes -c <credential_name> --param-file idpconfigs.txt --tag qlik/qliksense-cnab-bundle:<qliksense_version>`
|
||||
```
|
||||
|
||||
|
||||
## Packaging a Custom bundle
|
||||
|
||||
If files need to be added to the (qliksense-k8s repository)[https://github.com/qlik-oss/qliksense-k8s] in order to perform advanced configuration outside the scope of the what the operator provides, a custom bundle needs to be built.
|
||||
|
||||
Packaging of Qlik Sense on Kubernetes is done through a [Porter](https://porter.sh/) definition in the [Qlik Sense on Kubernetes configuration repository](https://github.com/qlik-oss/qliksense-k8s/blob/master/porter.yaml), the resulting bundle published on DockerHub as a [Cloud Natvie Application Bundle](https://cnab.io/) called [qliksense-cnab-bundle](https://hub.docker.com/r/qlik/qliksense-cnab-bundle)
|
||||
|
||||
To start, clone (https://github.com/qlik-oss/qliksense-k8s)[https://github.com/qlik-oss/qliksense-k8s] and modify the repo as desired, once finished make sure to be in the `qliksense-k8s` directory from which the porter bundle can be built:
|
||||
- `porter build`
|
||||
|
||||
Once built, all of the `porter` command that were used with `--tag` can be now be used without this flag provided that porter is executed with the `qliksense-k8s` directory. `porter` will automatically use the qliksense-k8s (and the porter.yaml) in the current directory.
|
||||
|
||||
@@ -1,210 +1,412 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/qlik-oss/sense-installer/pkg/qliksense"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
func buildAliasCommands(porterCmd *cobra.Command, q *qliksense.Qliksense) []*cobra.Command {
|
||||
|
||||
return []*cobra.Command{
|
||||
buildBuildAlias(porterCmd),
|
||||
buildInstallAlias(porterCmd, q),
|
||||
buildAboutAlias(porterCmd),
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func buildBuildAlias(porterCmd *cobra.Command) *cobra.Command {
|
||||
var (
|
||||
c *cobra.Command
|
||||
)
|
||||
c = &cobra.Command{
|
||||
Use: "build",
|
||||
Short: "Build a bundle",
|
||||
Long: "Builds the bundle in the current directory by generating a Dockerfile and a CNAB bundle.json, and then building the invocation image.",
|
||||
DisableFlagParsing: true,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
return porterCmd.RunE(porterCmd, append([]string{"build"}, args...))
|
||||
},
|
||||
Annotations: map[string]string{
|
||||
"group": "alias",
|
||||
},
|
||||
}
|
||||
return c
|
||||
}
|
||||
|
||||
type paramOptions struct {
|
||||
Params []string
|
||||
ParamFiles []string
|
||||
File string
|
||||
Name string
|
||||
InsecureRegistry bool
|
||||
CNABFile string
|
||||
// CredentialIdentifiers is a list of credential names or paths to make available to the bundle.
|
||||
CredentialIdentifiers []string
|
||||
Driver string
|
||||
Force bool
|
||||
Insecure bool
|
||||
Tag string
|
||||
}
|
||||
|
||||
func buildInstallAlias(porterCmd *cobra.Command, q *qliksense.Qliksense) *cobra.Command {
|
||||
var (
|
||||
c *cobra.Command
|
||||
opts *paramOptions
|
||||
registry *string
|
||||
)
|
||||
|
||||
opts = ¶mOptions{}
|
||||
|
||||
c = &cobra.Command{
|
||||
Use: "install [INSTANCE]",
|
||||
Short: "Install qliksense",
|
||||
Long: `Install a new instance of a bundle.
|
||||
|
||||
The first argument is the bundle instance name to create for the installation. 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 install
|
||||
qliksense install --insecure
|
||||
qliksense install qliksense --file qliksense/bundle.json
|
||||
qliksense install --param-file base-values.txt --param-file dev-values.txt --param test-mode=true --param header-color=blue
|
||||
qliksense install --cred kubernetes
|
||||
qliksense install --driver debug
|
||||
qliksense install MyAppFromTag --tag qlik/qliksense-cnab-bundle:v1.0.0
|
||||
`,
|
||||
//DisableFlagParsing: true,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
// Push images here.
|
||||
// TODO: Need to get the private reg from params
|
||||
if registry = opts.findKey("dockerRegistry"); registry != nil {
|
||||
if len(*registry) > 0 {
|
||||
q.TagAndPushImages(*registry)
|
||||
}
|
||||
}
|
||||
return porterCmd.RunE(porterCmd, append([]string{"install"}, args...))
|
||||
},
|
||||
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.")
|
||||
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 installing 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 buildAboutAlias(porterCmd *cobra.Command) *cobra.Command {
|
||||
var (
|
||||
c *cobra.Command
|
||||
)
|
||||
c = &cobra.Command{
|
||||
Use: "about",
|
||||
Short: "About Qlik Sense",
|
||||
Long: "Gives the verion of QLik Sense on Kuberntetes and versions of images.",
|
||||
DisableFlagParsing: true,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
return porterCmd.RunE(porterCmd, append([]string{"invoke", "--action", "about"}, args...))
|
||||
},
|
||||
Annotations: map[string]string{
|
||||
"group": "alias",
|
||||
},
|
||||
}
|
||||
return c
|
||||
}
|
||||
|
||||
func (o *paramOptions) findKey(param string) *string {
|
||||
var (
|
||||
value *string
|
||||
)
|
||||
if value = o.findParams(param); value != nil {
|
||||
return value
|
||||
}
|
||||
|
||||
if value = o.findParamFiles(param); value != nil {
|
||||
return value
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// parsedParams parses the variable assignments in Params.
|
||||
func (o *paramOptions) findParams(param string) *string {
|
||||
return o.findVariableKey(param, o.Params)
|
||||
}
|
||||
|
||||
// parseParamFiles parses the variable assignments in ParamFiles.
|
||||
func (o *paramOptions) findParamFiles(param string) *string {
|
||||
var (
|
||||
path string
|
||||
retStr *string
|
||||
)
|
||||
|
||||
for _, path = range o.ParamFiles {
|
||||
retStr = o.findParamFile(param, path)
|
||||
}
|
||||
|
||||
return retStr
|
||||
}
|
||||
|
||||
func (o *paramOptions) findParamFile(param string, path string) *string {
|
||||
var (
|
||||
f *os.File
|
||||
err error
|
||||
scanner *bufio.Scanner
|
||||
lines []string
|
||||
retStr *string
|
||||
)
|
||||
if f, err = os.Open(path); err == nil {
|
||||
defer f.Close()
|
||||
|
||||
scanner = bufio.NewScanner(f)
|
||||
for scanner.Scan() {
|
||||
lines = append(lines, scanner.Text())
|
||||
}
|
||||
|
||||
retStr = o.findVariableKey(param, lines)
|
||||
}
|
||||
return retStr
|
||||
}
|
||||
|
||||
func (o *paramOptions) findVariableKey(param string, params []string) *string {
|
||||
var (
|
||||
variable, value string
|
||||
)
|
||||
for _, p := range params {
|
||||
parts := strings.SplitN(p, "=", 2)
|
||||
if len(parts) >= 2 {
|
||||
variable = strings.TrimSpace(parts[0])
|
||||
if variable == param {
|
||||
value = strings.TrimSpace(parts[1])
|
||||
return &value
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/qlik-oss/sense-installer/pkg/qliksense"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
func buildAliasCommands(porterCmd *cobra.Command, q *qliksense.Qliksense) []*cobra.Command {
|
||||
|
||||
return []*cobra.Command{
|
||||
buildBuildAlias(porterCmd),
|
||||
buildInstallAlias(porterCmd, q),
|
||||
buildUpgradeAlias(porterCmd, q),
|
||||
buildAboutAlias(porterCmd),
|
||||
buildPreflightAlias(porterCmd, q),
|
||||
buildUninstallAlias(porterCmd, q),
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func buildBuildAlias(porterCmd *cobra.Command) *cobra.Command {
|
||||
var (
|
||||
c *cobra.Command
|
||||
)
|
||||
c = &cobra.Command{
|
||||
Use: "build",
|
||||
Short: "Build a bundle",
|
||||
Long: "Builds the bundle in the current directory by generating a Dockerfile and a CNAB bundle.json, and then building the invocation image.",
|
||||
DisableFlagParsing: true,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
return porterCmd.RunE(porterCmd, append([]string{"build"}, args...))
|
||||
},
|
||||
Annotations: map[string]string{
|
||||
"group": "alias",
|
||||
},
|
||||
}
|
||||
return c
|
||||
}
|
||||
|
||||
type paramOptions struct {
|
||||
aboutOptions
|
||||
Params []string
|
||||
ParamFiles []string
|
||||
Name string
|
||||
InsecureRegistry bool
|
||||
|
||||
// CredentialIdentifiers is a list of credential names or paths to make available to the bundle.
|
||||
CredentialIdentifiers []string
|
||||
Driver string
|
||||
Force bool
|
||||
Insecure bool
|
||||
}
|
||||
|
||||
func buildInstallAlias(porterCmd *cobra.Command, q *qliksense.Qliksense) *cobra.Command {
|
||||
var (
|
||||
c *cobra.Command
|
||||
opts *paramOptions
|
||||
registry *string
|
||||
)
|
||||
|
||||
opts = ¶mOptions{}
|
||||
|
||||
c = &cobra.Command{
|
||||
Use: "install [INSTANCE]",
|
||||
Short: "Install qliksense",
|
||||
Long: `Install a new instance of a bundle.
|
||||
|
||||
The first argument is the bundle instance name to create for the installation. 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 install
|
||||
qliksense install --version v1.0.0
|
||||
qliksense install --insecure
|
||||
qliksense install qliksense --file qliksense/bundle.json
|
||||
qliksense install --param-file base-values.txt --param-file dev-values.txt --param test-mode=true --param header-color=blue
|
||||
qliksense install --cred kubernetes
|
||||
qliksense install --driver debug
|
||||
qliksense install MyAppFromTag --tag qlik/qliksense-cnab-bundle:v1.0.0
|
||||
`,
|
||||
//DisableFlagParsing: true,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
// Push images here.
|
||||
// TODO: Need to get the private reg from params
|
||||
args = append(os.Args[2:], opts.getTagValue(args)...)
|
||||
if registry = opts.findKey("dockerRegistry"); registry != nil {
|
||||
if len(*registry) > 0 {
|
||||
q.TagAndPushImages(*registry)
|
||||
}
|
||||
}
|
||||
return porterCmd.RunE(porterCmd, append([]string{"install"}, args...))
|
||||
},
|
||||
Annotations: map[string]string{
|
||||
"group": "alias",
|
||||
},
|
||||
}
|
||||
f := c.Flags()
|
||||
f.StringVarP(&opts.Version, "version", "v", "latest",
|
||||
"Version of Qlik Sense to install")
|
||||
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.")
|
||||
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 installing 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 buildUpgradeAlias(porterCmd *cobra.Command, q *qliksense.Qliksense) *cobra.Command {
|
||||
var (
|
||||
c *cobra.Command
|
||||
opts *paramOptions
|
||||
registry *string
|
||||
)
|
||||
|
||||
opts = ¶mOptions{}
|
||||
|
||||
c = &cobra.Command{
|
||||
Use: "upgrade [INSTANCE]",
|
||||
Short: "Upgrade qliksense",
|
||||
Long: `Upgrade to a new instance of a bundle.
|
||||
|
||||
The first argument is the bundle instance name to upgrade for the installation. 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 upgrade
|
||||
qliksense upgrade --version v1.0.0
|
||||
qliksense upgrade --insecure
|
||||
qliksense upgrade qliksense --file qliksense/bundle.json
|
||||
qliksense upgrade --param-file base-values.txt --param-file dev-values.txt --param test-mode=true --param header-color=blue
|
||||
qliksense upgrade --cred kubernetes
|
||||
qliksense upgrade --driver debug
|
||||
qliksense upgrade MyAppFromTag --tag qlik/qliksense-cnab-bundle:v1.0.0
|
||||
`,
|
||||
//DisableFlagParsing: true,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
// Push images here.
|
||||
// TODO: Need to get the private reg from params
|
||||
args = append(os.Args[2:], opts.getTagValue(args)...)
|
||||
if registry = opts.findKey("dockerRegistry"); registry != nil {
|
||||
if len(*registry) > 0 {
|
||||
q.TagAndPushImages(*registry)
|
||||
}
|
||||
}
|
||||
return porterCmd.RunE(porterCmd, append([]string{"upgrade"}, args...))
|
||||
},
|
||||
Annotations: map[string]string{
|
||||
"group": "alias",
|
||||
},
|
||||
}
|
||||
f := c.Flags()
|
||||
f.StringVarP(&opts.Version, "version", "v", "latest",
|
||||
"Version of Qlik Sense to upgrade to")
|
||||
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.")
|
||||
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 installing 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 buildUninstallAlias(porterCmd *cobra.Command, q *qliksense.Qliksense) *cobra.Command {
|
||||
var (
|
||||
c *cobra.Command
|
||||
opts *paramOptions
|
||||
)
|
||||
|
||||
opts = ¶mOptions{}
|
||||
|
||||
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 {
|
||||
args = append(args, o.getTagValue(args)...)
|
||||
return args
|
||||
}
|
||||
|
||||
func (o *aboutOptions) getTagValue(args []string) []string {
|
||||
tagArr := []string{}
|
||||
if len(o.Tag) > 1 {
|
||||
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 {
|
||||
tagArr = []string{"--tag", "qlik/qliksense-cnab-bundle:" + o.Version}
|
||||
}
|
||||
}
|
||||
return tagArr
|
||||
}
|
||||
|
||||
type aboutOptions struct {
|
||||
Version string
|
||||
Tag string
|
||||
File string
|
||||
CNABFile string
|
||||
}
|
||||
|
||||
func buildAboutAlias(porterCmd *cobra.Command) *cobra.Command {
|
||||
var (
|
||||
c *cobra.Command
|
||||
opts *aboutOptions
|
||||
)
|
||||
|
||||
opts = &aboutOptions{}
|
||||
|
||||
c = &cobra.Command{
|
||||
Use: "about",
|
||||
Short: "About Qlik Sense",
|
||||
Long: "Gives the verion of QLik Sense on Kuberntetes and versions of images.",
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
args = opts.getTagDefaults(args)
|
||||
return porterCmd.RunE(porterCmd, append([]string{"invoke", "--action", "about"}, args...))
|
||||
},
|
||||
Annotations: map[string]string{
|
||||
"group": "alias",
|
||||
},
|
||||
}
|
||||
f := c.Flags()
|
||||
f.StringVarP(&opts.Version, "version", "v", "latest",
|
||||
"Version of Qlik Sense to install")
|
||||
f.StringVarP(&opts.Tag, "tag", "t", "",
|
||||
"Use a bundle in an OCI registry specified by the given tag")
|
||||
f.StringVarP(&opts.File, "file", "f", "",
|
||||
"Path to the porter manifest file. Defaults to the bundle in the current directory.")
|
||||
f.StringVar(&opts.CNABFile, "cnab-file", "",
|
||||
"Path to the CNAB bundle.json file.")
|
||||
return c
|
||||
}
|
||||
|
||||
func buildPreflightAlias(porterCmd *cobra.Command, q *qliksense.Qliksense) *cobra.Command {
|
||||
var (
|
||||
c *cobra.Command
|
||||
opts *paramOptions
|
||||
)
|
||||
|
||||
opts = ¶mOptions{}
|
||||
|
||||
c = &cobra.Command{
|
||||
Use: "preflight",
|
||||
Short: "Preflight Checks",
|
||||
Long: "Perform Preflight Checks",
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
args = append(os.Args[1:], opts.getTagDefaults(args)...)
|
||||
return porterCmd.RunE(porterCmd, append([]string{"invoke", "--action", "preflight"}, args...))
|
||||
},
|
||||
Annotations: map[string]string{
|
||||
"group": "alias",
|
||||
},
|
||||
}
|
||||
f := c.Flags()
|
||||
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.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.StringVarP(&opts.Tag, "tag", "t", "",
|
||||
"Use a bundle in an OCI registry specified by the given tag")
|
||||
f.StringVarP(&opts.Version, "version", "v", "latest",
|
||||
"Version of Qlik Sense to install")
|
||||
f.StringSliceVarP(&opts.CredentialIdentifiers, "cred", "c", nil,
|
||||
"Credential to use when installing the bundle. May be either a named set of credentials or a filepath, and specified multiple times.")
|
||||
return c
|
||||
}
|
||||
|
||||
func (o *paramOptions) findKey(param string) *string {
|
||||
var (
|
||||
value *string
|
||||
)
|
||||
if value = o.findParams(param); value != nil {
|
||||
return value
|
||||
}
|
||||
|
||||
if value = o.findParamFiles(param); value != nil {
|
||||
return value
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// parsedParams parses the variable assignments in Params.
|
||||
func (o *paramOptions) findParams(param string) *string {
|
||||
return o.findVariableKey(param, o.Params)
|
||||
}
|
||||
|
||||
// parseParamFiles parses the variable assignments in ParamFiles.
|
||||
func (o *paramOptions) findParamFiles(param string) *string {
|
||||
var (
|
||||
path string
|
||||
retStr *string
|
||||
)
|
||||
|
||||
for _, path = range o.ParamFiles {
|
||||
retStr = o.findParamFile(param, path)
|
||||
}
|
||||
|
||||
return retStr
|
||||
}
|
||||
|
||||
func (o *paramOptions) findParamFile(param string, path string) *string {
|
||||
var (
|
||||
f *os.File
|
||||
err error
|
||||
scanner *bufio.Scanner
|
||||
lines []string
|
||||
retStr *string
|
||||
)
|
||||
if f, err = os.Open(path); err == nil {
|
||||
defer f.Close()
|
||||
|
||||
scanner = bufio.NewScanner(f)
|
||||
for scanner.Scan() {
|
||||
lines = append(lines, scanner.Text())
|
||||
}
|
||||
|
||||
retStr = o.findVariableKey(param, lines)
|
||||
}
|
||||
return retStr
|
||||
}
|
||||
|
||||
func (o *paramOptions) findVariableKey(param string, params []string) *string {
|
||||
var (
|
||||
variable, value string
|
||||
)
|
||||
for _, p := range params {
|
||||
parts := strings.SplitN(p, "=", 2)
|
||||
if len(parts) >= 2 {
|
||||
variable = strings.TrimSpace(parts[0])
|
||||
if variable == param {
|
||||
value = strings.TrimSpace(parts[1])
|
||||
return &value
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
package main
|
||||
|
||||
|
||||
func main() {
|
||||
initAndExecute()
|
||||
}
|
||||
|
||||
|
||||
@@ -7,16 +7,27 @@ import (
|
||||
|
||||
func pullQliksenseImages(q *qliksense.Qliksense) *cobra.Command {
|
||||
var (
|
||||
cmd *cobra.Command
|
||||
cmd *cobra.Command
|
||||
opts *aboutOptions
|
||||
)
|
||||
opts = &aboutOptions{}
|
||||
|
||||
cmd = &cobra.Command{
|
||||
Use: "pull",
|
||||
Short: "Pull docke images for offline install",
|
||||
Example: ` qliksense pull`,
|
||||
Example: `qliksense pull`,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
return q.PullImages()
|
||||
return q.PullImages(opts.getTagDefaults(args))
|
||||
},
|
||||
}
|
||||
|
||||
f := cmd.Flags()
|
||||
f.StringVarP(&opts.Version, "version", "v", "latest",
|
||||
"From version of Qlik Sense The images will be pulled")
|
||||
f.StringVarP(&opts.Tag, "tag", "t", "",
|
||||
"Use a bundle in an OCI registry specified by the given tag")
|
||||
f.StringVarP(&opts.File, "file", "f", "",
|
||||
"Path to the porter manifest file. Defaults to the bundle in the current directory.")
|
||||
f.StringVar(&opts.CNABFile, "cnab-file", "",
|
||||
"Path to the CNAB bundle.json file.")
|
||||
return cmd
|
||||
}
|
||||
|
||||
@@ -11,18 +11,20 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/mitchellh/go-homedir"
|
||||
"github.com/qlik-oss/sense-installer/pkg"
|
||||
"github.com/qlik-oss/sense-installer/pkg/qliksense"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
const (
|
||||
porterURLBase = "https://deislabs.blob.core.windows.net/porter"
|
||||
porterHomeVar = "PORTER_HOME"
|
||||
porterDirVar = ".porter"
|
||||
mixinDirVar = "mixins"
|
||||
porterPermaLink = "latest"
|
||||
porterRuntime = "porter-runtime"
|
||||
// porterURLBase = "https://deislabs.blob.core.windows.net/porter"
|
||||
porterURLBase = "https://github.com/qlik-oss/sense-installer/releases/download"
|
||||
porterHomeVar = "PORTER_HOME"
|
||||
qlikSenseHomeVar = "QLIKSENSE_HOME"
|
||||
qlikSenseDirVar = ".qliksense"
|
||||
mixinDirVar = "mixins"
|
||||
porterRuntime = "porter-runtime"
|
||||
)
|
||||
|
||||
func initAndExecute() error {
|
||||
@@ -42,10 +44,12 @@ func initAndExecute() error {
|
||||
|
||||
func installPorter() (string, error) {
|
||||
var (
|
||||
homeDir, mixin, mixinOpts, porterHome, porterExe string
|
||||
mixinsVar = map[string]string{
|
||||
porterPermaLink = pkg.Version
|
||||
//porterPermaLink = "v0.3.0"
|
||||
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.9.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",
|
||||
@@ -64,17 +68,19 @@ func installPorter() (string, error) {
|
||||
if runtime.GOOS == "windows" {
|
||||
porterExe = porterExe + ".exe"
|
||||
}
|
||||
if porterHome = os.Getenv(porterHomeVar); porterHome == "" {
|
||||
if qlikSenseHome = os.Getenv(qlikSenseHomeVar); qlikSenseHome == "" {
|
||||
if homeDir, err = homedir.Dir(); err != nil {
|
||||
return "", err
|
||||
}
|
||||
if homeDir, err = homedir.Expand(homeDir); err != nil {
|
||||
return "", err
|
||||
}
|
||||
porterHome = filepath.Join(homeDir, porterDirVar)
|
||||
qlikSenseHome = filepath.Join(homeDir, qlikSenseDirVar)
|
||||
}
|
||||
porterExe = filepath.Join(porterHome, porterExe)
|
||||
if _, err = os.Stat(porterHome); err != nil {
|
||||
os.Setenv(porterHomeVar, qlikSenseHome)
|
||||
//TODO: Check if porter version is one alreadu is one for this build
|
||||
porterExe = filepath.Join(qlikSenseHome, porterExe)
|
||||
if _, err = os.Stat(qlikSenseHome); err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
downloadPorter = true
|
||||
} else {
|
||||
@@ -90,22 +96,29 @@ func installPorter() (string, error) {
|
||||
}
|
||||
}
|
||||
if downloadPorter {
|
||||
os.Mkdir(porterHome, os.ModePerm)
|
||||
if err = downloadFile(porterURLBase+"/"+porterPermaLink+"/porter-linux-amd64", filepath.Join(porterHome, porterRuntime)); err != nil {
|
||||
os.Mkdir(qlikSenseHome, os.ModePerm)
|
||||
destination = filepath.Join(qlikSenseHome, porterRuntime)
|
||||
if err = downloadFile(porterURLBase+"/"+porterPermaLink+"/porter-linux-amd64", destination); err != nil {
|
||||
return "", err
|
||||
}
|
||||
os.Chmod(destination, 0755)
|
||||
if runtime.GOOS == "linux" && runtime.GOARCH == "amd64" {
|
||||
if _, err = copy(filepath.Join(porterHome, porterRuntime), porterExe); err != nil {
|
||||
if _, err = copy(filepath.Join(qlikSenseHome, porterRuntime), porterExe); err != nil {
|
||||
return "", err
|
||||
}
|
||||
os.Chmod(porterExe, 0755)
|
||||
} else {
|
||||
if err = downloadFile(porterURLBase+"/"+porterPermaLink+"/"+"porter-"+runtime.GOOS+"-"+runtime.GOARCH, porterExe); err != nil {
|
||||
if runtime.GOOS == "windows" {
|
||||
ext = ".exe"
|
||||
}
|
||||
if err = downloadFile(porterURLBase+"/"+porterPermaLink+"/"+"porter-"+runtime.GOOS+"-"+runtime.GOARCH+ext, porterExe); err != nil {
|
||||
return "", err
|
||||
}
|
||||
os.Chmod(porterExe, 0755)
|
||||
}
|
||||
}
|
||||
|
||||
if _, err = os.Stat(filepath.Join(porterHome, mixinDirVar)); err != nil {
|
||||
if _, err = os.Stat(filepath.Join(qlikSenseHome, mixinDirVar)); err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
downloadMixins = mixinsVar
|
||||
} else {
|
||||
@@ -114,7 +127,7 @@ func installPorter() (string, error) {
|
||||
} else {
|
||||
downloadMixins = make(map[string]string)
|
||||
for mixin, mixinOpts = range mixinsVar {
|
||||
if _, err = os.Stat(filepath.Join(porterHome, mixinDirVar, mixin)); err != nil {
|
||||
if _, err = os.Stat(filepath.Join(qlikSenseHome, mixinDirVar, mixin)); err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
downloadMixins[mixin] = mixinOpts
|
||||
} else {
|
||||
@@ -124,7 +137,7 @@ func installPorter() (string, error) {
|
||||
}
|
||||
}
|
||||
for mixin, mixinOpts = range downloadMixins {
|
||||
cmd = exec.Command(porterExe, "mixin", "install", mixin, mixinOpts)
|
||||
cmd = exec.Command(porterExe, append([]string{"mixin", "install", mixin}, strings.Split(mixinOpts, " ")...)...)
|
||||
cmd.Stdout = os.Stdout
|
||||
cmd.Stderr = os.Stderr
|
||||
if err = cmd.Run(); err != nil {
|
||||
@@ -135,6 +148,15 @@ func installPorter() (string, error) {
|
||||
|
||||
}
|
||||
|
||||
var versionCmd = &cobra.Command{
|
||||
Use: "version",
|
||||
Short: "Print the version number of qliksense cli",
|
||||
Long: `All software has versions. This is Hugo's`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
fmt.Printf("%s (%s, %s)\n", pkg.Version, pkg.Commit, pkg.CommitDate)
|
||||
},
|
||||
}
|
||||
|
||||
func rootCmd(p *qliksense.Qliksense) *cobra.Command {
|
||||
var (
|
||||
cmd, porterCmd, alias *cobra.Command
|
||||
@@ -158,10 +180,11 @@ func rootCmd(p *qliksense.Qliksense) *cobra.Command {
|
||||
cmd.AddCommand(pullQliksenseImages(p))
|
||||
porterCmd = porter(p)
|
||||
cmd.AddCommand(porterCmd)
|
||||
for _, alias = range buildAliasCommands(porterCmd,p) {
|
||||
for _, alias = range buildAliasCommands(porterCmd, p) {
|
||||
cmd.AddCommand(alias)
|
||||
}
|
||||
|
||||
// add version command
|
||||
cmd.AddCommand(versionCmd)
|
||||
viper.SetEnvKeyReplacer(strings.NewReplacer("-", "_"))
|
||||
|
||||
return cmd
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -25,7 +27,7 @@ type Images struct {
|
||||
}
|
||||
|
||||
// PullImages ...
|
||||
func (p *Qliksense) PullImages() error {
|
||||
func (p *Qliksense) PullImages(args []string) error {
|
||||
var (
|
||||
image string
|
||||
err error
|
||||
@@ -33,8 +35,8 @@ func (p *Qliksense) PullImages() error {
|
||||
valid bool
|
||||
images Images
|
||||
)
|
||||
|
||||
if yamlVersion, err = p.CallPorter([]string{"invoke", "--action", "about"},
|
||||
println("getting images list...")
|
||||
if yamlVersion, err = p.CallPorter(append([]string{"invoke", "--action", "about"}, args...),
|
||||
func(x string) (out *string) {
|
||||
if strings.HasPrefix(x, "qlikSenseVersion") {
|
||||
valid = true
|
||||
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
8
pkg/version.go
Normal file
8
pkg/version.go
Normal file
@@ -0,0 +1,8 @@
|
||||
package pkg
|
||||
|
||||
// These are build-time values, set during an official release
|
||||
var (
|
||||
Commit string
|
||||
Version string
|
||||
CommitDate string
|
||||
)
|
||||
5
renovate.json
Normal file
5
renovate.json
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"extends": [
|
||||
"config:base"
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user