Skip to content

Instantly share code, notes, and snippets.

View evasilchenko's full-sized avatar

Eugene Vasilchenko evasilchenko

View GitHub Profile
@evasilchenko
evasilchenko / list_of_steps.rst
Last active November 24, 2016 05:46
List of possible deployment steps
  • run unit tests
  • create a deployable build artifact
  • upload the artifact to a private repo
  • run a chef recipe which will install the latest artifact from the remote repo to a provisioned server
  • launch end-to-end tests against the newly deployed version of your application
  • if end-to-end tests pass proceed to:
    • deploy the same artifact to the next server
    • run end-to-end tests on the next server
    • Repeat the two steps above until the artifact has been deployed to all the servers
#!groovy
// This deployment script assumes that there is only a single Jenkins server (master) and there are no agents.
// If the setup includes agents, then the stages should be reconfigured to take advantage of additional remote nodes.
// This script is assuming that you're using a multi-branch project but the majority directly translates to a regular pipeline project.
node {
// It's often recommended to run a django project from a virtual environment.
// This way you can manage all of your depedencies without affecting the rest of your system.
def installed = fileExists 'bin/activate'
@evasilchenko
evasilchenko / step2-1.groovy
Created December 2, 2016 04:50
Step 2 - 1
def installed = fileExists 'bin/activate'
if (!installed) {
stage("Install Python Virtual Enviroment") {
sh 'virtualenv --no-site-packages .'
}
}
stage ("Get Latest Code") {
checkout scm
}
stage ("Install Application Dependencies") {
sh '''
source bin/activate
pip install -r <relative path to requirements file>
deactivate
'''
}
stage ("Collect Static files") {
sh '''
source bin/activate
python <relative path to manage.py> collectstatic --noinput
deactivate
'''
}
stage ("Run Unit/Integration Tests") {
def testsError = null
try {
sh '''
source ../bin/activate
python <relative path to manage.py> jenkins
deactivate
'''
}
catch(err) {
#!groovy
// This deployment script assumes that there is only a single Jenkins server (master) and there are no agents.
// If the setup includes agents, then the stages should be reconfigured to take advantage of additional remote nodes.
// This script is assuming that you're using a multi-branch project but the majority directly translates to a regular pipeline project.
node {
// It's often recommended to run a django project from a virtual environment.
// This way you can manage all of your depedencies without affecting the rest of your system.
def installed = fileExists 'bin/activate'
def regExMatch = /\/|\./,
// We are going to use the global BUILD_TAG to identify our artifact file. Sometimes the BUILD_TAG might contain unwanted
// characters so we are going to strip them out and replace them with dashes
safeBuildName = jenkins.branch.MultiBranchProject.rawDecode(env.BUILD_TAG).replaceAll(regExMatch, "-"),
artifactFolder = "target",
fullFileName = "${safeBuildName}.tar.gz",
// Define the final location and file name for the artifact file
applicationZip = "${artifactFolder}/${fullFileName}",
// List out all of the relative paths to your django apps which your application relies upon
// and leave out things which should not get deployed like tests and mocks.
stage ("Copy Artifact file to Repo") {
node {
def deployTarget = '<target repo server to copy file to>',
deployFolder = '<absolute path to target folder which will store all artifacts files>'
sh "scp ${applicationZip} jenkins@${deployTarget}:${deployFolder}"
}
}