From 5775103aeda4d445139442481a476746a15b9fb2 Mon Sep 17 00:00:00 2001 From: Miguel Arias Date: Fri, 17 Oct 2025 11:56:37 +0100 Subject: [PATCH] FDN-0000: apibuilder generator moving to argo --- Jenkinsfile | 138 +++++++++++---------------- deploy/apibuilder-generator/app.yaml | 71 ++++++++++++++ 2 files changed, 127 insertions(+), 82 deletions(-) create mode 100644 deploy/apibuilder-generator/app.yaml diff --git a/Jenkinsfile b/Jenkinsfile index d93e5ea3..99cfd57a 100755 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,94 +1,68 @@ -properties([pipelineTriggers([githubPush()])]) +@Library('lib-jenkins-pipeline') _ -pipeline { - options { - disableConcurrentBuilds() - buildDiscarder(logRotator(numToKeepStr: '10')) - timeout(time: 30, unit: 'MINUTES') - } - agent { - kubernetes { - label 'worker-apibuilder-generator' - inheritFrom 'kaniko-slim' - } - } +// => Mandatory to use a definition before the node or Blue Ocean doesn't show the expected info +def newTagEveryRunMainBranch = "yes" // Force a new version and deploy clicking on Build Now in Jenkins +def sbtOnMain = "no" - environment { - ORG = 'flowcommerce' - } - - stages { - stage('Checkout') { - steps { - checkoutWithTags scm - - script { - VERSION = new flowSemver().calculateSemver() //requires checkout - } +// we can remove the pod_template block if we end up having only one template +// in jenkins config +// +String podLabel = "Jenkinsfile-apibuilder-generator" +podTemplate( + label: "${podLabel}", + inheritFrom : 'generic' +){ + node(podLabel) { + try { + checkoutWithTags scm + //Checkout the code from the repository + stage('Checkout') { + echo "Checking out branch: ${env.BRANCH_NAME}" + checkout scm } - } - stage('Commit SemVer tag') { - when { branch 'main' } - steps { - script { - new flowSemver().commitSemver(VERSION) - } + // => tagging function to identify what actions to take depending on the nature of the changes + stage ('tagging') { + semversion = taggingv2(newTagEveryMainRun: "${newTagEveryRunMainBranch}") + println(semversion) } - } - stage('Build and push docker image release') { - when { branch 'main' } - steps { - container('kaniko') { - script { - semver = VERSION.printable() - - sh """ - /kaniko/executor -f `pwd`/Dockerfile -c `pwd` \ - --snapshot-mode=redo --use-new-run \ - --destination ${env.ORG}/apibuilder-generator:$semver - """ - - } - } - } - } + // => Running the actions for each component in parallel + checkoutWithTags scm - stage('Display Helm Diff') { - when { - allOf { - not { branch 'main' } - changeRequest() - expression { - return changesCheck.hasChangesInDir('deploy') - } - } + String jsondata = ''' + [{"serviceName": "apibuilder-generator", + "dockerImageName": "apibuilder-generator", + "dockerFilePath" : "/Dockerfile", + "multiplatforms": "no"}] + ''' + withCredentials([string(credentialsId: "jenkins-argocd-token", variable: 'ARGOCD_AUTH_TOKEN')]) { + mainJenkinsBuildArgo( + semversion: "${semversion}", + pgImage: "flowcommerce/bentest-postgresql:latest", + componentargs: "${jsondata}", + sbtOnMain: "${sbtOnMain}" + // => optional + //orgName: "flowvault" + // SBT test + //sbtCommand: 'sbt clean flowLint coverage test scalafmtSbtCheck scalafmtCheck doc', + //playCpuLimit: "2", + //playMemoryRequest: "4Gi", + //pgCpuLimit: "1", + //pgMemoryRequest: "2Gi", + //sbtTestInMain: "${sbtOnMain}" + ) } - steps { - script { - container('helm') { - new helmDiff().diff('apibuilder-generator') - } - } - } - } - stage('Deploy Helm chart') { - when { branch 'main' } - parallel { - - stage('deploy apibuilder-generator') { - steps { - script { - container('helm') { - new helmCommonDeploy().deploy('apibuilder-generator', 'apicollective', VERSION.printable(), 420) - } - } - } - } - } + } catch (Exception e) { + // In case of an error, mark the build as failure + currentBuild.result = 'FAILURE' + throw e + } finally { + // Always clean up workspace and notify if needed + cleanWs() + echo "Pipeline execution finished" } } -} +} \ No newline at end of file diff --git a/deploy/apibuilder-generator/app.yaml b/deploy/apibuilder-generator/app.yaml new file mode 100644 index 00000000..b94eb8c9 --- /dev/null +++ b/deploy/apibuilder-generator/app.yaml @@ -0,0 +1,71 @@ +apiVersion: argoproj.io/v1alpha1 +kind: Application +metadata: + name: apibuilder-generator + namespace: argocd + finalizers: + - resources-finalizer.argocd.argoproj.io +spec: + destination: + namespace: apicollective + server: 'https://kubernetes.default.svc' + ignoreDifferences: + - group: networking.istio.io + kind: VirtualService + jsonPointers: + - /spec/http/0 + - group: datadoghq.com + kind: DatadogMonitor + jqPathExpressions: + - .spec.tags + # Required if enable KEDA autoscaler to avoid conflicts between + # ArgoCD and HPA managing the number of replicas + - group: "apps" + kind: "Deployment" + jsonPointers: + - /spec/replicas + - group: argoproj.io + kind: Rollout + jsonPointers: + - /spec/replicas + # Ignore cluster IP changes + - group: "" + kind: Service + jsonPointers: + - /spec/clusterIP + #This is a common issue with Argo Rollouts and Istio DestinationRule resources. + #The rollouts-pod-template-hash label is automatically managed + #by the Argo Rollouts controller and gets added dynamically during rollout operations + - group: networking.istio.io + kind: DestinationRule + jqPathExpressions: + - .spec.subsets[].labels["rollouts-pod-template-hash"] + ################################### + sources: + - repoURL: 'git@github.com:flowcommerce/generic-charts.git' + path: charts/flow-generic + targetRevision: v2.0.0 + helm: + parameters: + - name: deployments.live.version + value: "0.10.48" + valueFiles: + - $values/deploy/apibuilder-generator/values.yaml + - repoURL: 'git@github.com:apicollective/apibuilder-generator.git' + targetRevision: main + ref: values + + project: production + + ## Keep it commenting out during the transition process to avoid auto + ## sync applying changes automatically until transition is completed. + syncPolicy: + syncOptions: + - RespectIgnoreDifferences=true + - CreateNamespace=false # Namespace exists + - ApplyOutOfSyncOnly=true # Only sync out-of-sync resources + - ServerSideApply=true # Use server-side apply + - PruneLast=true # Prune after successful sync + automated: + prune: true + selfHeal: true