diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..84fdf9a --- /dev/null +++ b/.dockerignore @@ -0,0 +1,6 @@ +Dockerfile +Jenkinsfile +.git +.gitignore +.dockerignore +helm diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a126c27 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.idea +.DS_Store diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..0f9de79 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,2 @@ +FROM nginx:1.13.1 +COPY . /usr/share/nginx/html/ diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000..8aae5b5 --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,58 @@ +pipeline { + agent any + triggers { + pollSCM '* * * * *' + } + options { + buildDiscarder(logRotator(numToKeepStr: '10')) + } + stages { + stage('Build') { + when { + anyOf { + branch 'master' + branch 'dev' + } + } + steps { + populateRevision() + sh "docker build -t docker-registry.market.local/documentation-api:$REVISION ." + } + } + + stage('Publish') { + when { + anyOf { + branch 'master' + branch 'dev' + } + } + steps { + sh "docker push docker-registry.market.local/documentation-api:$REVISION" + } + } + + stage('Deploy to Test cluster') { + when { + branch 'dev' + } + steps { + helmUpgradeInstall('test-cluster', 'test', './helm/values/test.yaml', "${REVISION}", 'documentation-api', './helm/documentation-api') + } + } + + stage('Deploy to Prod cluster') { + when { + branch 'master' + } + steps { + helmUpgradeInstall('prod-cluster', 'prod', './helm/values/prod.yaml', "${REVISION}", 'documentation-api', './helm/documentation-api') + } + } + } + post { + failure { + reportToTelegram() + } + } +} diff --git a/helm/documentation-api/Chart.yaml b/helm/documentation-api/Chart.yaml new file mode 100644 index 0000000..4a999f0 --- /dev/null +++ b/helm/documentation-api/Chart.yaml @@ -0,0 +1,4 @@ +apiVersion: v1 +description: api.evotor.ru documentation +name: documentation-api +version: 0.1.0 diff --git a/helm/documentation-api/templates/deployment.yaml b/helm/documentation-api/templates/deployment.yaml new file mode 100644 index 0000000..9eb2abd --- /dev/null +++ b/helm/documentation-api/templates/deployment.yaml @@ -0,0 +1,29 @@ +apiVersion: apps/v1beta1 +kind: Deployment +metadata: + labels: + app: {{ .Chart.Name }} + name: {{ .Chart.Name }} +spec: + replicas: {{ .Values.replicaCount }} + strategy: + type: RollingUpdate + template: + metadata: + labels: + app: {{ .Chart.Name }} + spec: + containers: + - name: {{ .Chart.Name }} + image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}" + ports: + - name: http + containerPort: {{ .Values.service.internalPort }} + readinessProbe: + httpGet: + path: / + port: http + initialDelaySeconds: 15 + periodSeconds: 5 + resources: +{{ toYaml .Values.resources | indent 10}} diff --git a/helm/documentation-api/templates/ingress.yaml b/helm/documentation-api/templates/ingress.yaml new file mode 100644 index 0000000..c57ecaf --- /dev/null +++ b/helm/documentation-api/templates/ingress.yaml @@ -0,0 +1,21 @@ +{{- if .Values.ingress.enabled -}} +{{- $servicePort := .Values.service.internalPort -}} +{{- $serviceName := .Values.service.name}} +apiVersion: extensions/v1beta1 +kind: Ingress +metadata: + name: {{ .Chart.Name }} + labels: + app: {{ .Chart.Name }} +spec: + rules: + {{- range $host := .Values.ingress.hosts }} + - host: {{ $host }} + http: + paths: + - path: / + backend: + serviceName: {{ $serviceName }} + servicePort: {{ $servicePort }} + {{- end -}} +{{- end -}} \ No newline at end of file diff --git a/helm/documentation-api/templates/service.yaml b/helm/documentation-api/templates/service.yaml new file mode 100644 index 0000000..088a425 --- /dev/null +++ b/helm/documentation-api/templates/service.yaml @@ -0,0 +1,13 @@ +apiVersion: v1 +kind: Service +metadata: + labels: + app: {{ .Chart.Name }} + name: {{ .Values.service.name }} +spec: + ports: + - name: app + port: {{ .Values.service.externalPort }} + targetPort: {{ .Values.service.internalPort }} + selector: + app: {{ .Chart.Name }} \ No newline at end of file diff --git a/helm/documentation-api/values.yaml b/helm/documentation-api/values.yaml new file mode 100644 index 0000000..a7d56c2 --- /dev/null +++ b/helm/documentation-api/values.yaml @@ -0,0 +1,15 @@ +replicaCount: 2 +image: + repository: docker-registry.market.local/documentation-api + tag: jenkins-devops-devops-documentation-api-2 +service: + name: documentation-api + externalPort: 80 + internalPort: 80 +ingress: + enabled: false + hosts: [] + annotations: +resources: + limits: + memory: 200Mi diff --git a/helm/values/prod.yaml b/helm/values/prod.yaml new file mode 100644 index 0000000..9c60e56 --- /dev/null +++ b/helm/values/prod.yaml @@ -0,0 +1,2 @@ +ingress: + enabled: false diff --git a/helm/values/test.yaml b/helm/values/test.yaml new file mode 100644 index 0000000..6bd2572 --- /dev/null +++ b/helm/values/test.yaml @@ -0,0 +1,4 @@ +ingress: + enabled: true + hosts: + - documentation-api.test.market.local