From bd63371563d61b33f7ffe7599d847dd1ce53e281 Mon Sep 17 00:00:00 2001 From: Oladapo Fadeyi Date: Thu, 15 Aug 2019 23:52:49 +0100 Subject: [PATCH] #33 | Ola | Add Vert.x web build pack Added a maven-java11 based build pack for Vert.x Web --- packs/vertx-web/.dockerignore | 5 ++ packs/vertx-web/.gitignore | 9 ++++ packs/vertx-web/.helmignore | 27 ++++++++++ packs/vertx-web/Dockerfile | 16 ++++++ packs/vertx-web/charts/.helmignore | 21 ++++++++ packs/vertx-web/charts/Chart.yaml | 5 ++ packs/vertx-web/charts/Makefile | 48 +++++++++++++++++ packs/vertx-web/charts/README.md | 1 + packs/vertx-web/charts/templates/NOTES.txt | 4 ++ packs/vertx-web/charts/templates/_helpers.tpl | 16 ++++++ .../charts/templates/deployment.yaml | 51 +++++++++++++++++++ packs/vertx-web/charts/templates/ksvc.yaml | 40 +++++++++++++++ packs/vertx-web/charts/templates/service.yaml | 26 ++++++++++ packs/vertx-web/charts/values.yaml | 40 +++++++++++++++ packs/vertx-web/pipeline.yaml | 5 ++ packs/vertx-web/preview/Chart.yaml | 5 ++ packs/vertx-web/preview/Makefile | 18 +++++++ packs/vertx-web/preview/requirements.yaml | 16 ++++++ packs/vertx-web/preview/values.yaml | 22 ++++++++ packs/vertx-web/skaffold.yaml | 28 ++++++++++ packs/vertx-web/watch.sh | 6 +++ 21 files changed, 409 insertions(+) create mode 100644 packs/vertx-web/.dockerignore create mode 100644 packs/vertx-web/.gitignore create mode 100644 packs/vertx-web/.helmignore create mode 100644 packs/vertx-web/Dockerfile create mode 100644 packs/vertx-web/charts/.helmignore create mode 100644 packs/vertx-web/charts/Chart.yaml create mode 100644 packs/vertx-web/charts/Makefile create mode 100644 packs/vertx-web/charts/README.md create mode 100644 packs/vertx-web/charts/templates/NOTES.txt create mode 100644 packs/vertx-web/charts/templates/_helpers.tpl create mode 100644 packs/vertx-web/charts/templates/deployment.yaml create mode 100644 packs/vertx-web/charts/templates/ksvc.yaml create mode 100644 packs/vertx-web/charts/templates/service.yaml create mode 100644 packs/vertx-web/charts/values.yaml create mode 100644 packs/vertx-web/pipeline.yaml create mode 100644 packs/vertx-web/preview/Chart.yaml create mode 100755 packs/vertx-web/preview/Makefile create mode 100644 packs/vertx-web/preview/requirements.yaml create mode 100644 packs/vertx-web/preview/values.yaml create mode 100644 packs/vertx-web/skaffold.yaml create mode 100755 packs/vertx-web/watch.sh diff --git a/packs/vertx-web/.dockerignore b/packs/vertx-web/.dockerignore new file mode 100644 index 000000000..762752c83 --- /dev/null +++ b/packs/vertx-web/.dockerignore @@ -0,0 +1,5 @@ +draft.toml +charts/ +NOTICE +LICENSE +README.md \ No newline at end of file diff --git a/packs/vertx-web/.gitignore b/packs/vertx-web/.gitignore new file mode 100644 index 000000000..39f2745a5 --- /dev/null +++ b/packs/vertx-web/.gitignore @@ -0,0 +1,9 @@ +.project +.classpath +.idea +.cache +.DS_Store +*.im? +target +work +*.tgz \ No newline at end of file diff --git a/packs/vertx-web/.helmignore b/packs/vertx-web/.helmignore new file mode 100644 index 000000000..747e6e94a --- /dev/null +++ b/packs/vertx-web/.helmignore @@ -0,0 +1,27 @@ +# 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 +*.png + +# known compile time folders +target/ +node_modules/ +vendor/ \ No newline at end of file diff --git a/packs/vertx-web/Dockerfile b/packs/vertx-web/Dockerfile new file mode 100644 index 000000000..90232d1e9 --- /dev/null +++ b/packs/vertx-web/Dockerfile @@ -0,0 +1,16 @@ +FROM adoptopenjdk/openjdk11:alpine-jre + +MAINTAINER Luminara Team + +# Set the location of the verticles +ENV VERTX_HOME /usr/local/vertx + +EXPOSE 8080 + +# Launch the verticle +WORKDIR $VERTX_HOME +ENTRYPOINT ["sh", "-c"] +CMD ["exec java -jar vertx-app.jar -cluster"] + +# Copy your fat jar and the config file to the to the container +COPY target/*.jar $VERTX_HOME/vertx-app.jar \ No newline at end of file diff --git a/packs/vertx-web/charts/.helmignore b/packs/vertx-web/charts/.helmignore new file mode 100644 index 000000000..f0c131944 --- /dev/null +++ b/packs/vertx-web/charts/.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/packs/vertx-web/charts/Chart.yaml b/packs/vertx-web/charts/Chart.yaml new file mode 100644 index 000000000..bf28471bc --- /dev/null +++ b/packs/vertx-web/charts/Chart.yaml @@ -0,0 +1,5 @@ +name: maven +description: A Helm chart for Kubernetes +apiVersion: v1 +version: 0.1.0-SNAPSHOT +icon: https://raw.githubusercontent.com/jenkins-x/jenkins-x-platform/master/images/java.png \ No newline at end of file diff --git a/packs/vertx-web/charts/Makefile b/packs/vertx-web/charts/Makefile new file mode 100644 index 000000000..88639f8f3 --- /dev/null +++ b/packs/vertx-web/charts/Makefile @@ -0,0 +1,48 @@ +CHART_REPO := http://jenkins-x-chartmuseum:8080 +CURRENT=$(pwd) +NAME := REPLACE_ME_APP_NAME +OS := $(shell uname) +RELEASE_VERSION := $(shell cat ../../VERSION) + +build: clean + rm -rf requirements.lock + helm dependency build + helm lint + +install: clean build + helm install . --name ${NAME} + +upgrade: clean build + helm upgrade ${NAME} . + +delete: + helm delete --purge ${NAME} + +clean: + rm -rf charts + rm -rf ${NAME}*.tgz + +release: clean + helm dependency build + helm lint + helm init --client-only + helm package . + curl --fail -u $(CHARTMUSEUM_CREDS_USR):$(CHARTMUSEUM_CREDS_PSW) --data-binary "@$(NAME)-$(shell sed -n 's/^version: //p' Chart.yaml).tgz" $(CHART_REPO)/api/charts + rm -rf ${NAME}*.tgz% + +tag: +ifeq ($(OS),Darwin) + sed -i "" -e "s/version:.*/version: $(RELEASE_VERSION)/" Chart.yaml + sed -i "" -e "s/tag:.*/tag: $(RELEASE_VERSION)/" values.yaml +else ifeq ($(OS),Linux) + sed -i -e "s/version:.*/version: $(RELEASE_VERSION)/" Chart.yaml + sed -i -e "s|repository:.*|repository: $(DOCKER_REGISTRY)\/REPLACE_ME_DOCKER_REGISTRY_ORG\/REPLACE_ME_APP_NAME|" values.yaml + sed -i -e "s/tag:.*/tag: $(RELEASE_VERSION)/" values.yaml +else + echo "platfrom $(OS) not supported to release from" + exit -1 +endif + git add --all + git commit -m "release $(RELEASE_VERSION)" --allow-empty # if first release then no verion update is performed + git tag -fa v$(RELEASE_VERSION) -m "Release version $(RELEASE_VERSION)" + git push origin v$(RELEASE_VERSION) diff --git a/packs/vertx-web/charts/README.md b/packs/vertx-web/charts/README.md new file mode 100644 index 000000000..7c3946133 --- /dev/null +++ b/packs/vertx-web/charts/README.md @@ -0,0 +1 @@ +# Java application \ No newline at end of file diff --git a/packs/vertx-web/charts/templates/NOTES.txt b/packs/vertx-web/charts/templates/NOTES.txt new file mode 100644 index 000000000..97823be26 --- /dev/null +++ b/packs/vertx-web/charts/templates/NOTES.txt @@ -0,0 +1,4 @@ + +Get the application URL by running these commands: + +kubectl get ingress {{ template "fullname" . }} diff --git a/packs/vertx-web/charts/templates/_helpers.tpl b/packs/vertx-web/charts/templates/_helpers.tpl new file mode 100644 index 000000000..f0d83d2ed --- /dev/null +++ b/packs/vertx-web/charts/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/packs/vertx-web/charts/templates/deployment.yaml b/packs/vertx-web/charts/templates/deployment.yaml new file mode 100644 index 000000000..66c01e551 --- /dev/null +++ b/packs/vertx-web/charts/templates/deployment.yaml @@ -0,0 +1,51 @@ +{{- if .Values.knativeDeploy }} +{{- else }} +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" . }} +{{- if .Values.podAnnotations }} + annotations: +{{ toYaml .Values.podAnnotations | indent 8 }} +{{- end }} + spec: + containers: + - name: {{ .Chart.Name }} + image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}" + imagePullPolicy: {{ .Values.image.pullPolicy }} + env: +{{- range $pkey, $pval := .Values.env }} + - name: {{ $pkey }} + value: {{ quote $pval }} +{{- end }} + ports: + - containerPort: {{ .Values.service.internalPort }} + livenessProbe: + httpGet: + path: {{ .Values.probePath }} + port: {{ .Values.service.internalPort }} + initialDelaySeconds: {{ .Values.livenessProbe.initialDelaySeconds }} + periodSeconds: {{ .Values.livenessProbe.periodSeconds }} + successThreshold: {{ .Values.livenessProbe.successThreshold }} + timeoutSeconds: {{ .Values.livenessProbe.timeoutSeconds }} + readinessProbe: + httpGet: + path: {{ .Values.probePath }} + port: {{ .Values.service.internalPort }} + periodSeconds: {{ .Values.readinessProbe.periodSeconds }} + successThreshold: {{ .Values.readinessProbe.successThreshold }} + timeoutSeconds: {{ .Values.readinessProbe.timeoutSeconds }} + resources: +{{ toYaml .Values.resources | indent 12 }} + terminationGracePeriodSeconds: {{ .Values.terminationGracePeriodSeconds }} +{{- end }} diff --git a/packs/vertx-web/charts/templates/ksvc.yaml b/packs/vertx-web/charts/templates/ksvc.yaml new file mode 100644 index 000000000..b49200b72 --- /dev/null +++ b/packs/vertx-web/charts/templates/ksvc.yaml @@ -0,0 +1,40 @@ +{{- if .Values.knativeDeploy }} +apiVersion: serving.knative.dev/v1alpha1 +kind: Service +metadata: +{{- if .Values.service.name }} + name: {{ .Values.service.name }} +{{- else }} + name: {{ template "fullname" . }} +{{- end }} + labels: + chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}" +spec: + runLatest: + configuration: + revisionTemplate: + spec: + container: + image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}" + imagePullPolicy: {{ .Values.image.pullPolicy }} + env: +{{- range $pkey, $pval := .Values.env }} + - name: {{ $pkey }} + value: {{ quote $pval }} +{{- end }} + livenessProbe: + httpGet: + path: {{ .Values.probePath }} + initialDelaySeconds: {{ .Values.livenessProbe.initialDelaySeconds }} + periodSeconds: {{ .Values.livenessProbe.periodSeconds }} + successThreshold: {{ .Values.livenessProbe.successThreshold }} + timeoutSeconds: {{ .Values.livenessProbe.timeoutSeconds }} + readinessProbe: + httpGet: + path: {{ .Values.probePath }} + periodSeconds: {{ .Values.readinessProbe.periodSeconds }} + successThreshold: {{ .Values.readinessProbe.successThreshold }} + timeoutSeconds: {{ .Values.readinessProbe.timeoutSeconds }} + resources: +{{ toYaml .Values.resources | indent 14 }} +{{- end }} diff --git a/packs/vertx-web/charts/templates/service.yaml b/packs/vertx-web/charts/templates/service.yaml new file mode 100644 index 000000000..9321361e3 --- /dev/null +++ b/packs/vertx-web/charts/templates/service.yaml @@ -0,0 +1,26 @@ +{{- if .Values.knativeDeploy }} +{{- else }} +apiVersion: v1 +kind: Service +metadata: +{{- if .Values.service.name }} + name: {{ .Values.service.name }} +{{- else }} + name: {{ template "fullname" . }} +{{- end }} + labels: + chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}" +{{- if .Values.service.annotations }} + annotations: +{{ toYaml .Values.service.annotations | indent 4 }} +{{- end }} +spec: + type: {{ .Values.service.type }} + ports: + - port: {{ .Values.service.externalPort }} + targetPort: {{ .Values.service.internalPort }} + protocol: TCP + name: http + selector: + app: {{ template "fullname" . }} +{{- end }} diff --git a/packs/vertx-web/charts/values.yaml b/packs/vertx-web/charts/values.yaml new file mode 100644 index 000000000..fbe650895 --- /dev/null +++ b/packs/vertx-web/charts/values.yaml @@ -0,0 +1,40 @@ +# Default values for Maven projects. +# This is a YAML-formatted file. +# Declare variables to be passed into your templates. +replicaCount: 1 +image: + repository: draft + tag: dev + pullPolicy: IfNotPresent + +# define environment variables here as a map of key: value +env: + +# enable this flag to use knative serve to deploy the app +knativeDeploy: false + +service: + name: REPLACE_ME_APP_NAME + type: ClusterIP + externalPort: 80 + internalPort: 8080 + annotations: + fabric8.io/expose: "true" + fabric8.io/ingress.annotations: "kubernetes.io/ingress.class: nginx" +resources: + limits: + cpu: 500m + memory: 512Mi + requests: + cpu: 400m + memory: 512Mi +probePath: /health +livenessProbe: + initialDelaySeconds: 60 + periodSeconds: 10 + successThreshold: 1 + timeoutSeconds: 1 +readinessProbe: + periodSeconds: 10 + successThreshold: 1 + timeoutSeconds: 1 diff --git a/packs/vertx-web/pipeline.yaml b/packs/vertx-web/pipeline.yaml new file mode 100644 index 000000000..dc3282e9a --- /dev/null +++ b/packs/vertx-web/pipeline.yaml @@ -0,0 +1,5 @@ +extends: + file: ../maven/pipeline.yaml +agent: + label: jenkins-maven-java11 + container: maven diff --git a/packs/vertx-web/preview/Chart.yaml b/packs/vertx-web/preview/Chart.yaml new file mode 100644 index 000000000..0c32270fe --- /dev/null +++ b/packs/vertx-web/preview/Chart.yaml @@ -0,0 +1,5 @@ +apiVersion: v1 +description: A Helm chart for Kubernetes +name: preview +icon: https://raw.githubusercontent.com/jenkins-x/jenkins-x-platform/master/images/java.png +version: 0.1.0-SNAPSHOT diff --git a/packs/vertx-web/preview/Makefile b/packs/vertx-web/preview/Makefile new file mode 100755 index 000000000..dc2c852a6 --- /dev/null +++ b/packs/vertx-web/preview/Makefile @@ -0,0 +1,18 @@ +OS := $(shell uname) + +preview: +ifeq ($(OS),Darwin) + sed -i "" -e "s/version:.*/version: $(PREVIEW_VERSION)/" Chart.yaml + sed -i "" -e "s/version:.*/version: $(PREVIEW_VERSION)/" ../*/Chart.yaml + sed -i "" -e "s/tag:.*/tag: $(PREVIEW_VERSION)/" values.yaml +else ifeq ($(OS),Linux) + sed -i -e "s/version:.*/version: $(PREVIEW_VERSION)/" Chart.yaml + sed -i -e "s/version:.*/version: $(PREVIEW_VERSION)/" ../*/Chart.yaml + sed -i -e "s|repository:.*|repository: $(DOCKER_REGISTRY)\/REPLACE_ME_DOCKER_REGISTRY_ORG\/REPLACE_ME_APP_NAME|" values.yaml + sed -i -e "s/tag:.*/tag: $(PREVIEW_VERSION)/" values.yaml +else + echo "platfrom $(OS) not supported to release from" + exit -1 +endif + echo " version: $(PREVIEW_VERSION)" >> requirements.yaml + jx step helm build diff --git a/packs/vertx-web/preview/requirements.yaml b/packs/vertx-web/preview/requirements.yaml new file mode 100644 index 000000000..c8ac6acff --- /dev/null +++ b/packs/vertx-web/preview/requirements.yaml @@ -0,0 +1,16 @@ +# !! File must end with empty line !! +dependencies: +- alias: expose + name: exposecontroller + repository: http://chartmuseum.jenkins-x.io + version: 2.3.92 +- alias: cleanup + name: exposecontroller + repository: http://chartmuseum.jenkins-x.io + version: 2.3.92 + + # !! "alias: preview" must be last entry in dependencies array !! + # !! Place custom dependencies above !! +- alias: preview + name: REPLACE_ME_APP_NAME + repository: file://../REPLACE_ME_APP_NAME diff --git a/packs/vertx-web/preview/values.yaml b/packs/vertx-web/preview/values.yaml new file mode 100644 index 000000000..b53ceaa57 --- /dev/null +++ b/packs/vertx-web/preview/values.yaml @@ -0,0 +1,22 @@ + +expose: + Annotations: + helm.sh/hook: post-install,post-upgrade + helm.sh/hook-delete-policy: hook-succeeded + config: + exposer: Ingress + http: true + tlsacme: false + +cleanup: + Args: + - --cleanup + Annotations: + helm.sh/hook: pre-delete + helm.sh/hook-delete-policy: hook-succeeded + +preview: + image: + repository: + tag: + pullPolicy: IfNotPresent \ No newline at end of file diff --git a/packs/vertx-web/skaffold.yaml b/packs/vertx-web/skaffold.yaml new file mode 100644 index 000000000..a42889118 --- /dev/null +++ b/packs/vertx-web/skaffold.yaml @@ -0,0 +1,28 @@ +apiVersion: skaffold/v1beta2 +kind: Config +build: + artifacts: + - image: REPLACE_ME_DOCKER_REGISTRY_ORG/REPLACE_ME_APP_NAME + context: . + docker: {} + tagPolicy: + envTemplate: + template: '{{.DOCKER_REGISTRY}}/{{.IMAGE_NAME}}:{{.VERSION}}' + local: {} +deploy: + kubectl: {} +profiles: +- name: dev + build: + tagPolicy: + envTemplate: + template: '{{.DOCKER_REGISTRY}}/{{.IMAGE_NAME}}:{{.DIGEST_HEX}}' + local: {} + deploy: + helm: + releases: + - name: REPLACE_ME_APP_NAME + chartPath: charts/REPLACE_ME_APP_NAME + setValueTemplates: + image.repository: '{{.DOCKER_REGISTRY}}/{{.IMAGE_NAME}}' + image.tag: '{{.DIGEST_HEX}}' diff --git a/packs/vertx-web/watch.sh b/packs/vertx-web/watch.sh new file mode 100755 index 000000000..38e50af8a --- /dev/null +++ b/packs/vertx-web/watch.sh @@ -0,0 +1,6 @@ +#!/usr/bin/env bash + +# watch the java files and continously deploy the service +mvn clean install +skaffold run -p dev +reflex -r "\.java$" -- bash -c 'mvn install && skaffold run -p dev'