Adding dockerfile and helm chart templates

This commit is contained in:
Ishita Mehta 2019-12-11 14:53:02 +05:30
Родитель 732b3148b5
Коммит 92d2abec24
34 изменённых файлов: 513 добавлений и 2 удалений

1
deploy-aks/MANIFEST.in Normal file
Просмотреть файл

@ -0,0 +1 @@
recursive-include azext_aks_deploy/dev/resources/packs *

Просмотреть файл

@ -9,6 +9,7 @@ from knack.util import CLIError
from azext_aks_deploy.dev.common.git import get_repository_url_from_local_repo, uri_parse
from azext_aks_deploy.dev.common.github_api_helper import Files
from azext_aks_deploy.dev.resources.docker_helm_template import get_docker_and_helm_charts
logger = get_logger(__name__)
@ -34,6 +35,11 @@ def aks_deploy(aks_cluster=None, acr=None, repository=None):
languages = get_languages_for_repo(repo_name)
if not languages:
raise CLIError('Language detection has failed on this repository.')
elif 'Dockerfile' not in languages.keys():
language = list(languages.keys())[0]
docker_and_helm_charts = get_docker_and_helm_charts(language)
push_files_github(docker_and_helm_charts, repo_name, 'master', True,
message="Checking in dockerfile and helm charts for K8s deployment workflow.")
from azext_aks_deploy.dev.common.azure_cli_resources import (get_default_subscription_info,
get_aks_details,
get_acr_details)
@ -57,7 +63,7 @@ def aks_deploy(aks_cluster=None, acr=None, repository=None):
def get_yaml_template_for_repo(languages, cluster_details, acr_details, repo_name):
if 'JavaScript' in languages and 'Dockerfile' in languages:
if 'JavaScript' in languages:
logger.warning('Nodejs with dockerfile repository detected.')
files_to_return = []
# Read template file
@ -79,7 +85,7 @@ def get_yaml_template_for_repo(languages, cluster_details, acr_details, repo_nam
.replace(CLUSTER_PLACEHOLDER, cluster_details['name'])
.replace(RG_PLACEHOLDER, cluster_details['resourceGroup'])))
return files_to_return
elif 'Java' in languages and 'Dockerfile' in languages:
elif 'Java' in languages:
logger.warning('Java app with dockerfile repository detected.')
files_to_return = []
# Read template file

Просмотреть файл

@ -0,0 +1,57 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------
import os
from knack.log import get_logger
from knack.util import CLIError
from azext_aks_deploy.dev.common.github_api_helper import Files\
logger = get_logger(__name__)
PACKS_ROOT_STRING = os.path.sep+'packs'+os.path.sep
FILE_ABSOLUTE_PATH = os.path.abspath(os.path.dirname(__file__))
DOCKER_FILE_PATH = r'Dockerfile'
def get_file_content(path):
try:
filecontent=open(path).read()
return filecontent
except Exception as ex:
raise CLIError(ex)
def get_docker_template(language):
language_packs_path = get_supported_language_packs_path(language)
file_path = FILE_ABSOLUTE_PATH + language_packs_path + DOCKER_FILE_PATH
docker_file_content = get_file_content(file_path)
file_name = Files(path=DOCKER_FILE_PATH,content=docker_file_content)
logger.debug("Checkin file path: {}".format(file_name.path))
logger.debug("Checkin file content: {}".format(file_name.content))
return file_name
def get_docker_and_helm_charts(language):
language_packs_path = get_supported_language_packs_path(language)
files = []
abs_pack_path = FILE_ABSOLUTE_PATH+language_packs_path
# r=root, d=directories, f = files
for r, d,f in os.walk(abs_pack_path):
for file in f:
if '__pycache__' not in r and '__init__.py' not in file:
file_path = os.path.join(r, file)
file_content = get_file_content(file_path)
if file_path.startswith(abs_pack_path):
file_path=file_path[len(abs_pack_path):]
file_path = file_path.replace('\\','/')
file_obj = Files(path=file_path,content=file_content)
logger.debug("Checkin file path: {}".format(file_path))
logger.debug("Checkin file content: {}".format(file_content))
files.append(file_obj)
return files
def get_supported_language_packs_path(language):
LANGUAGE_PACKS_PATH = PACKS_ROOT_STRING + language.lower() + os.path.sep
if 'JavaScript' == language or 'Java' == language or 'Python' == language:
return LANGUAGE_PACKS_PATH
raise CLIError("Docker file and helm charts templates are only supported for Javascript , Java and Python languages."
"Please commit your Dockerfile and helm charts into the repo and run the 'az aks up'command again")

Просмотреть файл

@ -0,0 +1,6 @@
Dockerfile
draft.toml
charts/
target/
work/
.git/

Просмотреть файл

@ -0,0 +1,12 @@
FROM maven:3-jdk-11 as BUILD
COPY . /usr/src/app
RUN mvn --batch-mode -f /usr/src/app/pom.xml clean package
FROM openjdk:11-jre-slim
ENV PORT 4567
EXPOSE 4567
COPY --from=BUILD /usr/src/app/target /opt/target
WORKDIR /opt/target
CMD ["/bin/bash", "-c", "find -type f -name '*-with-dependencies.jar' | xargs java -jar"]

Просмотреть файл

@ -0,0 +1,21 @@
# 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

Просмотреть файл

@ -0,0 +1,4 @@
name: java
description: A Helm chart for Kubernetes
apiVersion: v1
version: v0.1.0

Просмотреть файл

@ -0,0 +1,15 @@
{{- if contains "NodePort" .Values.service.type }}
Get the application URL by running these commands:
export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ template "fullname" . }})
export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}")
echo http://$NODE_IP:$NODE_PORT/login
{{- else if contains "LoadBalancer" .Values.service.type }}
Get the application URL by running these commands:
NOTE: It may take a few minutes for the LoadBalancer IP to be available.
You can watch the status of by running 'kubectl get svc -w {{ template "fullname" . }}'
export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ template "fullname" . }} -o jsonpath='{.status.loadBalancer.ingress[0].ip}')
echo http://$SERVICE_IP:{{ .Values.service.externalPort }}
{{- else }}
http://{{ .Release.Name }}.{{ .Values.basedomain }} to access your application
{{- end }}

Просмотреть файл

@ -0,0 +1,16 @@
{{/* vim: set filetype=mustache: */}}
{{/*
Expand the name of the chart.
*/}}
{{- define "name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}}
{{- end -}}
{{/*
Create a default fully qualified app name.
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
*/}}
{{- define "fullname" -}}
{{- $name := default .Chart.Name .Values.nameOverride -}}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}}
{{- end -}}

Просмотреть файл

@ -0,0 +1,25 @@
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: {{ template "fullname" . }}
labels:
draft: {{ default "draft-app" .Values.draft }}
chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}"
spec:
replicas: {{ .Values.replicaCount }}
template:
metadata:
annotations:
buildID: {{ .Values.buildID }}
labels:
draft: {{ default "draft-app" .Values.draft }}
app: {{ template "fullname" . }}
spec:
containers:
- name: {{ .Chart.Name }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
ports:
- containerPort: {{ .Values.service.internalPort }}
resources:
{{ toYaml .Values.resources | indent 12 }}

Просмотреть файл

@ -0,0 +1,17 @@
{{- if .Values.ingress.enabled -}}
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: {{ template "fullname" . }}
labels:
chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}"
spec:
rules:
- host: {{ .Release.Name }}.{{ .Values.basedomain }}
http:
paths:
- path: /
backend:
serviceName: {{ template "fullname" . }}
servicePort: {{ .Values.service.externalPort }}
{{- end -}}

Просмотреть файл

@ -0,0 +1,15 @@
apiVersion: v1
kind: Service
metadata:
name: {{ template "fullname" . }}
labels:
chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}"
spec:
type: {{ .Values.service.type }}
ports:
- port: {{ .Values.service.externalPort }}
targetPort: {{ .Values.service.internalPort }}
protocol: TCP
name: {{ .Values.service.name }}
selector:
app: {{ template "fullname" . }}

Просмотреть файл

@ -0,0 +1,20 @@
# Default values for Maven projects.
# This is a YAML-formatted file.
# Declare variables to be passed into your templates.
replicaCount: 1
image:
pullPolicy: IfNotPresent
service:
name: java
type: ClusterIP
externalPort: 80
internalPort: 4567
resources:
limits:
cpu: 100m
memory: 128Mi
requests:
cpu: 100m
memory: 128Mi
ingress:
enabled: false

Просмотреть файл

@ -0,0 +1,3 @@
Dockerfile
draft.toml
charts/

Просмотреть файл

@ -0,0 +1,11 @@
FROM node:10
ENV PORT 8080
EXPOSE 8080
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
COPY package.json .
RUN npm install
COPY . .
CMD ["npm", "start"]

Просмотреть файл

@ -0,0 +1,21 @@
# 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

Просмотреть файл

@ -0,0 +1,4 @@
name: javascript
description: A Helm chart for Kubernetes
apiVersion: v1
version: v0.1.0

Просмотреть файл

@ -0,0 +1,15 @@
{{- if contains "NodePort" .Values.service.type }}
Get the application URL by running these commands:
export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ template "fullname" . }})
export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}")
echo http://$NODE_IP:$NODE_PORT/login
{{- else if contains "LoadBalancer" .Values.service.type }}
Get the application URL by running these commands:
NOTE: It may take a few minutes for the LoadBalancer IP to be available.
You can watch the status of by running 'kubectl get svc -w {{ template "fullname" . }}'
export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ template "fullname" . }} -o jsonpath='{.status.loadBalancer.ingress[0].ip}')
echo http://$SERVICE_IP:{{ .Values.service.externalPort }}
{{- else }}
http://{{ .Release.Name }}.{{ .Values.basedomain }} to access your application
{{- end }}

Просмотреть файл

@ -0,0 +1,16 @@
{{/* vim: set filetype=mustache: */}}
{{/*
Expand the name of the chart.
*/}}
{{- define "name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}}
{{- end -}}
{{/*
Create a default fully qualified app name.
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
*/}}
{{- define "fullname" -}}
{{- $name := default .Chart.Name .Values.nameOverride -}}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}}
{{- end -}}

Просмотреть файл

@ -0,0 +1,25 @@
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: {{ template "fullname" . }}
labels:
draft: {{ default "draft-app" .Values.draft }}
chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}"
spec:
replicas: {{ .Values.replicaCount }}
template:
metadata:
annotations:
buildID: {{ .Values.buildID }}
labels:
draft: {{ default "draft-app" .Values.draft }}
app: {{ template "fullname" . }}
spec:
containers:
- name: {{ .Chart.Name }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
ports:
- containerPort: {{ .Values.service.internalPort }}
resources:
{{ toYaml .Values.resources | indent 12 }}

Просмотреть файл

@ -0,0 +1,17 @@
{{- if .Values.ingress.enabled -}}
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: {{ template "fullname" . }}
labels:
chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}"
spec:
rules:
- host: {{ .Release.Name }}.{{ .Values.basedomain }}
http:
paths:
- path: /
backend:
serviceName: {{ template "fullname" . }}
servicePort: {{ .Values.service.externalPort }}
{{- end -}}

Просмотреть файл

@ -0,0 +1,15 @@
apiVersion: v1
kind: Service
metadata:
name: {{ template "fullname" . }}
labels:
chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}"
spec:
type: {{ .Values.service.type }}
ports:
- port: {{ .Values.service.externalPort }}
targetPort: {{ .Values.service.internalPort }}
protocol: TCP
name: {{ .Values.service.name }}
selector:
app: {{ template "fullname" . }}

Просмотреть файл

@ -0,0 +1,20 @@
# Default values for node.
# This is a YAML-formatted file.
# Declare variables to be passed into your templates.
replicaCount: 1
image:
pullPolicy: IfNotPresent
service:
name: node
type: ClusterIP
externalPort: 8080
internalPort: 8080
resources:
limits:
cpu: 100m
memory: 128Mi
requests:
cpu: 100m
memory: 128Mi
ingress:
enabled: false

Просмотреть файл

@ -0,0 +1,3 @@
Dockerfile
draft.toml
charts/

Просмотреть файл

@ -0,0 +1,12 @@
FROM python
ENV PORT 8080
EXPOSE 8080
WORKDIR /usr/src/app
COPY requirements.txt ./
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
ENTRYPOINT ["python"]
CMD ["app.py"]

Просмотреть файл

@ -0,0 +1,21 @@
# 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

Просмотреть файл

@ -0,0 +1,4 @@
name: python
description: A Helm chart for Kubernetes
apiVersion: v1
version: v0.1.0

Просмотреть файл

@ -0,0 +1,15 @@
{{- if contains "NodePort" .Values.service.type }}
Get the application URL by running these commands:
export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ template "fullname" . }})
export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}")
echo http://$NODE_IP:$NODE_PORT/login
{{- else if contains "LoadBalancer" .Values.service.type }}
Get the application URL by running these commands:
NOTE: It may take a few minutes for the LoadBalancer IP to be available.
You can watch the status of by running 'kubectl get svc -w {{ template "fullname" . }}'
export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ template "fullname" . }} -o jsonpath='{.status.loadBalancer.ingress[0].ip}')
echo http://$SERVICE_IP:{{ .Values.service.externalPort }}
{{- else }}
http://{{ .Release.Name }}.{{ .Values.basedomain }} to access your application
{{- end }}

Просмотреть файл

@ -0,0 +1,16 @@
{{/* vim: set filetype=mustache: */}}
{{/*
Expand the name of the chart.
*/}}
{{- define "name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}}
{{- end -}}
{{/*
Create a default fully qualified app name.
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
*/}}
{{- define "fullname" -}}
{{- $name := default .Chart.Name .Values.nameOverride -}}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}}
{{- end -}}

Просмотреть файл

@ -0,0 +1,25 @@
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: {{ template "fullname" . }}
labels:
draft: {{ default "draft-app" .Values.draft }}
chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}"
spec:
replicas: {{ .Values.replicaCount }}
template:
metadata:
annotations:
buildID: {{ .Values.buildID }}
labels:
draft: {{ default "draft-app" .Values.draft }}
app: {{ template "fullname" . }}
spec:
containers:
- name: {{ .Chart.Name }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
ports:
- containerPort: {{ .Values.service.internalPort }}
resources:
{{ toYaml .Values.resources | indent 12 }}

Просмотреть файл

@ -0,0 +1,17 @@
{{- if .Values.ingress.enabled -}}
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: {{ template "fullname" . }}
labels:
chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}"
spec:
rules:
- host: {{ .Release.Name }}.{{ .Values.basedomain }}
http:
paths:
- path: /
backend:
serviceName: {{ template "fullname" . }}
servicePort: {{ .Values.service.externalPort }}
{{- end -}}

Просмотреть файл

@ -0,0 +1,15 @@
apiVersion: v1
kind: Service
metadata:
name: {{ template "fullname" . }}
labels:
chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}"
spec:
type: {{ .Values.service.type }}
ports:
- port: {{ .Values.service.externalPort }}
targetPort: {{ .Values.service.internalPort }}
protocol: TCP
name: {{ .Values.service.name }}
selector:
app: {{ template "fullname" . }}

Просмотреть файл

@ -0,0 +1,20 @@
# Default values for python.
# This is a YAML-formatted file.
# Declare variables to be passed into your templates.
replicaCount: 1
image:
pullPolicy: IfNotPresent
service:
name: python
type: ClusterIP
externalPort: 80
internalPort: 8080
resources:
limits:
cpu: 100m
memory: 128Mi
requests:
cpu: 100m
memory: 128Mi
ingress:
enabled: false

Просмотреть файл

@ -59,5 +59,6 @@ setup(
classifiers=CLASSIFIERS,
package_data={'azext_aks_deploy': ['azext_metadata.json']},
packages=find_packages(exclude=["*.test", "*.test.*", "test.*", "test"]),
include_package_data=True,
install_requires=REQUIRES
)