diff --git a/Dockerfile b/Dockerfile index 56c3134..8bd0a7f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,2 +1 @@ -FROM httpd:2.4 -COPY ./index.html /usr/local/apache2/htdocs/ +FROM nginx diff --git a/Jenkinsfile b/Jenkinsfile index dfa7746..0cbcce6 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,42 +1,27 @@ pipeline { - environment { - registry = "192.168.1.81:5000/justme/myweb" - dockerImage = "" - } - - agent any + agent { label 'jenkins-docker-agent' } stages { - stage('Checkout Source') { steps { - git 'https://github.com/justmeandopensource/playjenkins.git' + git url:'https://github.com/ladung/playjenkins.git', branch:'test-deploy-dungla' } } - - stage('Build image') { - steps{ - script { - dockerImage = docker.build registry + ":$BUILD_NUMBER" - } + stage('Docker build') { + steps { + container('docker-dind') { + sh 'docker version' + sh 'docker build -t a:b -f Dockerfile .' } } - - stage('Push Image') { - steps{ - script { - docker.withRegistry( "" ) { - dockerImage.push() - } - } - } - } - +} stage('Deploy App') { steps { + sh 'ls -la' + sh 'java -version' script { - kubernetesDeploy(configs: "myweb.yaml", kubeconfigId: "mykubeconfig") + kubernetesDeploy(configs: "nginx.yaml", kubeconfigId: "kubeconfigdev") } } } diff --git a/Jenkinsfile.bak b/Jenkinsfile.bak new file mode 100644 index 0000000..6f96c68 --- /dev/null +++ b/Jenkinsfile.bak @@ -0,0 +1,27 @@ +podTemplate(containers: [ + containerTemplate(name: 'maven', image: 'maven:3.8.1-jdk-8', command: 'sleep', args: '99d') +]) +pipeline { + + agent { label 'jenkins-agent' } + + stages { + + stage('Checkout Source') { + steps { + git url:'https://github.com/ladung/playjenkins.git', branch:'test-deploy-stage' + } + } + + stage('Deploy App') { + steps { + sh 'ls -la' + script { + kubernetesDeploy(configs: "nginx.yaml", kubeconfigId: "kubeconfigdev") + } + } + } + + } + +} diff --git a/Jenkinsfile.bak2 b/Jenkinsfile.bak2 new file mode 100644 index 0000000..1b88bfb --- /dev/null +++ b/Jenkinsfile.bak2 @@ -0,0 +1,20 @@ +pipeline { + agent { + kubernetes { + //cloud 'kubernetes' + containerTemplate { + name 'maven' + image 'maven:3.8.1-jdk-8' + command 'sleep' + args '99d' + } + } + } + stages { + stage('Run maven') { + steps { + sh 'mvn -version' + } + } +} +} diff --git a/index.html b/index.html deleted file mode 100644 index 05abbe4..0000000 --- a/index.html +++ /dev/null @@ -1,7 +0,0 @@ -
-

Welcome to Just Me and OpenSource

-

v1.0

-

-

Demo of Jenkins CI/CD Pipeline using BlueOcean and Kubernetes Continuous Deployment plugins

- -
diff --git a/myweb.yaml b/nginx.yaml similarity index 58% rename from myweb.yaml rename to nginx.yaml index fba9532..a92dc98 100644 --- a/myweb.yaml +++ b/nginx.yaml @@ -3,36 +3,37 @@ apiVersion: apps/v1 kind: Deployment metadata: labels: - app: myweb - name: myweb + app: web + name: mynginx111 + namespace: dungla spec: replicas: 1 selector: matchLabels: - app: myweb + app: web template: metadata: labels: - app: myweb + app: web spec: containers: - - image: 192.168.1.81:5000/justme/myweb:1 - imagePullPolicy: Always - name: myweb + - image: nginx:$BUILD_NUMBER + name: mynginx --- apiVersion: v1 kind: Service metadata: labels: - app: myweb - name: myweb + app: web + name: mynginx + namespace: dungla spec: ports: - - nodePort: 32223 + - nodePort: 32224 port: 80 protocol: TCP targetPort: 80 selector: - app: myweb + app: web type: NodePort diff --git a/pod2.yml b/pod2.yml new file mode 100644 index 0000000..ee237b8 --- /dev/null +++ b/pod2.yml @@ -0,0 +1,20 @@ +apiVersion: v1 +kind: Pod +metadata: + name: dood +spec: + containers: + - name: docker-cmds + image: docker:1.12.6 + command: ['docker', 'run', '-p', '80:80', 'httpd:latest'] + resources: + requests: + cpu: 10m + memory: 256Mi + volumeMounts: + - mountPath: /var/run + name: docker-sock + volumes: + - name: docker-sock + hostPath: + path: /var/run