From 17c4ce1ff5c3e44a2a9366e445b947c0b3687a7f Mon Sep 17 00:00:00 2001 From: Cyrille Le Clerc Date: Wed, 31 Jan 2018 12:56:12 +0100 Subject: [PATCH] `draft create`, see https://github.com/Azure/draft/issues/523 --- .draftignore | 4 ++++ Dockerfile | 11 +++++++++++ charts/java/.helmignore | 21 +++++++++++++++++++++ charts/java/Chart.yaml | 4 ++++ charts/java/templates/NOTES.txt | 15 +++++++++++++++ charts/java/templates/_helpers.tpl | 16 ++++++++++++++++ charts/java/templates/deployment.yaml | 23 +++++++++++++++++++++++ charts/java/templates/ingress.yaml | 17 +++++++++++++++++ charts/java/templates/service.yaml | 15 +++++++++++++++ charts/java/values.yaml | 18 ++++++++++++++++++ draft.toml | 7 +++++++ 11 files changed, 151 insertions(+) create mode 100644 .draftignore create mode 100644 Dockerfile create mode 100755 charts/java/.helmignore create mode 100644 charts/java/Chart.yaml create mode 100755 charts/java/templates/NOTES.txt create mode 100755 charts/java/templates/_helpers.tpl create mode 100755 charts/java/templates/deployment.yaml create mode 100755 charts/java/templates/ingress.yaml create mode 100755 charts/java/templates/service.yaml create mode 100755 charts/java/values.yaml create mode 100644 draft.toml diff --git a/.draftignore b/.draftignore new file mode 100644 index 0000000..480702e --- /dev/null +++ b/.draftignore @@ -0,0 +1,4 @@ +*.swp +*.tmp +*.temp +.git* diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..0eacec9 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,11 @@ +FROM maven:3.5-jdk-8-alpine as BUILD + +COPY . /usr/src/app +RUN mvn -f /usr/src/app/pom.xml clean package + +FROM openjdk:8-jdk-alpine +ENV PORT 4567 +EXPOSE 4567 +COPY --from=BUILD /usr/src/app/target/helloworld-jar-with-dependencies.jar /opt/app.jar +WORKDIR /opt +CMD ["java", "-jar", "app.jar"] diff --git a/charts/java/.helmignore b/charts/java/.helmignore new file mode 100755 index 0000000..f0c1319 --- /dev/null +++ b/charts/java/.helmignore @@ -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 diff --git a/charts/java/Chart.yaml b/charts/java/Chart.yaml new file mode 100644 index 0000000..4a498de --- /dev/null +++ b/charts/java/Chart.yaml @@ -0,0 +1,4 @@ +apiVersion: v1 +description: A Helm chart for Kubernetes +name: java +version: v0.1.0 diff --git a/charts/java/templates/NOTES.txt b/charts/java/templates/NOTES.txt new file mode 100755 index 0000000..da948fa --- /dev/null +++ b/charts/java/templates/NOTES.txt @@ -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 }} diff --git a/charts/java/templates/_helpers.tpl b/charts/java/templates/_helpers.tpl new file mode 100755 index 0000000..f0d83d2 --- /dev/null +++ b/charts/java/templates/_helpers.tpl @@ -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 -}} diff --git a/charts/java/templates/deployment.yaml b/charts/java/templates/deployment.yaml new file mode 100755 index 0000000..95bb51a --- /dev/null +++ b/charts/java/templates/deployment.yaml @@ -0,0 +1,23 @@ +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: + 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 }} diff --git a/charts/java/templates/ingress.yaml b/charts/java/templates/ingress.yaml new file mode 100755 index 0000000..974e6f6 --- /dev/null +++ b/charts/java/templates/ingress.yaml @@ -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 -}} diff --git a/charts/java/templates/service.yaml b/charts/java/templates/service.yaml new file mode 100755 index 0000000..d524c8b --- /dev/null +++ b/charts/java/templates/service.yaml @@ -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" . }} diff --git a/charts/java/values.yaml b/charts/java/values.yaml new file mode 100755 index 0000000..4848ce0 --- /dev/null +++ b/charts/java/values.yaml @@ -0,0 +1,18 @@ +# Default values for Maven projects. +# This is a YAML-formatted file. +# Declare variables to be passed into your templates. +replicaCount: 2 +image: + pullPolicy: IfNotPresent +service: + name: java + type: ClusterIP + externalPort: 80 + internalPort: 4567 +resources: + limits: + cpu: 100m + memory: 128Mi + requests: + cpu: 100m + memory: 128Mi diff --git a/draft.toml b/draft.toml new file mode 100644 index 0000000..a27778f --- /dev/null +++ b/draft.toml @@ -0,0 +1,7 @@ +[environments] + [environments.development] + name = "draft-spring-boot-app" + namespace = "default" + wait = false + watch = false + watch_delay = 2