Commit 7f35bcb2 authored by Siva Rama Krishna's avatar Siva Rama Krishna

Initila commit

parents
Pipeline #5104 failed with stages
in 15 seconds
/target/
!.mvn/wrapper/maven-wrapper.jar
### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr
### NetBeans ###
/nbproject/private/
/build/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
\ No newline at end of file
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.yml //
ADD /target/demo-0.0.1-SNAPSHOT.jar //
ENTRYPOINT ["java", "-jar", "/demo-0.0.1-SNAPSHOT.jar"]
# java8_springboot-2.0.5-api-template-4.0
Java with Spring Boot
\ No newline at end of file
# 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 }}
env:
- name: "k8s.db.env"
value: "db-config-k8s"
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: /$2
#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
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.altimetrik.ee</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>demo</name>
<description>Demo project for Spring Boot with MySQL</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.5.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<swagger.annotations.version>1.5.20</swagger.annotations.version>
<swagger.version>2.8.0</swagger.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
<!-- Swagger based Dependencies -->
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-annotations</artifactId>
<version>${swagger.annotations.version}</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>${swagger.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>${swagger.version}</version>
<scope>compile</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
package com.altimetrik.ee.demo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;
@EnableAsync
@EnableScheduling
@SpringBootApplication(scanBasePackages = { "com.altimetrik" })
public class Application {
private static ConfigurableApplicationContext context;
public static void main(String[] args) {
context = SpringApplication.run(Application.class, args);
}
}
package com.altimetrik.ee.demo.bean;
public class ComponentDetailsBean {
private String componentName;
private String componentIdentifier;
public ComponentDetailsBean() {
super();
}
public ComponentDetailsBean(String componentName, String componentIdentifier) {
super();
this.componentName = componentName;
this.componentIdentifier = componentIdentifier;
}
public String getComponentName() {
return componentName;
}
public void setComponentName(String componentName) {
this.componentName = componentName;
}
public String getComponentIdentifier() {
return componentIdentifier;
}
public void setComponentIdentifier(String componentIdentifier) {
this.componentIdentifier = componentIdentifier;
}
@Override
public String toString() {
return "ComponentDetailsBean [componentName=" + componentName + ", componentIdentifier=" + componentIdentifier
+ "]";
}
}
package com.altimetrik.ee.demo.bean;
import java.util.List;
public class PairedComponentDetailsBean extends ComponentDetailsBean {
private List<ComponentDetailsBean> pairedComponentDetails;
public PairedComponentDetailsBean() {
super();
}
public PairedComponentDetailsBean(final String componentName, final String componentIdentifier) {
super(componentName, componentIdentifier);
}
public PairedComponentDetailsBean(final String componentName, final String componentIdentifier,
final List<ComponentDetailsBean> pairedComponentDetails) {
super(componentName, componentIdentifier);
this.pairedComponentDetails = pairedComponentDetails;
}
public PairedComponentDetailsBean(final ComponentDetailsBean componentDetails,
final List<ComponentDetailsBean> pairedComponentDetails) {
super(componentDetails.getComponentName(), componentDetails.getComponentIdentifier());
this.pairedComponentDetails = pairedComponentDetails;
}
public List<ComponentDetailsBean> getPairedComponentDetails() {
return pairedComponentDetails;
}
public void setPairedComponentDetails(List<ComponentDetailsBean> pairedComponentDetails) {
this.pairedComponentDetails = pairedComponentDetails;
}
}
package com.altimetrik.ee.demo.config;
import static springfox.documentation.builders.PathSelectors.regex;
import java.util.Collections;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
@Configuration
@EnableSwagger2
public class SwaggerConfig {
@Bean
public Docket productApi() {
return new Docket(DocumentationType.SWAGGER_2).select()
.apis(RequestHandlerSelectors.basePackage("com.altimetrik.ee.demo.controller")).paths(regex("/.*"))
.build().enable(true).apiInfo(metaData());
}
private ApiInfo metaData() {
return new ApiInfo("Demo Application", "Demo API Services", "2.0", "https://www.altimetrik.com/privacy-policy/",
new Contact("Playground", "https://playground.altimetrik.com", "pg-mgr1@altimetrik.com"),
"Apache License Version 2.0", "https://www.apache.org/licenses/LICENSE-2.0", Collections.emptyList());
}
}
package com.altimetrik.ee.demo.controller;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping(value = "/")
@CrossOrigin
public class Default {
@GetMapping(value = "/", produces = { "text/html" }, consumes = MediaType.ALL_VALUE)
public ResponseEntity<String> getUserDetailByGitlabEmailId() {
String data = "Welcome to Playground Engineering Environment";
return new ResponseEntity<>(data, HttpStatus.OK);
}
}
package com.altimetrik.ee.demo.controller;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.altimetrik.ee.demo.bean.PairedComponentDetailsBean;
import com.altimetrik.ee.demo.service.ComponentDetailsService;
import io.swagger.annotations.ApiOperation;
@RestController
@RequestMapping(value = "/service")
public class ServiceController {
protected static Logger logger = LoggerFactory.getLogger(ServiceController.class.getName());
@Value("${spring.application.name}")
private String applicationName;
@Autowired
private ComponentDetailsService componentDetailsService;
@GetMapping(value = "/")
@ApiOperation(value = "Get service name and identifier", notes = "Get service details and its corresponding values for all paired services", response = PairedComponentDetailsBean.class)
public PairedComponentDetailsBean findAll() {
return componentDetailsService.findAll(this.applicationName);
}
}
package com.altimetrik.ee.demo.service;
import org.springframework.stereotype.Service;
import com.altimetrik.ee.demo.bean.PairedComponentDetailsBean;
@Service
public interface ComponentDetailsService {
PairedComponentDetailsBean findAll(final String applicationName);
}
package com.altimetrik.ee.demo.service.impl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import com.altimetrik.ee.demo.bean.PairedComponentDetailsBean;
import com.altimetrik.ee.demo.service.ComponentDetailsService;
@Service
public class ComponentDetailsServiceImpl implements ComponentDetailsService {
protected static Logger logger = LoggerFactory.getLogger(ComponentDetailsServiceImpl.class.getName());
@Value("${spring.application.name}")
private String applicationName;
@Override
public PairedComponentDetailsBean findAll(final String applicationName) {
final PairedComponentDetailsBean pairedComponentDetails = new PairedComponentDetailsBean(applicationName,
applicationName);
return pairedComponentDetails;
}
}
# Spring properties
spring:
application:
name: demo # Service registers under this name
cron:
component:
identifier:
reg-ex: 0 0/60 * * * ?
# HTTP Server
server:
port: 8080 # HTTP (Tomcat) port
undertow:
accesslog:
enabled: true
# Logging configurations
logging:
level:
root: INFO
com.memorynotfound: DEBUG
org.springframework.web: INFO
org.springframework.security: INFO
org.hibernate.SQL: WARN
package com.altimetrik.ee.demo.tests;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
@SpringBootTest
public class ApplicationTests {
@Test
public void contextLoads() {
}
}
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