diff --git a/Jenkinsfile b/Jenkinsfile index 9db429a..9a57d48 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -2,64 +2,54 @@ pipeline { agent any - options { - disableConcurrentBuilds() - } environment { PROJECT_NAME = 'vn-rfid' - STACK_NAME = "${env.PROJECT_NAME}-${env.BRANCH_NAME}" } stages { - stage('Checkout') { + stage('Setup') { steps { - script { - switch (env.BRANCH_NAME) { - case 'master': - env.NODE_ENV = 'production' - break - } - } - - setEnv() + echo "NODE_NAME: ${env.NODE_NAME}" + echo "WORKSPACE: ${env.WORKSPACE}" } } stage('Build') { - when { anyOf { + when { branch 'master' - }} + } environment { CREDENTIALS = credentials('docker-registry') } steps { + script { + def packageJson = readJSON file: 'package.json' + env.VERSION = packageJson.version + } dockerBuild() } } stage('Deploy') { - when { anyOf { + when { branch 'master' - }} - environment { - DOCKER_HOST = "${env.SWARM_HOST}" } steps { - sh "docker stack deploy --with-registry-auth --compose-file docker-compose.yml ${env.STACK_NAME}" + script { + def packageJson = readJSON file: 'package.json' + env.VERSION = packageJson.version + } + withKubeConfig([ + serverUrl: "$KUBERNETES_API", + credentialsId: 'kubernetes', + namespace: 'vn-rfid' + ]) { + sh 'kubectl set image deployment/vn-rfid vn-rfid=$REGISTRY/vn-rfid:$VERSION' + } } } } post { always { - script { - if (!env.COMMITTER_EMAIL || currentBuild.currentResult == 'SUCCESS') return; - try { - mail( - to: env.COMMITTER_EMAIL, - subject: "Pipeline: ${env.JOB_NAME} (${env.BUILD_NUMBER}): ${currentBuild.currentResult}", - body: "Check status at ${env.BUILD_URL}" - ) - } catch (e) { - echo e.toString() - } - } + setEnv() + sendEmail() } } -} +} \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 9376705..62003e2 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,20 +1,7 @@ version: '3.7' services: main: - image: registry.verdnatura.es/vn-rfid:${BRANCH_NAME:?} + image: registry.verdnatura.es/vn-rfid:${VERSION:?} build: context: . - dockerfile: Dockerfile - ports: - - 8888 - configs: - - source: config - target: /app/config.local.yml - deploy: - placement: - constraints: - - node.role == worker -configs: - config: - external: true - name: vn-rfid_config \ No newline at end of file + dockerfile: Dockerfile \ No newline at end of file