Commit 8f98e49c authored by Siva Rama Krishna's avatar Siva Rama Krishna

validation stage for pipeline

parent 3922093d
variables:
RELEASE_NAME: "SERVICE_NAME"
SERVICE_PORT: 1099
REGISTRY_URL: 751503455312.dkr.ecr.us-west-2.amazonaws.com/pgnonprod
stages:
- Build
- Test
- ReleaseCleanup
- ReleaseDeploy
- Validation
Build:
stage: Build
script:
- mvn clean install
- $(aws ecr get-login --no-include-email --region us-west-2)
- docker build -t 751503455312.dkr.ecr.us-west-2.amazonaws.com/pgnonprod:$CI_PIPELINE_ID .
- docker push 751503455312.dkr.ecr.us-west-2.amazonaws.com/pgnonprod:$CI_PIPELINE_ID
ReleaseCleanup:
stage: ReleaseCleanup
script:
- echo `pwd`
- cd ./helm && /sbin/helm delete --purge $RELEASE_NAME && exit 0
allow_failure: true
ReleaseDeploy:
stage: ReleaseDeploy
script:
- echo `pwd`
- sed -i s/#BUILD_ID#/$CI_PIPELINE_ID/g ./helm/service/values.yaml
- sed -i s/#SERVICE_PORT#/$SERVICE_PORT/g ./helm/service/values.yaml
- cd ./helm && /sbin/helm install service --name $RELEASE_NAME
Validation:
stage: Validation
script:
- sleep 45
- if [ `curl -s -o /dev/null -I -w "%{http_code}" https://pgtest.altimetrik.com/$RELEASE_NAME` = "200" ]; then exit 0; else exit 1; fi
allow_failure: false
\ No newline at end of file
FROM openjdk:8-jre-alpine
ADD /src/main/resources/application.properties //
ADD /src/main/resources/application.yml //
ADD /src/main/resources/db-config.properties //
ADD /src/main/resources/db-config-k8s.properties //
ADD /target/demo-0.0.1-SNAPSHOT.jar //
ENTRYPOINT ["java", "-jar", "/demo-0.0.1-SNAPSHOT.jar"]
# 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/
apiVersion: v1
appVersion: "1.0"
description: A Helm chart for Kubernetes
name: SERVICE_NAME
version: 0.1.0
\ No newline at end of file
1. Get the application URL by running these commands:
{{- if .Values.ingress.enabled }}
{{- range $host := .Values.ingress.hosts }}
{{- range $.Values.ingress.paths }}
http{{ if $.Values.ingress.tls }}s{{ end }}://{{ $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 "SERVICE_NAME.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 svc -w {{ include "SERVICE_NAME.fullname" . }}'
export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "SERVICE_NAME.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 "SERVICE_NAME.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 }}
\ No newline at end of file
{{/* vim: set filetype=mustache: */}}
{{/*
Expand the name of the chart.
*/}}
{{- define "SERVICE_NAME.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 "SERVICE_NAME.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 "SERVICE_NAME.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}}
{{- end -}}
\ No newline at end of file
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "SERVICE_NAME.fullname" . }}
labels:
app.kubernetes.io/name: {{ include "SERVICE_NAME.name" . }}
helm.sh/chart: {{ include "SERVICE_NAME.chart" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
spec:
replicas: {{ .Values.replicaCount }}
selector:
matchLabels:
app.kubernetes.io/name: {{ include "SERVICE_NAME.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
template:
metadata:
labels:
app.kubernetes.io/name: {{ include "SERVICE_NAME.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
spec:
containers:
- name: {{ .Chart.Name }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
ports:
- name: http
containerPort: {{ .Values.service.internalport }}
protocol: TCP
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 }}
\ No newline at end of file
{{- if .Values.ingress.enabled -}}
{{- $fullName := include "SERVICE_NAME.fullname" . -}}
{{- $ingressPaths := .Values.ingress.paths -}}
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: {{ $fullName }}
labels:
app.kubernetes.io/name: {{ include "SERVICE_NAME.name" . }}
helm.sh/chart: {{ include "SERVICE_NAME.chart" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- 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: {{ . | quote }}
http:
paths:
{{- range $ingressPaths }}
- path: {{ . }}
backend:
serviceName: {{ $fullName }}
servicePort: http
{{- end }}
{{- end }}
{{- end }}
\ No newline at end of file
apiVersion: v1
kind: Service
metadata:
name: {{ include "SERVICE_NAME.fullname" . }}
labels:
app.kubernetes.io/name: {{ include "SERVICE_NAME.name" . }}
helm.sh/chart: {{ include "SERVICE_NAME.chart" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
spec:
type: {{ .Values.service.type }}
ports:
- port: {{ .Values.service.port }}
targetPort: http
protocol: TCP
name: http
selector:
app.kubernetes.io/name: {{ include "SERVICE_NAME.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
\ No newline at end of file
apiVersion: v1
kind: Pod
metadata:
name: "{{ include "SERVICE_NAME.fullname" . }}-test-connection"
labels:
app.kubernetes.io/name: {{ include "SERVICE_NAME.name" . }}
helm.sh/chart: {{ include "SERVICE_NAME.chart" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
annotations:
"helm.sh/hook": test-success
spec:
containers:
- name: wget
image: busybox
command: ['wget']
args: ['{{ include "SERVICE_NAME.fullname" . }}:{{ .Values.service.port }}']
restartPolicy: Never
\ No newline at end of file
# Default values for SERVICE_NAME.
# This is a YAML-formatted file.
# Declare variables to be passed into your templates.
replicaCount: 1
image:
repository: 751503455312.dkr.ecr.us-west-2.amazonaws.com/pgnonprod
tag: #BUILD_ID#
pullPolicy: IfNotPresent
nameOverride: ""
fullnameOverride: ""
service:
type: NodePort
port: 80
internalport: #SERVICE_PORT#
ingress:
enabled: true
annotations:
kubernetes.io/ingress.class: nginx
nginx.ingress.kubernetes.io/rewrite-target: /
#kubernetes.io/tls-acme: "true"
paths:
path: /SERVICE_NAME
hosts:
# - afe6ec7ed3f3711e9b98006759708723-313212737.us-west-2.elb.amazonaws.com
- pgtest.altimetrik.com
tls:
- secretName: custom-tls-cert
hosts:
- pgtest.altimetrik.com
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: {}
\ No newline at end of file
......@@ -71,6 +71,11 @@
<version>${swagger.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
</dependencies>
<build>
......
......@@ -4,6 +4,7 @@ import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.PropertySource;
import org.springframework.context.annotation.PropertySources;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;
......@@ -12,7 +13,8 @@ import com.altimetrik.ee.demo.service.ComponentDetailsService;
@EnableAsync
@EnableScheduling
@SpringBootApplication(scanBasePackages = { "com.altimetrik" })
@PropertySource("classpath:db-config.properties")
@PropertySources({ @PropertySource(value = "classpath:db-config.properties"),
@PropertySource(value = "classpath:${k8s.db.env}.properties", ignoreResourceNotFound = true) })
public class Application {
private static ConfigurableApplicationContext context;
......
......@@ -10,7 +10,7 @@ cron:
# HTTP Server
server:
# port: 8090 # HTTP (Tomcat) port
port: 8080 # HTTP (Tomcat) port
undertow:
accesslog:
enabled: true
......
spring.datasource.driverClassName=org.h2.Driver
spring.datasource.username=sa
spring.datasource.password=
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
# temporary data storage
spring.datasource.url = jdbc:h2:file:./src/main/resources/db
\ No newline at end of file
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