diff --git a/DockerFolder/HELM_KUBECTL/Dockerfile b/DockerFolder/HELM_KUBECTL/Dockerfile new file mode 100644 index 0000000..d61dcfe --- /dev/null +++ b/DockerFolder/HELM_KUBECTL/Dockerfile @@ -0,0 +1,28 @@ +FROM alpine + +ARG VCS_REF +ARG BUILD_DATE + +# Metadata +LABEL org.label-schema.vcs-ref=$VCS_REF \ + org.label-schema.name="helm-kubectl" \ + org.label-schema.url="https://hub.docker.com/r/dtzar/helm-kubectl/" \ + org.label-schema.vcs-url="https://github.com/dtzar/helm-kubectl" \ + org.label-schema.build-date=$BUILD_DATE + +# Note: Latest version of kubectl may be found at: +# https://aur.archlinux.org/packages/kubectl-bin/ +ENV KUBE_LATEST_VERSION="v1.13.2" +# Note: Latest version of helm may be found at: +# https://github.com/kubernetes/helm/releases +ENV HELM_VERSION="v2.12.3" + +RUN apk add --no-cache ca-certificates bash git \ + && wget -q https://storage.googleapis.com/kubernetes-release/release/${KUBE_LATEST_VERSION}/bin/linux/amd64/kubectl -O /usr/local/bin/kubectl \ + && chmod +x /usr/local/bin/kubectl \ + && wget -q https://storage.googleapis.com/kubernetes-helm/helm-${HELM_VERSION}-linux-amd64.tar.gz -O - | tar -xzO linux-amd64/helm > /usr/local/bin/helm \ + && chmod +x /usr/local/bin/helm + +WORKDIR /config + +CMD bash diff --git a/DockerFolder/jenkins_docker_image b/DockerFolder/jenkins_docker_image new file mode 100644 index 0000000..d05da6f --- /dev/null +++ b/DockerFolder/jenkins_docker_image @@ -0,0 +1,11 @@ +from jenkinsci/jenkins:lts +USER root +#Install Docker +RUN apt-get -qq update && \ +apt-get -qq -y install curl && \ +curl -sSL https://get.docker.com/ | sh +# Install kubectl and helm +RUN 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 && \ +mv ./kubectl /usr/local/bin/kubectl +RUN usermod -aG docker jenkins diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..9c79577 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,8 @@ +FROM python:3.6-alpine +MAINTAINER Maxim Zhovanik +WORKDIR /service/GET-SERV +COPY . /service/GET-SERV +RUN pip install -r /service/GET-SERV/app/requirements.txt +CMD ["python", "/service/GET-SERV/app/app.py"] + + diff --git a/E2E.yaml b/E2E.yaml new file mode 100644 index 0000000..911b9ce --- /dev/null +++ b/E2E.yaml @@ -0,0 +1,263 @@ +--- +apiVersion: v1 +kind: Namespace +metadata: + name: testing +--- +apiVersion: v1 +kind: ConfigMap +metadata: + namespace: testing + name: services-address +data: + POST_SERVICE_URL: post-service.testing.svc + VIEW_SERVICE_URL: get-service.testing.svc + DB_URL: db-service.testing.svc + URL_DB: db-service.testing.svc +--- +apiVersion: v1 +kind: Secret +metadata: + name: db-secret + namespace: testing +data: + username: ZGJhZG1pbg== + password: UGFzc3dvcmQ= + dbname: c3Jtc3lzdGVt +type: Opaque +--- +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + namespace: testing + labels: + app: pvc-postgres + name: postgres-pvc +spec: + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 2Gi +--- +apiVersion: extensions/v1beta1 +kind: Deployment +metadata: + namespace: testing + name: postgres + labels: + service: postgresdb +spec: + template: + metadata: + labels: + app: postgres + spec: + initContainers: + - name: volume-mount-hack + image: busybox + command: ["sh", "-c", "chown -R 999.999 /var/lib/postgresql/"] + volumeMounts: + - name: postgres-pv-claim + mountPath: /var/lib/postgresql/data + subPath: postgres + containers: + - image: postgres:9.6.2 + name: postgresql + env: + - name: POSTGRES_DB + valueFrom: + secretKeyRef: + name: db-secret + key: dbname + - name: POSTGRES_USER + valueFrom: + secretKeyRef: + name: db-secret + key: username + - name: POSTGRES_PASSWORD + valueFrom: + secretKeyRef: + name: db-secret + key: password + ports: + - containerPort: 5432 + volumeMounts: + - name: postgres-pv-claim + mountPath: /var/lib/postgresql/data + subPath: postgres + volumes: + - name: postgres-pv-claim + persistentVolumeClaim: + claimName: postgres-pvc +--- +kind: Service +apiVersion: v1 +metadata: + namespace: testing + name: srmsystemdb +spec: + selector: + app: postgres + ports: + - protocol: TCP + port: 5432 + targetPort: 5432 +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + namespace: testing + name: db-service +spec: + selector: + matchLabels: + app: db-service + template: + metadata: + labels: + app: db-service + spec: + initContainers: + - image: 100.71.71.71:5000/init-container:${params.imageTagDB_} + name: init-container-postgres + env: + - name: PGDATABASE + valueFrom: + secretKeyRef: + name: db-secret + key: dbname + - name: PGUSER + valueFrom: + secretKeyRef: + name: db-secret + key: username + - name: PGPASSWORD + valueFrom: + secretKeyRef: + name: db-secret + key: password + command: ['sh', '-c', '/bin/bash /tmp/check_dump.sh'] + containers: + - image: 100.71.71.71:5000/db-service:${params.imageTagDB_} + name: db-service + ports: + - containerPort: 5002 + env: + - name: POSTGRES_HOST + value: srmsystemdb + - name: POSTGRES_PORT + value: '5432' + - name: PGDATABASE + valueFrom: + secretKeyRef: + name: db-secret + key: dbname + - name: PGUSER + valueFrom: + secretKeyRef: + name: db-secret + key: username + - name: PGPASSWORD + valueFrom: + secretKeyRef: + name: db-secret + key: password +--- +kind: Service +apiVersion: v1 +metadata: + namespace: testing + name: db-service +spec: + selector: + app: db-service + ports: + - protocol: TCP + port: 5002 + targetPort: 5002 +--- +kind: Service +apiVersion: v1 +metadata: + namespace: testing + name: ui-service + labels: + app: ui +spec: + selector: + app: ui + ports: + - protocol: TCP + port: 5000 + targetPort: 5000 +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + namespace: testing + name: ui-deployment +spec: + selector: + matchLabels: + app: ui + replicas: 1 + template: + metadata: + labels: + app: ui + spec: + containers: + - name: ui + image: 100.71.71.71:5000/ui-service:${params.imageTagUI_} + ports: + - containerPort: 5000 + env: + - name: VIEW_SERVICE_URL + valueFrom: + configMapKeyRef: + name: services-address + key: VIEW_SERVICE_URL +--- +kind: Service +apiVersion: v1 +metadata: + namespace: testing + name: get-service + labels: + app: get +spec: + selector: + app: get + ports: + - protocol: TCP + port: 5003 + targetPort: 5003 +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + namespace: testing + name: get-deployment +spec: + selector: + matchLabels: + app: get + replicas: 1 + template: + metadata: + labels: + app: get + spec: + containers: + - name: get + image: 100.71.71.71:5000/get-service:${params.imageTagGET_} + ports: + - containerPort: 5003 + env: + - name: URL_DB + valueFrom: + configMapKeyRef: + name: services-address + key: URL_DB +--- diff --git a/Final_Magic/DeployCluster.sh b/Final_Magic/DeployCluster.sh new file mode 100755 index 0000000..d9634a9 --- /dev/null +++ b/Final_Magic/DeployCluster.sh @@ -0,0 +1,21 @@ +#!/bin/bash +export NAME=kubern.cluster.k8s.local +export KOPS_STATE_STORE=s3://crm-system-k8s +kops create cluster --zones eu-west-1a ${NAME} --master-size=t2.small --node-size=t2.small --node-count=2 --master-volume-size=8 --node-volume-size=8 +sleep 10 +kops get cluster --name ${NAME} -oyaml > cluster.yaml +cat <<__EOF__>> cluster.yaml + fileAssets: + - content: | + { + "insecure-registries" : ["100.71.71.71:5000"] + } + name: insecure-registries + path: /etc/docker/daemon.json + roles: + - Master + - Node +__EOF__ +sleep 5 +kops replace -f cluster.yaml +kops update cluster ${NAME} --yes diff --git a/Final_Magic/DeployRegistry.yaml b/Final_Magic/DeployRegistry.yaml new file mode 100644 index 0000000..48a533d --- /dev/null +++ b/Final_Magic/DeployRegistry.yaml @@ -0,0 +1,54 @@ +--- +apiVersion: v1 +kind: Service +apiVersion: v1 +metadata: + name: docker-registry +spec: + clusterIP: "100.71.71.71" + selector: + app: docker-registry + ports: + - name: http + protocol: TCP + port: 5000 + targetPort: 5000 +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: registry +spec: + replicas: 1 + selector: + matchLabels: + app: docker-registry + template: + metadata: + labels: + app: docker-registry + spec: + containers: + - name: registry + image: registry:2 + ports: + - name: registry-port + containerPort: 5000 + volumeMounts: + - mountPath: /var/lib/registry + name: images + volumes: + - name: images + persistentVolumeClaim: + claimName: registry-pv-claim +--- +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: registry-pv-claim +spec: + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 10Gi diff --git a/Final_Magic/cluster.yaml b/Final_Magic/cluster.yaml new file mode 100644 index 0000000..8334512 --- /dev/null +++ b/Final_Magic/cluster.yaml @@ -0,0 +1,58 @@ +apiVersion: kops/v1alpha2 +kind: Cluster +metadata: + creationTimestamp: 2019-02-14T17:33:50Z + name: kubern.cluster.k8s.local +spec: + api: + loadBalancer: + type: Public + authorization: + rbac: {} + channel: stable + cloudProvider: aws + configBase: s3://crm-system-k8s/kubern.cluster.k8s.local + etcdClusters: + - etcdMembers: + - instanceGroup: master-eu-west-1a + name: a + name: main + - etcdMembers: + - instanceGroup: master-eu-west-1a + name: a + name: events + iam: + allowContainerRegistry: true + legacy: false + kubelet: + anonymousAuth: false + kubernetesApiAccess: + - 0.0.0.0/0 + kubernetesVersion: 1.11.6 + masterPublicName: api.kubern.cluster.k8s.local + networkCIDR: 172.20.0.0/16 + networking: + kubenet: {} + nonMasqueradeCIDR: 100.64.0.0/10 + sshAccess: + - 0.0.0.0/0 + subnets: + - cidr: 172.20.32.0/19 + name: eu-west-1a + type: Public + zone: eu-west-1a + topology: + dns: + type: Public + masters: public + nodes: public + fileAssets: + - content: | + { + "insecure-registries" : ["100.71.71.71:5000"] + } + name: insecure-registries + path: /etc/docker/daemon.json + roles: + - Master + - Node diff --git a/Final_Magic/magic.sh b/Final_Magic/magic.sh new file mode 100755 index 0000000..0119f89 --- /dev/null +++ b/Final_Magic/magic.sh @@ -0,0 +1,17 @@ +#!/bin/bash + +. DeployCluster.sh + +sleep 3m + +kubectl apply -f DeployRegistry.yaml +kubectl apply -f myjob.yaml + +sleep 5m + +kubectl -n kube-system create serviceaccount tiller +kubectl create clusterrolebinding tiller \ + --clusterrole cluster-admin \ + --serviceaccount=kube-system:tiller +helm init --service-account tiller + diff --git a/Final_Magic/myjob.yaml b/Final_Magic/myjob.yaml new file mode 100644 index 0000000..77f5377 --- /dev/null +++ b/Final_Magic/myjob.yaml @@ -0,0 +1,814 @@ +apiVersion: v1 +kind: Namespace +metadata: + name: production + +--- + +apiVersion: v1 +kind: Namespace +metadata: + name: testing + +--- + +apiVersion: v1 +kind: Namespace +metadata: + name: production-bg +--- +#apiVersion: v1 +#kind: Secret +#metadata: +# name: db-secret +# namespace: production +#data: +# username: ZGJhZG1pbg== +# password: UGFzc3dvcmQ= +# dbname: c3Jtc3lzdGVt +#type: Opaque + +#--- + +apiVersion: v1 +kind: ServiceAccount +metadata: + name: jenkins + namespace: production-bg +--- + +apiVersion: v1 +kind: ServiceAccount +metadata: + name: jenkins + namespace: production + +--- + +kind: Role +apiVersion: rbac.authorization.k8s.io/v1 +metadata: + name: jenkins + namespace: production +rules: +- apiGroups: [""] + resources: ["pods"] + verbs: ["create","delete","get","list","patch","update","watch"] +- apiGroups: [""] + resources: ["pods/exec"] + verbs: ["create","delete","get","list","patch","update","watch"] +- apiGroups: [""] + resources: ["pods/log"] + verbs: ["get","list","watch"] +- apiGroups: [""] + resources: ["services"] + verbs: ["create","delete","get","list","patch","update","watch"] +- apiGroups: [""] + resources: ["deployments"] + verbs: ["create","delete","get","list","patch","update","watch"] +- apiGroups: ["apps"] + resources: ["deployments"] + verbs: ["create","delete","get","list","patch","update","watch"] +- apiGroups: ["extensions"] + resources: ["deployments"] + verbs: ["create","delete","get","list","patch","update","watch"] +- apiGroups: [""] + resources: ["persistentvolumeclaims"] + verbs: ["create","delete","get","list","patch","update","watch"] +- apiGroups: [""] + resources: ["secrets"] + verbs: ["get"] +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: RoleBinding +metadata: + name: jenkins + namespace: production +roleRef: + apiGroup: rbac.authorization.k8s.io + kind: Role + name: jenkins +subjects: +- kind: ServiceAccount + name: jenkins +--- + +apiVersion: v1 +kind: ServiceAccount +metadata: + name: jenkins + namespace: testing + +--- + +kind: Role +apiVersion: rbac.authorization.k8s.io/v1 +metadata: + name: jenkins-test + namespace: testing +rules: +- apiGroups: [""] + resources: ["pods"] + verbs: ["create","delete","get","list","patch","update","watch"] +- apiGroups: [""] + resources: ["pods/exec"] + verbs: ["create","delete","get","list","patch","update","watch"] +- apiGroups: [""] + resources: ["pods/log"] + verbs: ["get","list","watch"] +- apiGroups: [""] + resources: ["services"] + verbs: ["create","delete","get","list","patch","update","watch"] +- apiGroups: [""] + resources: ["deployments"] + verbs: ["create","delete","get","list","patch","update","watch"] +- apiGroups: ["apps"] + resources: ["deployments"] + verbs: ["create","delete","get","list","patch","update","watch"] +- apiGroups: ["extensions"] + resources: ["deployments"] + verbs: ["create","delete","get","list","patch","update","watch"] +- apiGroups: [""] + resources: ["persistentvolumeclaims"] + verbs: ["create","delete","get","list","patch","update","watch"] +- apiGroups: [""] + resources: ["secrets"] + verbs: ["create","delete","get","list","patch","update","watch"] +- apiGroups: [""] + resources: ["namespaces"] + verbs: ["create","delete","get","list","patch","update","watch"] +- apiGroups: [""] + resources: ["configmaps"] + verbs: ["create","delete","get","list","patch","update","watch"] +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: RoleBinding +metadata: + name: jenkins-test + namespace: testing +roleRef: + apiGroup: rbac.authorization.k8s.io + kind: Role + name: jenkins-test +subjects: +- kind: ServiceAccount + name: jenkins + namespace: production + +--- + +apiVersion: v1 +kind: ServiceAccount +metadata: + name: jenkins + namespace: kube-system + +--- + +kind: Role +apiVersion: rbac.authorization.k8s.io/v1 +metadata: + name: jenkins-kube + namespace: kube-system +rules: +- apiGroups: [""] + resources: ["pods"] + verbs: ["create","delete","get","list","patch","update","watch"] +- apiGroups: [""] + resources: ["pods/exec"] + verbs: ["create","delete","get","list","patch","update","watch"] +- apiGroups: [""] + resources: ["pods/log"] + verbs: ["get","list","watch"] +- apiGroups: [""] + resources: ["services"] + verbs: ["create","delete","get","list","patch","update","watch"] +- apiGroups: [""] + resources: ["deployments"] + verbs: ["create","delete","get","list","patch","update","watch"] +- apiGroups: ["apps"] + resources: ["deployments"] + verbs: ["create","delete","get","list","patch","update","watch"] +- apiGroups: ["extensions"] + resources: ["deployments"] + verbs: ["create","delete","get","list","patch","update","watch"] +- apiGroups: [""] + resources: ["persistentvolumeclaims"] + verbs: ["create","delete","get","list","patch","update","watch"] +- apiGroups: [""] + resources: ["secrets"] + verbs: ["create","delete","get","list","patch","update","watch"] +- apiGroups: [""] + resources: ["namespaces"] + verbs: ["create","delete","get","list","patch","update","watch"] +- apiGroups: [""] + resources: ["configmaps"] + verbs: ["create","delete","get","list","patch","update","watch"] +- apiGroups: [""] + resources: ["pods/portforward"] + verbs: ["create","delete","get","list","patch","update","watch"] + +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: RoleBinding +metadata: + name: jenkins-kube + namespace: kube-system +roleRef: + apiGroup: rbac.authorization.k8s.io + kind: Role + name: jenkins-kube +subjects: +- kind: ServiceAccount + name: jenkins + namespace: production +--- + + +kind: Role +apiVersion: rbac.authorization.k8s.io/v1 +metadata: + name: jenkins-bg + namespace: production-bg +rules: +- apiGroups: [""] + resources: ["pods"] + verbs: ["create","delete","get","list","patch","update","watch"] +- apiGroups: [""] + resources: ["pods/exec"] + verbs: ["create","delete","get","list","patch","update","watch"] +- apiGroups: [""] + resources: ["pods/log"] + verbs: ["get","list","watch"] +- apiGroups: [""] + resources: ["services"] + verbs: ["create","delete","get","list","patch","update","watch"] +- apiGroups: [""] + resources: ["deployments"] + verbs: ["create","delete","get","list","patch","update","watch"] +- apiGroups: ["apps"] + resources: ["deployments"] + verbs: ["create","delete","get","list","patch","update","watch"] +- apiGroups: ["extensions"] + resources: ["deployments"] + verbs: ["create","delete","get","list","patch","update","watch"] +- apiGroups: [""] + resources: ["persistentvolumeclaims"] + verbs: ["create","delete","get","list","patch","update","watch"] +- apiGroups: [""] + resources: ["secrets"] + verbs: ["create","delete","get","list","patch","update","watch"] +- apiGroups: [""] + resources: ["namespaces"] + verbs: ["create","delete","get","list","patch","update","watch"] +- apiGroups: [""] + resources: ["configmaps"] + verbs: ["create","delete","get","list","patch","update","watch"] +- apiGroups: [""] + resources: ["pods/portforward"] + verbs: ["create","delete","get","list","patch","update","watch"] + +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: RoleBinding +metadata: + name: jenkins-bg + namespace: production-bg +roleRef: + apiGroup: rbac.authorization.k8s.io + kind: Role + name: jenkins-kube +subjects: +- kind: ServiceAccount + name: jenkins + namespace: production +--- + +apiVersion: v1 +kind: ConfigMap +metadata: + namespace: production + name: services-address-v1 +data: + POST_SERVICE_URL: post-service-v1.production.svc + VIEW_SERVICE_URL: get-service-v1.production.svc + DB_URL: db-service-v1.production.svc + URL_DB: db-service-v1.production.svc +--- +apiVersion: v1 +kind: ConfigMap +metadata: + namespace: production + name: services-address +data: + POST_SERVICE_URL: post-service.production.svc + VIEW_SERVICE_URL: get-service.production.svc + DB_URL: db-service.production.svc + URL_DB: db-service.production.svc +--- +apiVersion: v1 +kind: ConfigMap +metadata: + namespace: production + name: services-address-v2 +data: + POST_SERVICE_URL: post-service-v2.production.svc + VIEW_SERVICE_URL: get-service-v2.production.svc + DB_URL: db-service-v2.production.svc + URL_DB: db-service-v2.production.svc +--- +apiVersion: v1 +kind: ConfigMap +metadata: + namespace: testing + name: services-address +data: + POST_SERVICE_URL: post-service.testing.svc + VIEW_SERVICE_URL: get-service.testing.svc + DB_URL: db-service.testing.svc + URL_DB: db-service.testing.svc + + +--- + +apiVersion: v1 +kind: ConfigMap +metadata: + namespace: production-bg + name: services-address-v1 +data: + POST_SERVICE_URL: post-service-v1.production-bg.svc + VIEW_SERVICE_URL: get-service-v1.production-bg.svc + DB_URL: db-service-v1.production-bg.svc + URL_DB: db-service-v1.production-bg.svc + +--- +apiVersion: v1 +kind: ConfigMap +metadata: + namespace: production-bg + name: services-address-v2 +data: + POST_SERVICE_URL: post-service-v2.production-bg.svc + VIEW_SERVICE_URL: get-service-v2.production-bg.svc + DB_URL: db-service-v2.production-bg.svc + URL_DB: db-service-v2.production-bg.svc +--- + + +apiVersion: v1 +data: + GitHub.xml: |- + + + + + GitHub + + + + + + + + + + git + + admgolovin + Slider256$ + + + github-1 + + admgolovin + $GITPWD + + + + + + + + + + + + + + + + false + + + + + + + true + 1 + 1 + + + + H/5 * * * * + 900000 + + + false + + + Kv-045DevOps + github-1 + + + Kubik-DB|SRM-GET|SRM-UI|SRM-DB + + + 1 + + + 1 + + + 1 + + + + + + + + Jenkinsfile + + + + + + + .* + true + + + + + +kind: ConfigMap +metadata: + creationTimestamp: "2019-01-18T03:22:02Z" + name: stark2 + namespace: production + resourceVersion: "96672" + selfLink: /api/v1/namespaces/default/configmaps/stark + uid: b70d8525-17fd-11e9-b845-02d08d5f4672 + +--- + +apiVersion: v1 +data: + config.xml: |- + + + + 2.150.2 + RUNNING + 2 + NORMAL + true + + false + + + true + false + + false + + ${JENKINS_HOME}/workspace/${ITEM_FULL_NAME} + ${ITEM_ROOTDIR}/builds + + + + + + kubernetes + + + https://kubernetes.default.svc + false + false + false + production + http://127.0.0.1:8080/ + kube-login + 10 + 5 + 0 + 0 + false + 32 + 600 + + + + 5 + 0 + + + + all + false + false + + + + all + 50000 + + + + + credentials.xml: |- + + + + + + + + + + GLOBAL + kube-login + + admin + $PASSWORD + + + GLOBAL + git_cred + + Maxghost33 + {AQAAABAAAAAg1cMYtdzX0b8pqPwU99XFsHEZtmsDLQy8n/RBMOnJnAj9ScoSD8i87dXfnx7TD0m+} + + + GLOBAL + docker_registry + + ghostgoose33 + {AQAAABAAAAAg8qaRTgg3fvfezKNrIlbz5LAhL3/WI0W5Nl4MLFgrPxYFSb8qACvkxcMFGvbtFQYx} + + + + + +kind: ConfigMap +metadata: + creationTimestamp: "2019-01-17T19:47:40Z" + name: jenconf + namespace: production + resourceVersion: "5227" + selfLink: /api/v1/namespaces/production/configmaps/jenconf + uid: bfec9ca6-1a90-11e9-a5b8-020fccbfb056 + +--- + +apiVersion: v1 +kind: Pod +metadata: + name: jenkins2 + namespace: production + labels: + service: jenkins2 +spec: + tolerations: + - key: "node" + operator: "Equal" + value: "boubde" + effect: "NoSchedule" + containers: + - name: stark-jenkins2 + image: admgolovin/myjenkins:v12 + volumeMounts: + - name: jenkins-config + mountPath: /var/jenkins_home/2/jobs/GitHub/ + - name: jenconf + mountPath: /var/jenkins_home/2 + lifecycle: + postStart: + exec: + command: ["/bin/sh","-c", "cp /var/jenkins_home/2/config.xml /var/jenkins_home/; cp /var/jenkins_home/2/credentials.xml /var/jenkins_home/; cp /var/jenkins_home/2/hudson.util.Secret /var/jenkins_home/secrets/; cp /var/jenkins_home/2/master.key /var/jenkins_home/secrets/; sleep 5m; java -jar /tools/jenkins-cli.jar -s http://127.0.0.1:8080 -auth admin:admin create-job GitHub < /var/jenkins_home/2/jobs/GitHub/GitHub.xml"] + serviceAccount: jenkins + serviceAccountName: jenkins + volumes: + - name: jenkins-config + configMap: + name: stark2 + - name: jenconf + configMap: + name: jenconf + restartPolicy: OnFailure + +# --- +# kind: Endpoints +# apiVersion: v1 +# metadata: +# name: my-service2 +# namespace: production +# subsets: +# - addresses: +# - ip: 10.0.0.1 +# targetRef: +# kind: Node +# name: node1 +# ports: +# - name: myjenkins +# port: 8080 +# protocol: TCP + +--- +kind: Service +apiVersion: v1 +metadata: + name: my-service + namespace: production +spec: + selector: + service: jenkins2 + ports: + - protocol: TCP + port: 8080 + targetPort: 8080 + type: LoadBalancer + +--- + +kind: Service +apiVersion: v1 +metadata: + name: jenkins-agent + namespace: production +spec: + selector: + service: jenkins2 + ports: + - protocol: TCP + port: 50000 + targetPort: 50000 + type: LoadBalancer + +--- + +apiVersion: v1 +kind: Secret +metadata: + name: test-secret + namespace: production +data: + password: YWRtaW4= + +--- + +# apiVersion: v1 +# kind: Pod +# metadata: +# name: dind-jen +# namespace: production +# spec: +# containers: +# - name: jnlp +# image: '/myjenkins:jenslave' +# args: ['\$(JENKINS_SECRET)'] +# env: +# - name: DOCKER_HOST +# value: tcp://localhost:2375 +# - name: dind +# image: docker:stable-dind +# securityContext: +# privileged: true +# volumeMounts: +# - name: dind-storage +# mountPath: /var/lib/docker +# volumes: +# - name: dind-storage +# emptyDir: {} + +--- + +# apiVersion: v1 +# kind: Pod +# metadata: +# name: jenslave +# namespace: production +# labels: +# service: jenkins +# spec: +# containers: +# - name: jnlp +# image: /myjenkins:jenslave +# resources: +# limits: +# memory: "600Mi" +# requests: +# memory: "500Mi" + +# apiVersion: apps/v1 +# kind: Deployment +# metadata: +# name: jenkins-storage +# namespace: production +# spec: +# selector: +# matchLabels: +# service: jenkins +# template: +# metadata: +# labels: +# service: jenkins +# spec: +# containers: +# - name: stark-jenkins +# image: ghostgoose33/jenkins-alp:v2 +# volumeMounts: +# - name: jenkins-config +# mountPath: /var/lib/jenkins/job/GitHub +# volumes: +# - name: jenkins-config +# configMap: +# name: stark2 + +--- + +# apiVersion: v1 +# kind: Pod +# metadata: +# name: jenkins2 +# namespace: production +# labels: +# service: jenkins2 +# spec: +# containers: +# - name: stark-jenkins2 +# image: ghostgoose33/jenkins-alp:v2 + +# restartPolicy: OnFailure + +--- +kind: Service +apiVersion: v1 +metadata: + namespace: production + name: ui + labels: + app: ui +spec: + selector: + app: ui + ports: + - protocol: TCP + port: 5000 + targetPort: 5000 +--- +kind: Service +apiVersion: v1 +metadata: + namespace: production + name: get-service + labels: + app: get-service +spec: + selector: + app: get-service + ports: + - protocol: TCP + port: 5003 + targetPort: 5003 +--- +kind: Service +apiVersion: v1 +metadata: + namespace: production + name: post-service + labels: + app: post-service +spec: + selector: + app: post-service + ports: + - protocol: TCP + port: 5001 + targetPort: 5001 +--- +kind: Service +apiVersion: v1 +metadata: + namespace: production + name: db-service +spec: + selector: + app: db-service + ports: + - protocol: TCP + port: 5002 + targetPort: 5002 +--- diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000..6e63cfc --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,84 @@ +def label = "mypod-${UUID.randomUUID().toString()}" + + +podTemplate(label: label, annotations: [podAnnotation(key: "sidecar.istio.io/inject", value: "false")], containers: [ + containerTemplate(name: 'python-alpine', image: 'ghostgoose33/python-alp:v3', command: 'cat', ttyEnabled: true), + containerTemplate(name: 'docker', image: 'ghostgoose33/docker-in:v1', command: 'cat', ttyEnabled: true) +], +volumes: [ + hostPathVolume(mountPath: '/var/run/docker.sock', hostPath: '/var/run/docker.sock') +], serviceAccount: "jenkins") +{ + +def dockerRegistry = "100.71.71.71:5000" +def Creds = "git_cred" +def projName = "get-service" +def imageVersion = "v2" +def imageName = "100.71.71.71:5000/get-service:${imageVersion}" +def imageN = '100.71.71.71:5000/get-service:' + +properties([ + parameters([ + stringParam( + defaultValue: '***', + description: 'TAG_Change', + name: 'service') + ]) +]) + + +node(label) +{ + try{ + stage("Pre-Test"){ + dir('get'){ + git(branch: "test", url: 'https://github.com/Kv-045DevOps/SRM-GET.git', credentialsId: "${Creds}") + imageTagGET = (sh (script: "git rev-parse --short HEAD", returnStdout: true)) + tmp = "1" + pathTocodeget = pwd() + } + } + stage("Test image_regisrty_check"){ + container("python-alpine"){ + check_new = (sh (script: "python3 /images-registry-test.py get-service ${imageTagGET}", returnStdout:true).trim()) + echo "${check_new}" + echo "${imageTagGET}" + echo "${params.imageTagGET_}" + } + } + + stage ("Unit Tests"){ + sh 'echo "Here will be unit testss"' + } + stage("Test code using PyLint and version build"){ + container('python-alpine'){ + //sh "python3 ${pathTocodeget}/sed_python.py template.yaml ${dockerRegistry}/get-service ${imageTag}" + sh "python3 /pylint-test.py ${pathTocodeget}/app/app.py" + } + } + stage("Build docker image"){ + container('docker'){ + pathdocker = pwd() + if ("${tmp}" == "${check_new}"){ + sh "docker build ${pathTocodeget} -t ${imageN}${imageTagGET}" + sh "docker images" + sh "cat /etc/docker/daemon.json" + sh "docker push ${imageN}${imageTagGET}" + sleep 20 + build(job: 'GitHub/GET-SERVICES/test1', parameters: [[$class: 'StringParameterValue', name:"imageTagGET_", value: "${imageTagGET}"], + [$class: 'StringParameterValue', name:"imageTagUI_", value: "${params.imageTagUI_}"], + [$class: 'StringParameterValue', name:"imageTagDB_", value: "${params.imageTagDB_}"], + [$class: 'StringParameterValue', name:"imageTagPOST_", value: "${params.imageTagPOST_}"], + [$class: 'StringParameterValue', name:"service", value: "get"]], wait: true) + } else { + echo "NO" + } + + } + } + } + catch(err){ + currentBuild.result = 'Failure' + } +} +} diff --git a/Jenkinsfile_deploy b/Jenkinsfile_deploy new file mode 100644 index 0000000..a9dd326 --- /dev/null +++ b/Jenkinsfile_deploy @@ -0,0 +1,244 @@ + +def label = "mypod-${UUID.randomUUID().toString()}" +def dockerRegistry = "100.71.71.71:5000" +def Creds = "git_cred" + +String deploy_db = """ +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + namespace: production + name: db-service +spec: + selector: + matchLabels: + app: db-service + template: + metadata: + labels: + app: db-service + spec: + initContainers: + - image: 100.71.71.71:5000/init-container:${params.imageTagDB_} + name: init-container-postgres + env: + - name: PGDATABASE + valueFrom: + secretKeyRef: + name: db-secret + key: dbname + - name: PGUSER + valueFrom: + secretKeyRef: + name: db-secret + key: username + - name: PGPASSWORD + valueFrom: + secretKeyRef: + name: db-secret + key: password + command: ['sh', '-c', '/bin/bash /tmp/check_dump.sh'] + containers: + - image: 100.71.71.71:5000/db-service:${params.imageTagDB_} + name: db-service + ports: + - containerPort: 5002 + env: + - name: POSTGRES_HOST + value: srmsystemdb + - name: POSTGRES_PORT + value: '5432' + - name: PGDATABASE + valueFrom: + secretKeyRef: + name: db-secret + key: dbname + - name: PGUSER + valueFrom: + secretKeyRef: + name: db-secret + key: username + - name: PGPASSWORD + valueFrom: + secretKeyRef: + name: db-secret + key: password +--- +kind: Service +apiVersion: v1 +metadata: + namespace: production + name: db-service +spec: + selector: + app: db-service + ports: + - protocol: TCP + port: 5002 + targetPort: 5002 +--- +""" + +String deploy_ui = """ +--- +kind: Service +apiVersion: v1 +metadata: + namespace: production + name: ui-service + labels: + app: ui +spec: + selector: + app: ui + ports: + - protocol: TCP + port: 5000 + targetPort: 5000 + +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + namespace: production + name: ui-deployment +spec: + selector: + matchLabels: + app: ui + replicas: 1 + template: + metadata: + labels: + app: ui + spec: + containers: + - name: ui + image: 100.71.71.71:5000/ui-service:${params.imageTagUI_} + ports: + - containerPort: 5000 + env: + - name: POST_SERVICE_URL + valueFrom: + configMapKeyRef: + name: services-address + key: POST_SERVICE_URL + - name: VIEW_SERVICE_URL + valueFrom: + configMapKeyRef: + name: services-address + key: VIEW_SERVICE_URL +""" + +String deploy_get = """ +--- +kind: Service +apiVersion: v1 +metadata: + namespace: production + name: get-service + labels: + app: get +spec: + selector: + app: get + ports: + - protocol: TCP + port: 5003 + targetPort: 5003 + +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + namespace: production + name: get-deployment +spec: + selector: + matchLabels: + app: get + replicas: 1 + template: + metadata: + labels: + app: get + spec: + containers: + - name: get + image: 100.71.71.71:5000/get-service:${params.imageTagGET_} + ports: + - containerPort: 5003 + env: + - name: URL_DB + valueFrom: + configMapKeyRef: + name: services-address + key: URL_DB +""" + +properties([ + parameters([ + stringParam( + defaultValue: '***', + description: '', + name: 'service') + ]) +]) + +podTemplate(label: label, containers: [ + containerTemplate(name: 'python-alpine', image: 'ghostgoose33/python-alp:v3', command: 'cat', ttyEnabled: true), + containerTemplate(name: 'kubectl', image: 'lachlanevenson/k8s-kubectl:v1.8.8', command: 'cat', ttyEnabled: true) +], +volumes: [ + hostPathVolume(mountPath: '/var/run/docker.sock', hostPath: '/var/run/docker.sock') +], serviceAccount: "jenkins") +{ + + +node(label) +{ + try{ + stage("Deploy to Kubernetes"){ + build(job: 'GitHub/Kubik-DB/master', parameters: [[$class: 'StringParameterValue', name:"service", value: "***"]], wait: true) + if(params.service == "db"){ + container ("kubectl"){ + sh """echo "$deploy_db" | kubectl apply -f -""" + + } + } + if(params.service == "get"){ + container ("kubectl"){ + sh """echo "$deploy_get" | kubectl apply -f -""" + + } + } + if(params.service == "ui"){ + container ("kubectl"){ + sh """echo "$deploy_ui" | kubectl apply -f -""" + + } + } + + if(params.service == "post"){ + container ("kubectl"){ + sh """echo "$deploy_post" | kubectl apply -f -""" + + } + } + } + + sleep 10 + + stage ("Prod Tests"){ + container('python-alpine'){ + //sh "python3 /e2e-test-prod.py" + } + } + + } + catch(err){ + currentBuild.result = 'Failure' + } +} +} diff --git a/Jenkinsfile_e2e_test b/Jenkinsfile_e2e_test new file mode 100644 index 0000000..c445c5c --- /dev/null +++ b/Jenkinsfile_e2e_test @@ -0,0 +1,325 @@ +def label = "mypod-${UUID.randomUUID().toString()}" +def dockerRegistry = "100.71.71.71:5000" +def Creds = "git_cred" + +String e2e_YAML = """--- +apiVersion: v1 +kind: Namespace +metadata: + name: testing +--- +apiVersion: v1 +kind: ConfigMap +metadata: + namespace: testing + name: services-address +data: + POST_SERVICE_URL: post-service.testing.svc + VIEW_SERVICE_URL: get-service.testing.svc + DB_URL: db-service.testing.svc + URL_DB: db-service.testing.svc +--- +apiVersion: v1 +kind: Secret +metadata: + name: db-secret + namespace: testing +data: + username: ZGJhZG1pbg== + password: UGFzc3dvcmQ= + dbname: c3Jtc3lzdGVt +type: Opaque +--- +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + namespace: testing + labels: + app: pvc-postgres + name: postgres-pvc +spec: + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 2Gi +--- +apiVersion: extensions/v1beta1 +kind: Deployment +metadata: + namespace: testing + name: postgres + labels: + service: postgresdb +spec: + template: + metadata: + labels: + app: postgres + spec: + initContainers: + - name: volume-mount-hack + image: busybox + command: ["sh", "-c", "chown -R 999.999 /var/lib/postgresql/"] + volumeMounts: + - name: postgres-pv-claim + mountPath: /var/lib/postgresql/data + subPath: postgres + containers: + - image: postgres:9.6.2 + name: postgresql + env: + - name: POSTGRES_DB + valueFrom: + secretKeyRef: + name: db-secret + key: dbname + - name: POSTGRES_USER + valueFrom: + secretKeyRef: + name: db-secret + key: username + - name: POSTGRES_PASSWORD + valueFrom: + secretKeyRef: + name: db-secret + key: password + ports: + - containerPort: 5432 + volumeMounts: + - name: postgres-pv-claim + mountPath: /var/lib/postgresql/data + subPath: postgres + volumes: + - name: postgres-pv-claim + persistentVolumeClaim: + claimName: postgres-pvc +--- +kind: Service +apiVersion: v1 +metadata: + namespace: testing + name: srmsystemdb +spec: + selector: + app: postgres + ports: + - protocol: TCP + port: 5432 + targetPort: 5432 +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + namespace: testing + name: db-service +spec: + selector: + matchLabels: + app: db-service + template: + metadata: + labels: + app: db-service + spec: + initContainers: + - image: 100.71.71.71:5000/init-container:${params.imageTagDB_} + name: init-container-postgres + env: + - name: PGDATABASE + valueFrom: + secretKeyRef: + name: db-secret + key: dbname + - name: PGUSER + valueFrom: + secretKeyRef: + name: db-secret + key: username + - name: PGPASSWORD + valueFrom: + secretKeyRef: + name: db-secret + key: password + command: ['sh', '-c', '/bin/bash /tmp/check_dump.sh'] + containers: + - image: 100.71.71.71:5000/db-service:${params.imageTagDB_} + name: db-service + ports: + - containerPort: 5002 + env: + - name: POSTGRES_HOST + value: srmsystemdb + - name: POSTGRES_PORT + value: '5432' + - name: PGDATABASE + valueFrom: + secretKeyRef: + name: db-secret + key: dbname + - name: PGUSER + valueFrom: + secretKeyRef: + name: db-secret + key: username + - name: PGPASSWORD + valueFrom: + secretKeyRef: + name: db-secret + key: password +--- +kind: Service +apiVersion: v1 +metadata: + namespace: testing + name: db-service +spec: + selector: + app: db-service + ports: + - protocol: TCP + port: 5002 + targetPort: 5002 +--- +kind: Service +apiVersion: v1 +metadata: + namespace: testing + name: ui-service + labels: + app: ui +spec: + selector: + app: ui + ports: + - protocol: TCP + port: 5000 + targetPort: 5000 +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + namespace: testing + name: ui-deployment +spec: + selector: + matchLabels: + app: ui + replicas: 1 + template: + metadata: + labels: + app: ui + spec: + containers: + - name: ui + image: 100.71.71.71:5000/ui-service:${params.imageTagUI_} + ports: + - containerPort: 5000 + env: + - name: VIEW_SERVICE_URL + valueFrom: + configMapKeyRef: + name: services-address + key: VIEW_SERVICE_URL +--- +kind: Service +apiVersion: v1 +metadata: + namespace: testing + name: get-service + labels: + app: get +spec: + selector: + app: get + ports: + - protocol: TCP + port: 5003 + targetPort: 5003 +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + namespace: testing + name: get-deployment +spec: + selector: + matchLabels: + app: get + replicas: 1 + template: + metadata: + labels: + app: get + spec: + containers: + - name: get + image: 100.71.71.71:5000/get-service:${params.imageTagGET_} + ports: + - containerPort: 5003 + env: + - name: URL_DB + valueFrom: + configMapKeyRef: + name: services-address + key: URL_DB +--- +""" + +properties([ + parameters([ + stringParam( + defaultValue: '***', + description: '', + name: 'service') + ]) +]) + +podTemplate(label: label, containers: [ + containerTemplate(name: 'python-alpine', image: 'ghostgoose33/python-alp:v3', command: 'cat', ttyEnabled: true), + containerTemplate(name: 'docker', image: 'ghostgoose33/docker-in:v1', command: 'cat', ttyEnabled: true), + containerTemplate(name: 'kubectl', image: 'lachlanevenson/k8s-kubectl:v1.8.8', command: 'cat', ttyEnabled: true) +], +volumes: [ + hostPathVolume(mountPath: '/var/run/docker.sock', hostPath: '/var/run/docker.sock') +], serviceAccount: "jenkins") +{ + + +node(label) +{ + try{ + + stage("E2E Test - Stage 1"){ + container('kubectl'){ + writeYaml file: 'temp.yaml', data: e2e_YAML + //sh 'echo "$e2e_YAML"' + echo "$e2e_YAML" + sh """echo "$e2e_YAML" | kubectl apply -f -""" + sh "kubectl get pods --namespace=testing" + } + } + sleep 20 + stage ("E2E Tests - Stage 2"){ + container('python-alpine'){ + sh 'echo "Here is e2e test"' + sh "python3 /e2e-test-test.py" + } + } + + stage ("Deploy"){ + + build(job: 'test_deploy', parameters: [[$class: 'StringParameterValue', name:"imageTagGET_", value: "${params.imageTagGET_}"], + [$class: 'StringParameterValue', name:"imageTagUI_", value: "${params.imageTagUI_}"], + [$class: 'StringParameterValue', name:"imageTagDB_", value: "${params.imageTagDB_}"], + [$class: 'StringParameterValue', name:"imageTagPOST_", value: "${params.imageTagPOST_}"], + [$class: 'StringParameterValue', name:"service", value: "${params.service}"]], wait: true) + } + + } + catch(err){ + currentBuild.result = 'Failure' + } +} +} diff --git a/Jenkinsfile_lst_new b/Jenkinsfile_lst_new new file mode 100644 index 0000000..b05edaa --- /dev/null +++ b/Jenkinsfile_lst_new @@ -0,0 +1,137 @@ +@NonCPS +def mapToList(depmap) { + def dlist = [] + for (def entry2 in depmap) { + dlist.add(new java.util.AbstractMap.SimpleImmutableEntry(entry2.key, entry2.value)) + } + dlist +} + +def label = "mypod-${UUID.randomUUID().toString()}" + + +podTemplate(label: label, containers: [ + containerTemplate(name: 'python-alpine', image: 'ghostgoose33/python-alp:v1', command: 'cat', ttyEnabled: true), + containerTemplate(name: 'docker', image: 'ghostgoose33/docker-in:v1', command: 'cat', ttyEnabled: true), + containerTemplate(name: 'kubectl', image: 'lachlanevenson/k8s-kubectl:v1.8.8', command: 'cat', ttyEnabled: true) +], +volumes: [ + hostPathVolume(mountPath: '/var/run/docker.sock', hostPath: '/var/run/docker.sock') +], serviceAccount: "jenkins") +{ + +def dockerRegistry = "100.71.71.71:5000" +def Creds = "git_cred" +def projName = "get-service" +def imageVersion = "v2" +def imageName = "100.71.71.71:5000/get-service:${imageVersion}" +def imageN = '100.71.71.71:5000/get-service:' +def buildResult +def paramss = ["GitHub/SRM-GET/test", "GitHub/SRM-UI/test", "GitHub/SRM-DB/test"] + +node(label) +{ + try{ + stage("Pre-Test"){ + dir('db'){ + git(branch: "test", url: 'https://github.com/Kv-045DevOps/SRM-DB.git', credentialsId: "${Creds}") + imageTagDB = sh (script: "git rev-parse --short HEAD", returnStdout: true) + pathTocodedb=pwd() + } + dir('ui'){ + git(branch: "test", url: 'https://github.com/Kv-045DevOps/SRM-UI.git', credentialsId: "${Creds}") + imageTagUI = sh (script: "git rev-parse --short HEAD", returnStdout: true) + pathTocodeui=pwd() + } + dir('post'){ + git(branch: "test", url: 'https://github.com/Kv-045DevOps/SRM-POST.git', credentialsId: "${Creds}") + imageTagPOST = sh (script: "git rev-parse --short HEAD", returnStdout: true) + pathTocodepost=pwd() + } + dir('ini'){ + git(branch: "master", url: 'https://github.com/Kv-045DevOps/Kubik-DB.git', credentialsId: "${Creds}") + imageTagINI = (sh (script: "git rev-parse --short HEAD", returnStdout: true)) + pathTocodeini=pwd() + } + dir('get'){ + git(branch: "test", url: 'https://github.com/Kv-045DevOps/SRM-GET.git', credentialsId: "${Creds}") + imageTagGET = (sh (script: "git rev-parse --short HEAD", returnStdout: true)) + pathTocodeget = pwd() + } + + } + stage('Build and push Docker images') { + def jobs = [:] + for(i = 0; i < paramss.size(); i += 1) { + def param = paramss[i] + jobs["Jobs_build_${i}"] = { + build job: param, parameters: [string(name: 'Name', value: param)], waitForFinish: true + } + } + parallel jobs + } + stage("E2E-Test-pre"){ + container('python-alpine'){ + sh "ls /home/jenkins/workspace/" + def map = [:] + map = [ + 'get':[tag: "${imageTagGET}", path: "${pathTocodeget}"], 'post':[tag: "${imageTagPOST}", path: "${pathTocodepost}"], + 'db':[tag: "${imageTagDB}", path: "${pathTocodedb}"], 'ui':[tag: "${imageTagUI}", path: "${pathTocodeui}"] + ] + map.each{ k, v -> sh "python3 ${v['path']}/sed_python.py ${pathTocodeget}/E2E.yaml ${dockerRegistry}/${k}-service ${v['tag']}" } + sh "python3 ${pathTocodedb}/sed_python.py ${pathTocodeget}/E2E.yaml ${dockerRegistry}/init-container ${imageTagDB}" + } + + } + stage("Docker images"){ + container("docker"){ + sh "docker images" + } + } + stage("E2E Test - Stage 1"){ + container('kubectl'){ + sh "kubectl apply -f ${pathTocodeget}/E2E.yaml" + sh "kubectl get pods --namespace=testing" + } + } + sleep 10 + stage ("E2E Tests - Stage 2"){ + container('python-alpine'){ + sh 'echo "Here is e2e test"' + sh "python3 ${pathTocodeget}/e2e-test-test.py" + } + } + stage("Deploy to Kubernetes"){ + container('python-alpine'){ + sh "python3 ${pathTocodeget}/sed_python.py ${pathTocodeget}/template.yaml ${dockerRegistry}/get-service ${imageTagGET}" + //sh "python3 ${pathTocodepost}/sed_python.py ${pathTocodeget}/template.yaml ${dockerRegistry}/post-service ${imageTagPOST}" + sh "python3 ${pathTocodedb}/sed_python.py ${pathTocodedb}/template.yaml ${dockerRegistry}/db-service ${imageTagDB}" + sh "python3 ${pathTocodeui}/sed_python.py ${pathTocodeui}/template.yaml ${dockerRegistry}/ui-service ${imageTagUI}" + sh "python3 ${pathTocodedb}/sed_python.py ${pathTocodedb}/template.yaml ${dockerRegistry}/init-container ${imageTagDB}" + } + container('kubectl'){ + def temp = [:] + temp = [ + 'ini':"${pathTocodeini}", 'db':"${pathTocodedb}", + 'get':"${pathTocodeget}", 'ui':"${pathTocodeui}" + //, 'post':"${pathTocodepost}" + ] + temp.each{ k, v -> sh "kubectl apply -f ${v}/template.yaml" } + //sh "kubectl apply -f ${pathTocodepost}/template.yml" + sh "kubectl get pods --namespace=production" + + } + } + stage ("Prod Tests - Stage 1"){ + container('python-alpine'){ + sh 'echo "Here is prod test"' + sh "python3 ${pathTocodeget}/e2e-test-prod.py" + } + } + } + catch(err){ + currentBuild.result = 'Failure' + } +} +} +sleep 10 diff --git a/Jenkinsfile_main b/Jenkinsfile_main new file mode 100644 index 0000000..f8205a3 --- /dev/null +++ b/Jenkinsfile_main @@ -0,0 +1,53 @@ +def buildResult +def paramss = ["GitHub/SRM-GET/PR-3", "GitHub/SRM-UI/test", "GitHub/SRM-DB/PR-2", "GitHub/SRM-POST/test"] +def dockerRegistry = "100.71.71.71:5000" +def Creds = "git_cred" +properties([ + parameters([ + stringParam( + defaultValue: 'v2.0', + description: 'Current version', + name: 'imageTagGET_'), + stringParam( + defaultValue: 'v2.0', + description: 'Current version', + name: 'imageTagUI_'), + stringParam( + defaultValue: 'v2.0', + description: 'Current version', + name: 'imageTagDB_'), + stringParam( + defaultValue: 'v2.0', + description: 'Current version', + name: 'imageTagPOST_'), + stringParam( + defaultValue: '*', + description: 'E2E Test', + name: 'e2e_YAML') + ]) +]) + +node { + stage('Build and push Docker images') { + git(branch: "test", url: 'https://github.com/Kv-045DevOps/SRM-DB.git', credentialsId: "${Creds}") + imageTagDB = sh (script: "git rev-parse --short HEAD", returnStdout: true) + git(branch: "test", url: 'https://github.com/Kv-045DevOps/SRM-UI.git', credentialsId: "${Creds}") + imageTagUI = sh (script: "git rev-parse --short HEAD", returnStdout: true) + git(branch: "test", url: 'https://github.com/Kv-045DevOps/SRM-POST.git', credentialsId: "${Creds}") + imageTagPOST = sh (script: "git rev-parse --short HEAD", returnStdout: true) + git(branch: "master", url: 'https://github.com/Kv-045DevOps/Kubik-DB.git', credentialsId: "${Creds}") + imageTagINI = (sh (script: "git rev-parse --short HEAD", returnStdout: true)) + git(branch: "test", url: 'https://github.com/Kv-045DevOps/SRM-GET.git', credentialsId: "${Creds}") + imageTagGET = (sh (script: "git rev-parse --short HEAD", returnStdout: true)) + def jobs = [:] + for(i = 0; i < paramss.size(); i += 1) { + def param = paramss[i] + jobs["Jobs_build_${i}"] = { + build job: param, parameters: [[$class: 'StringParameterValue', name: "imageTagGET_", value: "${imageTagGET}"], + [$class: 'StringParameterValue', name: "imageTagUI_", value: "${imageTagUI}"], + [$class: 'StringParameterValue', name: "imageTagDB_", value: "${imageTagDB}"]], wait: true + } + } + parallel jobs + } +} diff --git a/Jenkinsfile_v3.0_minor b/Jenkinsfile_v3.0_minor new file mode 100644 index 0000000..4acdb17 --- /dev/null +++ b/Jenkinsfile_v3.0_minor @@ -0,0 +1,26 @@ +def buildResult +def paramss = ["GitHub/SRM-GET/test", "GitHub/SRM-UI/test", "GitHub/SRM-DB/test"] +properties([ + parameters([ + stringParam( + defaultValue: 'v3.0', + description: '', + name: 'imageTag'), + stringParam( + defaultValue: '***', + description: '', + name: 'namespace') + ]) +]) + + stage('Build and push Docker images') { + def jobs = [:] + for(i = 0; i < paramss.size(); i += 1) { + def param = paramss[i] + jobs["Jobs_build_${i}"] = { + build job: param, parameters: [[$class: 'StringParameterValue', name: "imageTag", + value: "${params.imageTag}"]], wait: true + } + } + parallel jobs + } diff --git a/Jenkinsfiles_Helm/Blue-Green/Jenkinsfile_delete_pod b/Jenkinsfiles_Helm/Blue-Green/Jenkinsfile_delete_pod new file mode 100644 index 0000000..40f7ccf --- /dev/null +++ b/Jenkinsfiles_Helm/Blue-Green/Jenkinsfile_delete_pod @@ -0,0 +1,99 @@ + +def label = "mypod-${UUID.randomUUID().toString()}" +def dockerRegistry = "100.71.71.71:5000" +def Creds = "git_cred" + +properties([ + parameters([ + stringParam( + defaultValue: '***', + description: '', + name: 'service'), + choice(choices: ["db", "ui", "get", "post"], description: 'What Service?', name: "servicedel"), + choice(choices: ["v1", "v2"], description: 'What version?', name: "versiondel") + ]) +]) + +podTemplate(label: label, annotations: [podAnnotation(key: "sidecar.istio.io/inject", value: "false")], containers: [ + containerTemplate(name: 'python-alpine', image: 'ghostgoose33/python-alp:v3', command: 'cat', ttyEnabled: true), + containerTemplate(name: 'helm', image: 'ghostgoose33/kubectl_helm:v1', command: 'cat', ttyEnabled: true) +], +volumes: [ + hostPathVolume(mountPath: '/var/run/docker.sock', hostPath: '/var/run/docker.sock') +], serviceAccount: "jenkins") +{ + + +node(label) +{ + try{ + stage("Pre-Test"){ + dir('get'){ + git(branch: "test", url: 'https://github.com/Kv-045DevOps/SRM-GET.git', credentialsId: "${Creds}") + imageTagUI = (sh (script: "git rev-parse --short HEAD", returnStdout: true)) + tmp = "1" + pathTocodeget = pwd() + } + } + stage("Deploy to Kubernetes"){ + if(params.servicedel == "db"){ + container ("helm"){ + if (params.versiondel == "v2"){ + sh "helm delete db-service-v2 --purge" + sh "helm upgrade --install --namespace production --force istio-rules-db-v1 ${pathTocodeget}/List-Helm-Charts/istio-rules --set weight.v1=100, --set weight.v2=0, --set app.name=db-service, --set port=5002, --set vers=v1" + } + if (params.versiondel == "v1"){ + sh "helm delete db-service-v1 --purge" + } + } + } + if(params.servicedel == "get"){ + container ("helm"){ + if (params.versiondel == "v2"){ + sh "helm delete get-service-v2 --purge" + sh "helm upgrade --install --namespace production --force istio-rules-get-v1 ${pathTocodeget}/List-Helm-Charts/istio-rules --set weight.v1=100, --set weight.v2=0, --set app.name=get-service, --set port=5003, --set vers=v1" + } + if (params.versiondel == "v1"){ + sh "helm delete get-service-v1 --purge" + } + } + } + if(params.servicedel == "ui"){ + container ("helm"){ + if (params.versiondel == "v2"){ + sh "helm delete ui-service-v2 --purge" + sh "helm upgrade --install --namespace production --force istio-rules-ui-v1 ${pathTocodeget}/List-Helm-Charts/istio-rules --set weight.v1=100, --set weight.v2=0, --set app.name=ui, --set port=5000, --set vers=v1" + } + if (params.versiondel == "v1"){ + sh "helm delete ui-service-v1 --purge" + } + } + } + if(params.servicedel == "post"){ + container ("helm"){ + if (params.versiondel == "v2"){ + sh "helm delete post-service-v2 --purge" + sh "helm upgrade --install --namespace production --force istio-rules-post-v1 ${pathTocodeget}/List-Helm-Charts/istio-rules --set weight.v1=100, --set weight.v2=0, --set app.name=post-service, --set port=5001, --set vers=v1" + } + if (params.versiondel == "v1"){ + sh "helm delete post-service-v1 --purge" + } + } + } + + } + + sleep 10 + + stage ("Prod Tests"){ + container('python-alpine'){ + //sh "python3 /e2e-test-prod.py" + } + } + + } + catch(err){ + currentBuild.result = 'Failure' + } +} +} diff --git a/Jenkinsfiles_Helm/Blue-Green/Jenkinsfile_deploy_bg b/Jenkinsfiles_Helm/Blue-Green/Jenkinsfile_deploy_bg new file mode 100644 index 0000000..ef0120e --- /dev/null +++ b/Jenkinsfiles_Helm/Blue-Green/Jenkinsfile_deploy_bg @@ -0,0 +1,99 @@ + +def label = "mypod-${UUID.randomUUID().toString()}" +def dockerRegistry = "100.71.71.71:5000" +def Creds = "git_cred" + +properties([ + parameters([ + stringParam( + defaultValue: '***', + description: '', + name: 'service'), + choice(choices: ["db", "ui", "get", "post"], description: 'What Service?', name: "servicedel"), + choice(choices: ["v1", "v2"], description: 'What version?', name: "versiondel") + ]) +]) + +podTemplate(label: label, annotations: [podAnnotation(key: "sidecar.istio.io/inject", value: "false")], containers: [ + containerTemplate(name: 'python-alpine', image: 'ghostgoose33/python-alp:v3', command: 'cat', ttyEnabled: true), + containerTemplate(name: 'helm', image: 'ghostgoose33/kubectl_helm:v1', command: 'cat', ttyEnabled: true) +], +volumes: [ + hostPathVolume(mountPath: '/var/run/docker.sock', hostPath: '/var/run/docker.sock') +], serviceAccount: "jenkins") +{ + + +node(label) +{ + try{ + stage("Pre-Test"){ + dir('get'){ + git(branch: "test", url: 'https://github.com/Kv-045DevOps/SRM-GET.git', credentialsId: "${Creds}") + imageTagUI = (sh (script: "git rev-parse --short HEAD", returnStdout: true)) + tmp = "1" + pathTocodeget = pwd() + } + } + stage("Deploy to Kubernetes"){ + if(params.servicedel == "db"){ + container ("helm"){ + if (params.versiondel == "v2"){ + sh "helm delete db-service-v2 --purge" + sh "helm upgrade --install --namespace production --force istio-rules-db ${pathTocodeget}/List-Helm-Charts/istio-rules --set weight.v1=100 --set weight.v2=0 --set app=db-service" + } + if (params.versiondel == "v1"){ + sh "helm delete db-service-v1 --purge" + } + } + } + if(params.servicedel == "get"){ + container ("helm"){ + if (params.versiondel == "v2"){ + sh "helm delete get-service-v2 --purge" + sh "helm upgrade --install --namespace production --force istio-rules-get ${pathTocodeget}/List-Helm-Charts/istio-rules --set weight.v1=100 --set weight.v2=0 --set app=get" + } + if (params.versiondel == "v1"){ + sh "helm delete get-service-v1 --purge" + } + } + } + if(params.servicedel == "ui"){ + container ("helm"){ + if (params.versiondel == "v2"){ + sh "helm delete ui-service-v2 --purge" + sh "helm upgrade --install --namespace production --force istio-rules-ui ${pathTocodeget}/List-Helm-Charts/istio-rules --set weight.v1=100 --set weight.v2=0 --set app=ui" + } + if (params.versiondel == "v1"){ + sh "helm delete ui-service-v1 --purge" + } + } + } + if(params.servicedel == "post"){ + container ("helm"){ + if (params.versiondel == "v2"){ + sh "helm delete post-service-v2 --purge" + sh "helm upgrade --install --namespace production --force istio-rules-post ${pathTocodeget}/List-Helm-Charts/istio-rules --set weight.v1=100 --set weight.v2=0 --set app=post" + } + if (params.versiondel == "v1"){ + sh "helm delete post-service-v1 --purge" + } + } + } + + } + + sleep 10 + + stage ("Prod Tests"){ + container('python-alpine'){ + //sh "python3 /e2e-test-prod.py" + } + } + + } + catch(err){ + currentBuild.result = 'Failure' + } +} +} diff --git a/Jenkinsfiles_Helm/Jenkinsfile_deploy b/Jenkinsfiles_Helm/Jenkinsfile_deploy new file mode 100644 index 0000000..d58ced1 --- /dev/null +++ b/Jenkinsfiles_Helm/Jenkinsfile_deploy @@ -0,0 +1,68 @@ + +def label = "mypod-${UUID.randomUUID().toString()}" + +properties([ + parameters([ + stringParam( + defaultValue: '***', + description: '', + name: 'service') + ]) +]) + +podTemplate(label: label, containers: [ + containerTemplate(name: 'python-alpine', image: 'ghostgoose33/python-alp:v3', command: 'cat', ttyEnabled: true), + containerTemplate(name: 'helm', image: 'ghostgoose33/kubectl_helm:v1', command: 'cat', ttyEnabled: true) +], +volumes: [ + hostPathVolume(mountPath: '/var/run/docker.sock', hostPath: '/var/run/docker.sock') +], serviceAccount: "jenkins") +{ + + +node(label) +{ + try{ + + stage("Deploy to Kubernetes"){ + if(params.service == "db"){ + container ("helm"){ + sh "helm upgrade --install --namespace production --force db-service chartmuseum/db-service --set=deploy.version=v1,image.tag=${params.imageTagDB_}" + + } + } + if(params.service == "get"){ + container ("helm"){ + sh "helm upgrade --install --namespace production --force get-service chartmuseum/get-service --set=deploy.version=v1,image.tag=${params.imageTagGET_}" + + } + } + if(params.service == "ui"){ + container ("helm"){ + sh "helm upgrade --install --namespace production --force ui-service chartmuseum/ui-service --set=deploy.version=v1,image.tag=${params.imageTagUI_}" + + } + } + + if(params.service == "post"){ + container ("helm"){ + sh "helm upgrade --install --namespace production --force post-service chartmuseum/post-service --set=deploy.version=v1,image.tag=${params.imageTagPOST_}" + + } + } + } + + sleep 10 + + stage ("Prod Tests"){ + container('python-alpine'){ + //sh "python3 /e2e-test-prod.py" + } + } + + } + catch(err){ + currentBuild.result = 'Failure' + } +} +} diff --git a/Jenkinsfiles_Helm/Jenkinsfile_e2e_test b/Jenkinsfiles_Helm/Jenkinsfile_e2e_test new file mode 100644 index 0000000..e0c5141 --- /dev/null +++ b/Jenkinsfiles_Helm/Jenkinsfile_e2e_test @@ -0,0 +1,59 @@ +def label = "mypod-${UUID.randomUUID().toString()}" + +String get = "${params.imageTagGET_}" +String ui = "${params.imageTagUI_}" +String db = "${params.imageTagDB_}" + +properties([ + parameters([ + stringParam( + defaultValue: '***', + description: '', + name: 'service') + ]) +]) + +podTemplate(label: label, containers: [ + containerTemplate(name: 'python-alpine', image: 'ghostgoose33/python-alp:v3', command: 'cat', ttyEnabled: true), + containerTemplate(name: 'docker', image: 'ghostgoose33/docker-in:v1', command: 'cat', ttyEnabled: true), + containerTemplate(name: 'helm', image: 'ghostgoose33/kubectl_helm:v1', command: 'cat', ttyEnabled: true) +], +volumes: [ + hostPathVolume(mountPath: '/var/run/docker.sock', hostPath: '/var/run/docker.sock') +], serviceAccount: "jenkins") +{ + + +node(label) +{ + try{ + + stage("E2E Test - Stage 1"){ + container('helm'){ + sh """helm upgrade --install --force e2e-testing chartmuseum/e2e-testing --set=deploy.version=v1,image.tag.ui=${ui},image.tag.get=${get},image.tag.db=${db} --namespace testing""" + sh "kubectl get pods --namespace=testing" + } + } + sleep 20 + stage ("E2E Tests - Stage 2"){ + container('python-alpine'){ + sh 'echo "Here is e2e test"' + sh "python3 /e2e-test-test.py" + } + } + + stage ("Deploy"){ + + build(job: 'test_deploy', parameters: [[$class: 'StringParameterValue', name:"imageTagGET_", value: "${params.imageTagGET_}"], + [$class: 'StringParameterValue', name:"imageTagUI_", value: "${params.imageTagUI_}"], + [$class: 'StringParameterValue', name:"imageTagDB_", value: "${params.imageTagDB_}"], + [$class: 'StringParameterValue', name:"imageTagPOST_", value: "${params.imageTagPOST_}"], + [$class: 'StringParameterValue', name:"service", value: "${params.service}"]], wait: true) + } + + } + catch(err){ + currentBuild.result = 'Failure' + } +} +} diff --git a/Jenkinsfiles_Helm/Jenkinsfile_e2e_test_v2 b/Jenkinsfiles_Helm/Jenkinsfile_e2e_test_v2 new file mode 100644 index 0000000..18ede2d --- /dev/null +++ b/Jenkinsfiles_Helm/Jenkinsfile_e2e_test_v2 @@ -0,0 +1,60 @@ +def label = "mypod-${UUID.randomUUID().toString()}" + +String get = "${params.imageTagGET_}" +String ui = "${params.imageTagUI_}" +String db = "${params.imageTagDB_}" + +properties([ + parameters([ + stringParam( + defaultValue: '***', + description: '', + name: 'service') + ]) +]) + +podTemplate(label: label, containers: [ + containerTemplate(name: 'python-alpine', image: 'ghostgoose33/python-alp:v3', command: 'cat', ttyEnabled: true), + containerTemplate(name: 'docker', image: 'ghostgoose33/docker-in:v1', command: 'cat', ttyEnabled: true), + containerTemplate(name: 'helm', image: 'ghostgoose33/kubectl_helm:v1', command: 'cat', ttyEnabled: true) +], +volumes: [ + hostPathVolume(mountPath: '/var/run/docker.sock', hostPath: '/var/run/docker.sock') +], serviceAccount: "jenkins") +{ + + +node(label) +{ + try{ + stage("E2E Test - Stage 1"){ + container('helm'){ + sh "helm upgrade --install --namespace testing --force e2e-testing-db chartmuseum/e2e-testing-db --set=deploy.version=v1,image.tag.db=${db}" + sh "helm upgrade --install --namespace testing --force e2e-testing-get chartmuseum/e2e-testing-get --set=deploy.version=v1,image.tag.get=${get}" + sh "helm upgrade --install --namespace testing --force e2e-testing-ui chartmuseum/e2e-testing-ui --set=deploy.version=v1,image.tag.ui=${ui}" + sh "kubectl get pods --namespace=testing" + } + } + sleep 40 + stage ("E2E Tests - Stage 2"){ + container('python-alpine'){ + sh 'echo "Here is e2e test"' + sh "python3 /e2e-test-test.py" + } + } + + stage ("Deploy"){ + + build(job: 'test_deploy', parameters: [[$class: 'StringParameterValue', name:"imageTagGET_", value: "${params.imageTagGET_}"], + [$class: 'StringParameterValue', name:"imageTagUI_", value: "${params.imageTagUI_}"], + [$class: 'StringParameterValue', name:"imageTagDB_", value: "${params.imageTagDB_}"], + [$class: 'StringParameterValue', name:"imageTagPOST_", value: "${params.imageTagPOST_}"], + [$class: 'StringParameterValue', name:"service", value: "${params.service}"]], wait: true) + } + + } + catch(err){ + currentBuild.result = 'Failure' + } +} +} diff --git a/Jenkinsfiles_Helm/Jenkinsfiles_deploy_helm_loc b/Jenkinsfiles_Helm/Jenkinsfiles_deploy_helm_loc new file mode 100644 index 0000000..1119c5e --- /dev/null +++ b/Jenkinsfiles_Helm/Jenkinsfiles_deploy_helm_loc @@ -0,0 +1,77 @@ + +def label = "mypod-${UUID.randomUUID().toString()}" +def dockerRegistry = "100.71.71.71:5000" +def Creds = "git_cred" + +properties([ + parameters([ + stringParam( + defaultValue: '***', + description: '', + name: 'service') + ]) +]) + +podTemplate(label: label, annotations: [podAnnotation(key: "sidecar.istio.io/inject", value: "false")], containers: [ + containerTemplate(name: 'python-alpine', image: 'ghostgoose33/python-alp:v3', command: 'cat', ttyEnabled: true), + containerTemplate(name: 'helm', image: 'ghostgoose33/kubectl_helm:v1', command: 'cat', ttyEnabled: true) +], +volumes: [ + hostPathVolume(mountPath: '/var/run/docker.sock', hostPath: '/var/run/docker.sock') +], serviceAccount: "jenkins") +{ + + +node(label) +{ + try{ + stage("Pre-Test"){ + dir('get'){ + git(branch: "test", url: 'https://github.com/Kv-045DevOps/SRM-GET.git', credentialsId: "${Creds}") + imageTagUI = (sh (script: "git rev-parse --short HEAD", returnStdout: true)) + tmp = "1" + pathTocodeget = pwd() + } + } + stage("Deploy to Kubernetes"){ + if(params.service == "db"){ + container ("helm"){ + sh "helm upgrade --install --namespace production --force db-service ${pathTocodeget}/List-Helm-Charts/db-service --set=deploy.version=v1,image.tag=${params.imageTagDB_}" + + } + } + if(params.service == "get"){ + container ("helm"){ + sh "helm upgrade --install --namespace production --force get-service ${pathTocodeget}/List-Helm-Charts/get-service --set=deploy.version=v1,image.tag=${params.imageTagGET_}" + + } + } + if(params.service == "ui"){ + container ("helm"){ + sh "helm upgrade --install --namespace production --force ui-service ${pathTocodeget}/List-Helm-Charts/ui-service --set=deploy.version=v1,image.tag=${params.imageTagUI_}" + + } + } + + if(params.service == "post"){ + container ("helm"){ + sh "helm upgrade --install --namespace production --force post-service ${pathTocodeget}/List-Helm-Charts/post-service --set=deploy.version=v1,image.tag=${post}" + + } + } + } + + sleep 10 + + stage ("Prod Tests"){ + container('python-alpine'){ + //sh "python3 /e2e-test-prod.py" + } + } + + } + catch(err){ + currentBuild.result = 'Failure' + } +} +} diff --git a/Jenkinsfiles_Helm/Jenkinsfiles_e2e_helm_loc b/Jenkinsfiles_Helm/Jenkinsfiles_e2e_helm_loc new file mode 100644 index 0000000..1ba90ce --- /dev/null +++ b/Jenkinsfiles_Helm/Jenkinsfiles_e2e_helm_loc @@ -0,0 +1,71 @@ +def label = "mypod-${UUID.randomUUID().toString()}" +def dockerRegistry = "100.71.71.71:5000" +def Creds = "git_cred" + +String e2e_YAML = """ """ +String get = "${params.imageTagGET_}" +String ui = "${params.imageTagUI_}" +String db = "${params.imageTagDB_}" + +properties([ + parameters([ + stringParam( + defaultValue: '***', + description: '', + name: 'service') + ]) +]) + +podTemplate(label: label, annotations: [podAnnotation(key: "sidecar.istio.io/inject", value: "false")], containers: [ + containerTemplate(name: 'python-alpine', image: 'ghostgoose33/python-alp:v3', command: 'cat', ttyEnabled: true), + containerTemplate(name: 'docker', image: 'ghostgoose33/docker-in:v1', command: 'cat', ttyEnabled: true), + containerTemplate(name: 'helm', image: 'ghostgoose33/kubectl_helm:v1', command: 'cat', ttyEnabled: true) +], +volumes: [ + hostPathVolume(mountPath: '/var/run/docker.sock', hostPath: '/var/run/docker.sock') +], serviceAccount: "jenkins") +{ + + +node(label) +{ + try{ + stage("Pre-Test"){ + dir('get'){ + git(branch: "test", url: 'https://github.com/Kv-045DevOps/SRM-GET.git', credentialsId: "${Creds}") + imageTagUI = (sh (script: "git rev-parse --short HEAD", returnStdout: true)) + tmp = "1" + pathTocodeget = pwd() + } + } + stage("E2E Test - Stage 1"){ + container('helm'){ + sh "helm upgrade --install --namespace testing --force e2e-testing-db ${pathTocodeget}/List-Helm-Charts/e2e-testing-db --set=deploy.version=v1,image.tag.db=${db}" + sh "helm upgrade --install --namespace testing --force e2e-testing-get ${pathTocodeget}/List-Helm-Charts/e2e-testing-get --set=deploy.version=v1,image.tag.get=${get}" + sh "helm upgrade --install --namespace testing --force e2e-testing-ui ${pathTocodeget}/List-Helm-Charts/e2e-testing-ui --set=deploy.version=v1,image.tag.ui=${ui}" + sh "kubectl get pods --namespace=testing" + } + } + sleep 40 + stage ("E2E Tests - Stage 2"){ + container('python-alpine'){ + sh 'echo "Here is e2e test"' + sh "python3 /e2e-test-test.py" + } + } + + stage ("Deploy"){ + + build(job: 'test_deploy', parameters: [[$class: 'StringParameterValue', name:"imageTagGET_", value: "${params.imageTagGET_}"], + [$class: 'StringParameterValue', name:"imageTagUI_", value: "${params.imageTagUI_}"], + [$class: 'StringParameterValue', name:"imageTagDB_", value: "${params.imageTagDB_}"], + [$class: 'StringParameterValue', name:"imageTagPOST_", value: "${params.imageTagPOST_}"], + [$class: 'StringParameterValue', name:"service", value: "${params.service}"]], wait: true) + } + + } + catch(err){ + currentBuild.result = 'Failure' + } +} +} diff --git a/Kuben (1).yml b/Kuben (1).yml new file mode 100644 index 0000000..604e45c --- /dev/null +++ b/Kuben (1).yml @@ -0,0 +1,290 @@ +apiVersion: v1 +kind: Namespace +metadata: + name: testing + +--- +apiVersion: v1 +kind: ConfigMap +metadata: + namespace: testing + name: services-address +data: + POST_SERVICE_URL: post-service.production.svc + VIEW_SERVICE_URL: get-service.production.svc + DB_URL: db-service.production.svc + URL_DB: db-service.production.svc + +--- + +#Test secret +apiVersion: v1 +kind: Secret +metadata: + name: db-secret + namespace: testing +data: + username: ZGJhZG1pbg== + password: UGFzc3dvcmQ= + dbname: c3Jtc3lzdGVt +type: Opaque + +# --- +# kind: PersistentVolume +# apiVersion: v1 +# metadata: +# name: postgres-pv +# labels: +# type: local +# spec: +# storageClassName: manual +# capacity: +# storage: 100M +# accessModes: +# - ReadWriteOnce +# hostPath: +# path: "/mnt/data" + +# --- +# kind: StorageClass +# apiVersion: storage.k8s.io/v1 +# metadata: +# name: slow +# provisioner: kubernetes.io/aws-ebs +# parameters: +# type: gp2 +# zone: sa-east-1a +# fsType: ext4 +# reclaimPolicy: Retain + +--- +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + namespace: testing + labels: + app: pvc-postgres + name: postgres-pvc +spec: + #storageClassName: slow + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 2Gi + +# --- +# apiVersion: v1 +# kind: PersistentVolumeClaim +# metadata: +# labels: +# service: postgresdb +# namespace: production +# name: postgres-pvc +# spec: +# accessModes: +# - ReadWriteOnce +# resources: +# requests: +# storage: 2Gi + +--- +apiVersion: extensions/v1beta1 +kind: Deployment +metadata: + namespace: testing + name: postgres + labels: + service: postgresdb +spec: + template: + metadata: + labels: + app: postgres + spec: + initContainers: + - name: volume-mount-hack + image: busybox + command: ["sh", "-c", "chown -R 999:999 /var/lib/postgresql/"] + volumeMounts: + - name: postgres-pv-claim + mountPath: /var/lib/postgresql/data + subPath: postgres + containers: + - image: postgres:9.6.2 + name: postgresql + env: + - name: POSTGRES_DB + valueFrom: + secretKeyRef: + name: db-secret + key: dbname + - name: POSTGRES_USER + valueFrom: + secretKeyRef: + name: db-secret + key: username + - name: POSTGRES_PASSWORD + valueFrom: + secretKeyRef: + name: db-secret + key: password + ports: + - containerPort: 5432 + volumeMounts: + - name: postgres-pv-claim + mountPath: /var/lib/postgresql/data + subPath: postgres + volumes: + - name: postgres-pv-claim + persistentVolumeClaim: + claimName: postgres-pvc + +--- +kind: Service +apiVersion: v1 +metadata: + namespace: testing + name: srmsystemdb +spec: + selector: + app: postgres + ports: + - protocol: TCP + port: 5432 + targetPort: 5432 +--- + +kind: Service +apiVersion: v1 +metadata: + name: post-service + namespace: testing + labels: + app: post +spec: + selector: + app: post + ports: + - protocol: TCP + port: 80 + targetPort: 5001 + +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: post-deployment + namespace: testing +spec: + selector: + matchLabels: + app: post + replicas: 1 + template: + metadata: + labels: + app: post + spec: + containers: + - name: post + image: 100:71:71:71:5000/post-service:2.1 + ports: + - containerPort: 5001 + env: + - name: DB_URL + valueFrom: + configMapKeyRef: + name: services-address + key: DB_URL +--- +kind: Service +apiVersion: v1 +metadata: + name: get-service + namespace: testing + labels: + app: get +spec: + selector: + app: get + ports: + - protocol: TCP + port: 80 + targetPort: 5003 + +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: get-deployment + namespace: testing +spec: + selector: + matchLabels: + app: get + replicas: 1 + template: + metadata: + labels: + app: get + spec: + containers: + - name: get + image: 100:71:71:71:5000/get-python:v2 + ports: + - containerPort: 5003 + env: + - name: URL_DB + valueFrom: + configMapKeyRef: + name: services-address + key: URL_DB +--- +kind: Service +apiVersion: v1 +metadata: + name: ui-service + namespace: testing + labels: + app: ui +spec: + selector: + app: ui + ports: + - protocol: TCP + port: 80 + targetPort: 5000 + +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: ui-deployment + namespace: testing +spec: + selector: + matchLabels: + app: ui + replicas: 1 + template: + metadata: + labels: + app: ui + spec: + containers: + - name: ui + image: 100:71:71:71:5000/ui-service:latest + ports: + - containerPort: 5000 + env: + - name: POST_SERVICE_URL + valueFrom: + configMapKeyRef: + name: services-address + key: POST_SERVICE_URL + - name: VIEW_SERVICE_URL + valueFrom: + configMapKeyRef: + name: services-address + key: VIEW_SERVICE_URL diff --git a/List-Helm-Charts/db-service-bg/.helmignore b/List-Helm-Charts/db-service-bg/.helmignore new file mode 100644 index 0000000..50af031 --- /dev/null +++ b/List-Helm-Charts/db-service-bg/.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/List-Helm-Charts/db-service-bg/Chart.yaml b/List-Helm-Charts/db-service-bg/Chart.yaml new file mode 100644 index 0000000..008107a --- /dev/null +++ b/List-Helm-Charts/db-service-bg/Chart.yaml @@ -0,0 +1,5 @@ +apiVersion: v1 +appVersion: "1.0" +description: A Helm chart for Kubernetes +name: db-service-bg +version: 0.1.0 diff --git a/List-Helm-Charts/db-service-bg/templates/template.yaml b/List-Helm-Charts/db-service-bg/templates/template.yaml new file mode 100644 index 0000000..696c27a --- /dev/null +++ b/List-Helm-Charts/db-service-bg/templates/template.yaml @@ -0,0 +1,72 @@ +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + namespace: production + name: db-service-{{ .Values.deploy.version }} +spec: + selector: + matchLabels: + app: db-service + template: + metadata: + labels: + app: db-service + version: {{ .Values.deploy.version }} + spec: + initContainers: + - image: 100.71.71.71:5000/init-container:{{ .Values.image.tag }} + name: init-container-postgres + env: + - name: PGHOST + valueFrom: + secretKeyRef: + name: db-secret + key: dbhost + - name: PGDATABASE + valueFrom: + secretKeyRef: + name: db-secret + key: dbname + - name: PGUSER + valueFrom: + secretKeyRef: + name: db-secret + key: username + - name: PGPASSWORD + valueFrom: + secretKeyRef: + name: db-secret + key: password + - name: PGPORT + value: "5432" + command: ['sh', '-c', '/bin/bash /tmp/check_dump.sh'] + containers: + - image: 100.71.71.71:5000/db-service:{{ .Values.image.tag }} + name: db-service + ports: + - containerPort: 5002 + env: + - name: POSTGRES_HOST + valueFrom: + secretKeyRef: + name: db-secret + key: dbhost + - name: POSTGRES_PORT + value: "5432" + - name: PGDATABASE + valueFrom: + secretKeyRef: + name: db-secret + key: dbname + - name: PGUSER + valueFrom: + secretKeyRef: + name: db-secret + key: username + - name: PGPASSWORD + valueFrom: + secretKeyRef: + name: db-secret + key: password +--- diff --git a/List-Helm-Charts/db-service-bg/values.yaml b/List-Helm-Charts/db-service-bg/values.yaml new file mode 100644 index 0000000..1f09568 --- /dev/null +++ b/List-Helm-Charts/db-service-bg/values.yaml @@ -0,0 +1,33 @@ +# Default values for UI-SERVICE. +# This is a YAML-formatted file. +# Declare variables to be passed into your templates. + +replicaCount: 1 + +image: + repository: 100.71.71.71:5000 + tag: "" +conf: + ver: "" +app: + name: get + version: "" + +service: + type: ClusterIP + port: 5000 + servicename: get-service + +namespace: production + +deploy: + version: "" + +resources: {} + # limits: + # cpu: 100m + # memory: 128Mi + # requests: + # cpu: 100m + # memory: 128Mi + diff --git a/List-Helm-Charts/db-service/.helmignore b/List-Helm-Charts/db-service/.helmignore new file mode 100644 index 0000000..50af031 --- /dev/null +++ b/List-Helm-Charts/db-service/.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/List-Helm-Charts/db-service/Chart.yaml b/List-Helm-Charts/db-service/Chart.yaml new file mode 100644 index 0000000..847f529 --- /dev/null +++ b/List-Helm-Charts/db-service/Chart.yaml @@ -0,0 +1,5 @@ +apiVersion: v1 +appVersion: "1.0" +description: A Helm chart for Kubernetes +name: db-service +version: 0.1.0 diff --git a/List-Helm-Charts/db-service/templates/template.yaml b/List-Helm-Charts/db-service/templates/template.yaml new file mode 100644 index 0000000..eeb2970 --- /dev/null +++ b/List-Helm-Charts/db-service/templates/template.yaml @@ -0,0 +1,73 @@ +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + namespace: production + name: db-service-{{ .Values.deploy.version }} +spec: + selector: + matchLabels: + app: db-service + template: + metadata: + labels: + app: db-service + version: {{ .Values.deploy.version }} + + spec: + initContainers: + - image: 100.71.71.71:5000/init-container:{{ .Values.image.tag }} + name: init-container-postgres + env: + - name: PGHOST + valueFrom: + secretKeyRef: + name: db-secret + key: dbhost + - name: PGDATABASE + valueFrom: + secretKeyRef: + name: db-secret + key: dbname + - name: PGUSER + valueFrom: + secretKeyRef: + name: db-secret + key: username + - name: PGPASSWORD + valueFrom: + secretKeyRef: + name: db-secret + key: password + - name: PGPORT + value: "5432" + command: ['sh', '-c', '/bin/bash /tmp/check_dump.sh'] + containers: + - image: 100.71.71.71:5000/db-service:{{ .Values.image.tag }} + name: db-service + ports: + - containerPort: 5002 + env: + - name: POSTGRES_HOST + valueFrom: + secretKeyRef: + name: db-secret + key: dbhost + - name: POSTGRES_PORT + value: "5432" + - name: PGDATABASE + valueFrom: + secretKeyRef: + name: db-secret + key: dbname + - name: PGUSER + valueFrom: + secretKeyRef: + name: db-secret + key: username + - name: PGPASSWORD + valueFrom: + secretKeyRef: + name: db-secret + key: password +--- diff --git a/List-Helm-Charts/db-service/values.yaml b/List-Helm-Charts/db-service/values.yaml new file mode 100644 index 0000000..3fd9b23 --- /dev/null +++ b/List-Helm-Charts/db-service/values.yaml @@ -0,0 +1,31 @@ +# Default values for UI-SERVICE. +# This is a YAML-formatted file. +# Declare variables to be passed into your templates. + +replicaCount: 1 + +image: + repository: 100.71.71.71:5000 + tag: "" + +app: + name: db + +service: + type: ClusterIP + port: 5000 + servicename: db-service + +namespace: production + +deploy: + version: "" + +resources: {} + # limits: + # cpu: 100m + # memory: 128Mi + # requests: + # cpu: 100m + # memory: 128Mi + diff --git a/List-Helm-Charts/e2e-testing-db/.helmignore b/List-Helm-Charts/e2e-testing-db/.helmignore new file mode 100644 index 0000000..50af031 --- /dev/null +++ b/List-Helm-Charts/e2e-testing-db/.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/List-Helm-Charts/e2e-testing-db/Chart.yaml b/List-Helm-Charts/e2e-testing-db/Chart.yaml new file mode 100644 index 0000000..05690dc --- /dev/null +++ b/List-Helm-Charts/e2e-testing-db/Chart.yaml @@ -0,0 +1,5 @@ +apiVersion: v1 +appVersion: "1.0" +description: A Helm chart for Kubernetes +name: e2e-testing-db +version: 0.1.0 diff --git a/List-Helm-Charts/e2e-testing-db/templates/template.yaml b/List-Helm-Charts/e2e-testing-db/templates/template.yaml new file mode 100644 index 0000000..3e2b7d5 --- /dev/null +++ b/List-Helm-Charts/e2e-testing-db/templates/template.yaml @@ -0,0 +1,178 @@ +--- +#apiVersion: v1 +#kind: ConfigMap +#metadata: +# namespace: {{ .Values.namespace }} +# name: services-address +#data: +# POST_SERVICE_URL: post-service.testing.svc +# VIEW_SERVICE_URL: get-service.testing.svc +# DB_URL: db-service.testing.svc +# URL_DB: db-service.testing.svc +#--- +apiVersion: v1 +kind: Secret +metadata: + name: db-secret + namespace: {{ .Values.namespace }} +data: + username: ZGJhZG1pbg== + password: UGFzc3dvcmQ= + dbname: c3Jtc3lzdGVt +type: Opaque +--- +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + namespace: {{ .Values.namespace }} + labels: + app: pvc-postgres + name: postgres-pvc +spec: + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 2Gi +--- +apiVersion: extensions/v1beta1 +kind: Deployment +metadata: + namespace: {{ .Values.namespace }} + name: postgres + labels: + service: postgresdb +spec: + template: + metadata: + labels: + app: postgres + spec: + initContainers: + - name: volume-mount-hack + image: busybox + command: ["sh", "-c", "chown -R 999.999 /var/lib/postgresql/"] + volumeMounts: + - name: postgres-pv-claim + mountPath: /var/lib/postgresql/data + subPath: postgres + containers: + - image: postgres:9.6.2 + name: postgresql + env: + - name: POSTGRES_DB + valueFrom: + secretKeyRef: + name: db-secret + key: dbname + - name: POSTGRES_USER + valueFrom: + secretKeyRef: + name: db-secret + key: username + - name: POSTGRES_PASSWORD + valueFrom: + secretKeyRef: + name: db-secret + key: password + ports: + - containerPort: 5432 + volumeMounts: + - name: postgres-pv-claim + mountPath: /var/lib/postgresql/data + subPath: postgres + volumes: + - name: postgres-pv-claim + persistentVolumeClaim: + claimName: postgres-pvc +--- +kind: Service +apiVersion: v1 +metadata: + namespace: {{ .Values.namespace }} + name: srmsystemdb +spec: + selector: + app: postgres + ports: + - protocol: TCP + port: 5432 + targetPort: 5432 +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + namespace: {{ .Values.namespace }} + name: db-service +spec: + selector: + matchLabels: + app: db-service + template: + metadata: + labels: + app: db-service + spec: + initContainers: + - image: "{{ .Values.image.repository }}/init-container:{{ .Values.image.tag.db }}" + name: init-container-postgres + env: + - name: PGDATABASE + valueFrom: + secretKeyRef: + name: db-secret + key: dbname + - name: PGHOST + value: srmsystemdb + - name: PGPORT + value: '5432' + - name: PGUSER + valueFrom: + secretKeyRef: + name: db-secret + key: username + - name: PGPASSWORD + valueFrom: + secretKeyRef: + name: db-secret + key: password + command: ['sh', '-c', '/bin/bash /tmp/check_dump.sh'] + containers: + - image: "{{ .Values.image.repository }}/db-service:{{ .Values.image.tag.db }}" + name: db-service + ports: + - containerPort: 5002 + env: + - name: POSTGRES_HOST + value: srmsystemdb + - name: POSTGRES_PORT + value: '5432' + - name: PGDATABASE + valueFrom: + secretKeyRef: + name: db-secret + key: dbname + - name: PGUSER + valueFrom: + secretKeyRef: + name: db-secret + key: username + - name: PGPASSWORD + valueFrom: + secretKeyRef: + name: db-secret + key: password +--- +kind: Service +apiVersion: v1 +metadata: + namespace: {{ .Values.namespace }} + name: db-service +spec: + selector: + app: db-service + ports: + - protocol: TCP + port: 5002 + targetPort: 5002 +--- diff --git a/List-Helm-Charts/e2e-testing-db/values.yaml b/List-Helm-Charts/e2e-testing-db/values.yaml new file mode 100644 index 0000000..5aab868 --- /dev/null +++ b/List-Helm-Charts/e2e-testing-db/values.yaml @@ -0,0 +1,34 @@ +# Default values for UI-SERVICE. +# This is a YAML-formatted file. +# Declare variables to be passed into your templates. + +replicaCount: 1 + +image: + repository: 100.71.71.71:5000 + tag: + ui: "" + get: "" + db: "" + post: "" + +app: + name: ui + +service: + type: ClusterIP + port: 5000 + +namespace: testing + +deploy: + version: "" + +resources: {} + # limits: + # cpu: 100m + # memory: 128Mi + # requests: + # cpu: 100m + # memory: 128Mi + diff --git a/List-Helm-Charts/e2e-testing-get/.helmignore b/List-Helm-Charts/e2e-testing-get/.helmignore new file mode 100644 index 0000000..50af031 --- /dev/null +++ b/List-Helm-Charts/e2e-testing-get/.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/List-Helm-Charts/e2e-testing-get/Chart.yaml b/List-Helm-Charts/e2e-testing-get/Chart.yaml new file mode 100644 index 0000000..96ae34f --- /dev/null +++ b/List-Helm-Charts/e2e-testing-get/Chart.yaml @@ -0,0 +1,5 @@ +apiVersion: v1 +appVersion: "1.0" +description: A Helm chart for Kubernetes +name: e2e-testing-get +version: 0.1.0 diff --git a/List-Helm-Charts/e2e-testing-get/templates/template.yaml b/List-Helm-Charts/e2e-testing-get/templates/template.yaml new file mode 100644 index 0000000..3733ba3 --- /dev/null +++ b/List-Helm-Charts/e2e-testing-get/templates/template.yaml @@ -0,0 +1,43 @@ +--- +kind: Service +apiVersion: v1 +metadata: + namespace: {{ .Values.namespace }} + name: get-service + labels: + app: get +spec: + selector: + app: get + ports: + - protocol: TCP + port: 5003 + targetPort: 5003 +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + namespace: {{ .Values.namespace }} + name: get-deployment +spec: + selector: + matchLabels: + app: get + replicas: 1 + template: + metadata: + labels: + app: get + spec: + containers: + - name: get + image: "{{ .Values.image.repository }}/get-service:{{ .Values.image.tag.get }}" + ports: + - containerPort: 5003 + env: + - name: URL_DB + valueFrom: + configMapKeyRef: + name: services-address + key: URL_DB +--- diff --git a/List-Helm-Charts/e2e-testing-get/values.yaml b/List-Helm-Charts/e2e-testing-get/values.yaml new file mode 100644 index 0000000..5aab868 --- /dev/null +++ b/List-Helm-Charts/e2e-testing-get/values.yaml @@ -0,0 +1,34 @@ +# Default values for UI-SERVICE. +# This is a YAML-formatted file. +# Declare variables to be passed into your templates. + +replicaCount: 1 + +image: + repository: 100.71.71.71:5000 + tag: + ui: "" + get: "" + db: "" + post: "" + +app: + name: ui + +service: + type: ClusterIP + port: 5000 + +namespace: testing + +deploy: + version: "" + +resources: {} + # limits: + # cpu: 100m + # memory: 128Mi + # requests: + # cpu: 100m + # memory: 128Mi + diff --git a/List-Helm-Charts/e2e-testing-post/.helmignore b/List-Helm-Charts/e2e-testing-post/.helmignore new file mode 100644 index 0000000..50af031 --- /dev/null +++ b/List-Helm-Charts/e2e-testing-post/.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/List-Helm-Charts/e2e-testing-post/Chart.yaml b/List-Helm-Charts/e2e-testing-post/Chart.yaml new file mode 100644 index 0000000..0561013 --- /dev/null +++ b/List-Helm-Charts/e2e-testing-post/Chart.yaml @@ -0,0 +1,5 @@ +apiVersion: v1 +appVersion: "1.0" +description: A Helm chart for Kubernetes +name: e2e-testing-post +version: 0.1.0 diff --git a/List-Helm-Charts/e2e-testing-post/templates/template.yaml b/List-Helm-Charts/e2e-testing-post/templates/template.yaml new file mode 100644 index 0000000..c0bbc6d --- /dev/null +++ b/List-Helm-Charts/e2e-testing-post/templates/template.yaml @@ -0,0 +1,44 @@ +--- +kind: Service +apiVersion: v1 +metadata: + namespace: testing + name: post-service + labels: + app: post +spec: + selector: + app: post + ports: + - protocol: TCP + port: 5001 + targetPort: 5001 + +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + namespace: testing + name: post-deployment +spec: + selector: + matchLabels: + app: post + replicas: 1 + template: + metadata: + labels: + app: post + spec: + containers: + - name: post + image: 100.71.71.71:5000/post-service:{{ .Values.image.tag.post }} + ports: + - containerPort: 5001 + env: + - name: DB_URL + valueFrom: + configMapKeyRef: + name: services-address + key: DB_URL +--- diff --git a/List-Helm-Charts/e2e-testing-post/values.yaml b/List-Helm-Charts/e2e-testing-post/values.yaml new file mode 100644 index 0000000..06ab2bf --- /dev/null +++ b/List-Helm-Charts/e2e-testing-post/values.yaml @@ -0,0 +1,34 @@ +# Default values for UI-SERVICE. +# This is a YAML-formatted file. +# Declare variables to be passed into your templates. + +replicaCount: 1 + +image: + repository: 100.71.71.71:5000 + tag: + ui: "" + get: "" + db: "" + post: "" + +app: + name: post + +service: + type: ClusterIP + port: 5000 + +namespace: testing + +deploy: + version: "" + +resources: {} + # limits: + # cpu: 100m + # memory: 128Mi + # requests: + # cpu: 100m + # memory: 128Mi + diff --git a/List-Helm-Charts/e2e-testing-ui/.helmignore b/List-Helm-Charts/e2e-testing-ui/.helmignore new file mode 100644 index 0000000..50af031 --- /dev/null +++ b/List-Helm-Charts/e2e-testing-ui/.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/List-Helm-Charts/e2e-testing-ui/Chart.yaml b/List-Helm-Charts/e2e-testing-ui/Chart.yaml new file mode 100644 index 0000000..cf0b9b3 --- /dev/null +++ b/List-Helm-Charts/e2e-testing-ui/Chart.yaml @@ -0,0 +1,5 @@ +apiVersion: v1 +appVersion: "1.0" +description: A Helm chart for Kubernetes +name: e2e-testing-ui +version: 0.1.0 diff --git a/List-Helm-Charts/e2e-testing-ui/templates/template.yaml b/List-Helm-Charts/e2e-testing-ui/templates/template.yaml new file mode 100644 index 0000000..7630c23 --- /dev/null +++ b/List-Helm-Charts/e2e-testing-ui/templates/template.yaml @@ -0,0 +1,48 @@ +--- +kind: Service +apiVersion: v1 +metadata: + namespace: {{ .Values.namespace }} + name: ui-service + labels: + app: ui +spec: + selector: + app: ui + ports: + - protocol: TCP + port: 5000 + targetPort: 5000 +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + namespace: {{ .Values.namespace }} + name: ui-deployment +spec: + selector: + matchLabels: + app: ui + replicas: 1 + template: + metadata: + labels: + app: ui + spec: + containers: + - name: ui + image: "{{ .Values.image.repository }}/ui-service:{{ .Values.image.tag.ui }}" + ports: + - containerPort: 5000 + env: + - name: VIEW_SERVICE_URL + valueFrom: + configMapKeyRef: + name: services-address + key: VIEW_SERVICE_URL + - name: POST_SERVICE_URL + valueFrom: + configMapKeyRef: + name: services-address + key: POST_SERVICE_URL +--- diff --git a/List-Helm-Charts/e2e-testing-ui/values.yaml b/List-Helm-Charts/e2e-testing-ui/values.yaml new file mode 100644 index 0000000..5aab868 --- /dev/null +++ b/List-Helm-Charts/e2e-testing-ui/values.yaml @@ -0,0 +1,34 @@ +# Default values for UI-SERVICE. +# This is a YAML-formatted file. +# Declare variables to be passed into your templates. + +replicaCount: 1 + +image: + repository: 100.71.71.71:5000 + tag: + ui: "" + get: "" + db: "" + post: "" + +app: + name: ui + +service: + type: ClusterIP + port: 5000 + +namespace: testing + +deploy: + version: "" + +resources: {} + # limits: + # cpu: 100m + # memory: 128Mi + # requests: + # cpu: 100m + # memory: 128Mi + diff --git a/List-Helm-Charts/e2e-testing/.helmignore b/List-Helm-Charts/e2e-testing/.helmignore new file mode 100644 index 0000000..50af031 --- /dev/null +++ b/List-Helm-Charts/e2e-testing/.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/List-Helm-Charts/e2e-testing/Chart.yaml b/List-Helm-Charts/e2e-testing/Chart.yaml new file mode 100644 index 0000000..b08cc5a --- /dev/null +++ b/List-Helm-Charts/e2e-testing/Chart.yaml @@ -0,0 +1,5 @@ +apiVersion: v1 +appVersion: "1.0" +description: A Helm chart for Kubernetes +name: e2e-testing +version: 0.1.0 diff --git a/List-Helm-Charts/e2e-testing/templates/templates-e2e.yaml b/List-Helm-Charts/e2e-testing/templates/templates-e2e.yaml new file mode 100644 index 0000000..4f6bbc5 --- /dev/null +++ b/List-Helm-Charts/e2e-testing/templates/templates-e2e.yaml @@ -0,0 +1,258 @@ +--- +apiVersion: v1 +kind: ConfigMap +metadata: + namespace: {{ .Values.namespace }} + name: services-address +data: + POST_SERVICE_URL: post-service.testing.svc + VIEW_SERVICE_URL: get-service.testing.svc + DB_URL: db-service.testing.svc + URL_DB: db-service.testing.svc +--- +apiVersion: v1 +kind: Secret +metadata: + name: db-secret + namespace: {{ .Values.namespace }} +data: + username: ZGJhZG1pbg== + password: UGFzc3dvcmQ= + dbname: c3Jtc3lzdGVt +type: Opaque +--- +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + namespace: {{ .Values.namespace }} + labels: + app: pvc-postgres + name: postgres-pvc +spec: + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 2Gi +--- +apiVersion: extensions/v1beta1 +kind: Deployment +metadata: + namespace: {{ .Values.namespace }} + name: postgres + labels: + service: postgresdb +spec: + template: + metadata: + labels: + app: postgres + spec: + initContainers: + - name: volume-mount-hack + image: busybox + command: ["sh", "-c", "chown -R 999.999 /var/lib/postgresql/"] + volumeMounts: + - name: postgres-pv-claim + mountPath: /var/lib/postgresql/data + subPath: postgres + containers: + - image: postgres:9.6.2 + name: postgresql + env: + - name: POSTGRES_DB + valueFrom: + secretKeyRef: + name: db-secret + key: dbname + - name: POSTGRES_USER + valueFrom: + secretKeyRef: + name: db-secret + key: username + - name: POSTGRES_PASSWORD + valueFrom: + secretKeyRef: + name: db-secret + key: password + ports: + - containerPort: 5432 + volumeMounts: + - name: postgres-pv-claim + mountPath: /var/lib/postgresql/data + subPath: postgres + volumes: + - name: postgres-pv-claim + persistentVolumeClaim: + claimName: postgres-pvc +--- +kind: Service +apiVersion: v1 +metadata: + namespace: {{ .Values.namespace }} + name: srmsystemdb +spec: + selector: + app: postgres + ports: + - protocol: TCP + port: 5432 + targetPort: 5432 +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + namespace: {{ .Values.namespace }} + name: db-service +spec: + selector: + matchLabels: + app: db-service + template: + metadata: + labels: + app: db-service + spec: + initContainers: + - image: "{{ .Values.image.repository }}/init-container:{{ .Values.image.tag.db }}" + name: init-container-postgres + env: + - name: PGDATABASE + valueFrom: + secretKeyRef: + name: db-secret + key: dbname + - name: PGUSER + valueFrom: + secretKeyRef: + name: db-secret + key: username + - name: PGPASSWORD + valueFrom: + secretKeyRef: + name: db-secret + key: password + command: ['sh', '-c', '/bin/bash /tmp/check_dump.sh'] + containers: + - image: "{{ .Values.image.repository }}/db-service:{{ .Values.image.tag.db }}" + name: db-service + ports: + - containerPort: 5002 + env: + - name: POSTGRES_HOST + value: srmsystemdb + - name: POSTGRES_PORT + value: '5432' + - name: PGDATABASE + valueFrom: + secretKeyRef: + name: db-secret + key: dbname + - name: PGUSER + valueFrom: + secretKeyRef: + name: db-secret + key: username + - name: PGPASSWORD + valueFrom: + secretKeyRef: + name: db-secret + key: password +--- +kind: Service +apiVersion: v1 +metadata: + namespace: {{ .Values.namespace }} + name: db-service +spec: + selector: + app: db-service + ports: + - protocol: TCP + port: 5002 + targetPort: 5002 +--- +kind: Service +apiVersion: v1 +metadata: + namespace: {{ .Values.namespace }} + name: ui-service + labels: + app: ui +spec: + selector: + app: ui + ports: + - protocol: TCP + port: 5000 + targetPort: 5000 +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + namespace: {{ .Values.namespace }} + name: ui-deployment +spec: + selector: + matchLabels: + app: ui + replicas: 1 + template: + metadata: + labels: + app: ui + spec: + containers: + - name: ui + image: "{{ .Values.image.repository }}/ui-service:{{ .Values.image.tag.ui }}" + ports: + - containerPort: 5000 + env: + - name: VIEW_SERVICE_URL + valueFrom: + configMapKeyRef: + name: services-address + key: VIEW_SERVICE_URL +--- +kind: Service +apiVersion: v1 +metadata: + namespace: {{ .Values.namespace }} + name: get-service + labels: + app: get +spec: + selector: + app: get + ports: + - protocol: TCP + port: 5003 + targetPort: 5003 +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + namespace: {{ .Values.namespace }} + name: get-deployment +spec: + selector: + matchLabels: + app: get + replicas: 1 + template: + metadata: + labels: + app: get + spec: + containers: + - name: get + image: "{{ .Values.image.repository }}/get-service:{{ .Values.image.tag.get }}" + ports: + - containerPort: 5003 + env: + - name: URL_DB + valueFrom: + configMapKeyRef: + name: services-address + key: URL_DB +--- diff --git a/List-Helm-Charts/e2e-testing/values.yaml b/List-Helm-Charts/e2e-testing/values.yaml new file mode 100644 index 0000000..5aab868 --- /dev/null +++ b/List-Helm-Charts/e2e-testing/values.yaml @@ -0,0 +1,34 @@ +# Default values for UI-SERVICE. +# This is a YAML-formatted file. +# Declare variables to be passed into your templates. + +replicaCount: 1 + +image: + repository: 100.71.71.71:5000 + tag: + ui: "" + get: "" + db: "" + post: "" + +app: + name: ui + +service: + type: ClusterIP + port: 5000 + +namespace: testing + +deploy: + version: "" + +resources: {} + # limits: + # cpu: 100m + # memory: 128Mi + # requests: + # cpu: 100m + # memory: 128Mi + diff --git a/List-Helm-Charts/get-service-bg/.helmignore b/List-Helm-Charts/get-service-bg/.helmignore new file mode 100644 index 0000000..50af031 --- /dev/null +++ b/List-Helm-Charts/get-service-bg/.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/List-Helm-Charts/get-service-bg/Chart.yaml b/List-Helm-Charts/get-service-bg/Chart.yaml new file mode 100644 index 0000000..9c558c7 --- /dev/null +++ b/List-Helm-Charts/get-service-bg/Chart.yaml @@ -0,0 +1,5 @@ +apiVersion: v1 +appVersion: "1.0" +description: A Helm chart for Kubernetes +name: get-service-bg +version: 0.1.0 diff --git a/List-Helm-Charts/get-service-bg/templates/template.yaml b/List-Helm-Charts/get-service-bg/templates/template.yaml new file mode 100644 index 0000000..472405e --- /dev/null +++ b/List-Helm-Charts/get-service-bg/templates/template.yaml @@ -0,0 +1,28 @@ +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + namespace: production + name: get-deployment-{{ .Values.deploy.version }} +spec: + selector: + matchLabels: + app: get-service + replicas: 1 + template: + metadata: + labels: + app: get-service + version: {{ .Values.deploy.version }} + spec: + containers: + - name: get-service + image: "{{ .Values.image.repository }}/get-service:{{ .Values.image.tag }}" + ports: + - containerPort: 5003 + env: + - name: URL_DB + valueFrom: + configMapKeyRef: + name: services-address + key: URL_DB diff --git a/List-Helm-Charts/get-service-bg/values.yaml b/List-Helm-Charts/get-service-bg/values.yaml new file mode 100644 index 0000000..e182f3a --- /dev/null +++ b/List-Helm-Charts/get-service-bg/values.yaml @@ -0,0 +1,34 @@ +# Default values for UI-SERVICE. +# This is a YAML-formatted file. +# Declare variables to be passed into your templates. + +replicaCount: 1 + +image: + repository: 100.71.71.71:5000 + tag: "" + +app: + name: get + version: "" + +conf: + ver: "" +service: + type: ClusterIP + port: 5000 + servicename: get-service + +namespace: production + +deploy: + version: "" + +resources: {} + # limits: + # cpu: 100m + # memory: 128Mi + # requests: + # cpu: 100m + # memory: 128Mi + diff --git a/List-Helm-Charts/get-service/.helmignore b/List-Helm-Charts/get-service/.helmignore new file mode 100644 index 0000000..50af031 --- /dev/null +++ b/List-Helm-Charts/get-service/.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/List-Helm-Charts/get-service/Chart.yaml b/List-Helm-Charts/get-service/Chart.yaml new file mode 100644 index 0000000..53452e8 --- /dev/null +++ b/List-Helm-Charts/get-service/Chart.yaml @@ -0,0 +1,5 @@ +apiVersion: v1 +appVersion: "1.0" +description: A Helm chart for Kubernetes +name: get-service +version: 0.1.0 diff --git a/List-Helm-Charts/get-service/templates/template.yaml b/List-Helm-Charts/get-service/templates/template.yaml new file mode 100644 index 0000000..04a5805 --- /dev/null +++ b/List-Helm-Charts/get-service/templates/template.yaml @@ -0,0 +1,29 @@ +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + namespace: production + name: get-deployment-{{ .Values.deploy.version }} +spec: + selector: + matchLabels: + app: get-service + replicas: 1 + template: + metadata: + labels: + app: get-service + version: {{ .Values.deploy.version }} + + spec: + containers: + - name: get-service + image: "{{ .Values.image.repository }}/get-service:{{ .Values.image.tag }}" + ports: + - containerPort: 5003 + env: + - name: URL_DB + valueFrom: + configMapKeyRef: + name: services-address + key: URL_DB diff --git a/List-Helm-Charts/get-service/values.yaml b/List-Helm-Charts/get-service/values.yaml new file mode 100644 index 0000000..46fdf65 --- /dev/null +++ b/List-Helm-Charts/get-service/values.yaml @@ -0,0 +1,35 @@ +# Default values for UI-SERVICE. +# This is a YAML-formatted file. +# Declare variables to be passed into your templates. + +replicaCount: 1 + +image: + repository: 100.71.71.71:5000 + tag: "" + +conf: + ver: "" + +app: + name: get + version: "" + +service: + type: ClusterIP + port: 5000 + servicename: get-service + +namespace: production + +deploy: + version: "" + +resources: {} + # limits: + # cpu: 100m + # memory: 128Mi + # requests: + # cpu: 100m + # memory: 128Mi + diff --git a/List-Helm-Charts/istio-rules/.helmignore b/List-Helm-Charts/istio-rules/.helmignore new file mode 100644 index 0000000..50af031 --- /dev/null +++ b/List-Helm-Charts/istio-rules/.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/List-Helm-Charts/istio-rules/Chart.yaml b/List-Helm-Charts/istio-rules/Chart.yaml new file mode 100644 index 0000000..4628561 --- /dev/null +++ b/List-Helm-Charts/istio-rules/Chart.yaml @@ -0,0 +1,5 @@ +apiVersion: v1 +appVersion: "1.0" +description: A Helm chart for Kubernetes +name: istio-rules +version: 0.1.0 diff --git a/List-Helm-Charts/istio-rules/templates/template.yaml b/List-Helm-Charts/istio-rules/templates/template.yaml new file mode 100644 index 0000000..f4a7112 --- /dev/null +++ b/List-Helm-Charts/istio-rules/templates/template.yaml @@ -0,0 +1,39 @@ +--- +apiVersion: networking.istio.io/v1alpha3 +kind: DestinationRule +metadata: + name: {{ .Values.app.name }}-{{ .Values.vers }} +spec: + host: {{ .Values.app.name }} + subsets: + - name: v1 + labels: + version: v1 + - name: v2 + labels: + version: v2 +--- +apiVersion: networking.istio.io/v1alpha3 +kind: VirtualService +metadata: + name: {{ .Values.app.name }}-{{ .Values.vers }} +spec: + hosts: + - "*" + gateways: + - srm-gateway + http: + - route: + - destination: + host: {{ .Values.app.name }} + subset: v1 + port: + number: {{ .Values.port }} + weight: {{ .Values.weight.v1 }} + - destination: + host: {{ .Values.app.name }} + subset: v2 + port: + number: {{ .Values.port }} + weight: {{ .Values.weight.v2 }} +--- diff --git a/List-Helm-Charts/istio-rules/values.yaml b/List-Helm-Charts/istio-rules/values.yaml new file mode 100644 index 0000000..961801a --- /dev/null +++ b/List-Helm-Charts/istio-rules/values.yaml @@ -0,0 +1,25 @@ +# Default values for istio-rules. +# This is a YAML-formatted file. +# Declare variables to be passed into your templates. + +replicaCount: 1 + +image: + repository: 100.71.71.71:5000 + tag: "" + + +app: + name: "" + +vers: "" + +deploy: + version: "" + + +weight: + v1: "" + v2: "" + +port: "" diff --git a/List-Helm-Charts/post-service-bg/.helmignore b/List-Helm-Charts/post-service-bg/.helmignore new file mode 100644 index 0000000..50af031 --- /dev/null +++ b/List-Helm-Charts/post-service-bg/.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/List-Helm-Charts/post-service-bg/Chart.yaml b/List-Helm-Charts/post-service-bg/Chart.yaml new file mode 100644 index 0000000..4c36a96 --- /dev/null +++ b/List-Helm-Charts/post-service-bg/Chart.yaml @@ -0,0 +1,5 @@ +apiVersion: v1 +appVersion: "1.0" +description: A Helm chart for Kubernetes +name: post-service-bg +version: 0.1.0 diff --git a/List-Helm-Charts/post-service-bg/templates/template.yaml b/List-Helm-Charts/post-service-bg/templates/template.yaml new file mode 100644 index 0000000..2a5958a --- /dev/null +++ b/List-Helm-Charts/post-service-bg/templates/template.yaml @@ -0,0 +1,29 @@ +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + namespace: production + name: post-deployment-{{ .Values.deploy.version }} +spec: + selector: + matchLabels: + app: post-service + replicas: 1 + template: + metadata: + labels: + app: post-service + version: {{ .Values.deploy.version }} + spec: + containers: + - name: post-service + image: 100.71.71.71:5000/post-service:{{ .Values.image.tag }} + ports: + - containerPort: 5001 + env: + - name: DB_URL + valueFrom: + configMapKeyRef: + name: services-address + key: DB_URL +--- diff --git a/List-Helm-Charts/post-service-bg/values.yaml b/List-Helm-Charts/post-service-bg/values.yaml new file mode 100644 index 0000000..2ea6ea2 --- /dev/null +++ b/List-Helm-Charts/post-service-bg/values.yaml @@ -0,0 +1,38 @@ +# Default values for post-service-bg. +# This is a YAML-formatted file. +# Declare variables to be passed into your templates. + +replicaCount: 1 + +# Default values for UI-SERVICE. +# This is a YAML-formatted file. +# Declare variables to be passed into your templates. + +replicaCount: 1 + +image: + repository: 100.71.71.71:5000 + tag: "" + +app: + name: post + version: "" + +service: + type: ClusterIP + port: 5000 + servicename: post-service + +namespace: production + +deploy: + version: "" + +resources: {} + # limits: + # cpu: 100m + # memory: 128Mi + # requests: + # cpu: 100m + # memory: 128Mi + diff --git a/List-Helm-Charts/post-service/.helmignore b/List-Helm-Charts/post-service/.helmignore new file mode 100644 index 0000000..50af031 --- /dev/null +++ b/List-Helm-Charts/post-service/.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/List-Helm-Charts/post-service/Chart.yaml b/List-Helm-Charts/post-service/Chart.yaml new file mode 100644 index 0000000..c413ed8 --- /dev/null +++ b/List-Helm-Charts/post-service/Chart.yaml @@ -0,0 +1,5 @@ +apiVersion: v1 +appVersion: "1.0" +description: A Helm chart for Kubernetes +name: post-service +version: 0.1.0 diff --git a/List-Helm-Charts/post-service/templates/template.yaml b/List-Helm-Charts/post-service/templates/template.yaml new file mode 100644 index 0000000..63c3b28 --- /dev/null +++ b/List-Helm-Charts/post-service/templates/template.yaml @@ -0,0 +1,28 @@ +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + namespace: production + name: post-deployment-{{ .Values.deploy.version }} +spec: + selector: + matchLabels: + app: post-service + replicas: 1 + template: + metadata: + labels: + app: post-service + spec: + containers: + - name: post-service + image: 100.71.71.71:5000/post-service:{{ .Values.image.tag }} + ports: + - containerPort: 5001 + env: + - name: DB_URL + valueFrom: + configMapKeyRef: + name: services-address + key: DB_URL +--- diff --git a/List-Helm-Charts/post-service/values.yaml b/List-Helm-Charts/post-service/values.yaml new file mode 100644 index 0000000..e4f9449 --- /dev/null +++ b/List-Helm-Charts/post-service/values.yaml @@ -0,0 +1,35 @@ +# Default values for UI-SERVICE. +# This is a YAML-formatted file. +# Declare variables to be passed into your templates. + +replicaCount: 1 + +image: + repository: 100.71.71.71:5000 + tag: "" + +conf: + ver: "" + +app: + name: post + version: "" + +service: + type: ClusterIP + port: 5000 + servicename: post-service + +namespace: production + +deploy: + version: "" + +resources: {} + # limits: + # cpu: 100m + # memory: 128Mi + # requests: + # cpu: 100m + # memory: 128Mi + diff --git a/List-Helm-Charts/ui-service-bg/.helmignore b/List-Helm-Charts/ui-service-bg/.helmignore new file mode 100644 index 0000000..50af031 --- /dev/null +++ b/List-Helm-Charts/ui-service-bg/.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/List-Helm-Charts/ui-service-bg/Chart.yaml b/List-Helm-Charts/ui-service-bg/Chart.yaml new file mode 100644 index 0000000..10ef83a --- /dev/null +++ b/List-Helm-Charts/ui-service-bg/Chart.yaml @@ -0,0 +1,5 @@ +apiVersion: v1 +appVersion: "1.0" +description: A Helm chart for Kubernetes +name: ui-service-bg +version: 0.1.0 diff --git a/List-Helm-Charts/ui-service-bg/templates/template.yaml b/List-Helm-Charts/ui-service-bg/templates/template.yaml new file mode 100644 index 0000000..10ac6f8 --- /dev/null +++ b/List-Helm-Charts/ui-service-bg/templates/template.yaml @@ -0,0 +1,35 @@ +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + namespace: {{ .Values.namespace }} + name: ui-deployment-{{ .Values.deploy.version }} +spec: + selector: + matchLabels: + app: ui + version: {{ .Values.deploy.version }} + replicas: 1 + template: + metadata: + labels: + app: {{ .Values.app.name }} + version: {{ .Values.deploy.version }} + spec: + containers: + - name: {{ .Values.app.name }} + image: "{{ .Values.image.repository }}/{{ .Values.service.servicename }}:{{ .Values.image.tag }}" + ports: + - containerPort: 5000 + env: + - name: POST_SERVICE_URL + valueFrom: + configMapKeyRef: + name: services-address + key: POST_SERVICE_URL + - name: VIEW_SERVICE_URL + valueFrom: + configMapKeyRef: + name: services-address + key: VIEW_SERVICE_URL +--- diff --git a/List-Helm-Charts/ui-service-bg/values.yaml b/List-Helm-Charts/ui-service-bg/values.yaml new file mode 100644 index 0000000..d5d6815 --- /dev/null +++ b/List-Helm-Charts/ui-service-bg/values.yaml @@ -0,0 +1,33 @@ +# Default values for UI-SERVICE. +# This is a YAML-formatted file. +# Declare variables to be passed into your templates. + +replicaCount: 1 + +image: + repository: 100.71.71.71:5000 + tag: "" + +app: + name: ui + version: "" +conf: + ver: "" +service: + type: ClusterIP + port: 5000 + servicename: ui + +namespace: production + +deploy: + version: "" + +resources: {} + # limits: + # cpu: 100m + # memory: 128Mi + # requests: + # cpu: 100m + # memory: 128Mi + diff --git a/List-Helm-Charts/ui-service/.helmignore b/List-Helm-Charts/ui-service/.helmignore new file mode 100644 index 0000000..50af031 --- /dev/null +++ b/List-Helm-Charts/ui-service/.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/List-Helm-Charts/ui-service/Chart.yaml b/List-Helm-Charts/ui-service/Chart.yaml new file mode 100644 index 0000000..d5aae26 --- /dev/null +++ b/List-Helm-Charts/ui-service/Chart.yaml @@ -0,0 +1,5 @@ +apiVersion: v1 +appVersion: "1.0" +description: A Helm chart for Kubernetes +name: ui-service +version: 0.1.0 diff --git a/List-Helm-Charts/ui-service/templates/template.yaml b/List-Helm-Charts/ui-service/templates/template.yaml new file mode 100644 index 0000000..3adeeab --- /dev/null +++ b/List-Helm-Charts/ui-service/templates/template.yaml @@ -0,0 +1,35 @@ +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + namespace: {{ .Values.namespace }} + name: ui-deployment-{{ .Values.deploy.version }} + +spec: + selector: + matchLabels: + app: ui + version: {{ .Values.deploy.version }} + replicas: 1 + template: + metadata: + labels: + app: ui + version: {{ .Values.deploy.version }} + spec: + containers: + - name: "{{ .Values.app.name }}-{{ .Values.deploy.version }}" + image: "{{ .Values.image.repository }}/ui-service:{{ .Values.image.tag }}" + ports: + - containerPort: 5000 + env: + - name: POST_SERVICE_URL + valueFrom: + configMapKeyRef: + name: services-address + key: POST_SERVICE_URL + - name: VIEW_SERVICE_URL + valueFrom: + configMapKeyRef: + name: services-address + key: VIEW_SERVICE_URL diff --git a/List-Helm-Charts/ui-service/values.yaml b/List-Helm-Charts/ui-service/values.yaml new file mode 100644 index 0000000..c7c2baa --- /dev/null +++ b/List-Helm-Charts/ui-service/values.yaml @@ -0,0 +1,35 @@ +# Default values for UI-SERVICE. +# This is a YAML-formatted file. +# Declare variables to be passed into your templates. + +replicaCount: 1 + +image: + repository: 100.71.71.71:5000 + tag: "" + name: ui-service + +conf: + ver: "" + +app: + name: ui + +service: + type: ClusterIP + port: 5000 + servicename: ui + +namespace: production + +deploy: + version: "" + +resources: {} + # limits: + # cpu: 100m + # memory: 128Mi + # requests: + # cpu: 100m + # memory: 128Mi + diff --git a/app/app.py b/app/app.py index 8cb159c..63ee982 100644 --- a/app/app.py +++ b/app/app.py @@ -8,10 +8,10 @@ -URL_DEP = str(os.getenv("URL_DB")) + 'get-dep' -URL_EMPL = str(os.getenv("URL_DB")) + 'get-empl' -URL_TEAM = str(os.getenv("URL_DB")) + 'get-team' -URL_ALL = str(os.getenv("URL_DB")) + 'get-info' +URL_DEP = 'http://' + str(os.getenv("URL_DB")) + ':5002/get-dep' +URL_EMPL = 'http://' + str(os.getenv("URL_DB")) + ':5002/get-empl' +URL_TEAM = 'http://' + str(os.getenv("URL_DB")) + ':5002/get-team' +URL_ALL = 'http://' + str(os.getenv("URL_DB")) + ':5002/get-info' def print_url(): print(URL_DEP) @@ -22,8 +22,11 @@ def print_url(): def get_dep(): r = requests.get(URL_DEP) if r.status_code == 200: + print(type(r.content)) + print(r.content) return r.content else: + print(r.status_code) return (r.status_code, r.headers) def get_empl(): @@ -121,5 +124,5 @@ def get_one(): if __name__ == '__main__': - app.run(debug=True,host='0.0.0.0',port='5003') + app.run(host="0.0.0.0", port="5003") diff --git a/app/unit_tests.py b/app/unit_tests.py new file mode 100644 index 0000000..9254d27 --- /dev/null +++ b/app/unit_tests.py @@ -0,0 +1,46 @@ +import unittest +from app import * +import json +import requests +import responses + +class parse_json_success(unittest.TestCase): + + def test_received_url(self): + self.assertEqual(self.s, parse_json(self.arg1, self.arg2, self.arg3)) + + @classmethod + def setUpClass(cls): + cls.arg1 = {'DEP': ['IT', 'Man']} + cls.arg2 = {'Manager': 'Goose1'} + cls.arg3 = {'Personal': 33} + cls.s = json.dumps({'DEP': ['IT', 'Man'], 'Manager': 'Goose1', 'Personal': 33}) + def setUp(self): + print("\nTest for func success 'parse_json()'") + def tearDown(self): + print ("Finish tests for success result func 'parse_json()'") + +class parse_json_failed(unittest.TestCase): + + def test_failed_res(self): + self.assertNotEqual(self.s, parse_json(self.arg1, self.arg2, self.arg3)) + def test_exception_res(self): + with self.assertRaises(Exception): + parse_json(self.arg4) + + @classmethod + def setUpClass(cls): + cls.arg1 = {'DEP': ['IT', 'Man']} + cls.arg2 = {'Manager': 'Goose1'} + cls.arg3 = {'Personal': 33} + cls.arg4 = [1, "String"] + cls.s = {'DEP': ['IT', 'Man'], 'Manager': 'Goose1', 'Personal': 33} + def setUp(self): + print("\nTest for func 'parse_json()'") + def tearDown(self): + print ("Finish tests for result func 'parse_json()'") + + + +if __name__ == '__main__': + unittest.main() diff --git a/dockerfile b/dockerfile deleted file mode 100644 index 8671c09..0000000 --- a/dockerfile +++ /dev/null @@ -1,8 +0,0 @@ -FROM python:3.6-alpine -MAINTAINER Maxim Zhovanik -WORKDIR /service/GET-SERV -COPY . /service/GET-SERV -RUN pip install -r /service/GET-SERV/project_get/app/requirements.txt -CMD ["python", "/service/GET-SERV/project_get/app/app.py"] - - diff --git a/e2e-test-prod.py b/e2e-test-prod.py new file mode 100644 index 0000000..eb80e3b --- /dev/null +++ b/e2e-test-prod.py @@ -0,0 +1,19 @@ +import os +import time +import requests + +def main(): + check_services() + + + +def check_services(): + URL = "http://ui-service.production.svc:5000/" + req = requests.get(URL) + if req.status_code == 200: + print("Tests UI successfull pass") + else: + raise Exception("Fucking bitch!!!! Opssss") + +if __name__ == '__main__': + main() diff --git a/e2e-test-test.py b/e2e-test-test.py new file mode 100644 index 0000000..2ae928f --- /dev/null +++ b/e2e-test-test.py @@ -0,0 +1,26 @@ +import os +import requests +import time + +def main(): + check_services() + + + +def check_services(): + URL = "http://ui-service.testing.svc:5000" + req = requests.get(URL) + if req.status_code == 200: + print("Test UI successfull pass") + else: + raise Exception("Fucking bitch!!!! Opssss") +# URL_GET = "http://ui-service.testing.svc:5000/salaries" +# time.sleep(5) +# reques = requests.get(URL_GET) +# if reques.status_code == 200: +# print("UI success to GET") +# else: +# raise Exception("Fucking bitch again!!!! Opssss. You are unclever animal") + +if __name__ == '__main__': + main() diff --git a/images-registry-test.py b/images-registry-test.py new file mode 100644 index 0000000..ec3737e --- /dev/null +++ b/images-registry-test.py @@ -0,0 +1,28 @@ +import sys +import os +import requests +import json + +def main(): + check_image() + + +def check_image(): + tmp = requests.get("http://100.71.71.71:5000/v2/" + sys.argv[1] + "/tags/list") + req = tmp.json() + #print(req) + if (tmp.status_code == 404): + print("1") + return 1 + else: + if req["name"] == sys.argv[1] and sys.argv[2] in req["tags"]: + print("0") + return 0 + else: + #raise Exception("Image with tag " + sys.argv[1] + " does not exist in Docker Registry with IP: " + sys.argv[1]) + print("1") + return 1 + + +if __name__=='__main__': + main() diff --git a/jenkins-pod-test.yaml b/jenkins-pod-test.yaml new file mode 100644 index 0000000..5401861 --- /dev/null +++ b/jenkins-pod-test.yaml @@ -0,0 +1,27 @@ +kind: Service +apiVersion: v1 +metadata: + name: registry + namespace: stark-cluster +spec: + selector: + service: jenkins-srvs + ports: + - port: 5000 + targetPort: 5000 + type: LoadBalancer + +--- + +apiVersion: v1 +kind: Pod +metadata: + name: jenkins-pod + namespace: stark-cluster + labels: + service: jenkins-srvs +spec: + containers: + - name: jenkins-demo + image: 100.71.71.71/get-python:3rt3y3h + diff --git a/jenkins-pod.yaml b/jenkins-pod.yaml new file mode 100644 index 0000000..1313b9f --- /dev/null +++ b/jenkins-pod.yaml @@ -0,0 +1,28 @@ +kind: Service +apiVersion: v1 +metadata: + name: registry + namespace: stark-cluster +spec: + selector: + service: jenkins-srvs + ports: + - port: 5000 + targetPort: 5000 + type: LoadBalancer + +--- + +apiVersion: v1 +kind: Pod +metadata: + name: jenkins-pod + namespace: stark-cluster + labels: + service: jenkins-srvs +spec: + containers: + - name: jenkins-demo + image: ghostgoose33/get-python:v1 + + diff --git a/myjob_modified.yaml b/myjob_modified.yaml new file mode 100644 index 0000000..610d53f --- /dev/null +++ b/myjob_modified.yaml @@ -0,0 +1,571 @@ +apiVersion: v1 +kind: Namespace +metadata: + name: production + +--- + +apiVersion: v1 +kind: Namespace +metadata: + name: testing + +--- +apiVersion: v1 +kind: Secret +metadata: + name: db-secret + namespace: production +data: + username: ZGJhZG1pbg== + password: UGFzc3dvcmQ= + dbname: c3Jtc3lzdGVt +type: Opaque + +--- + +apiVersion: v1 +kind: ServiceAccount +metadata: + name: jenkins + namespace: production + +--- + +kind: Role +apiVersion: rbac.authorization.k8s.io/v1 +metadata: + name: jenkins + namespace: production +rules: +- apiGroups: [""] + resources: ["pods"] + verbs: ["create","delete","get","list","patch","update","watch"] +- apiGroups: [""] + resources: ["pods/exec"] + verbs: ["create","delete","get","list","patch","update","watch"] +- apiGroups: [""] + resources: ["pods/log"] + verbs: ["get","list","watch"] +- apiGroups: [""] + resources: ["services"] + verbs: ["create","delete","get","list","patch","update","watch"] +- apiGroups: [""] + resources: ["deployments"] + verbs: ["create","delete","get","list","patch","update","watch"] +- apiGroups: ["apps"] + resources: ["deployments"] + verbs: ["create","delete","get","list","patch","update","watch"] +- apiGroups: ["extensions"] + resources: ["deployments"] + verbs: ["create","delete","get","list","patch","update","watch"] +- apiGroups: [""] + resources: ["persistentvolumeclaims"] + verbs: ["create","delete","get","list","patch","update","watch"] +- apiGroups: [""] + resources: ["secrets"] + verbs: ["get"] +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: RoleBinding +metadata: + name: jenkins + namespace: production +roleRef: + apiGroup: rbac.authorization.k8s.io + kind: Role + name: jenkins +subjects: +- kind: ServiceAccount + name: jenkins +--- + +apiVersion: v1 +kind: ServiceAccount +metadata: + name: jenkins + namespace: testing + +--- + +kind: Role +apiVersion: rbac.authorization.k8s.io/v1 +metadata: + name: jenkins-test + namespace: testing +rules: +- apiGroups: [""] + resources: ["pods"] + verbs: ["create","delete","get","list","patch","update","watch"] +- apiGroups: [""] + resources: ["pods/exec"] + verbs: ["create","delete","get","list","patch","update","watch"] +- apiGroups: [""] + resources: ["pods/log"] + verbs: ["get","list","watch"] +- apiGroups: [""] + resources: ["services"] + verbs: ["create","delete","get","list","patch","update","watch"] +- apiGroups: [""] + resources: ["deployments"] + verbs: ["create","delete","get","list","patch","update","watch"] +- apiGroups: ["apps"] + resources: ["deployments"] + verbs: ["create","delete","get","list","patch","update","watch"] +- apiGroups: ["extensions"] + resources: ["deployments"] + verbs: ["create","delete","get","list","patch","update","watch"] +- apiGroups: [""] + resources: ["persistentvolumeclaims"] + verbs: ["create","delete","get","list","patch","update","watch"] +- apiGroups: [""] + resources: ["secrets"] + verbs: ["create","delete","get","list","patch","update","watch"] +- apiGroups: [""] + resources: ["namespaces"] + verbs: ["create","delete","get","list","patch","update","watch"] +- apiGroups: [""] + resources: ["configmaps"] + verbs: ["create","delete","get","list","patch","update","watch"] +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: RoleBinding +metadata: + name: jenkins-test + namespace: testing +roleRef: + apiGroup: rbac.authorization.k8s.io + kind: Role + name: jenkins-test +subjects: +- kind: ServiceAccount + name: jenkins + namespace: production +--- + + + +apiVersion: v1 +kind: ConfigMap +metadata: + namespace: production + name: services-address +data: + POST_SERVICE_URL: post-service.production.svc + VIEW_SERVICE_URL: get-service.production.svc + DB_URL: db-service.production.svc + URL_DB: db-service.production.svc + +--- + +apiVersion: v1 +kind: ConfigMap +metadata: + namespace: testing + name: services-address +data: + POST_SERVICE_URL: post-service.production.svc + VIEW_SERVICE_URL: get-service.production.svc + DB_URL: db-service.production.svc + URL_DB: db-service.production.svc + +--- + +apiVersion: v1 +data: + GitHub.xml: |- + + + + + GitHub + + + + + + + + + + git + + admgolovin + Slider256$ + + + github-1 + + admgolovin + $GITPWD + + + + + + + + + + + + + + + + false + + + + + + + true + 1 + 1 + + + + H/5 * * * * + 900000 + + + false + + + Kv-045DevOps + github-1 + + + Kubik-DB|SRM-GET|SRM-UI|SRM-DB + + + 1 + + + 1 + + + 1 + + + + + + + + Jenkinsfile + + + + + + + .* + true + + + + + +kind: ConfigMap +metadata: + creationTimestamp: "2019-01-18T03:22:02Z" + name: stark2 + namespace: production + resourceVersion: "96672" + selfLink: /api/v1/namespaces/default/configmaps/stark + uid: b70d8525-17fd-11e9-b845-02d08d5f4672 + +--- + +apiVersion: v1 +data: + config.xml: |- + + + + 2.150.2 + RUNNING + 2 + NORMAL + true + + false + + + true + false + + false + + ${JENKINS_HOME}/workspace/${ITEM_FULL_NAME} + ${ITEM_ROOTDIR}/builds + + + + + + kubernetes + + + https://kubernetes.default.svc + false + false + false + production + http://127.0.0.1:8080/ + kube-login + 10 + 5 + 0 + 0 + false + 32 + 600 + + + + 5 + 0 + + + + all + false + false + + + + all + 50000 + + + + + credentials.xml: |- + + + + + + + + + + GLOBAL + kube-login + + admin + $PASSWORD + + + GLOBAL + git_cred + + Maxghost33 + {AQAAABAAAAAg1cMYtdzX0b8pqPwU99XFsHEZtmsDLQy8n/RBMOnJnAj9ScoSD8i87dXfnx7TD0m+} + + + GLOBAL + docker_registry + + ghostgoose33 + {AQAAABAAAAAg8qaRTgg3fvfezKNrIlbz5LAhL3/WI0W5Nl4MLFgrPxYFSb8qACvkxcMFGvbtFQYx} + + + + + +kind: ConfigMap +metadata: + creationTimestamp: "2019-01-17T19:47:40Z" + name: jenconf + namespace: production + resourceVersion: "5227" + selfLink: /api/v1/namespaces/production/configmaps/jenconf + uid: bfec9ca6-1a90-11e9-a5b8-020fccbfb056 + +--- + +apiVersion: v1 +kind: Pod +metadata: + name: jenkins2 + namespace: production + labels: + service: jenkins2 +spec: + tolerations: + - key: "node" + operator: "Equal" + value: "boubde" + effect: "NoSchedule" + containers: + - name: stark-jenkins2 + image: admgolovin/myjenkins:v12 + volumeMounts: + - name: jenkins-config + mountPath: /var/jenkins_home/2/jobs/GitHub/ + - name: jenconf + mountPath: /var/jenkins_home/2 + lifecycle: + postStart: + exec: + command: ["/bin/sh","-c", "cp /var/jenkins_home/2/config.xml /var/jenkins_home/; cp /var/jenkins_home/2/credentials.xml /var/jenkins_home/; cp /var/jenkins_home/2/hudson.util.Secret /var/jenkins_home/secrets/; cp /var/jenkins_home/2/master.key /var/jenkins_home/secrets/; sleep 5m; java -jar /tools/jenkins-cli.jar -s http://127.0.0.1:8080 -auth admin:admin create-job GitHub < /var/jenkins_home/2/jobs/GitHub/GitHub.xml"] + serviceAccount: jenkins + serviceAccountName: jenkins + volumes: + - name: jenkins-config + configMap: + name: stark2 + - name: jenconf + configMap: + name: jenconf + restartPolicy: OnFailure + +# --- +# kind: Endpoints +# apiVersion: v1 +# metadata: +# name: my-service2 +# namespace: production +# subsets: +# - addresses: +# - ip: 10.0.0.1 +# targetRef: +# kind: Node +# name: node1 +# ports: +# - name: myjenkins +# port: 8080 +# protocol: TCP + +--- +kind: Service +apiVersion: v1 +metadata: + name: my-service + namespace: production +spec: + selector: + service: jenkins2 + ports: + - protocol: TCP + port: 8080 + targetPort: 8080 + type: LoadBalancer + +--- + +kind: Service +apiVersion: v1 +metadata: + name: jenkins-agent + namespace: production +spec: + selector: + service: jenkins2 + ports: + - protocol: TCP + port: 50000 + targetPort: 50000 + type: LoadBalancer + +--- + +apiVersion: v1 +kind: Secret +metadata: + name: test-secret + namespace: production +data: + password: YWRtaW4= + +--- + +# apiVersion: v1 +# kind: Pod +# metadata: +# name: dind-jen +# namespace: production +# spec: +# containers: +# - name: jnlp +# image: '/myjenkins:jenslave' +# args: ['\$(JENKINS_SECRET)'] +# env: +# - name: DOCKER_HOST +# value: tcp://localhost:2375 +# - name: dind +# image: docker:stable-dind +# securityContext: +# privileged: true +# volumeMounts: +# - name: dind-storage +# mountPath: /var/lib/docker +# volumes: +# - name: dind-storage +# emptyDir: {} + +--- + +# apiVersion: v1 +# kind: Pod +# metadata: +# name: jenslave +# namespace: production +# labels: +# service: jenkins +# spec: +# containers: +# - name: jnlp +# image: /myjenkins:jenslave +# resources: +# limits: +# memory: "600Mi" +# requests: +# memory: "500Mi" + +# apiVersion: apps/v1 +# kind: Deployment +# metadata: +# name: jenkins-storage +# namespace: production +# spec: +# selector: +# matchLabels: +# service: jenkins +# template: +# metadata: +# labels: +# service: jenkins +# spec: +# containers: +# - name: stark-jenkins +# image: ghostgoose33/jenkins-alp:v2 +# volumeMounts: +# - name: jenkins-config +# mountPath: /var/lib/jenkins/job/GitHub +# volumes: +# - name: jenkins-config +# configMap: +# name: stark2 + +--- + +# apiVersion: v1 +# kind: Pod +# metadata: +# name: jenkins2 +# namespace: production +# labels: +# service: jenkins2 +# spec: +# containers: +# - name: stark-jenkins2 +# image: ghostgoose33/jenkins-alp:v2 + +# restartPolicy: OnFailure + +--- diff --git a/pylint-test.py b/pylint-test.py new file mode 100644 index 0000000..3d1bf44 --- /dev/null +++ b/pylint-test.py @@ -0,0 +1,20 @@ +import os +import sys +from pylint.lint import Run + +def main(): + check_rate_code() + + +def check_rate_code(): + results = Run([sys.argv[1]], do_exit=False) + if (results.linter.stats['global_note'] <= 5): + raise Exception("Code rate smaller than standard") + return 1 + else: + print(results.linter.stats['global_note']) + return 0 + + +if __name__=='__main__': + main() diff --git a/sed_python.py b/sed_python.py new file mode 100644 index 0000000..8936dea --- /dev/null +++ b/sed_python.py @@ -0,0 +1,13 @@ +import os +import sys + +with open(sys.argv[1], 'r') as file: + str_tmp = "ghostgoose" + data = file.read() + tmp = sys.argv[2] + ":" + sys.argv[3] + data = data.replace("100.71.71.71:5000/get-service:v2", tmp) + print(data) + + +with open(sys.argv[1], 'w') as file: + file.write( data ) diff --git a/sed_python_test.py b/sed_python_test.py new file mode 100644 index 0000000..da5b56d --- /dev/null +++ b/sed_python_test.py @@ -0,0 +1,21 @@ +import os +import sys + +with open(sys.argv[1], 'r') as file: + #arr_s = sys.argv[2].split(',') + #print(arr_s) + str_tmp = "ghostgoose" + arr_f = ["100.71.71.71:5000/get-service", "100.71.71.71:5000/post-service", "100.71.71.71:5000/ui-service", "100.71.71.71:5000/db-service", "100.71.71.71:5000/init-container"] + arr = ["100.71.71.71:5000/get-service:v2", "100.71.71.71:5000/post-service:2.1", "100.71.71.71:5000/ui-service:latest", "100.71.71.71:5000/db-service:latest", "100.71.71.71:5000/init-container:latest"] + data = file.read() + print(len(arr_f)) + for i in range(len(arr_f)): + tmp = arr_f[i] + ":" + sys.argv[i+2] + data = data.replace(arr[i], tmp) + + + + +with open(sys.argv[1], 'w') as file: + file.write( data ) + print(data) diff --git a/string.txt b/string.txt new file mode 100644 index 0000000..78127b9 --- /dev/null +++ b/string.txt @@ -0,0 +1,334 @@ +def label = "mypod-${UUID.randomUUID().toString()}" +def dockerRegistry = "100.71.71.71:5000" +def Creds = "git_cred" + +String e2e_YAML = """--- \ +apiVersion: v1 \ +kind: Namespace \ +metadata: \ + name: testing \ +--- \ +apiVersion: v1 \ +kind: ConfigMap \ +metadata:\ + namespace: testing\ + name: services-address\ +data:\ + POST_SERVICE_URL: post-service.testing.svc\ + VIEW_SERVICE_URL: get-service.testing.svc\ + DB_URL: db-service.testing.svc\ + URL_DB: db-service.testing.svc\ +---\ +apiVersion: v1\ +kind: Secret\ +metadata:\ + name: db-secret\ + namespace: testing\ +data:\ + username: ZGJhZG1pbg==\ + password: UGFzc3dvcmQ=\ + dbname: c3Jtc3lzdGVt\ +type: Opaque\ +---\ +apiVersion: v1\ +kind: PersistentVolumeClaim\ +metadata:\ + namespace: testing\ + labels:\ + app: pvc-postgres\ + name: postgres-pvc\ +spec:\ + accessModes:\ + - ReadWriteOnce\ + resources:\ + requests:\ + storage: 2Gi\ +---\ +apiVersion: extensions/v1beta1\ +kind: Deployment\ +metadata:\ + namespace: testing\ + name: postgres\ + labels:\ + service: postgresdb\ +spec:\ + template:\ + metadata:\ + labels:\ + app: postgres\ + spec:\ + initContainers:\ + - name: volume-mount-hack\ + image: busybox\ + command: ["sh", "-c", "chown -R 999:999 /var/lib/postgresql/"]\ + volumeMounts:\ + - name: postgres-pv-claim\ + mountPath: /var/lib/postgresql/data\ + subPath: postgres\ + containers:\ + - image: postgres:9.6.2\ + name: postgresql\ + env:\ + - name: POSTGRES_DB\ + valueFrom:\ + secretKeyRef:\ + name: db-secret\ + key: dbname\ + - name: POSTGRES_USER\ + valueFrom:\ + secretKeyRef:\ + name: db-secret\ + key: username\ + - name: POSTGRES_PASSWORD\ + valueFrom:\ + secretKeyRef:\ + name: db-secret\ + key: password\ + ports:\ + - containerPort: 5432\ + volumeMounts:\ + - name: postgres-pv-claim\ + mountPath: /var/lib/postgresql/data\ + subPath: postgres\ + volumes:\ + - name: postgres-pv-claim\ + persistentVolumeClaim:\ + claimName: postgres-pvc\ +---\ +kind: Service\ +apiVersion: v1\ +metadata:\ + namespace: testing\ + name: srmsystemdb\ +spec:\ + selector:\ + app: postgres\ + ports:\ + - protocol: TCP\ + port: 5432\ + targetPort: 5432\ +---\ +apiVersion: extensions/v1beta1\ +kind: Deployment\ +metadata:\ + namespace: testing\ + name: db-service\ +spec:\ + template:\ + metadata:\ + labels:\ + app: db-service\ + spec:\ + initContainers:\ + - image: 100.71.71.71:5000/init-container:${params.imageTagDB_}\ + name: init-container-postgres\ + env:\ + - name: PGDATABASE\ + valueFrom:\ + secretKeyRef:\ + name: db-secret\ + key: dbname\ + - name: PGUSER\ + valueFrom:\ + secretKeyRef:\ + name: db-secret\ + key: username\ + - name: PGPASSWORD\ + valueFrom:\ + secretKeyRef:\ + name: db-secret\ + key: password\ + command: ['sh', '-c', '/bin/bash /tmp/check_dump.sh']\ + containers:\ + - image: 100.71.71.71:5000/db-service:${params.imageTagDB_}\ + name: db-service\ + ports:\ + - containerPort: 5002\ + env:\ + - name: POSTGRES_HOST\ + value: srmsystemdb\ + - name: POSTGRES_PORT\ + value: "5432"\ + - name: PGDATABASE\ + valueFrom:\ + secretKeyRef:\ + name: db-secret\ + key: dbname\ + - name: PGUSER\ + valueFrom:\ + secretKeyRef:\ + name: db-secret\ + key: username\ + - name: PGPASSWORD\ + valueFrom:\ + secretKeyRef:\ + name: db-secret\ + key: password \ +---\ +kind: Service\ +apiVersion: v1\ +metadata:\ + namespace: testing\ + name: db-service\ +spec:\ + selector:\ + app: db-service\ + ports:\ + - protocol: TCP\ + port: 5002\ + targetPort: 5002\ +---\ +kind: Service\ +apiVersion: v1\ +metadata:\ + namespace: testing\ + name: ui-service\ + labels:\ + app: ui\ +spec:\ + selector:\ + app: ui\ + ports:\ + - protocol: TCP\ + port: 5000\ + targetPort: 5000\ +---\ +apiVersion: apps/v1\ +kind: Deployment\ +metadata:\ + namespace: testing\ + name: ui-deployment\ +spec:\ + selector:\ + matchLabels:\ + app: ui\ + replicas: 1\ + template:\ + metadata:\ + labels:\ + app: ui\ + spec:\ + containers:\ + - name: ui\ + image: 100.71.71.71:5000/ui-service:${params.imageTagUI_}\ + ports:\ + - containerPort: 5000\ + env:\ +# - name: POST_SERVICE_URL\ +# valueFrom:\ +# configMapKeyRef:\ +# name: services-address\ +# key: POST_SERVICE_URL\ + - name: VIEW_SERVICE_URL\ + valueFrom:\ + configMapKeyRef:\ + name: services-address\ + key: VIEW_SERVICE_URL\ +---\ +kind: Service\ +apiVersion: v1\ +metadata:\ + namespace: testing\ + name: get-service\ + labels:\ + app: get\ +spec:\ + selector:\ + app: get\ + ports:\ + - protocol: TCP\ + port: 5003\ + targetPort: 5003\ +---\ +apiVersion: apps/v1\ +kind: Deployment\ +metadata:\ + namespace: testing\ + name: get-deployment\ +spec:\ + selector:\ + matchLabels:\ + app: get\ + replicas: 1\ + template:\ + metadata:\ + labels:\ + app: get\ + spec:\ + containers:\ + - name: get\ + image: 100.71.71.71:5000/get-service:${params.imageTagGET_}\ + ports:\ + - containerPort: 5003\ + env:\ + - name: URL_DB\ + valueFrom:\ + configMapKeyRef:\ + name: services-address\ + key: URL_DB\ +--- """ + +properties([ + parameters([ + stringParam( + defaultValue: "***", + description: '', + name: 'imageTagGET_'), + stringParam( + defaultValue: "***", + description: '', + name: 'imageTagUI_'), + stringParam( + defaultValue: "***", + description: '', + name: 'imageTagDB_'), + stringParam( + defaultValue: '***', + description: '', + name: 'namespace') + ]) +]) + +podTemplate(label: label, containers: [ + containerTemplate(name: 'python-alpine', image: 'ghostgoose33/python-alp:v1', command: 'cat', ttyEnabled: true), + containerTemplate(name: 'docker', image: 'ghostgoose33/docker-in:v1', command: 'cat', ttyEnabled: true), + containerTemplate(name: 'kubectl', image: 'lachlanevenson/k8s-kubectl:v1.8.8', command: 'cat', ttyEnabled: true) +], +volumes: [ + hostPathVolume(mountPath: '/var/run/docker.sock', hostPath: '/var/run/docker.sock') +], serviceAccount: "jenkins") +{ + + +node(label) +{ + try{ + + stage("E2E Test - Stage 1"){ + container('kubectl'){ + sh (script: "echo ${e2e_YAML} | kubectl apply -n namespace -f -", returnStdout: true) + sh "kubectl get pods --namespace=testing" + } + } + sleep 20 + stage ("E2E Tests - Stage 2"){ + container('python-alpine'){ + // sh 'echo "Here is e2e test"' + //sh "python3 ${pathTocodeget}/e2e-test-test.py" + } + } + + stage ("Deploy"){ + + //build(job: 'test_deploy', parameters: [[$class: 'StringParameterValue', name:"imageTagGET", value: "${params.imageTagGET}"], + //[$class: 'StringParameterValue', name:"imageTagUI", value: "${params.imageTagUI}"], + //[$class: 'StringParameterValue', name:"imageTagDB", value: "${params.imageTagDB}"], + //[$class: 'StringParameterValue', name:"imageTagPOST", value: "${params.imageTagPOST}"]], wait: true) + } + + } + catch(err){ + currentBuild.result = 'Failure' + } +} +} diff --git a/template-test.yml b/template-test.yml new file mode 100644 index 0000000..1513a2e --- /dev/null +++ b/template-test.yml @@ -0,0 +1,43 @@ +--- +kind: Service +apiVersion: v1 +metadata: + namespace: testing + name: get-service + labels: + app: get +spec: + selector: + app: get + ports: + - protocol: TCP + port: 5003 + targetPort: 5003 + +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + namespace: testing + name: get-deployment +spec: + selector: + matchLabels: + app: get + replicas: 1 + template: + metadata: + labels: + app: get + spec: + containers: + - name: get + image: 100.71.71.71:5000/get-service:v2 + ports: + - containerPort: 5003 + env: + - name: URL_DB + valueFrom: + configMapKeyRef: + name: services-address + key: URL_DB diff --git a/template.yaml b/template.yaml new file mode 100644 index 0000000..a276cf6 --- /dev/null +++ b/template.yaml @@ -0,0 +1,43 @@ +--- +kind: Service +apiVersion: v1 +metadata: + namespace: production + name: get-service + labels: + app: get +spec: + selector: + app: get + ports: + - protocol: TCP + port: 5003 + targetPort: 5003 + +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + namespace: production + name: get-deployment +spec: + selector: + matchLabels: + app: get + replicas: 1 + template: + metadata: + labels: + app: get + spec: + containers: + - name: get + image: 100.71.71.71:5000/get-service:v2 + ports: + - containerPort: 5003 + env: + - name: URL_DB + valueFrom: + configMapKeyRef: + name: services-address + key: URL_DB