From f186e002fed3e6f9d074d62242c9a8a125a2d18c Mon Sep 17 00:00:00 2001 From: Cristian Curteanu Date: Wed, 19 Feb 2025 11:45:51 +0200 Subject: [PATCH 1/9] [CBP-9884] - add jenkinsfile and unit tests stage --- Jenkinsfile | 55 +++++++++++++++++++++++++++++++++++++ cbci-templates/fmforci.yaml | 17 ++++++++++++ 2 files changed, 72 insertions(+) create mode 100644 Jenkinsfile create mode 100644 cbci-templates/fmforci.yaml diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000..ca22ee1 --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,55 @@ +pipeline { + agent any + + libraries { + lib('fm-shared-library@main') + }//end libraries. Github Repo: https://github.com/rollout/fm-cbci-shared-library + + options { + // timestamps() + timeout(time: 45, unit: 'MINUTES') + }//end options + + stages { + stage('Checkout') { + steps { + checkout scm + } + } + + stage("Run unit tests"){ + agent { + kubernetes { + label 'unit-test-' + UUID.randomUUID().toString() + inheritFrom 'default' + yamlFile './cbci-templates/fmforci.yaml' + } + } + + steps { + container(name: "server", shell: "bash") { + withCredentials([ + sshUserPrivateKey(credentialsId: 'SDK_E2E_SSH_KEY', keyFileVariable: 'SDK_E2E_SSH_KEY', passphraseVariable: '', usernameVariable: 'cloudbees.eslint@cloudbees.com'), + file(credentialsId: 'ENV_SECRETS', variable: 'ENV_SECRETS_PATH'), + ]) { + addGitHubFingerprint() + echo "====++++executing Run tests++++====" + sh script: 'cd ./v6 && go test ./core/...', + label: "Running unit tests" + } + } + } + post{ + success{ + script { + echo 'Unit Tests OK; posting results' + currentBuild.result = 'SUCCESS' + } + } + failure{ + echo 'Unit Tests Failed;' + } + } + } + } +} diff --git a/cbci-templates/fmforci.yaml b/cbci-templates/fmforci.yaml new file mode 100644 index 0000000..0ec14fd --- /dev/null +++ b/cbci-templates/fmforci.yaml @@ -0,0 +1,17 @@ +apiVersion: v1 +kind: Pod +metadata: + name: fm-rox-go-sdk +spec: + serviceAccountName: ops-gcr-rw + containers: + - name: server + image: golang:alpine + tty: true + resources: + requests: + memory: "4Gi" + cpu: "2000m" + limits: + memory: "4Gi" + cpu: "2000m" From 2b1483e58b1f89fcd63db76a33eef2459c1bd768 Mon Sep 17 00:00:00 2001 From: Cristian Curteanu Date: Mon, 24 Feb 2025 17:34:24 +0200 Subject: [PATCH 2/9] [wip] - move back to sh shell --- Jenkinsfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index ca22ee1..a9418ab 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -27,14 +27,14 @@ pipeline { } steps { - container(name: "server", shell: "bash") { + container(name: "server", shell: "sh") { withCredentials([ sshUserPrivateKey(credentialsId: 'SDK_E2E_SSH_KEY', keyFileVariable: 'SDK_E2E_SSH_KEY', passphraseVariable: '', usernameVariable: 'cloudbees.eslint@cloudbees.com'), file(credentialsId: 'ENV_SECRETS', variable: 'ENV_SECRETS_PATH'), ]) { addGitHubFingerprint() echo "====++++executing Run tests++++====" - sh script: 'cd ./v6 && go test ./core/...', + sh script: 'cd ./v6 && /usr/local/go/bin/go test ./core/...', label: "Running unit tests" } } From 110d45c3e7092df32ab68af10a91d71a4803594c Mon Sep 17 00:00:00 2001 From: Cristian Curteanu Date: Mon, 24 Feb 2025 18:45:11 +0200 Subject: [PATCH 3/9] wip --- Jenkinsfile | 14 ++++++++------ cbci-templates/fmforci.yaml | 2 +- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index a9418ab..50b31db 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -21,7 +21,7 @@ pipeline { agent { kubernetes { label 'unit-test-' + UUID.randomUUID().toString() - inheritFrom 'default' + inheritFrom 'golang' yamlFile './cbci-templates/fmforci.yaml' } } @@ -30,12 +30,14 @@ pipeline { container(name: "server", shell: "sh") { withCredentials([ sshUserPrivateKey(credentialsId: 'SDK_E2E_SSH_KEY', keyFileVariable: 'SDK_E2E_SSH_KEY', passphraseVariable: '', usernameVariable: 'cloudbees.eslint@cloudbees.com'), - file(credentialsId: 'ENV_SECRETS', variable: 'ENV_SECRETS_PATH'), + // file(credentialsId: 'ENV_SECRETS', variable: 'ENV_SECRETS_PATH'), ]) { - addGitHubFingerprint() - echo "====++++executing Run tests++++====" - sh script: 'cd ./v6 && /usr/local/go/bin/go test ./core/...', - label: "Running unit tests" + withEnv(['PATH+GO=$PATH:/usr/local/go/bin']) { + echo "====++++executing Run tests++++====" + sh 'echo "Current PATH: $PATH"' + sh script: 'cd ./v6 && go test ./core/...', + label: "Running unit tests" + } } } } diff --git a/cbci-templates/fmforci.yaml b/cbci-templates/fmforci.yaml index 0ec14fd..5c145af 100644 --- a/cbci-templates/fmforci.yaml +++ b/cbci-templates/fmforci.yaml @@ -6,7 +6,7 @@ spec: serviceAccountName: ops-gcr-rw containers: - name: server - image: golang:alpine + image: golang:1.18 tty: true resources: requests: From c298db3d8b7a461cc3e17cc7f404ee0018b85136 Mon Sep 17 00:00:00 2001 From: Cristian Curteanu Date: Tue, 25 Feb 2025 15:53:56 +0200 Subject: [PATCH 4/9] fix: add e2e tests --- Jenkinsfile | 62 +++++++++++++++++++++++++++++++++++-- cbci-templates/fmforci.yaml | 12 +++++++ 2 files changed, 71 insertions(+), 3 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 50b31db..91a8e76 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -17,7 +17,7 @@ pipeline { } } - stage("Run unit tests"){ + stage("Run Unit tests"){ agent { kubernetes { label 'unit-test-' + UUID.randomUUID().toString() @@ -32,9 +32,8 @@ pipeline { sshUserPrivateKey(credentialsId: 'SDK_E2E_SSH_KEY', keyFileVariable: 'SDK_E2E_SSH_KEY', passphraseVariable: '', usernameVariable: 'cloudbees.eslint@cloudbees.com'), // file(credentialsId: 'ENV_SECRETS', variable: 'ENV_SECRETS_PATH'), ]) { - withEnv(['PATH+GO=$PATH:/usr/local/go/bin']) { + withEnv(["PATH+GO=$PATH:/usr/local/go/bin"]) { echo "====++++executing Run tests++++====" - sh 'echo "Current PATH: $PATH"' sh script: 'cd ./v6 && go test ./core/...', label: "Running unit tests" } @@ -53,5 +52,62 @@ pipeline { } } } + + stage("Run E2E tests"){ + agent { + kubernetes { + label 'e2e-tests-' + UUID.randomUUID().toString() + inheritFrom 'default' + yamlFile './cbci-templates/fmforci.yaml' + } + } + + steps { + container("rox-proxy") { + waitForRoxProxy() + } + + container(name: "server", shell: 'sh') { + withCredentials([ + string(credentialsId: 'TEST_E2E_BEARER', variable: 'TEST_E2E_BEARER'), + sshUserPrivateKey(credentialsId: 'SDK_E2E_SSH_KEY', keyFileVariable: 'SDK_E2E_SSH_KEY', passphraseVariable: '', usernameVariable: 'cloudbees.eslint@cloudbees.com'), + sshUserPrivateKey(credentialsId: 'SDK_E2E_TESTS_DEPLOY_KEY', keyFileVariable: 'SDK_E2E_TESTS_DEPLOY_KEY', passphraseVariable: '', usernameVariable: 'cloudbees.eslint@cloudbees.com'), + ]) { + script { + addGitHubFingerprint() + TESTENVPARAMS = "QA_E2E_BEARER=$TEST_E2E_BEARER API_HOST=https://api.test.rollout.io CD_API_ENDPOINT=https://api.test.rollout.io/device/get_configuration CD_S3_ENDPOINT=https://rox-conf.test.rollout.io/ SS_API_ENDPOINT=https://api.test.rollout.io/device/update_state_store/ SS_S3_ENDPOINT=https://rox-state.test.rollout.io/ CLIENT_DATA_CACHE_KEY=client_data ANALYTICS_ENDPOINT=https://analytic.test.rollout.io/ NOTIFICATIONS_ENDPOINT=https://push.test.rollout.io/sse" + + withEnv(["GIT_SSH_COMMAND=ssh -i ${SDK_E2E_SSH_KEY}", "PATH+GO=$PATH:/usr/local/go/bin"]) { + sh "echo ${TESTENVPARAMS}" + sh script: """ + apt-get update && apt-get install -y curl gnupg + curl -sL https://deb.nodesource.com/setup_lts.x | bash - + apt-get install -y nodejs && npm install -g yarn + + git clone git@github.com:rollout/sdk-end-2-end-tests.git + ls -la + ln -s ${pwd()}/v6/driver ./sdk-end-2-end-tests/drivers/go + cd sdk-end-2-end-tests + yarn install --frozen-lockfile + SDK_LANG=go ${TESTENVPARAMS} NODE_ENV=container yarn test:env + """, label: "Pull SDK end2 tests repository" + }// end withEnv + } + } + } + } + post{ + always{ + echo "====++++always++++====" + } + success{ + echo "====++++Run E2E tests executed successfully++++====" + } + failure{ + echo "====++++Run E2E tests execution failed++++====" + } + + } + } } } diff --git a/cbci-templates/fmforci.yaml b/cbci-templates/fmforci.yaml index 5c145af..aaceb6a 100644 --- a/cbci-templates/fmforci.yaml +++ b/cbci-templates/fmforci.yaml @@ -15,3 +15,15 @@ spec: limits: memory: "4Gi" cpu: "2000m" + - name: rox-proxy + image: rollout/simple-proxy + tty: true + ports: + - containerPort: 8080 + resources: + requests: + memory: "1Gi" + cpu: "1000m" + limits: + memory: "1Gi" + cpu: "1000m" From da211b261fb6b11eace7cccb62b24e8d0a0b05d8 Mon Sep 17 00:00:00 2001 From: Cristian Curteanu Date: Wed, 26 Feb 2025 10:59:22 +0200 Subject: [PATCH 5/9] fix: add condition for end-to-end tests to run on PR merge to master --- Jenkinsfile | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 91a8e76..54de707 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -62,6 +62,10 @@ pipeline { } } + when { + branch 'master' + } + steps { container("rox-proxy") { waitForRoxProxy() @@ -97,14 +101,14 @@ pipeline { } } post{ - always{ - echo "====++++always++++====" - } success{ - echo "====++++Run E2E tests executed successfully++++====" + script { + echo 'E2E Tests OK; posting results' + currentBuild.result = 'SUCCESS' + } } failure{ - echo "====++++Run E2E tests execution failed++++====" + echo 'E2E Tests Failed;' } } From 1e54e7e5172e96039ac65ce4d611656a0f918a0f Mon Sep 17 00:00:00 2001 From: Cristian Curteanu Date: Wed, 26 Feb 2025 11:13:36 +0200 Subject: [PATCH 6/9] fix: cleanup jenkinsfile --- Jenkinsfile | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 54de707..131294a 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -6,7 +6,6 @@ pipeline { }//end libraries. Github Repo: https://github.com/rollout/fm-cbci-shared-library options { - // timestamps() timeout(time: 45, unit: 'MINUTES') }//end options @@ -30,10 +29,9 @@ pipeline { container(name: "server", shell: "sh") { withCredentials([ sshUserPrivateKey(credentialsId: 'SDK_E2E_SSH_KEY', keyFileVariable: 'SDK_E2E_SSH_KEY', passphraseVariable: '', usernameVariable: 'cloudbees.eslint@cloudbees.com'), - // file(credentialsId: 'ENV_SECRETS', variable: 'ENV_SECRETS_PATH'), ]) { withEnv(["PATH+GO=$PATH:/usr/local/go/bin"]) { - echo "====++++executing Run tests++++====" + echo "Executing Run tests" sh script: 'cd ./v6 && go test ./core/...', label: "Running unit tests" } @@ -82,7 +80,7 @@ pipeline { TESTENVPARAMS = "QA_E2E_BEARER=$TEST_E2E_BEARER API_HOST=https://api.test.rollout.io CD_API_ENDPOINT=https://api.test.rollout.io/device/get_configuration CD_S3_ENDPOINT=https://rox-conf.test.rollout.io/ SS_API_ENDPOINT=https://api.test.rollout.io/device/update_state_store/ SS_S3_ENDPOINT=https://rox-state.test.rollout.io/ CLIENT_DATA_CACHE_KEY=client_data ANALYTICS_ENDPOINT=https://analytic.test.rollout.io/ NOTIFICATIONS_ENDPOINT=https://push.test.rollout.io/sse" withEnv(["GIT_SSH_COMMAND=ssh -i ${SDK_E2E_SSH_KEY}", "PATH+GO=$PATH:/usr/local/go/bin"]) { - sh "echo ${TESTENVPARAMS}" + echo "Executing E2E tests" sh script: """ apt-get update && apt-get install -y curl gnupg curl -sL https://deb.nodesource.com/setup_lts.x | bash - @@ -90,7 +88,7 @@ pipeline { git clone git@github.com:rollout/sdk-end-2-end-tests.git ls -la - ln -s ${pwd()}/v6/driver ./sdk-end-2-end-tests/drivers/go + ln -s ./v6/driver ./sdk-end-2-end-tests/drivers/go cd sdk-end-2-end-tests yarn install --frozen-lockfile SDK_LANG=go ${TESTENVPARAMS} NODE_ENV=container yarn test:env From 0672eeb45108fac94f849f7d80c33aad6bc7ede5 Mon Sep 17 00:00:00 2001 From: Cristian Curteanu Date: Wed, 26 Feb 2025 11:32:51 +0200 Subject: [PATCH 7/9] fix: remove GHA workflows --- .github/workflows/e2e_tests.yaml | 50 -------------------------------- .github/workflows/release.yaml | 27 ----------------- .github/workflows/run_tests.yaml | 13 --------- 3 files changed, 90 deletions(-) delete mode 100644 .github/workflows/e2e_tests.yaml delete mode 100644 .github/workflows/release.yaml delete mode 100644 .github/workflows/run_tests.yaml diff --git a/.github/workflows/e2e_tests.yaml b/.github/workflows/e2e_tests.yaml deleted file mode 100644 index 453642f..0000000 --- a/.github/workflows/e2e_tests.yaml +++ /dev/null @@ -1,50 +0,0 @@ -name: E2E tests - -on: - push: - branches: - - master - pull_request: - branches: - - master - -jobs: - build: - - runs-on: macos-12 - - steps: - - uses: actions/checkout@v2 - with: - path: rox-go - - name: Checkout e2e tests - uses: actions/checkout@v2 - with: - repository: rollout/sdk-end-2-end-tests - ref: master - ssh-key: ${{ secrets.SDK_E2E_TESTS_DEPLOY_KEY }} - path: sdk-end-2-end-tests - - name: link driver - working-directory: ./sdk-end-2-end-tests/drivers - run: ln -s $GITHUB_WORKSPACE/rox-go/v5/driver go - - name: build e2e node driver - working-directory: ./sdk-end-2-end-tests/drivers/nodejs - run: | - yarn install --frozen-lockfile - - name: build and run e2e - working-directory: ./sdk-end-2-end-tests - run: | - yarn install --frozen-lockfile - QA_E2E_BEARER=$QA_E2E_BEARER API_HOST=https://api.test.rollout.io CD_API_ENDPOINT=https://api.test.rollout.io/device/get_configuration CD_S3_ENDPOINT=https://rox-conf.test.rollout.io/ SS_API_ENDPOINT=https://api.test.rollout.io/device/update_state_store/ SS_S3_ENDPOINT=https://rox-state.test.rollout.io/ CLIENT_DATA_CACHE_KEY=client_data ANALYTICS_ENDPOINT=https://analytic.test.rollout.io/ NOTIFICATIONS_ENDPOINT=https://push.test.rollout.io/sse SDK_LANG=go NODE_ENV=container yarn test:env - env: - QA_E2E_BEARER: ${{ secrets.QA_E2E_BEARER }} -# TODO: implement EU hosting support -# - name: build and run e2e eu hosting -# working-directory: ./sdk-end-2-end-tests -# run: | -# QA_E2E_BEARER=$QA_EU_E2E_BEARER SDK_LANG=go NODE_ENV=qa HOSTING=eu yarn test:env -# env: -# QA_EU_E2E_BEARER: ${{ secrets.QA_EU_E2E_BEARER }} - - name: Show e2e server driver logs - if: ${{ always() }} - run: cat ./sdk-end-2-end-tests/drivers/go/log_1234.out || echo "no log file" diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml deleted file mode 100644 index 1a46513..0000000 --- a/.github/workflows/release.yaml +++ /dev/null @@ -1,27 +0,0 @@ -name: Release - -on: - push: - tags: - - "v*.*.*" - -jobs: - release: - runs-on: macos-12 - - steps: - - name: Set version - id: vars - uses: battila7/get-version-action@v2 - - - name: Create Release - id: create_release - uses: actions/create-release@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - tag_name: ${{ steps.vars.outputs.version }} - release_name: ${{ steps.vars.outputs.version }} - body: Release ${{ steps.vars.outputs.version }} - draft: false - prerelease: false diff --git a/.github/workflows/run_tests.yaml b/.github/workflows/run_tests.yaml deleted file mode 100644 index a50b4b1..0000000 --- a/.github/workflows/run_tests.yaml +++ /dev/null @@ -1,13 +0,0 @@ -name: Unit Tests - -on: [push] - -jobs: - unit_tests: - runs-on: macos-12 - - steps: - - uses: actions/checkout@v2 - - name: Run tests - run: go test ./core/... - working-directory: ./v5 From 4247ea667c60712558d98af875e091a6220b5a79 Mon Sep 17 00:00:00 2001 From: Cristian Curteanu Date: Fri, 28 Feb 2025 16:43:59 +0200 Subject: [PATCH 8/9] fix: cleanup --- Jenkinsfile | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 131294a..a567c7c 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -19,7 +19,6 @@ pipeline { stage("Run Unit tests"){ agent { kubernetes { - label 'unit-test-' + UUID.randomUUID().toString() inheritFrom 'golang' yamlFile './cbci-templates/fmforci.yaml' } @@ -40,10 +39,7 @@ pipeline { } post{ success{ - script { - echo 'Unit Tests OK; posting results' - currentBuild.result = 'SUCCESS' - } + echo 'Unit Tests OK; posting results' } failure{ echo 'Unit Tests Failed;' @@ -54,7 +50,6 @@ pipeline { stage("Run E2E tests"){ agent { kubernetes { - label 'e2e-tests-' + UUID.randomUUID().toString() inheritFrom 'default' yamlFile './cbci-templates/fmforci.yaml' } @@ -87,8 +82,7 @@ pipeline { apt-get install -y nodejs && npm install -g yarn git clone git@github.com:rollout/sdk-end-2-end-tests.git - ls -la - ln -s ./v6/driver ./sdk-end-2-end-tests/drivers/go + ln -s ${pwd()}/v6/driver/ ${pwd()}/sdk-end-2-end-tests/drivers/go cd sdk-end-2-end-tests yarn install --frozen-lockfile SDK_LANG=go ${TESTENVPARAMS} NODE_ENV=container yarn test:env @@ -100,10 +94,7 @@ pipeline { } post{ success{ - script { - echo 'E2E Tests OK; posting results' - currentBuild.result = 'SUCCESS' - } + echo 'E2E Tests OK; posting results' } failure{ echo 'E2E Tests Failed;' From fc61b4729a86314d5806ea052c347d28740b6e61 Mon Sep 17 00:00:00 2001 From: Cristian Curteanu Date: Tue, 4 Mar 2025 12:30:56 +0200 Subject: [PATCH 9/9] fix: cleanup PATH env variable for all stages --- Jenkinsfile | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index a567c7c..c7df7ee 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -9,6 +9,10 @@ pipeline { timeout(time: 45, unit: 'MINUTES') }//end options + environment { + PATH = "/usr/local/go/bin:${env.PATH}" + } + stages { stage('Checkout') { steps { @@ -29,11 +33,9 @@ pipeline { withCredentials([ sshUserPrivateKey(credentialsId: 'SDK_E2E_SSH_KEY', keyFileVariable: 'SDK_E2E_SSH_KEY', passphraseVariable: '', usernameVariable: 'cloudbees.eslint@cloudbees.com'), ]) { - withEnv(["PATH+GO=$PATH:/usr/local/go/bin"]) { - echo "Executing Run tests" - sh script: 'cd ./v6 && go test ./core/...', - label: "Running unit tests" - } + echo "Executing Run tests" + sh script: 'cd ./v6 && go test ./core/...', + label: "Running unit tests" } } } @@ -74,7 +76,7 @@ pipeline { addGitHubFingerprint() TESTENVPARAMS = "QA_E2E_BEARER=$TEST_E2E_BEARER API_HOST=https://api.test.rollout.io CD_API_ENDPOINT=https://api.test.rollout.io/device/get_configuration CD_S3_ENDPOINT=https://rox-conf.test.rollout.io/ SS_API_ENDPOINT=https://api.test.rollout.io/device/update_state_store/ SS_S3_ENDPOINT=https://rox-state.test.rollout.io/ CLIENT_DATA_CACHE_KEY=client_data ANALYTICS_ENDPOINT=https://analytic.test.rollout.io/ NOTIFICATIONS_ENDPOINT=https://push.test.rollout.io/sse" - withEnv(["GIT_SSH_COMMAND=ssh -i ${SDK_E2E_SSH_KEY}", "PATH+GO=$PATH:/usr/local/go/bin"]) { + withEnv(["GIT_SSH_COMMAND=ssh -i ${SDK_E2E_SSH_KEY}"]) { echo "Executing E2E tests" sh script: """ apt-get update && apt-get install -y curl gnupg @@ -85,7 +87,7 @@ pipeline { ln -s ${pwd()}/v6/driver/ ${pwd()}/sdk-end-2-end-tests/drivers/go cd sdk-end-2-end-tests yarn install --frozen-lockfile - SDK_LANG=go ${TESTENVPARAMS} NODE_ENV=container yarn test:env + SDK_LANG=go ${TESTENVPARAMS} NODE_ENV=container yarn test:env """, label: "Pull SDK end2 tests repository" }// end withEnv }