From db400ae6ca74f49b9712d115c5df7ccd5796c815 Mon Sep 17 00:00:00 2001 From: root Date: Thu, 8 Dec 2022 09:26:29 +0000 Subject: [PATCH 1/5] python project files --- Dockerfile | 7 +++++++ README.md | 1 + demo.py | 10 ++++++++++ requirements.txt | 3 +++ 4 files changed, 21 insertions(+) create mode 100644 Dockerfile create mode 100644 README.md create mode 100644 demo.py create mode 100644 requirements.txt diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..0cd04dc --- /dev/null +++ b/Dockerfile @@ -0,0 +1,7 @@ +FROM python:alpine3.7 +COPY . /app +WORKDIR /app +RUN pip install -r requirements.txt +EXPOSE 5001 +ENTRYPOINT [ "python" ] +CMD [ "demo.py" ] diff --git a/README.md b/README.md new file mode 100644 index 0000000..20d3fde --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +# python-flask-docker-project \ No newline at end of file diff --git a/demo.py b/demo.py new file mode 100644 index 0000000..0966f90 --- /dev/null +++ b/demo.py @@ -0,0 +1,10 @@ +from flask import Flask +app = Flask(__name__) + +@app.route('/') +def hello(): + return "welcome to the flask tutorials" + + +if __name__ == "__main__": + app.run(host ='0.0.0.0', port = 5001, debug = True) diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..db07929 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,3 @@ +flask +mysql-connector-python +boto3 From 73648583113f4538289fb1fbf2877fa98fdf5062 Mon Sep 17 00:00:00 2001 From: techcoms <120088252+techcoms@users.noreply.github.com> Date: Fri, 9 Dec 2022 12:00:07 +0530 Subject: [PATCH 2/5] Create Jenkinsfile --- Jenkinsfile | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 Jenkinsfile diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000..6ecf055 --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,41 @@ +pipeline{ + options { + buildDiscarder(logRotator(numToKeepStr: '2', artifactNumToKeepStr: '6')) + } + agent any + environment { + DOCKERHUB_REPO = "techcoms/backend-python" + GITHUB_URL = "${params.url}" + BRANCH = "${params.branch}" + + } + stages{ + stage("git checkout"){ + steps{ + git branch: "${BRANCH}", credentialsId: 'github-creds', url: "${GITHUB_URL}" + } + } + + stage("build docker image"){ + steps { + sh "docker build -t ${DOCKERHUB_REPO}:${BUILD_NUMBER} ." + } + } + stage("login to dockerhub and push image"){ + steps { + withCredentials([usernamePassword(credentialsId: 'dockerhub-creds', passwordVariable: 'PASSWORD', usernameVariable: 'USERNAME')]) { + sh "docker login -u $USERNAME -p $PASSWORD " + sh "docker push ${DOCKERHUB_REPO}:${BUILD_NUMBER}" + + } + } + } + } + post{ + changed{ + mail to: "techcomsdevops@gmail.com", + subject: "jenkins build:${currentBuild.currentResult}: ${env.JOB_NAME}", + body: "${currentBuild.currentResult}: Job ${env.JOB_NAME}\nMore Info can be found here: ${env.BUILD_URL}" + } + } +} From e4af8f4b7acfed340b5c8f9cd96a61a424cbb0c1 Mon Sep 17 00:00:00 2001 From: techcoms <120088252+techcoms@users.noreply.github.com> Date: Fri, 9 Dec 2022 12:20:16 +0530 Subject: [PATCH 3/5] Update Jenkinsfile --- Jenkinsfile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 6ecf055..f948983 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -5,14 +5,14 @@ pipeline{ agent any environment { DOCKERHUB_REPO = "techcoms/backend-python" - GITHUB_URL = "${params.url}" - BRANCH = "${params.branch}" +// GITHUB_URL = "${params.url}" +// BRANCH = "${params.branch}" } stages{ stage("git checkout"){ steps{ - git branch: "${BRANCH}", credentialsId: 'github-creds', url: "${GITHUB_URL}" + git branch: "master", credentialsId: 'github-creds', url: "https://github.com/techcoms/backend-python.git" } } From c97f9398ecc6908e91114be262b7b5c7055938af Mon Sep 17 00:00:00 2001 From: techcoms <120088252+techcoms@users.noreply.github.com> Date: Mon, 12 Dec 2022 13:34:29 +0530 Subject: [PATCH 4/5] Update Jenkinsfile --- Jenkinsfile | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Jenkinsfile b/Jenkinsfile index f948983..b2a77cc 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -21,6 +21,11 @@ pipeline{ sh "docker build -t ${DOCKERHUB_REPO}:${BUILD_NUMBER} ." } } + stage('run a docker container'){ + steps{ + sh "docker run -d -p 8088:5001 ${DOCKERHUB_REPO}:${BUILD_NUMBER}" + } + } stage("login to dockerhub and push image"){ steps { withCredentials([usernamePassword(credentialsId: 'dockerhub-creds', passwordVariable: 'PASSWORD', usernameVariable: 'USERNAME')]) { From 9d465562ff525290495a474afd514b9862dd35d1 Mon Sep 17 00:00:00 2001 From: techcoms <120088252+techcoms@users.noreply.github.com> Date: Mon, 12 Dec 2022 13:40:38 +0530 Subject: [PATCH 5/5] Update Jenkinsfile --- Jenkinsfile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index b2a77cc..615ffb9 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -5,14 +5,14 @@ pipeline{ agent any environment { DOCKERHUB_REPO = "techcoms/backend-python" -// GITHUB_URL = "${params.url}" -// BRANCH = "${params.branch}" + GITHUB_URL = "${params.url}" + BRANCH = "${params.branch}" } stages{ stage("git checkout"){ steps{ - git branch: "master", credentialsId: 'github-creds', url: "https://github.com/techcoms/backend-python.git" + git branch: "${BRANCH}", credentialsId: 'github-creds', url: "${GITHUB_URL}" } }