Skip to content
This repository was archived by the owner on Nov 16, 2020. It is now read-only.

Commit 99faeca

Browse files
committed
Install and configure docker registry chart
Deploys docker-registry chart and configures dispatch's imageRegistry with the Cluster IP of the docker-registry service. Also, adds a skipAuth flag to the install config.
1 parent 5153f7a commit 99faeca

File tree

3 files changed

+74
-60
lines changed

3 files changed

+74
-60
lines changed

README.md

Lines changed: 3 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,6 @@ $ brew install kubernetes-helm
3737
$ helm init
3838
```
3939

40-
### Configure Authentication
41-
Configure an OAuth2 Client App at GitHub with instruction [How to Create OAuth Client
42-
App](https://vmware.github.io/dispatch/guides/create-oauth-client-app.html)
43-
44-
You should have ``<oauth-client-id>``, ``<oauth-client-secret>`` and ``<oauth-cookie-secret>`` now.
45-
4640
### Download Dispatch CLI
4741
Get the dispatch command:
4842
```
@@ -57,31 +51,15 @@ Fetch the IP address of minikube as this will be used the host for dispatch serv
5751
export DISPATCH_HOST=$(minikube ip)
5852
```
5953

60-
Dispatch requires a container registry to build and push images for your functions. If you don't have a
61-
container registry, you can always use DockerHub by specifying your credentials.
62-
63-
Configure the installation by substituting docker credentials and OAuth2 client details.
54+
Configure the installation
6455
```
6556
$ cat << EOF > config.yaml
6657
apiGateway:
6758
host: $DISPATCH_HOST
6859
dispatch:
6960
host: $DISPATCH_HOST
7061
debug: true
71-
imageRegistry:
72-
# The <registry name> format varies by the container registry provider.
73-
# For dockerhub, use your <username>
74-
# For Google Container Registry, use gcr.io/[GCR-PROJECT-ID]
75-
name: <registry name>
76-
# Username for registry authentication
77-
username: <username>
78-
# Password for registry authentication
79-
password: <password>
80-
# Email for registry authentication
81-
email: <email>
82-
oauth2Proxy:
83-
clientID: <oauth2-client-id>
84-
clientSecret: <oauth2-client-secret>
62+
skipAuth: true
8563
EOF
8664
```
8765

@@ -100,28 +78,10 @@ cat $HOME/.dispatch/config.json
10078
"organization": "",
10179
"cookie": "",
10280
"insecure": true,
103-
"skipauth": false,
81+
"skipauth": true,
10482
"Json": false
10583
}
10684
```
107-
Make a note of the `<port>` as this will be used in the next step.
108-
109-
#### Update the Callback URL of your OAuth2 Client App:
110-
111-
Dispatch runs on a non-standard https port on minikube since it uses
112-
NodePort for the ingress controller service. Hence, update the
113-
Authorization callback URL of your OAuth2 Client App (created by following
114-
[How to Create OAuth Client App](docs/_guides/create-oauth-client-app.md)) from
115-
`https://<DISPATCH_HOST>/oauth2` to `https://<DISPATCH_HOST>:<port>/oauth2`
116-
where `<port>` can be found in your dispatch config file available at
117-
$HOME/.dispatch/config.json.
118-
119-
### Login to Dispatch:
120-
Note:- You will be directed to github for authorization
121-
```
122-
$ ./dispatch-darwin login
123-
You have successfully logged in, cookie saved to /Users/bjung/.dispatch/config.json
124-
```
12585

12686
At this point, the environment is up and working. Let's seed the service
12787
with some images and functions. In order to get the examples, you will need

pkg/dispatchcli/cmd/install.go

Lines changed: 59 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ type chartConfig struct {
4242
Version string `json:"version,omitempty" validate:"omitempty"`
4343
}
4444

45+
type dockerRegistry struct {
46+
Chart *chartConfig `json:"chart,omitempty" validate:"required"`
47+
}
48+
4549
type ingressConfig struct {
4650
Chart *chartConfig `json:"chart,omitempty" validate:"required"`
4751
ServiceType string `json:"serviceType,omitempty" validate:"required,eq=NodePort|eq=LoadBalancer|eq=ClusterIP"`
@@ -92,18 +96,19 @@ type imageRegistryConfig struct {
9296
Username string `json:"username,omitempty" validate:"required"`
9397
}
9498
type dispatchInstallConfig struct {
95-
Chart *chartConfig `json:"chart,omitempty" validate:"required"`
96-
Host string `json:"host,omitempty" validate:"required,hostname|ip"`
97-
Port int `json:"port,omitempty" validate:"required"`
98-
Organization string `json:"organization,omitempty" validate:"required"`
99-
Image *imageConfig `json:"image,omitempty" validate:"omitempty"`
100-
Debug bool `json:"debug,omitempty" validate:"omitempty"`
101-
Trace bool `json:"trace,omitempty" validate:"omitempty"`
102-
Database string `json:"database,omitempty" validate:"required,eq=postgres"`
103-
PersistData bool `json:"persistData,omitempty" validate:"omitempty"`
104-
ImageRegistry imageRegistryConfig `json:"imageRegistry,omitempty" validate:"required"`
105-
OAuth2Proxy *oauth2ProxyConfig `json:"oauth2Proxy,omitempty" validate:"required"`
106-
TLS *tlsConfig `json:"tls,omitempty" validate:"required"`
99+
Chart *chartConfig `json:"chart,omitempty" validate:"required"`
100+
Host string `json:"host,omitempty" validate:"required,hostname|ip"`
101+
Port int `json:"port,omitempty" validate:"required"`
102+
Organization string `json:"organization,omitempty" validate:"required"`
103+
Image *imageConfig `json:"image,omitempty" validate:"omitempty"`
104+
Debug bool `json:"debug,omitempty" validate:"omitempty"`
105+
Trace bool `json:"trace,omitempty" validate:"omitempty"`
106+
Database string `json:"database,omitempty" validate:"required,eq=postgres"`
107+
PersistData bool `json:"persistData,omitempty" validate:"omitempty"`
108+
ImageRegistry *imageRegistryConfig `json:"imageRegistry,omitempty" validate:"omitempty"`
109+
OAuth2Proxy *oauth2ProxyConfig `json:"oauth2Proxy,omitempty" validate:"required"`
110+
TLS *tlsConfig `json:"tls,omitempty" validate:"required"`
111+
SkipAuth bool `json:"skipAuth,omitempty" validate:"omitempty"`
107112
}
108113

109114
type installConfig struct {
@@ -113,6 +118,7 @@ type installConfig struct {
113118
APIGateway *apiGatewayConfig `json:"apiGateway,omitempty" validate:"required"`
114119
OpenFaas *openfaasConfig `json:"openfaas,omitempty" validate:"required"`
115120
DispatchConfig *dispatchInstallConfig `json:"dispatch,omitempty" validate:"required"`
121+
DockerRegistry *dockerRegistry `json:"dockerRegistry,omitempty" validate:"omitempty"`
116122
}
117123

118124
var (
@@ -303,6 +309,7 @@ func writeConfig(out, errOut io.Writer, configDir string, config *installConfig)
303309
dispatchConfig.Organization = config.DispatchConfig.Organization
304310
dispatchConfig.Host = config.DispatchConfig.Host
305311
dispatchConfig.Port = config.DispatchConfig.Port
312+
dispatchConfig.SkipAuth = config.DispatchConfig.SkipAuth
306313
b, err := json.MarshalIndent(dispatchConfig, "", " ")
307314
if err != nil {
308315
return err
@@ -384,6 +391,19 @@ func getK8sServiceNodePort(service, namespace string, https bool) (int, error) {
384391
return nodePort, nil
385392
}
386393

394+
func getK8sServiceClusterIP(service, namespace string) (string, error) {
395+
396+
kubectl := exec.Command(
397+
"kubectl", "get", "svc", service, "-n", namespace,
398+
"-o", fmt.Sprintf("jsonpath={.spec.clusterIP}"))
399+
400+
kubectlOut, err := kubectl.CombinedOutput()
401+
if err != nil {
402+
return "", errors.Wrapf(err, string(kubectlOut))
403+
}
404+
return string(kubectlOut), nil
405+
}
406+
387407
func runInstall(out, errOut io.Writer, cmd *cobra.Command, args []string) error {
388408

389409
config, err := readConfig(out, errOut, installConfigFile)
@@ -510,6 +530,29 @@ func runInstall(out, errOut io.Writer, cmd *cobra.Command, args []string) error
510530
return errors.Wrapf(err, "Error installing openfaas chart")
511531
}
512532
}
533+
534+
if config.DispatchConfig.ImageRegistry == nil && installService("docker-registry") {
535+
if config.DockerRegistry == nil {
536+
return errors.New("Missing docker-registry chart configuration")
537+
}
538+
err = helmInstall(out, errOut, config.DockerRegistry.Chart, nil)
539+
if err != nil {
540+
return errors.Wrapf(err, "Error installing docker-registry chart")
541+
}
542+
serviceName := fmt.Sprintf("%s-%s", config.DockerRegistry.Chart.Chart, config.DockerRegistry.Chart.Release)
543+
serviceIP, err := getK8sServiceClusterIP(serviceName, config.DockerRegistry.Chart.Namespace)
544+
if err != nil {
545+
return err
546+
}
547+
registryName := fmt.Sprintf("%s:5000", serviceIP)
548+
config.DispatchConfig.ImageRegistry = &imageRegistryConfig{
549+
Name: registryName,
550+
Username: "",
551+
Password: "",
552+
Email: "",
553+
}
554+
}
555+
513556
if installService("dispatch") {
514557
chart := path.Join(installChartsDir, "dispatch")
515558
if installChartsDir != "dispatch" {
@@ -529,6 +572,10 @@ func runInstall(out, errOut io.Writer, cmd *cobra.Command, args []string) error
529572
config.DispatchConfig.OAuth2Proxy.CookieSecret = base64.StdEncoding.EncodeToString(cookie)
530573
}
531574

575+
// To handle the case if only dispatch service was installed.
576+
if config.DispatchConfig.ImageRegistry == nil {
577+
return errors.New("Missing Image Registry configuration")
578+
}
532579
// we need to marshal username, password and email to ensure they are properly escaped
533580
dockerAuth := struct {
534581
Username string `json:"username"`

pkg/dispatchcli/cmd/install_config.go

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ package cmd
77

88
const defaultInstallConfigYaml = `
99
HelmRepositoryURL: https://s3-us-west-2.amazonaws.com/dispatch-charts
10+
dockerRegistry:
11+
chart:
12+
chart: docker-registry
13+
namespace: dispatch
14+
release: docker-registry
15+
repo: https://kubernetes-charts.storage.googleapis.com
1016
ingress:
1117
chart:
1218
chart: nginx-ingress
@@ -59,11 +65,12 @@ dispatch:
5965
debug: true
6066
trace: true
6167
persistData: false
62-
imageRegistry:
63-
name:
64-
username: <username>
65-
email:
66-
password: <password>
68+
skipAuth: false
69+
#imageRegistry:
70+
# name:
71+
# username:
72+
# email:
73+
# password:
6774
oauth2Proxy:
6875
clientID: <client-id>
6976
clientSecret: <client-secret>

0 commit comments

Comments
 (0)