diff --git a/.env b/.env new file mode 100644 index 0000000..ed147e1 --- /dev/null +++ b/.env @@ -0,0 +1,7 @@ +MYSQL_IP=mysqlserverhost +MYSQL_USER= +MYSQL_PASS= +MYSQL_DBNAME=toolingdb + +env.BRANCH_NAME=feature +env.BUILD_NUMBER='0.0.1' diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4c49bd7 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.env diff --git a/Dockerfile b/Dockerfile index aba30a1..90bc5c4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,5 @@ FROM php:7-apache -MAINTAINER Dare dare@darey.io +# MAINTAINER Dare dare@darey.io ENV MYSQL_IP=$MYSQL_IP ENV MYSQL_USER=$MYSQL_USER diff --git a/Jenkinsfile b/Jenkinsfile index e17ef79..24d3136 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,73 +1,53 @@ pipeline { - agent { - kubernetes { - yaml ''' - apiVersion: v1 - kind: Pod - spec: - containers: - - name: maven - image: maven:alpine - command: - - cat - tty: true - - name: docker - image: docker:latest - command: - - cat - tty: true - volumeMounts: - - mountPath: /var/run/docker.sock - name: docker-sock - volumes: - - name: docker-sock - hostPath: - path: /var/run/docker.sock - ''' - } + agent any + options { + buildDiscarder(logRotator(numToKeepStr: '5')) + } + environment { + DOCKERHUB_CREDENTIALS = credentials('dockerhub') } + stages { - stage('Clone') { - steps { - container('maven') { - git branch: 'main', changelog: false, poll: false, url: 'https://mohdsabir-cloudside@bitbucket.org/mohdsabir-cloudside/java-app.git' - } - } - } - stage('Build-Jar-file') { + stage('Build image for tooling-app') { steps { - container('maven') { - sh 'mvn package' - } + sh 'docker build -t stlng/tooling-${env.BRANCH_NAME}:${env.BUILD_NUMBER} .' } } - stage('Build-Docker-Image') { + + stage('Test Stage: testing endpoint') { steps { - container('docker') { - sh 'docker build -t dareyregistry/java-app:latest .' - } - } - } - stage('Login-Into-Docker') { + sh 'docker-compose -f tooling.yml up -d' + + script { + while (true) { + def response = httpRequest 'http://localhost:5000' + if (response.status == 200) { + sh 'echo $DOCKERHUB_CREDENTIALS_PSW | docker login -u $DOCKERHUB_CREDENTIALS_USR --password-stdin' + } + break + } + } + } + } + + stage('Push docker image to docker hub registry') { + when { expression { response.status == 200 } } steps { - container('docker') { - sh 'docker login -u dareyregistry -p Phartion001ng' + sh 'docker push stlng/tooling-${env.BRANCH_NAME}:${env.BUILD_NUMBER}' } } - } - stage('Push-Images-Docker-to-DockerHub') { - steps { - container('docker') { - sh 'docker push dareyregistry/java-app:latest' + + stage('Cleaning up') { + steps{ + sh 'docker compose -f tooling.yml down' + sh 'docker rmi tooling-${env.BRANCH_NAME}:${env.BUILD_NUMBER}' } - } - } - } + } + post { always { - container('docker') { - sh 'docker logout' - } + sh 'docker logout' + } } } -} \ No newline at end of file + } diff --git a/Jenkinsfile.bak b/Jenkinsfile.bak new file mode 100644 index 0000000..854cda1 --- /dev/null +++ b/Jenkinsfile.bak @@ -0,0 +1,32 @@ +pipeline { + agent any + options { + buildDiscarder(logRotator(numToKeepStr: '5')) + } + environment { + PATH = '/usr/bin/sh' + DOCKERHUB_CREDENTIALS = credentials('dockerhub') + } + stages { + stage('Build image for toolng-app') { + steps { + sh 'docker build -t stlng/tooling-master:0.0.1 .' + } + } + stage('Login to docker hub') { + steps { + sh 'echo $DOCKERHUB_CREDENTIALS_PSW | docker login -u $DOCKERHUB_CREDENTIALS_USR --password-stdin' + } + } + stage('Push docker image to docker hub registry') { + steps { + sh 'docker push stlng/tooling-master:0.0.1' + } + } + } + post { + always { + sh 'docker logout' + } + } +} \ No newline at end of file diff --git a/Jenkinsfile.bk b/Jenkinsfile.bk new file mode 100644 index 0000000..e17ef79 --- /dev/null +++ b/Jenkinsfile.bk @@ -0,0 +1,73 @@ +pipeline { + agent { + kubernetes { + yaml ''' + apiVersion: v1 + kind: Pod + spec: + containers: + - name: maven + image: maven:alpine + command: + - cat + tty: true + - name: docker + image: docker:latest + command: + - cat + tty: true + volumeMounts: + - mountPath: /var/run/docker.sock + name: docker-sock + volumes: + - name: docker-sock + hostPath: + path: /var/run/docker.sock + ''' + } + } + stages { + stage('Clone') { + steps { + container('maven') { + git branch: 'main', changelog: false, poll: false, url: 'https://mohdsabir-cloudside@bitbucket.org/mohdsabir-cloudside/java-app.git' + } + } + } + stage('Build-Jar-file') { + steps { + container('maven') { + sh 'mvn package' + } + } + } + stage('Build-Docker-Image') { + steps { + container('docker') { + sh 'docker build -t dareyregistry/java-app:latest .' + } + } + } + stage('Login-Into-Docker') { + steps { + container('docker') { + sh 'docker login -u dareyregistry -p Phartion001ng' + } + } + } + stage('Push-Images-Docker-to-DockerHub') { + steps { + container('docker') { + sh 'docker push dareyregistry/java-app:latest' + } + } + } + } + post { + always { + container('docker') { + sh 'docker logout' + } + } + } +} \ No newline at end of file diff --git a/Jenkinsfile.bk1 b/Jenkinsfile.bk1 new file mode 100644 index 0000000..f90ba78 --- /dev/null +++ b/Jenkinsfile.bk1 @@ -0,0 +1,61 @@ +pipeline { + agent any + options { + buildDiscarder(logRotator(numToKeepStr: '5')) + } + environment { + PATH = '/usr/bin/sh' + DOCKERHUB_CREDENTIALS = credentials('dockerhub') + } + stages { + stage('Build image for tooling-app') { + steps { + sh 'docker build -t stlng/tooling-master:0.0.2 .' + } + } + + stage('Build container for tooling-app') { + steps { + sh 'docker compose -f tooling.yml up -d' + } + } + + stage('Test Stage') { + steps { + httpRequest url:"http://localhost:5000", + validResponseCodes:'200' + + // echo "HTTP response status code: ${status_code}" + + // if (status_code != "200") { + // error('URL status different from 200. FAILURE') + // } + } + } + + stage('Login to docker hub') { + steps { + sh 'echo $DOCKERHUB_CREDENTIALS_PSW | docker login -u $DOCKERHUB_CREDENTIALS_USR --password-stdin' + } + } + + stage('Push docker image to docker hub registry') { + steps { + sh 'docker push stlng/tooling-master:0.0.2' + } + } + + stage('docker hub logout') { + steps{ + sh 'docker logout' + } + } + + post { + always { + cleanWs() + sh 'docker compose -f tooling.yml down' + } + } + } + } \ No newline at end of file diff --git a/create_user.sql b/create_user.sql new file mode 100644 index 0000000..3da2b59 --- /dev/null +++ b/create_user.sql @@ -0,0 +1 @@ +CREATE USER ''@'%' IDENTIFIED BY ''; GRANT ALL PRIVILEGES ON * . * TO ''@'%'; \ No newline at end of file diff --git a/docker b/docker new file mode 100644 index 0000000..8804619 --- /dev/null +++ b/docker @@ -0,0 +1,10 @@ +Command 'shell' not found, did you mean: + command 'spell' from deb spell (1.0-24.2) + command 'rshell' from deb pyboard-rshell (0.0.31-0ubuntu1) + command 'bshell' from deb avahi-ui-utils (0.8-5ubuntu5) + command 'jshell' from deb openjdk-11-jdk-headless (11.0.18+10-0ubuntu1~22.04) + command 'jshell' from deb openjdk-17-jdk-headless (17.0.6+10-0ubuntu1~22.04) + command 'jshell' from deb openjdk-18-jdk-headless (18.0.2+9-2~22.04) + command 'jshell' from deb openjdk-19-jdk-headless (19.0.2+7-0ubuntu3~22.04) + command 'shelr' from deb shelr (0.16.3-2.1) +Try: sudo apt install diff --git a/html/.env b/html/.env index 8c4f143..5085de5 100644 --- a/html/.env +++ b/html/.env @@ -1,6 +1,6 @@ # input your environment variables MYSQL_IP=mysqlserverhost -MYSQL_USER=Admin -MYSQL_PASS=Admin.com -MYSQL_DBNAME=toolingdb \ No newline at end of file +MYSQL_USER= +MYSQL_PASS= +MYSQL_DBNAME=toolingdb diff --git a/html/db_conn.php b/html/db_conn.php index c5e4626..3b24209 100644 --- a/html/db_conn.php +++ b/html/db_conn.php @@ -9,7 +9,6 @@ // enabling environment variable for php - $servername = $_ENV["MYSQL_IP"]; // input servername $username = $_ENV["MYSQL_USER"]; // input username $password = $_ENV["MYSQL_PASS"]; //input password @@ -17,8 +16,10 @@ // Create connection + $conn = new mysqli($servername, $username, $password, $dbname); + // Check connection if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); diff --git a/test.txt b/test.txt deleted file mode 100644 index 9a74024..0000000 --- a/test.txt +++ /dev/null @@ -1 +0,0 @@ -Testing git connectivity diff --git a/tooling.bak b/tooling.bak new file mode 100644 index 0000000..571cf42 --- /dev/null +++ b/tooling.bak @@ -0,0 +1,39 @@ +version: "3.9" +services: + tooling_frontend: + build: . + container_name: tooling + ports: + - "5000:80" + volumes: + - tooling_frontend:/var/www/html + networks: + - tooling_app_network + links: + - db + db: + image: mysql/mysql-server:latest + container_name: mysqlserverhost + ports: + - 3306:3306 + restart: always + environment: + # MYSQL_DATABASE: 'toolingdb' + # MYSQL_USER: '' + # MYSQL_PASSWORD: '' + # MYSQL_RANDOM_ROOT_PASSWORD: '1' + + MYSQL_DATABASE: '${MYSQL_DBNAME}' + MYSQL_USER: '${MYSQL_USER}' + MYSQL_PASSWORD: '${MYSQL_PASS}' + MYSQL_RANDOM_ROOT_PASSWORD: '1' + volumes: + - db:/var/lib/mysql + networks: + - tooling_app_network +volumes: + tooling_frontend: + db: +networks: + tooling_app_network : {} + \ No newline at end of file diff --git a/tooling.yml b/tooling.yml new file mode 100644 index 0000000..058c2e3 --- /dev/null +++ b/tooling.yml @@ -0,0 +1,23 @@ +version: "3.9" +services: + tooling_frontend: + image: stlng/tooling-${env.BRANCH_NAME}:${env.BUILD_NUMBER} + ports: + - "5000:80" + volumes: + - tooling_frontend:/var/www/html + links: + - db + db: + image: mysql:5.7 + restart: always + environment: + MYSQL_DATABASE: '${MYSQL_DBNAME}' + MYSQL_USER: '${MYSQL_USER}' + MYSQL_PASSWORD: '${MYSQL_PASS}' + MYSQL_RANDOM_ROOT_PASSWORD: '1' + volumes: + - db:/var/lib/mysql +volumes: + tooling_frontend: + db: