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

Commit 5153f7a

Browse files
authored
WIP: images are now built not just pass-through (#167)
This is the first step towards being able to build images with dependencies. We now build a docker image based on the base-image. There are other cool things in this commit, such as being able to use a local repository (yay!) `helm install stable/docker-registry`. * Added docker in docker side-cars to image manager and function manager so that they can reach local repos within the k8s cluster - Set DOCKER_HOST to the localhost socket as opposed to the host's unix socket * Build docker images based on the base-image * Unify the repostory config (do we need separate repo configs for FaaSs and image manager?) * Function manager is more async now as images are not necessarily "ready" when function created. - Should make "sync" smarter... * Tried to generalize the image building, but I haven't changed the function manager code to use it... yet. * Image manager now uses global config. Testing Done: - Installed and ran chart - Needs more tests and e2e
1 parent 70daecb commit 5153f7a

File tree

28 files changed

+478
-129
lines changed

28 files changed

+478
-129
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ Make a note of the `<port>` as this will be used in the next step.
111111
Dispatch runs on a non-standard https port on minikube since it uses
112112
NodePort for the ingress controller service. Hence, update the
113113
Authorization callback URL of your OAuth2 Client App (created by following
114-
[How to Create OAuth Client App](docs/create-oauth-client-app.md)) from
114+
[How to Create OAuth Client App](docs/_guides/create-oauth-client-app.md)) from
115115
`https://<DISPATCH_HOST>/oauth2` to `https://<DISPATCH_HOST>:<port>/oauth2`
116116
where `<port>` can be found in your dispatch config file available at
117117
$HOME/.dispatch/config.json.

charts/dispatch/charts/application-manager/templates/ingress.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ spec:
3131
{{- if $tls.secretName }}
3232
tls:
3333
- secretName: {{ $tls.secretName }}
34+
{{- if $ingress_host }}
3435
hosts:
3536
- {{ default .Values.global.host .Values.ingress.host }}
37+
{{- end -}}
3638
{{- end -}}
3739
{{- end -}}

charts/dispatch/charts/function-manager/templates/config-map.yaml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,13 @@ data:
88
config.json: |-
99
{
1010
"openwhisk": {
11-
"auth_token": "{{ .Values.faas.openwhisk.authToken }}",
1211
"host": "{{ .Values.faas.openwhisk.host }}"
1312
},
1413
"openfaas": {
15-
"gateway": "{{ .Values.faas.openfaas.gateway }}",
16-
"image_registry": "{{ .Values.faas.openfaas.imageRegistry }}",
17-
"registry_auth": "{{ .Values.faas.openfaas.registryAuth }}"
14+
"gateway": "{{ .Values.faas.openfaas.gateway }}"
15+
},
16+
"registry": {
17+
"uri": "{{ default .Values.global.registry.uri .Values.registry.uri }}",
18+
"auth": "{{ default .Values.global.registry.auth .Values.registry.auth }}"
1819
}
1920
}

charts/dispatch/charts/function-manager/templates/deployment.yaml

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,21 +74,33 @@ spec:
7474
- mountPath: /data/config
7575
name: {{ template "fullname" . }}-config
7676
readOnly: true
77-
- mountPath: "/var/run/docker.sock"
78-
name: {{ template "fullname" . }}-docker
7977
- mountPath: "/data/tls"
8078
name: tls
8179
readOnly: true
8280
env:
8381
- name: DOCKER_API_VERSION
8482
value: "1.24"
83+
- name: DOCKER_HOST
84+
value: "tcp://localhost:2375"
8585
- name: ORGANIZATION
8686
valueFrom:
8787
configMapKeyRef:
8888
name: {{ template "fullname" . }}
8989
key: organization
9090
resources:
9191
{{ toYaml .Values.resources | indent 12 }}
92+
- name: {{ .Chart.Name }}-docker
93+
image: docker:dind
94+
imagePullPolicy: {{ default .Values.global.pullPolicy .Values.image.pullPolicy }}
95+
{{- if default .Values.global.registry.insecure .Values.registry.insecure }}
96+
args:
97+
- --insecure-registry={{ default .Values.global.registry.uri .Values.registry.uri }}
98+
{{- end }}
99+
securityContext:
100+
privileged: true
101+
volumeMounts:
102+
- name: docker-graph-storage
103+
mountPath: /var/lib/docker
92104
volumes:
93105
- name: {{ template "fullname" . }}
94106
{{- if default .Values.global.data.persist .Values.data.persist }}
@@ -103,12 +115,11 @@ spec:
103115
items:
104116
- key: config.json
105117
path: {{ template "name" . }}.json
106-
- name: {{ template "fullname" . }}-docker
107-
hostPath:
108-
path: /var/run/docker.sock
109118
- name: tls
110119
secret:
111120
secretName: dispatch-tls
121+
- name: docker-graph-storage
122+
emptyDir: {}
112123
{{- if .Values.nodeSelector }}
113124
nodeSelector:
114125
{{ toYaml .Values.nodeSelector | indent 8 }}

charts/dispatch/charts/function-manager/values.yaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,9 @@ faas:
4242
host: "52.91.175.16"
4343
openfaas:
4444
gateway: "http://gateway.openfaas:8080/"
45-
imageRegistry: "vmware"
46-
registryAuth: SECRET
45+
registry: {}
46+
# insecure: true
47+
# uri: docker-docker-registry.docker.svc.cluster.local:5000
4748
data:
4849
# persist: false
4950
hostPath: /var/function-manager

charts/dispatch/charts/image-manager/templates/config-map.yaml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,10 @@ metadata:
55
namespace: {{ .Release.Namespace }}
66
data:
77
organization: {{ .Values.global.organization }}
8-
serverless.json: |-
9-
{}
8+
config.json: |-
9+
{
10+
"registry": {
11+
"uri": "{{ default .Values.global.registry.uri .Values.registry.uri }}",
12+
"auth": "{{ default .Values.global.registry.auth .Values.registry.auth }}"
13+
}
14+
}

charts/dispatch/charts/image-manager/templates/deployment.yaml

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ spec:
2626
image: "{{ default .Values.global.image.host .Values.image.host }}/{{ .Values.image.repository }}:{{ default .Values.global.image.tag .Values.image.tag }}"
2727
imagePullPolicy: {{ default .Values.global.pullPolicy .Values.image.pullPolicy }}
2828
args:
29+
- "--config=/data/config/{{ template "name" . }}.json"
2930
- "--organization=$(ORGANIZATION)"
3031
- "--host=0.0.0.0"
3132
- "--port={{ .Values.service.internalPort }}"
@@ -66,21 +67,36 @@ spec:
6667
volumeMounts:
6768
- mountPath: "/data/{{ template "name" . }}"
6869
name: {{ template "fullname" . }}
69-
- mountPath: "/var/run/docker.sock"
70-
name: {{ template "fullname" . }}-docker
70+
- mountPath: /data/config
71+
name: {{ template "fullname" . }}-config
72+
readOnly: true
7173
- mountPath: "/data/tls"
7274
name: tls
7375
readOnly: true
7476
env:
7577
- name: DOCKER_API_VERSION
7678
value: "1.24"
79+
- name: DOCKER_HOST
80+
value: "tcp://localhost:2375"
7781
- name: ORGANIZATION
7882
valueFrom:
7983
configMapKeyRef:
8084
name: {{ template "fullname" . }}
8185
key: organization
8286
resources:
8387
{{ toYaml .Values.resources | indent 12 }}
88+
- name: {{ .Chart.Name }}-docker
89+
image: docker:dind
90+
imagePullPolicy: {{ default .Values.global.pullPolicy .Values.image.pullPolicy }}
91+
{{- if default .Values.global.registry.insecure .Values.registry.insecure }}
92+
args:
93+
- --insecure-registry={{ default .Values.global.registry.uri .Values.registry.uri }}
94+
{{- end }}
95+
securityContext:
96+
privileged: true
97+
volumeMounts:
98+
- name: docker-graph-storage
99+
mountPath: /var/lib/docker
84100
volumes:
85101
- name: {{ template "fullname" . }}
86102
{{- if default .Values.global.data.persist .Values.data.persist }}
@@ -89,12 +105,17 @@ spec:
89105
{{- else }}
90106
emptyDir: {}
91107
{{- end }}
92-
- name: {{ template "fullname" . }}-docker
93-
hostPath:
94-
path: /var/run/docker.sock
108+
- name: {{ template "fullname" . }}-config
109+
configMap:
110+
name: {{ template "fullname" . }}
111+
items:
112+
- key: config.json
113+
path: {{ template "name" . }}.json
95114
- name: tls
96115
secret:
97116
secretName: dispatch-tls
117+
- name: docker-graph-storage
118+
emptyDir: {}
98119
{{- if .Values.nodeSelector }}
99120
nodeSelector:
100121
{{ toYaml .Values.nodeSelector | indent 8 }}

charts/dispatch/charts/image-manager/values.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ resources: {}
3535
#requests:
3636
# cpu: 100m
3737
# memory: 128Mi
38+
registry: {}
39+
# insecure: true
40+
# uri: docker-docker-registry.docker.svc.cluster.local:5000
3841
data:
3942
# persist: false
4043
hostPath: /var/image-manager

charts/dispatch/values.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ global:
55
pullPolicy: IfNotPresent
66
organization: dispatch
77
image:
8-
tag: v0.1.2
8+
tag: v0.1.3
99
host: vmware
1010
debug: true
1111
trace: false
@@ -25,5 +25,8 @@ global:
2525
database: dispatch
2626
namespace: dispatch
2727
release: postgres
28+
registry:
29+
insecure: true
30+
uri: docker-docker-registry.docker.svc.cluster.local:5000
2831
rabbitmq:
2932
rabbitmqPassword: serverless

cmd/function-manager/main.go

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,23 +32,23 @@ import (
3232
"github.com/vmware/dispatch/pkg/trace"
3333
)
3434

35-
var drivers = map[string]func() functions.FaaSDriver{
36-
"openfaas": func() functions.FaaSDriver {
35+
var drivers = map[string]func(string) functions.FaaSDriver{
36+
"openfaas": func(registryAuth string) functions.FaaSDriver {
3737
faas, err := openfaas.New(&openfaas.Config{
3838
Gateway: config.Global.OpenFaas.Gateway,
39-
ImageRegistry: config.Global.OpenFaas.ImageRegistry,
40-
RegistryAuth: config.Global.OpenFaas.RegistryAuth,
39+
ImageRegistry: config.Global.Registry.RegistryURI,
40+
RegistryAuth: registryAuth,
4141
})
4242
if err != nil {
4343
log.Fatalf("Error starting OpenFaaS driver: %+v", err)
4444
}
4545
return faas
4646
},
47-
"riff": func() functions.FaaSDriver {
47+
"riff": func(registryAuth string) functions.FaaSDriver {
4848
faas, err := riff.New(&riff.Config{
49-
ImageRegistry: config.Global.Riff.ImageRegistry,
49+
ImageRegistry: config.Global.Registry.RegistryURI,
50+
RegistryAuth: registryAuth,
5051
Gateway: config.Global.Riff.Gateway,
51-
RegistryAuth: config.Global.Riff.RegistryAuth,
5252
K8sConfig: config.Global.Riff.K8sConfig,
5353
RiffNamespace: config.Global.Riff.RiffNamespace,
5454
})
@@ -57,7 +57,7 @@ var drivers = map[string]func() functions.FaaSDriver{
5757
}
5858
return faas
5959
},
60-
"openwhisk": func() functions.FaaSDriver {
60+
"openwhisk": func(registryAuth string) functions.FaaSDriver {
6161
faas, err := openwhisk.New(&openwhisk.Config{
6262
AuthToken: config.Global.Openwhisk.AuthToken,
6363
Host: config.Global.Openwhisk.Host,
@@ -132,6 +132,11 @@ func main() {
132132

133133
config.Global = config.LoadConfiguration(functionmanager.FunctionManagerFlags.Config)
134134

135+
registryAuth := config.Global.Registry.RegistryAuth
136+
if config.Global.Registry.RegistryAuth == "" {
137+
registryAuth = config.EmptyRegistryAuth
138+
}
139+
135140
es, err := entitystore.NewFromBackend(
136141
entitystore.BackendConfig{
137142
Backend: functionmanager.FunctionManagerFlags.DbBackend,
@@ -144,7 +149,7 @@ func main() {
144149
log.Fatalln(err)
145150
}
146151

147-
faas := drivers[functionmanager.FunctionManagerFlags.Faas]()
152+
faas := drivers[functionmanager.FunctionManagerFlags.Faas](registryAuth)
148153

149154
c := &functionmanager.ControllerConfig{
150155
ResyncPeriod: time.Duration(functionmanager.FunctionManagerFlags.ResyncPeriod) * time.Second,

0 commit comments

Comments
 (0)