diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000..46cb126 --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,67 @@ +pipeline { + agent any + environment { + DOCKER_REGISTRY_URL = 'marcin00.azurecr.io' + DOCKER_IMAGE = "${DOCKER_REGISTRY_URL}/user-microservice:${GIT_COMMIT}" + ACR_NAME = 'marcin00' + } + stages { + stage('Checkout') { + steps { + checkout scm + } + } + stage('Test python app') { + steps { + script { + sh ''' + python -m venv env + env/bin/pip install -r requirements.txt pytest + env/bin/pytest . --junit-xml=pytest_junit.xml + ''' + } + } + post { + always { + junit testResults: '**/*pytest_junit.xml' + } + } + } + stage('Build & test docker image') { + steps { + script { + appImage = docker.build("${DOCKER_IMAGE}") + + sh label: 'Install dgoss', script: ''' + curl -s -L https://github.com/aelsabbahy/goss/releases/latest/download/goss-linux-amd64 -o goss + curl -s -L https://github.com/aelsabbahy/goss/releases/latest/download/dgoss -o dgoss + chmod +rx *goss + ''' + + withEnv(["GOSS_OPTS=-f junit", 'GOSS_PATH=./goss', "SQLALCHEMY_DATABASE_URI=sqlite:///:memory:"]) { + sh label: 'run image tests', script: './dgoss run ${DOCKER_IMAGE} > goss_junit.xml' + } + } + } + post { + always { + junit testResults: '**/*goss_junit.xml' + } + } + } + stage('Deploy') { + steps { + script { + az login --identity + az acr login --name ${ACR_NAME} + docker push ${DOCKER_IMAGE} + } + } + } + } + post { + cleanup { + script { cleanWs() } + } + } +}