Commit 2388c064 authored by Stephen Spencer's avatar Stephen Spencer

Refactored Docker chart.

Has logic to properly deploy init-containers to v1.5-1.9 (and
probably beyond) clusters
parents
# Patterns to ignore when building packages.
# This supports shell glob matching, relative path matching, and
# negation (prefixed with !). Only one pattern per line.
.DS_Store
# Common VCS dirs
.git/
.gitignore
.bzr/
.bzrignore
.hg/
.hgignore
.svn/
# Common backup files
*.swp
*.bak
*.tmp
*~
# Various IDEs
.project
.idea/
*.tmproj
Dockerfile
apiVersion: v1
description: RevSys, LLC; Docker
name: Docker-CI
version: 1.0.0
FROM docker:18-dind
RUN addgroup -g 412 docker
{
"log-driver": "gcplogs",
"group": "root",
"iptables": true,
"ip-masq": true
}
{{/* vim: set filetype=sls sw=2 ts=2: */}}
{{- define "InitMethod" -}}
{{- $major := .Capabilities.KubeVersion.Major -}}
{{- $minor := .Capabilities.KubeVersion.Minor -}}
{{- if and (lt (int $major) 2) (lt (int $minor) 8) }}
{{- printf "annotation" -}}
{{- else -}}
{{- if (eq (int $major) 1) and (ge (int $minor) 8) }}
{{- printf "spec" -}}
{{- end -}} {{/* else if */}}
{{- end -}} {{/* if */}}
{{- end -}} {{/* define */}}
{{/* vim: set filetype=sls sw=2 ts=2: */}}
{{- define "InitSpec" }}
{{- if eq (include "InitMethod" .) "spec" }}
{{- $env := .Values.Env }}
{{- $volumes := .Values.VolumeMounts }}
{{- $image := ( printf "%s:%s" .Values.Image .Values.ImageTag ) }}
initContainers:
{{- range .Values.InitCommands }}
-
name: {{ .name }}
image: {{ $image }}
command: ["/bin/sh", "-c"]
args:
- {{ .command | quote }}
env:
{{ toYaml $env | indent 6 }}
volumeMounts:
{{ toYaml $volumes | indent 6 }}
{{- end }} {{/* range */}}
{{- end }} {{/* if */}}
{{- end }} {{/* define */}}
{{- define "InitAnnotation" }}
{{- if eq (include "InitMethod" .) "annotation" }}
{{- $env := .Values.Env }}
{{- $volumes := .Values.VolumeMounts }}
{{- $image := ( printf "%s:%s" .Values.Image .Values.ImageTag ) }}
pod.beta.kubernetes.io/init-containers: '[
{{- range .Values.InitCommands }}
{
"name": {{ .name | quote }},
"image": {{ $image | quote }},
"command": ["/bin/sh", "-c"],
"args": [ {{ .command | quote }} ],
"env":
{{ toJson $env | indent 10 -}},
"volumeMounts":
{{ toJson $volumes | indent 10 }}
},
{{- end }}
{
"name": "nop",
"image": {{ $image | quote }},
"command": ["/bin/echo", "nothing to see here. move along."]
}
]'
{{- end }}
{{- end }}
apiVersion: v1
kind: ConfigMap
metadata:
name: docker-config
namespace: {{.Release.Namespace}}
labels:
app: {{.Values.Plug}}
env: {{.Values.deploymentEnvironment}}
heritage: {{.Release.Service | quote }}
release: {{ .Release.Name | quote }}
chart: {{.Chart.Name}}-{{.Chart.Version}}
data:
config: |+
{{ .Files.Get (printf "settings/one") | indent 4 }}
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: {{.Values.Plug}}-{{.Values.deploymentEnvironment}}
namespace: {{.Release.Namespace}}
labels:
app: {{.Values.Plug}}
env: {{.Values.deploymentEnvironment}}
imageTag: {{.Values.ImageTag | quote }}
heritage: {{.Release.Service | quote }}
release: {{ .Release.Name | quote }}
chart: {{.Chart.Name}}-{{.Chart.Version}}
spec:
selector:
matchLabels:
app: {{.Values.Plug}}-{{.Values.deploymentEnvironment}}
env: {{.Values.deploymentEnvironment}}
imageTag: {{.Values.ImageTag | quote }}
release: {{ .Release.Name | quote }}
template:
metadata:
labels:
app: {{.Values.Plug}}-{{.Values.deploymentEnvironment}}
env: {{.Values.deploymentEnvironment}}
imageTag: {{.Values.ImageTag | quote }}
release: {{ .Release.Name | quote }}
annotations:
chksum/config: {{ include (print $.Template.BasePath "/configmap.yaml") . | sha256sum | quote }}
{{- include "InitAnnotation" . | indent 8 }}
spec:
{{- include "InitSpec" . | indent 6 }}
{{- if .Values.NodeSelectors }}
nodeSelector:
{{- toYaml .Values.NodeSelectors | indent 10 }}
{{- end }}
volumes:
{{ toYaml .Values.Volumes | indent 8 }}
containers:
-
name: docker
image: {{.Values.Image}}:{{.Values.ImageTag}}
command:
- /usr/local/bin/dockerd
args:
- --config-file=/etc/docker/config.json
- -H
- 0.0.0.0:49152
- --dns
- 8.8.8.8
- --insecure-registry
- registry--ci.ci
securityContext:
privileged: true
ports:
-
protocol: TCP
containerPort: 49152
volumeMounts:
{{ toYaml .Values.VolumeMounts | indent 12 }}
env:
{{ toYaml .Values.Env | indent 12 }}
apiVersion: v1
kind: Service
metadata:
name: {{.Values.Plug}}-{{.Values.deploymentEnvironment}}
namespace: {{.Release.Namespace}}
labels:
heritage: {{.Release.Service | quote }}
release: {{ .Release.Name | quote }}
chart: {{.Chart.Name}}-{{.Chart.Version}}
image: {{.Values.ImageTag | quote }}
spec:
ports:
-
port: 49152
targetPort: 49152
protocol: TCP
selector:
name: {{.Values.Plug}}-{{.Values.deploymentEnvironment}}
env: {{.Values.deploymentEnvironment}}
# vim: ft=sls nolist
Image: docker
ImageTag: &itag "18-dind"
deploymentEnvironment: &env demo
Plug: docker
NodeSelectors: []
InitCommands:
-
name: config
command: cp /etc/docker_/config.json /etc/docker/
Env:
-
name: DOCKER_HOST
value: localhost:49152
-
name: IMAGE_TAG
value: *itag
-
name: X_NODE_NAME
valueFrom:
fieldRef:
fieldPath: spec.nodeName
apiVersion: v1
-
name: X_POD_IP
valueFrom:
fieldRef:
fieldPath: status.podIP
apiVersion: v1
-
name: X_KUBE_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
apiVersion: v1
-
name: X_DEPLOYMENT_ENV
value: *env
-
name: X_POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
apiVersion: v1
# Volumes
Volumes:
-
name: docker-config
configMap:
name: docker-config
items:
-
key: config
path: config.json
mode: 0600
-
name: docker-config-directory
emptyDir: {}
VolumeMounts:
-
name: docker-config
mountPath: /etc/docker_
-
name: docker-config-directory
mountPath: /etc/docker
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment