Files
netbox/.jenkins
Marco Ceppi cca2c6b680 Vapor API Scaffold (#2)
* Updated README

* Start of Vapor Netbox Module

* Add api/vapor route

* Ignore virtualenv

* Query devices assigned to users

* Add vapor/interfaces route

* adds docker-compose file to manage postgres/redis

- Initial test suite for the vapor api module. (Django tests are kind of
  hard and slow)

* Init pipeline

 - Adds a tox harness to run the test suite
 - Test running in tox
 - Clone example config to config.py
 - Add the kubernetes agent + dependent services to complete tests in
   the podspec
 - some really hacky sed configuration on the fly

* Init Docker build

- Adds the dockerfile assets from vapor-ware/netbox-docker
- Slight changes to keep the root directory clean (nesting dirs in
  docker path)
- Adds a rudimentary job label to build on micro-k8s builder
- adds docker build/publish stages to the pipeline for branch builds.
- dockerignore the project dir as its fetching packages from GHAPI

* Cleanups

* More unittests
2019-09-24 13:53:58 -04:00

118 lines
3.3 KiB
Plaintext

def getSafeBranchName() {
return "${env.BRANCH_NAME}".replace('/', '-')
}
def getTagName() {
def branchName = getSafeBranchName()
return "${branchName}.${env.BUILD_NUMBER}"
}
pipeline {
// disallow unconfigured stages
// each stage will have to declare an agent block and direct the pipeline
// how to execute. This skips the implicit agent scheduling.
agent none
environment {
TAG = getTagName()
IMAGE = 'vaporio/netbox'
}
stages {
stage('Test') {
/*
# Setup an agent dynamically using the following podspec. Netbox requires
# redis and postgres by default (they've disabled all the other backend drivers
# so we'll tack those on to the pods with some sane defaults.
# Note: this targets units on the vapor-build cluster (implicit) This may not be
# desireable in the case of building docker images.
*/
agent {
kubernetes {
defaultContainer 'jnlp'
yaml """
apiVersion: v1
kind: Pod
metadata:
labels:
jenkins/job: netbox
spec:
containers:
- name: python
image: vaporio/jenkins-agent-python36:latest
command:
- cat
tty: true
- name: postgres
image: postgres:10
env:
- name: POSTGRES_USER
value: netbox
- name: POSTGRES_PASSWORD
value: netbox
- name: redis
image: redis:latest
nodeSelector:
cloud.google.com/gke-nodepool: jenkins
tolerations:
- key: role
operator: Equal
value: jenkins
effect: NoSchedule
"""
}
}
steps {
container('python') {
/*
# in the netbox/netbox path there is an example configuration file
# clone this file and set up a permissive configuration for CI
# using the values we declared in the podspec
*/
dir('netbox/netbox') {
sh """
cp configuration.example.py configuration.py
sed -i -e "s/ALLOWED_HOSTS = .*/ALLOWED_HOSTS = ['*']/g" configuration.py
sed -i -e "s/SECRET_KEY = .*/SECRET_KEY = 'netboxci'/g" configuration.py
sed -i -e "s/USER': .*/USER': 'netbox',/g" configuration.py
sed -i -e "s/PASSWORD': .*/PASSWORD': 'netbox',/g" configuration.py
"""
}
// finally, kick off tox to run the entire test suite
sh 'tox'
}
}
}
stage('The Great British Baking Show') {
/* the docker-build agent is statically enlisted in jenkins. it runs
on the micro-k8s unit in vaporio/foundation:latest and has a uid1000
accessible docker */
when {
not {
changeRequest()
}
}
agent {
label 'docker-build'
}
steps {
container('docker') {
// embed tags from build env to do image tracing later
sh '''
docker build . \
-f Dockerfile \
--build-arg BUILD_DATE=$(date -u +%Y-%m-%dT%T 2> /dev/null) \
--build-arg VCS_REF=${GIT_COMMIT} \
--build-arg BUILD_VERSION=${BUILD_TAG} \
--build-arg BRANCH=${BRANCH_NAME} \
-t ${IMAGE}:${TAG}
'''
withDockerRegistry(registry: [credentialsId: 'vio-docker-hub']) {
sh "docker push ${env.IMAGE}:${env.TAG}"
}
}
}
}
}
}