Skip to content

Commit

Permalink
Added Jenkinsfile that pushes to Pypi and DockerHub
Browse files Browse the repository at this point in the history
  • Loading branch information
kadenlnelson committed Mar 5, 2019
1 parent d38e475 commit a533072
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 1 deletion.
19 changes: 19 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
venv
__pycache__

.eggs
*.egg-info
dist
build
AUTHORS
ChangeLog

.DS_Store

doc/_*

.idea

*.xlsx

*.log
15 changes: 15 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FROM python:3.7.2

LABEL maintainer="kaden@vermilion.tech"

WORKDIR /usr/src/app

COPY requirements.txt .

RUN pip install --no-cache-dir -r requirements.txt

COPY . .

ENTRYPOINT [ "python", "-m", "realvalidation" ]

CMD [ "--help" ]
75 changes: 75 additions & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
pipeline {
agent any

environment {
COMMIT_MESSAGE = """${sh(
returnStdout: true,
script: "git --no-pager log --format='medium' -1 ${GIT_COMMIT}"
)}"""
COMMIT_HASH = """${sh(
returnStdout: true,
script: "git describe --always"
)}"""

PYTHON_VERSION = '3.7.2'

PYPIRC_CREDENTIALS = "pypirc-kaden-vt"

DOCKER_REPO = "kadenlnelson/realvalidation"
DOCKER_CREDENTIALS = "docker-hub-kadenlnelson"
}

stages {
stage('Notify Slack') {
steps {
slackSend(color: '#000000', message: "Build Started - ${env.JOB_NAME} ${env.BUILD_NUMBER} (<${env.BUILD_URL}|Open>)\n```${env.COMMIT_MESSAGE}```")
}
}

stage('Build & Push Python Distributions') {
agent { docker { image "python:${PYTHON_VERSION}" } }
steps {
sh 'pip install -r requirements.txt'
sh 'rm -rf dist'
sh 'python setup.py sdist bdist_wheel'
script {
SEMVER = """${sh(
returnStdout: true,
script: "python setup.py --version"
)}"""
}
withCredentials([file(credentialsId: "${PYPIRC_CREDENTIALS}", variable: 'PYPIRC')]) {
sh 'twine upload --config-file $PYPIRC dist/*'
}
slackSend (color: '#ffde57', message: "PyPi Package Pushed - https://pypi.org/project/realvalidation/\n```\nTry it out!\n\npip install realvalidation==${SEMVER}```")
}
}

stage('Build & Push Docker Image') {
agent { docker { image 'docker:18.09.2' } }
steps {
script {
def branchName = "${GIT_BRANCH}".replace('/', '_')
def image = docker.build("${DOCKER_REPO}")

docker.withRegistry('', "${DOCKER_CREDENTIALS}") {
image.push(branchName)
image.push("${SEMVER}")
}
}

slackSend (color: '#0db7ed', message: "Docker Image Built & Pushed - https://hub.docker.com/r/kadenlnelson/realvalidation/tags\n```\nTry it out!\n\ndocker run --rm ${DOCKER_REPO}:${SEMVER}```")
}
}
}

post {
failure {
slackSend (color: '#FF0000', message: "Build Failed! - ${env.JOB_NAME} ${env.BUILD_NUMBER} (<${env.BUILD_URL}|Open>)")
}

success {
slackSend (color: '#00FF00', message: "Success! - ${env.JOB_NAME} ${env.BUILD_NUMBER} (<${env.BUILD_URL}|Open>)")
}
}
}
5 changes: 4 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,8 @@ requests==2.21.0
openpyxl==2.6.0

pbr==5.1.2

Sphinx==1.8.4
sphinx-rtd-theme==0.4.3
sphinx-rtd-theme==0.4.3

twine==1.13.0

0 comments on commit a533072

Please sign in to comment.