From db400ae6ca74f49b9712d115c5df7ccd5796c815 Mon Sep 17 00:00:00 2001 From: root Date: Thu, 8 Dec 2022 09:26:29 +0000 Subject: [PATCH 1/8] 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/8] 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/8] 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 028b40a97efa9c2722996f16836e85c8f0a54bad Mon Sep 17 00:00:00 2001 From: techcoms <120088252+techcoms@users.noreply.github.com> Date: Fri, 9 Dec 2022 12:31:09 +0530 Subject: [PATCH 4/8] Update Jenkinsfile --- Jenkinsfile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index f948983..6ecf055 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}" } } From 5dc2733d4cbc1671f91f60b6911e4f47dfa73ee6 Mon Sep 17 00:00:00 2001 From: techcoms <120088252+techcoms@users.noreply.github.com> Date: Fri, 9 Dec 2022 12:43:29 +0530 Subject: [PATCH 5/8] Update Jenkinsfile --- Jenkinsfile | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 6ecf055..1afae42 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -23,11 +23,8 @@ pipeline{ } 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}" - - } + sh "aws ecr get-login-password --region ap-south-1 | docker login --username AWS --password-stdin 894228636591.dkr.ecr.ap-south-1.amazonaws.com" + sh "docker push ${ECR_REGISTRY}:${BUILD_NUMBER}" } } } From 65fd5e3d85826f6fef006d64dfa2a93328cd4e5c Mon Sep 17 00:00:00 2001 From: techcoms <120088252+techcoms@users.noreply.github.com> Date: Fri, 9 Dec 2022 12:54:01 +0530 Subject: [PATCH 6/8] Update Jenkinsfile --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 1afae42..8fd23eb 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -4,7 +4,7 @@ pipeline{ } agent any environment { - DOCKERHUB_REPO = "techcoms/backend-python" + ECR_REGISTRY = "894228636591.dkr.ecr.ap-south-1.amazonaws.com/techcoms/backend-python" GITHUB_URL = "${params.url}" BRANCH = "${params.branch}" From 92e5edad4c74f4b8eac8ca32ee0888fbc452e842 Mon Sep 17 00:00:00 2001 From: techcoms <120088252+techcoms@users.noreply.github.com> Date: Fri, 9 Dec 2022 12:57:14 +0530 Subject: [PATCH 7/8] Update Jenkinsfile --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 8fd23eb..61ac12e 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -18,7 +18,7 @@ pipeline{ stage("build docker image"){ steps { - sh "docker build -t ${DOCKERHUB_REPO}:${BUILD_NUMBER} ." + sh "docker build -t ${ECR_REGISTRY}:${BUILD_NUMBER} ." } } stage("login to dockerhub and push image"){ From 50ec1713607b8e434d2029e8ae563003b0e48d46 Mon Sep 17 00:00:00 2001 From: techcoms <120088252+techcoms@users.noreply.github.com> Date: Fri, 9 Dec 2022 13:06:41 +0530 Subject: [PATCH 8/8] Update Jenkinsfile --- Jenkinsfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 61ac12e..fb7a036 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,10 +1,10 @@ pipeline{ - options { + options {https://github.com/techcoms/backend-python/blob/push-ecr/Jenkinsfile buildDiscarder(logRotator(numToKeepStr: '2', artifactNumToKeepStr: '6')) } agent any environment { - ECR_REGISTRY = "894228636591.dkr.ecr.ap-south-1.amazonaws.com/techcoms/backend-python" + ECR_REGISTRY = "894228636591.dkr.ecr.ap-south-1.amazonaws.com/backend-python" GITHUB_URL = "${params.url}" BRANCH = "${params.branch}"