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/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000..fb7a036 --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,38 @@ +pipeline{ + 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/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 ${ECR_REGISTRY}:${BUILD_NUMBER} ." + } + } + stage("login to dockerhub and push image"){ + steps { + 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}" + } + } + } + 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}" + } + } +} diff --git a/README.md b/README.md index 4d47f7e..20d3fde 100644 --- a/README.md +++ b/README.md @@ -1 +1 @@ -# backend-python \ No newline at end of file +# 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