diff --git a/.github/workflows/amuniym.yml b/.github/workflows/amuniym.yml new file mode 100644 index 0000000..134a42e --- /dev/null +++ b/.github/workflows/amuniym.yml @@ -0,0 +1,43 @@ +name: Amuniym CI + +on: + push: + branches: + - master + - 'releases/*' + tags: + - v1.0 +jobs: + build: + + runs-on: ubuntu-18.04 + + steps: + - uses: actions/checkout@v1 + - name: Docker Login + run: docker login -u ${{ secrets.USERNAME }} -p ${{ secrets.PASSWORD }} + shell: bash + - name: Docker Image Build + run: docker image build -t engincanhoke/githubci:latest . + shell: bash + - name: Docker Image Push + run: docker push engincanhoke/githubci:latest + shell: bash + - name: Installations + run: | + echo "deb [signed-by=/usr/share/keyrings/cloud.google.gpg] http://packages.cloud.google.com/apt cloud-sdk main" | sudo tee -a /etc/apt/sources.list.d/google-cloud-sdk.list && \ + curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key --keyring /usr/share/keyrings/cloud.google.gpg add - && \ + sudo apt-get update && sudo apt-get install google-cloud-sdk && \ + curl -LO https://storage.googleapis.com/kubernetes-release/release/`curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt`/bin/linux/amd64/kubectl && \ + chmod +x ./kubectl && \ + sudo mv ./kubectl /usr/local/bin/kubectl && \ + curl -L https://git.io/get_helm.sh | bash && \ + echo ${{ secrets.DEPLOYER }} | base64 --decode > deployer.json && \ + gcloud auth activate-service-account ${{ secrets.SERVICEACCOUNT }} --key-file=$(pwd)/deployer.json --project=${{ secrets.PROJECTNAME }} && \ + gcloud container clusters get-credentials ${{ secrets.CLUSTERNAME }} --zone ${{ secrets.ZONE }} && \ + helm init --client-only + + + shell: bash + - name: Helm deploy + run: helm upgrade --install helloworld hello-world --namespace application --set image.tag="latest" diff --git a/Dockerfile b/Dockerfile index 0e04922..12cd549 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,18 +1,12 @@ -FROM dockerfile/java:oracle-java8 - -ENV MAVEN_VERSION 3.2.5 - -RUN curl -sSL http://archive.apache.org/dist/maven/maven-3/$MAVEN_VERSION/binaries/apache-maven-$MAVEN_VERSION-bin.tar.gz | tar xzf - -C /usr/share \ - && mv /usr/share/apache-maven-$MAVEN_VERSION /usr/share/maven \ - && ln -s /usr/share/maven/bin/mvn /usr/bin/mvn - -ENV MAVEN_HOME /usr/share/maven - +FROM maven:3-jdk-8-alpine as builder + COPY . /data/springboot-helloworld WORKDIR /data/springboot-helloworld +RUN ["mvn", "clean", "install", "-Dmaven.test.skip=true"] -RUN ["mvn", "clean", "install"] +FROM openjdk:8-alpine +WORKDIR /data +COPY --from=builder /data/springboot-helloworld/target/*.jar ./app.jar EXPOSE 8080 - -CMD ["java", "-jar", "target/helloworld-0.0.1-SNAPSHOT.jar"] \ No newline at end of file +CMD ["java", "-jar", "app.jar"] diff --git a/config b/config new file mode 100644 index 0000000..ae25472 --- /dev/null +++ b/config @@ -0,0 +1,26 @@ +apiVersion: v1 +clusters: +- cluster: + certificate-authority-data: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSURDekNDQWZPZ0F3SUJBZ0lRSWFCYW1lNmJoTGFLY0taazBvMEpDREFOQmdrcWhraUc5dzBCQVFzRkFEQXYKTVMwd0t3WURWUVFERXlSaVlXRXdaRGxtWWkwd1l6TmtMVFF3WVdNdFlXRTFPUzB6TkRneVlXUTFOV00xTXpjdwpIaGNOTVRrd09UQTJNVEl4TmpBeVdoY05NalF3T1RBME1UTXhOakF5V2pBdk1TMHdLd1lEVlFRREV5UmlZV0V3ClpEbG1ZaTB3WXpOa0xUUXdZV010WVdFMU9TMHpORGd5WVdRMU5XTTFNemN3Z2dFaU1BMEdDU3FHU0liM0RRRUIKQVFVQUE0SUJEd0F3Z2dFS0FvSUJBUURYYTUvWE11c1NIRmQ2UTF1bm5WZ3dqS0NYVGlVZ0t2OHBKUktsYVNxdgowdXFXMjZEMFprVXRHYUxxWDBvWTB5TlJMTGpZRGRxWG9ZSEJNZllhUEY5NzlmTVFzSEJzYjdnWmZZTHQyR0ZDCi9za0htUFI2SXQya25DR3RIQ2lZSUNCdDRSYmZUb0VqNDNiSzdGd3pmdE9uNkl0dmRudmZBMnl4UmxSRjg1RmEKVW5vSzk3U29wdUtIa2FhR1NBeGxGb1pIb1VicnpRalI3ZTVlN2dEWW8zZUdTNjdIZ01NUWVsbFhuNFkvUDRRQQppRnFDMU5OYWRsaE9MZ01jMjJhWHFJM3E4Tngrblp1UHcwUUhjUXJONVVaVU9nQitxb0w4ZWFJYkJtRGF2RFFrCnNyN3lzdDgrUEFRR3U5V0lGaDMyMjBtV012M2Q5ajR2aSt3ZVZiSmM0dllIQWdNQkFBR2pJekFoTUE0R0ExVWQKRHdFQi93UUVBd0lDQkRBUEJnTlZIUk1CQWY4RUJUQURBUUgvTUEwR0NTcUdTSWIzRFFFQkN3VUFBNElCQVFEUQozaGlvdHROVEVDZWpFdjQvd1d0N3J4cXhTVWFsNTV5azJUUUlpc2dVOEp4NTErWVZTc1lob1FCZTlla2xFV1lmClIweEV6bm1nUzhhZGJJYktkTFViSXU0K3E1aksyM2hYUHNtOXM1aHQvWXYzRnhKMFVUV2ZnbVhYTlgzNTVuMWkKcERxMkM0MkZFZHREaFhFQVJQR3NQOUcrQ0tEazlhcDFjOE1aNzhBd1RtSkppWnJQWEI2SjZuMWY4L2UzdWxydQptKzlvc3FmOTR0dFgwaU9sNThaNDhCdmtGa1IvOEdxakxSK0pic1VoL0NySzg1aTVEL2cyd0ZxR1NjR2JKNUhWClFOQ0dPTFdGczdkZmZZQTZsUzRKSmNseU82TnAvdm9lUCtReENkdFNVb0dOVlE5NDhINSs1VWFJNlFJamxsazMKRnNrUWVuaCtxNFlPM25iekJGa3cKLS0tLS1FTkQgQ0VSVElGSUNBVEUtLS0tLQo= + server: https://35.228.176.115 + name: gke_axial-history-248207_europe-north1-b_standard-cluster-1 +contexts: +- context: + cluster: gke_axial-history-248207_europe-north1-b_standard-cluster-1 + user: gke_axial-history-248207_europe-north1-b_standard-cluster-1 + name: gke_axial-history-248207_europe-north1-b_standard-cluster-1 +current-context: gke_axial-history-248207_europe-north1-b_standard-cluster-1 +kind: Config +preferences: {} +users: +- name: gke_axial-history-248207_europe-north1-b_standard-cluster-1 + user: + auth-provider: + config: + access-token: ya29.Il-HB4_VLKYnVHUWOi9qv3UNuqWu49ROQvN_Efiy4P2v8K8oDf02kxfeOCRPMUan6S8hsVXjFn5warL4wM3shgkmOTvA6HbYqqEMACAZKs-29mnOCJrXsaBQKP5d3QegDw + cmd-args: config config-helper --format=json + cmd-path: /usr/lib64/google-cloud-sdk/bin/gcloud + expiry: "2019-09-18T15:49:06Z" + expiry-key: '{.credential.token_expiry}' + token-key: '{.credential.access_token}' + name: gcp diff --git a/hello-world/.helmignore b/hello-world/.helmignore new file mode 100644 index 0000000..50af031 --- /dev/null +++ b/hello-world/.helmignore @@ -0,0 +1,22 @@ +# 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 +.vscode/ diff --git a/hello-world/Chart.yaml b/hello-world/Chart.yaml new file mode 100644 index 0000000..6469f8b --- /dev/null +++ b/hello-world/Chart.yaml @@ -0,0 +1,5 @@ +apiVersion: v1 +appVersion: "1.0" +description: A Helm chart for Kubernetes +name: hello-world +version: 0.1.0 diff --git a/hello-world/templates/NOTES.txt b/hello-world/templates/NOTES.txt new file mode 100644 index 0000000..1da2924 --- /dev/null +++ b/hello-world/templates/NOTES.txt @@ -0,0 +1,21 @@ +1. Get the application URL by running these commands: +{{- if .Values.ingress.enabled }} +{{- range $host := .Values.ingress.hosts }} + {{- range .paths }} + http{{ if $.Values.ingress.tls }}s{{ end }}://{{ $host.host }}{{ . }} + {{- end }} +{{- end }} +{{- else if contains "NodePort" .Values.service.type }} + export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "hello-world.fullname" . }}) + export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}") + echo http://$NODE_IP:$NODE_PORT +{{- else if contains "LoadBalancer" .Values.service.type }} + NOTE: It may take a few minutes for the LoadBalancer IP to be available. + You can watch the status of by running 'kubectl get --namespace {{ .Release.Namespace }} svc -w {{ include "hello-world.fullname" . }}' + export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "hello-world.fullname" . }} -o jsonpath='{.status.loadBalancer.ingress[0].ip}') + echo http://$SERVICE_IP:{{ .Values.service.port }} +{{- else if contains "ClusterIP" .Values.service.type }} + export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "hello-world.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}") + echo "Visit http://127.0.0.1:8080 to use your application" + kubectl port-forward $POD_NAME 8080:80 +{{- end }} diff --git a/hello-world/templates/_helpers.tpl b/hello-world/templates/_helpers.tpl new file mode 100644 index 0000000..051fff4 --- /dev/null +++ b/hello-world/templates/_helpers.tpl @@ -0,0 +1,45 @@ +{{/* vim: set filetype=mustache: */}} +{{/* +Expand the name of the chart. +*/}} +{{- define "hello-world.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). +If release name contains chart name it will be used as a full name. +*/}} +{{- define "hello-world.fullname" -}} +{{- if .Values.fullnameOverride -}} +{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" -}} +{{- else -}} +{{- $name := default .Chart.Name .Values.nameOverride -}} +{{- if contains $name .Release.Name -}} +{{- .Release.Name | trunc 63 | trimSuffix "-" -}} +{{- else -}} +{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}} +{{- end -}} +{{- end -}} +{{- end -}} + +{{/* +Create chart name and version as used by the chart label. +*/}} +{{- define "hello-world.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}} +{{- end -}} + +{{/* +Common labels +*/}} +{{- define "hello-world.labels" -}} +app.kubernetes.io/name: {{ include "hello-world.name" . }} +helm.sh/chart: {{ include "hello-world.chart" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- if .Chart.AppVersion }} +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} +{{- end }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end -}} diff --git a/hello-world/templates/deployment.yaml b/hello-world/templates/deployment.yaml new file mode 100644 index 0000000..a120dc8 --- /dev/null +++ b/hello-world/templates/deployment.yaml @@ -0,0 +1,50 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ include "hello-world.fullname" . }} + labels: +{{ include "hello-world.labels" . | indent 4 }} +spec: + replicas: {{ .Values.replicaCount }} + selector: + matchLabels: + app.kubernetes.io/name: {{ include "hello-world.name" . }} + app.kubernetes.io/instance: {{ .Release.Name }} + template: + metadata: + labels: + app.kubernetes.io/name: {{ include "hello-world.name" . }} + app.kubernetes.io/instance: {{ .Release.Name }} + spec: + imagePullSecrets: + - name: myregistrykey + containers: + - name: {{ .Chart.Name }} + image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}" + imagePullPolicy: {{ .Values.image.pullPolicy }} + ports: + - name: http + containerPort: 8080 + protocol: TCP + livenessProbe: + httpGet: + path: / + port: http + readinessProbe: + httpGet: + path: / + port: http + resources: + {{- toYaml .Values.resources | nindent 12 }} + {{- with .Values.nodeSelector }} + nodeSelector: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.affinity }} + affinity: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.tolerations }} + tolerations: + {{- toYaml . | nindent 8 }} + {{- end }} diff --git a/hello-world/templates/ingress.yaml b/hello-world/templates/ingress.yaml new file mode 100644 index 0000000..64a417b --- /dev/null +++ b/hello-world/templates/ingress.yaml @@ -0,0 +1,36 @@ +{{- if .Values.ingress.enabled -}} +{{- $fullName := include "hello-world.fullname" . -}} +apiVersion: extensions/v1beta1 +kind: Ingress +metadata: + name: {{ $fullName }} + labels: +{{ include "hello-world.labels" . | indent 4 }} + {{- with .Values.ingress.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +spec: +{{- if .Values.ingress.tls }} + tls: + {{- range .Values.ingress.tls }} + - hosts: + {{- range .hosts }} + - {{ . | quote }} + {{- end }} + secretName: {{ .secretName }} + {{- end }} +{{- end }} + rules: + {{- range .Values.ingress.hosts }} + - host: {{ .host | quote }} + http: + paths: + {{- range .paths }} + - path: {{ . }} + backend: + serviceName: {{ $fullName }} + servicePort: http + {{- end }} + {{- end }} +{{- end }} diff --git a/hello-world/templates/service.yaml b/hello-world/templates/service.yaml new file mode 100644 index 0000000..f07a604 --- /dev/null +++ b/hello-world/templates/service.yaml @@ -0,0 +1,16 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ include "hello-world.fullname" . }} + labels: +{{ include "hello-world.labels" . | indent 4 }} +spec: + type: {{ .Values.service.type }} + ports: + - port: {{ .Values.service.port }} + targetPort: http + protocol: TCP + name: http + selector: + app.kubernetes.io/name: {{ include "hello-world.name" . }} + app.kubernetes.io/instance: {{ .Release.Name }} diff --git a/hello-world/templates/tests/test-connection.yaml b/hello-world/templates/tests/test-connection.yaml new file mode 100644 index 0000000..cc4fa71 --- /dev/null +++ b/hello-world/templates/tests/test-connection.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Pod +metadata: + name: "{{ include "hello-world.fullname" . }}-test-connection" + labels: +{{ include "hello-world.labels" . | indent 4 }} + annotations: + "helm.sh/hook": test-success +spec: + containers: + - name: wget + image: busybox + command: ['wget'] + args: ['{{ include "hello-world.fullname" . }}:{{ .Values.service.port }}'] + restartPolicy: Never diff --git a/hello-world/values.yaml b/hello-world/values.yaml new file mode 100644 index 0000000..d9be1a7 --- /dev/null +++ b/hello-world/values.yaml @@ -0,0 +1,51 @@ +# Default values for hello-world. +# This is a YAML-formatted file. +# Declare variables to be passed into your templates. + +replicaCount: 2 + +image: + repository: mertongngl/hello + tag: latest + pullPolicy: IfNotPresent + +imagePullSecrets: [] +nameOverride: "" +fullnameOverride: "" + +service: + type: ClusterIP + port: 80 + +ingress: + enabled: true + annotations: {} + # kubernetes.io/ingress.class: nginx + # kubernetes.io/tls-acme: "true" + hosts: + - host: mertcase.bestcloudfor.me + paths: + - "/" + + tls: [] + # - secretName: chart-example-tls + # hosts: + # - chart-example.local + +resources: {} + # We usually recommend not to specify default resources and to leave this as a conscious + # choice for the user. This also increases chances charts run on environments with little + # resources, such as Minikube. If you do want to specify resources, uncomment the following + # lines, adjust them as necessary, and remove the curly braces after 'resources:'. + # limits: + # cpu: 100m + # memory: 128Mi + # requests: + # cpu: 100m + # memory: 128Mi + +nodeSelector: {} + +tolerations: [] + +affinity: {} diff --git a/src/main/java/com/gazgeek/helloworld/controller/HomeController.java b/src/main/java/com/gazgeek/helloworld/controller/HomeController.java index c2df952..ad319f5 100644 --- a/src/main/java/com/gazgeek/helloworld/controller/HomeController.java +++ b/src/main/java/com/gazgeek/helloworld/controller/HomeController.java @@ -8,7 +8,7 @@ public class HomeController { @RequestMapping("/") String home() { - return "Hello from GazGeek!"; + return "Hello from Engin!"; } } diff --git a/src/test/java/com/gazgeek/helloworld/HomeControllerTest.java b/src/test/java/com/gazgeek/helloworld/HomeControllerTest.java index 2271622..32e88d3 100644 --- a/src/test/java/com/gazgeek/helloworld/HomeControllerTest.java +++ b/src/test/java/com/gazgeek/helloworld/HomeControllerTest.java @@ -28,7 +28,7 @@ public class HomeControllerTest { public void helloWorld() { getRequest("/") .assertStatusCode(OK) - .assertResponseBody("Hello from GazGeek!"); + .assertResponseBody("Hello from Engin!"); } private HelloWorldResponse getRequest(String uri) {