diff --git a/Jenkinsfile b/Jenkinsfile index 60327d9141b9db072259c5267e8fbd5765ea8fb8..94f0060dd684c28ef2c38757b47d0e7b85e1d96b 100755 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -26,6 +26,42 @@ def helmBuildAndPushToRegistry( } } +def prompt(msg) { + try{ + timeout(time: 24, unit: 'SECONDS') { + try { + input msg + echo "User gave approval" + return true + } catch (ignored) { + echo "User pressed NO" + return false + } + } + } catch (ignored){ + echo "Nothing is pressed and prompt timed out" + return false + } +} + +def deploy(String fluxRepo){ + withCredentials([usernamePassword(credentialsId: 'nynjaci-github-push-token', + usernameVariable:'GIT_USERNAME', + passwordVariable:'GIT_PASSWORD')]) { + sh 'git clone https://${GIT_USERNAME}:${GIT_PASSWORD}@github.com/NYNJA-MC/flux-deploy-'+fluxRepo + dir( "flux-deploy-"+fluxRepo) { + sh 'ls -l' + sh 'sed -i "0,/tag:/ s/tag.*/tag: $IMAGE_BUILD_TAG.'+gitHash+'/" releases/callconf/callconf.yaml' + sh "git add releases/callconf/callconf.yaml" + + sh 'git config --global push.default simple' + sh 'git config --global user.email "ci@nynja.biz"' + sh 'git config --global user.name "Nynja CI"' + sh 'git commit -m "Updated $APP_NAME tag to $IMAGE_BUILD_TAG."' + gitHash + sh "git push https://${GIT_USERNAME}:${GIT_PASSWORD}@github.com/NYNJA-MC/flux-deploy-"+fluxRepo+" @:master" + } + } +} pipeline { environment { @@ -139,7 +175,6 @@ pipeline { stage('Create image') { steps { container('calling') { - sh "/usr/bin/docker build -t $IMAGE_NAME:$IMAGE_BUILD_TAG."+gitHash+" -t $IMAGE_NAME:$IMAGE_TAG -f components/focus/Dockerfile ." withCredentials([file(credentialsId: 'jenkins-gcr-publisher', variable: 'KEY_FILE')]) { sh 'docker login -u _json_key -p "$(cat $KEY_FILE)" https://eu.gcr.io' @@ -153,31 +188,21 @@ pipeline { sh "docker push $IMAGE_NAME-history:$IMAGE_TAG" } } - timeout(time: 24, unit: 'HOURS') { input 'Deploy to staging ?' } } - post { failure { echo 'Deploy to staging aborted' }} + } + stage('Deploy updated image on dev') { + when { not { branch 'production'}} + steps{ container('calling'){ deploy("dev") } } } stage('Deploy updated image on staging') { - steps{ - container('calling') { - withCredentials([usernamePassword(credentialsId: 'nynjaci-github-push-token', usernameVariable:'GIT_USERNAME', passwordVariable:'GIT_PASSWORD')]) { - sh 'git clone https://${GIT_USERNAME}:${GIT_PASSWORD}@github.com/NYNJA-MC/flux-deploy-staging' - dir( "flux-deploy-staging"){ - - sh 'ls -l' - sh 'sed -i "0,/tag:/ s/tag.*/tag: $IMAGE_BUILD_TAG.'+gitHash+'/" releases/callconf/callconf.yaml' - sh "git add releases/callconf/callconf.yaml" - - sh 'git config --global push.default simple' - sh 'git config --global user.email "ci@nynja.biz"' - sh 'git config --global user.name "Nynja CI"' - sh 'git commit -m "Updated $APP_NAME tag to $IMAGE_BUILD_TAG."' + gitHash - sh "git push https://${GIT_USERNAME}:${GIT_PASSWORD}@github.com/NYNJA-MC/flux-deploy-staging @:master" - } - } - } - } + when { branch 'production' + expression {prompt('Deploy to staging?')}} + steps{ container('calling') { deploy("staging") } } + } + stage('Deploy updated image on prod') { + when { branch 'production' + expression {prompt('Deploy to PROD?')} } + steps{ container('calling') { deploy("prod") } } } - } } diff --git a/lib/vertx-util/src/main/java/com/nynjacoin/nccs/lib/vertxutil/restclient/RetryExecutor.java b/lib/vertx-util/src/main/java/com/nynjacoin/nccs/lib/vertxutil/restclient/RetryExecutor.java index 0d4925561a6c32d16ae622998283567275a5ec51..bfd5646fe0bb11e30841e3e4a63f78a0356fd03c 100644 --- a/lib/vertx-util/src/main/java/com/nynjacoin/nccs/lib/vertxutil/restclient/RetryExecutor.java +++ b/lib/vertx-util/src/main/java/com/nynjacoin/nccs/lib/vertxutil/restclient/RetryExecutor.java @@ -1,5 +1,6 @@ package com.nynjacoin.nccs.lib.vertxutil.restclient; +import com.nynjacoin.nccs.lib.util.UuidGenerator; import io.vertx.core.AsyncResult; import io.vertx.core.Future; import io.vertx.core.Handler; @@ -10,6 +11,7 @@ import io.vertx.ext.web.client.HttpRequest; import io.vertx.ext.web.client.HttpResponse; import io.vertx.ext.web.codec.BodyCodec; import java.util.Objects; +import org.apache.logging.log4j.Level; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -84,7 +86,21 @@ public class RetryExecutor { return response; } + private static final Level BODY_LOG_LEVEL = Level.DEBUG; + + private void execute( + HttpRequest request, + JsonObject body, + Future response, + int retries) { + + String requestId = UuidGenerator.generate(); + LOGGER.log(BODY_LOG_LEVEL, "{}: sending {}", requestId, body); + execute(requestId, request, body, response, retries); + } + private void execute( + String requestId, HttpRequest request, JsonObject body, Future response, @@ -92,11 +108,12 @@ public class RetryExecutor { Handler>> handler = ar -> { if (isOk(ar)) { + LOGGER.debug("{}: OK", requestId); response.complete(ar.result().body()); return; } if (retries < maxRetries && mustRetry(ar)) { - LOGGER.warn("Retriable failure to {}: {}", request, getError(ar)); + LOGGER.warn("{}: retryable failure: {}", requestId, getError(ar)); int newRetries = retries + 1; long retryAfter = retryMilliseconds * newRetries; vertx.setTimer( @@ -105,7 +122,10 @@ public class RetryExecutor { ); } else { Throwable t = getThrowable(ar); - LOGGER.error("Failure to {}: {}", request.toString(), t.getMessage()); + if (BODY_LOG_LEVEL.isLessSpecificThan(LOGGER.getLevel())) { + LOGGER.debug("{}: failed to send {}", requestId, body); + } + LOGGER.error("{}: FAILURE: {}", requestId, t.getMessage()); response.fail(t); } };