From 95b56a7c3687f22f9db921c8d28f706bb0b79f40 Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Mon, 27 May 2024 13:11:57 +0200 Subject: [PATCH] ci: refs #7442 Kubernetes deploy --- Jenkinsfile | 24 ++++++++++++++++++------ docker-compose.yml | 19 +------------------ package.json | 2 +- 3 files changed, 20 insertions(+), 25 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index a13e2bb..b3ac3f7 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -4,12 +4,12 @@ pipeline { agent any environment { PROJECT_NAME = 'worker-time-control' - STACK_NAME = "${env.PROJECT_NAME}-${env.BRANCH_NAME}" } stages { stage('Checkout') { steps { - setEnv() + echo "NODE_NAME: ${env.NODE_NAME}" + echo "WORKSPACE: ${env.WORKSPACE}" } } stage('Build') { @@ -21,6 +21,10 @@ pipeline { CREDENTIALS = credentials('docker-registry') } steps { + script { + def packageJson = readJSON file: 'package.json' + env.VERSION = packageJson.version + } dockerBuild() } } @@ -29,16 +33,24 @@ pipeline { branch 'test' branch 'master' }} - environment { - DOCKER_HOST = "${env.SWARM_HOST}" - } steps { - sh "docker stack deploy --with-registry-auth --prune --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: 'worker-time-control' + ]) { + sh 'kubectl set image deployment/worker-time-control-$BRANCH_NAME worker-time-control-$BRANCH_NAME=$REGISTRY/worker-time-control:$VERSION' + } } } } post { always { + setEnv() sendEmail() } } diff --git a/docker-compose.yml b/docker-compose.yml index e73a285..6769074 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,22 +1,5 @@ version: '3.7' services: main: - image: registry.verdnatura.es/worker-time-control:${BRANCH_NAME:?} + image: registry.verdnatura.es/worker-time-control:${VERSION:?} build: . - ports: - - 80 - configs: - - source: config - target: /usr/local/apache2/htdocs/config.js - deploy: - replicas: 1 - placement: - constraints: - - node.role == worker - resources: - limits: - memory: 500M -configs: - config: - external: true - name: worker-time-control_${BRANCH_NAME:?}_config diff --git a/package.json b/package.json index df5aff1..fd39dfd 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "worker-time-control", - "version": "1.0.2", + "version": "24.22.1", "author": "Verdnatura Levante SL", "description": "Verdnatura Time Control", "license": "GPL-3.0",