-
Notifications
You must be signed in to change notification settings - Fork 77
Back port Jenkinsfile and associated changes to generator/build (3.21) #3494
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,148 @@ | ||
| pipeline { | ||
| agent { label 'CONTAINERS' } | ||
| environment { | ||
| REPOS = "core enterprise nova masterfiles northerntechhq/nt-docs" | ||
| PR_BASE = getPR_BASE() | ||
| DOCS_BRANCH = getDOCS_BRANCH() | ||
| PACKAGE_JOB = "cf-remote" | ||
| PACKAGE_UPLOAD_DIRECTORY = "n/a" | ||
| PACKAGE_BUILD = "n/a" | ||
| } | ||
| parameters { | ||
| string(name: "CORE_REV", defaultValue: '', description: 'used for changelog, examples. Use NUMBER or "pull/NUMBER/merge" for pull request (it\'s merged version, THIS DOESN\'T MERGE THE PR) or "pull/NUMBER/head" to build the docs with the non-merged code. Special syntax \'tag:SOME_TAG\' can be used to use a tag as a revision.') | ||
| string(name: "NOVA_REV", defaultValue: '', description: 'used for changelog. Use NUMBER or "pull/NUMBER/merge" for pull request (it\'s merged version, THIS DOESN\'T MERGE THE PR) or "pull/NUMBER/head" to build the docs with the non-merged code. Special syntax \'tag:SOME_TAG\' can be used to use a tag as a revision.') | ||
| string(name: "ENTERPRISE_REV", defaultValue: '', description: 'used for changelog. Use NUMBER or "pull/NUMBER/merge" for pull request (it\'s merged version, THIS DOESN\'T MERGE THE PR) or "pull/NUMBER/head" to build the docs with the non-merged code. Special syntax \'tag:SOME_TAG\' can be used to use a tag as a revision.') | ||
| string(name: "MASTERFILES_REV", defaultValue: '', description: 'used to document masterfiles. Use NUMBER or "pull/NUMBER/merge" for pull request (it\'s merged version, THIS DOESN\'T MERGE THE PR) or "pull/NUMBER/head" to build the docs with the non-merged code. Special syntax \'tag:SOME_TAG\' can be used to use a tag as a revision.') | ||
| string(name: "DOCS_REV", defaultValue: '', description: 'Use NUMBER or "pull/NUMBER/merge" for pull request (it\'s merged version, THIS DOESN\'T MERGE THE PR) or "pull/NUMBER/head" to build the docs with the non-merged code. Special syntax \'tag:SOME_TAG\' can be used to use a tag as a revision.') | ||
| string(name: "NT_DOCS_REV", defaultValue: '', description: 'Use NUMBER or "pull/NUMBER/merge" for pull request (it\'s merged version, THIS DOESN\'T MERGE THE PR) or "pull/NUMBER/head" to build the docs with the non-merged code. Special syntax \'tag:SOME_TAG\' can be used to use a tag as a revision.') | ||
| string(name: "DOCS_BRANCH", defaultValue: '', description: 'Where to upload artifacts - to http://buildcache.cloud.cfengine.com/packages/build-documentation-$DOCS_BRANCH/ and https://docs.cfengine.com/docs/$DOCS_BRANCH/') | ||
| string(name: "PACKAGE_JOB", defaultValue: 'cf-remote', description: 'where to get CFEngine HUB package from, either a dir at http://buildcache.cloud.cfengine.com/packages like testing-pr or a keyword cf-remote to use cf-remote download') | ||
| string(name: "USE_NIGHTLIES_FOR", defaultValue: '', description: 'branch whose nightlies to use (master, 3.18.x, etc) - will be one of http://buildcache.cloud.cfengine.com/packages/testing-pr/jenkins-$USE_NIGHTLIES_FOR-nightly-pipeline-$NUMBER/') | ||
| } | ||
| options { | ||
| checkoutToSubdirectory('documentation') | ||
| } | ||
| stages { | ||
| stage('Environment check') { | ||
| steps { | ||
| sh 'env' | ||
| sh 'whoami; pwd; ls' | ||
| sh 'uname -a; cat /etc/os-release' | ||
| } | ||
| } | ||
| // we clean FIRST and NOT at the end of the job so that we can replay various stages and have the build result from previous runs | ||
| stage('Clean workspace') { | ||
| steps { | ||
| sh 'for r in $REPOS; do rm -rf "$(basename "$r")"; done' | ||
| } | ||
| } | ||
| stage('Checkout repositories'){ | ||
| steps { | ||
| script { | ||
| if (env.CHANGE_ID) { | ||
| sh "echo \"${pullRequest.title}\" > pull-request-title" | ||
| sh "echo \"${pullRequest.body}\" > pull-request-body" | ||
| } | ||
| } | ||
| sh "curl -O https://raw.githubusercontent.com/cfengine/buildscripts/refs/heads/master/ci/create-revisions-file.sh" | ||
| sh "chmod u+x ./create-revisions-file.sh" | ||
| sh "./create-revisions-file.sh" | ||
| sh "cat revisions" | ||
| sh "curl -O https://gitlab.com/Northern.tech/OpenSource/GODS/-/raw/master/parallel_git_rev_fetch.sh" | ||
| sh "chmod u+x ./parallel_git_rev_fetch.sh" | ||
|
|
||
| withCredentials([sshUserPrivateKey(credentialsId:"autobuild", keyFileVariable: "key")]) { | ||
| sh 'export GIT_SSH_COMMAND="ssh -i $key"; ./parallel_git_rev_fetch.sh revisions' | ||
| } | ||
| } | ||
| } | ||
| stage('Build documentation') { | ||
| steps { | ||
| sh 'bash -x documentation/generator/build/run.sh' | ||
| } | ||
| } | ||
| stage('Publish to buildcache') { | ||
| steps { | ||
| sshPublisher( | ||
| // we must use alwaysPublishFromMaster: true because our CONTAINERS build hosts are not in the private network which has access to buildcache.cloud.cfengine.com | ||
| alwaysPublishFromMaster: true, | ||
| publishers: [ | ||
| sshPublisherDesc( | ||
| configName: 'buildcache.cloud.cfengine.com', | ||
| transfers: [ | ||
| sshTransfer( | ||
| cleanRemote: false, | ||
| excludes: '', | ||
| execCommand: ''' | ||
| #!/usr/bin/env bash | ||
| set -x | ||
| WRKDIR="$(pwd)" | ||
| export WRKDIR | ||
|
|
||
| mkdir -p upload | ||
| mkdir -p output | ||
|
|
||
| # find two tarballs | ||
| archive="$(find upload -name "cfengine-documentation-*.tar.gz")" | ||
| tarball=$(findfind upload -name packed-for-shipping.tar.gz) | ||
| echo "TARBALL: $tarball" | ||
| echo "ARCHIVE: $archive" | ||
|
|
||
| # unpack $tarball | ||
| ( # shubshell to change directories | ||
| cd "$(dirname "$tarball")" || exit | ||
| tar zxvf packed-for-shipping.tar.gz | ||
| rm packed-for-shipping.tar.gz | ||
|
|
||
| # move $archive to the _site | ||
| mv "$WRKDIR/$archive" _site | ||
|
|
||
| ls -la | ||
| ) | ||
|
|
||
| ls -la upload | ||
|
|
||
| # note: this triggers systemd job to AV-scan new files | ||
| # and move them to proper places | ||
| mv upload/* output | ||
| ''', | ||
| execTimeout: 120000, | ||
| flatten: false, | ||
| makeEmptyDirs: false, | ||
| noDefaultExcludes: false, | ||
| patternSeparator: '[, ]+', | ||
| remoteDirectory: getRemoteDirectory(), | ||
| remoteDirectorySDF: false, | ||
| removePrefix: '', | ||
| sourceFiles: 'output/' | ||
| ) // sshTransfer | ||
| ], // transfers | ||
| usePromotionTimestamp: false, | ||
| useWorkspaceInPromotion: false, | ||
| verbose: false | ||
| ) // sshPublisherDesc | ||
| ] // publishers | ||
| ) // sshPublisher | ||
| } // steps | ||
| } // stage('Publish to buildcache') | ||
| } // stages | ||
| } | ||
| def getDOCS_BRANCH() { | ||
| if (env.DOCS_BRANCH) { | ||
| return env.DOCS_BRANCH | ||
| } else if (env.CHANGE_ID) { | ||
| return "${env.CHANGE_TARGET}" | ||
| } else { | ||
| return "${env.BRANCH_NAME}" | ||
| } | ||
| } | ||
| def getPR_BASE() { | ||
| if (env.CHANGE_ID) { | ||
| return "${pullRequest.base}" | ||
| } else { | ||
| return "" | ||
| } | ||
| } | ||
| def getRemoteDirectory() { | ||
| return "upload/${env.BUILD_TAG}/build-documentation-${env.DOCS_BRANCH}/${env.BUILD_TAG}/" | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,13 +9,22 @@ if [ "$#" != 4 ]; then | |
| exit 1 | ||
| fi | ||
|
|
||
| echo "$(basename "$0"): Diagnostic facts about execution environment:" | ||
| echo "======" | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nice |
||
| whoami | ||
| cat /etc/os-release | ||
| free -h | ||
| df -h | ||
| uname -a | ||
| echo "======" | ||
|
|
||
|
|
||
| export BRANCH=$1 | ||
| export PACKAGE_JOB=$2 | ||
| export PACKAGE_UPLOAD_DIRECTORY=$3 | ||
| export PACKAGE_BUILD=$4 | ||
|
|
||
| export JOB_TO_UPLOAD=$PACKAGE_JOB | ||
| export FLAG_FILE_URL="http://buildcache.cfengine.com/packages/$PACKAGE_JOB/$PACKAGE_UPLOAD_DIRECTORY/PACKAGES_HUB_x86_64_linux_ubuntu_22/core-commitID" | ||
| export NO_OUTPUT_DIR=1 | ||
|
|
||
| env | ||
|
|
@@ -64,30 +73,47 @@ test ! -z "$PACKAGE_UPLOAD_DIRECTORY" | |
| test ! -z "$PACKAGE_BUILD" | ||
|
|
||
|
|
||
| echo "Waiting for flag file to appear" | ||
| for i in $(seq 30); do | ||
| if wget -O- "$FLAG_FILE_URL"; then | ||
| break | ||
| fi | ||
| echo "Waiting 10 sec" | ||
| sleep 10 | ||
| done | ||
| # check if flag file is there - if not, script will fail here | ||
| wget -O- "$FLAG_FILE_URL" | ||
|
|
||
| echo "Detecting version" | ||
| HUB_DIR_NAME=PACKAGES_HUB_x86_64_linux_ubuntu_22 | ||
| HUB_DIR_URL="http://buildcache.cfengine.com/packages/$PACKAGE_JOB/$PACKAGE_UPLOAD_DIRECTORY/$HUB_DIR_NAME/" | ||
| HUB_PACKAGE_NAME="$(wget "$HUB_DIR_URL" -O- | sed '/\.deb/!d;s/.*"\([^"]*\.deb\)".*/\1/')" | ||
|
|
||
| fetch_file "$HUB_DIR_URL$HUB_PACKAGE_NAME" "cfengine-nova-hub.deb" 12 | ||
| echo "Install hub package" | ||
| if [ "$PACKAGE_JOB" = "cf-remote" ]; then | ||
| echo "Install using cf-remote" | ||
| sudo apt update -y | ||
| sudo apt install -y python3-venv pipx | ||
| pipx install cf-remote | ||
| export PATH="$HOME/.local/bin:$PATH" | ||
| # shellcheck source=/dev/null | ||
| source /etc/os-release | ||
| rm -rf ~/.cfengine/cf-remote/packages # to ensure we only get one | ||
| # in case of LTS branches like 3.21 (without .x since we are in documentation repo) need to add on .x | ||
| if [ "$(expr "$BRANCH" : ".*.x")" = 0 ]; then | ||
| if [ "$BRANCH" = "master" ]; then | ||
| _VERSION=master | ||
| else | ||
| _VERSION="$BRANCH".x | ||
| fi | ||
| else | ||
| _VERSION="$BRANCH" # in case someone copy/pastes this to a repo besides documentation | ||
| fi | ||
| cf-remote --version "$_VERSION" download "${ID}$(echo "${VERSION_ID}" | cut -d. -f1)" hub "$(uname -m)" | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. cool |
||
| find "$HOME/.cfengine" # debug | ||
| find "$HOME/.cfengine" -name '*.deb' -print0 | xargs -0 -I{} cp {} cfengine-nova-hub.deb | ||
| else | ||
| echo "Installing with old-style fetch_file function" | ||
| HUB_DIR_NAME=PACKAGES_HUB_x86_64_linux_ubuntu_22 | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should ubuntu and 22 here come from os_release vars?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. well, this part is the as-is/as-was portion so left the same. It could. |
||
| HUB_DIR_URL="http://buildcache.cfengine.com/packages/$PACKAGE_JOB/$PACKAGE_UPLOAD_DIRECTORY/$HUB_DIR_NAME/" | ||
| HUB_PACKAGE_NAME="$(wget "$HUB_DIR_URL" -O- | sed '/\.deb/!d;s/.*"\([^"]*\.deb\)".*/\1/')" | ||
|
|
||
| fetch_file "$HUB_DIR_URL$HUB_PACKAGE_NAME" "cfengine-nova-hub.deb" 12 | ||
| fi | ||
|
|
||
| sudo apt-get -y purge cfengine-nova-hub || true | ||
| sudo rm -rf /*/cfengine | ||
|
|
||
| # unpack | ||
| # we unpack the hub package instead of installing to get around trouble with the package trying to start up services in a container which doesn't work all that well (yet, 2025) | ||
| sudo dpkg --unpack cfengine-nova-hub.deb | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🤯 TIL |
||
| rm cfengine-nova-hub.deb | ||
|
|
||
| # TODO: why copy the masterfiles from the package over the top of one we checked out which could have changes from a PR? | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, that wouldn't seem to make sense. |
||
| sudo cp -a /var/cfengine/share/NovaBase/masterfiles "$WRKDIR" | ||
| sudo chmod -R a+rX "$WRKDIR"/masterfiles | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,8 +3,9 @@ | |
| set -ex | ||
| trap "echo FAILURE" ERR | ||
|
|
||
| if ! buildah inspect docs-revamp-22 >/dev/null 2>&1; then | ||
| buildah build-using-dockerfile -t docs-revamp-22 documentation/generator/build | ||
| image_name=docs-revamp-22 | ||
| if ! buildah inspect "$image_name" >/dev/null 2>&1; then | ||
| buildah build-using-dockerfile -t "$image_name" documentation/generator/build | ||
| fi | ||
|
|
||
| # Current path must have the following repos cloned: | ||
|
|
@@ -14,13 +15,23 @@ fi | |
| # * masterfiles (used to document masterfies) | ||
| # * documentation (this repo) | ||
|
|
||
| # These env vars must be defined: | ||
| true "${BRANCH?undefined}" | ||
| # The PACKAGE* vars are not needed for fast-build jobs as they use cf-remote --version $BRANCH install | ||
| # We still require them to have a value but by current convention (until cf-remote --version testing-pr-build-number works) we set them to cf-remote in documentation/Jenkinsfile | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. that's going to be nice. |
||
| true "${PACKAGE_JOB?undefined}" | ||
| true "${PACKAGE_UPLOAD_DIRECTORY?undefined}" | ||
| true "${PACKAGE_BUILD?undefined}" | ||
|
|
||
| c=$(buildah from -v "$PWD":/nt docs-revamp-22) | ||
| # figure out BRANCH from jenkins environment variables | ||
| if [ -n "$PR_BASE" ]; then | ||
| # PR_BASE comes from documentation/Jenkinsfile and ${pullRequest.base} | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. thank you for examples. |
||
| BRANCH="$PR_BASE" | ||
| elif [ -n "$BRANCH_NAME" ]; then | ||
| # jenkins, for pull requests this will be e.g. PR-<number> so not used | ||
| # for non-pull reqeusts this will be master, 3.24.x, etc | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
| BRANCH="$BRANCH_NAME" | ||
| fi | ||
|
|
||
| c=$(buildah from -v "$PWD":/nt "$image_name") | ||
| trap 'buildah run "$c" bash -c "sudo chown -R root:root /nt; sudo chmod -R a+rwX /nt"; buildah rm "$c" >/dev/null' EXIT | ||
| buildah run "$c" bash -x documentation/generator/build/main.sh "$BRANCH" "$PACKAGE_JOB" "$PACKAGE_UPLOAD_DIRECTORY" "$PACKAGE_BUILD" | ||
| buildah run "$c" bash -x documentation/generator/_scripts/_publish.sh "$BRANCH" | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍