Mohammed Naser | 1220717 | 2024-02-05 18:49:35 -0500 | [diff] [blame^] | 1 | pipeline { |
| 2 | agent none |
| 3 | |
| 4 | options { |
| 5 | disableConcurrentBuilds(abortPrevious: true); |
| 6 | } |
| 7 | |
| 8 | // TODO: periodic multi-node jobs |
| 9 | |
| 10 | environment { |
| 11 | TEST_REGISTRY = "registry.atmosphere.dev:5000/${env.BRANCH_NAME.toLowerCase()}" |
| 12 | PROD_REGISTRY = "ghcr.io/vexxhost/atmosphere" |
| 13 | REGISTRY = "${env.BRANCH_NAME == 'main' ? PROD_REGISTRY : TEST_REGISTRY}" |
| 14 | |
| 15 | EARTHLY_CI = 'true' |
| 16 | EARTHLY_BUILD_ARGS = "REGISTRY=${REGISTRY}" |
| 17 | } |
| 18 | |
| 19 | stages { |
| 20 | stage('lint') { |
| 21 | parallel { |
| 22 | stage('ansible-lint') { |
| 23 | agent { |
| 24 | label 'earthly' |
| 25 | } |
| 26 | |
| 27 | steps { |
| 28 | sh 'earthly --output +lint.ansible-lint' |
| 29 | } |
| 30 | |
| 31 | post { |
| 32 | always { |
| 33 | junit testResults: 'ansible-lint.xml', allowEmptyResults: true |
| 34 | } |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | stage('helm') { |
| 39 | agent { |
| 40 | label 'earthly' |
| 41 | } |
| 42 | |
| 43 | steps { |
| 44 | sh 'earthly --output +lint.helm' |
| 45 | } |
| 46 | |
| 47 | post { |
| 48 | always { |
| 49 | junit testResults: 'output/junit-helm-*.xml', allowEmptyResults: true |
| 50 | } |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | stage('markdownlint') { |
| 55 | agent { |
| 56 | label 'earthly' |
| 57 | } |
| 58 | |
| 59 | steps { |
| 60 | sh 'earthly --output +lint.markdownlint' |
| 61 | } |
| 62 | |
| 63 | post { |
| 64 | always { |
| 65 | junit testResults: 'junit.xml', allowEmptyResults: true |
| 66 | } |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | stage('image-manifest') { |
| 71 | agent { |
| 72 | label 'earthly' |
| 73 | } |
| 74 | |
| 75 | steps { |
| 76 | sh 'earthly +lint.image-manifest' |
| 77 | } |
| 78 | } |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | stage('unit') { |
| 83 | parallel { |
| 84 | stage('go') { |
| 85 | agent { |
| 86 | label 'earthly' |
| 87 | } |
| 88 | |
| 89 | steps { |
| 90 | sh 'earthly --output +unit.go' |
| 91 | } |
| 92 | |
| 93 | post { |
| 94 | always { |
| 95 | junit 'junit-go.xml' |
| 96 | } |
| 97 | } |
| 98 | } |
| 99 | } |
| 100 | } |
| 101 | |
| 102 | stage('build') { |
| 103 | parallel { |
| 104 | stage('collection') { |
| 105 | agent { |
| 106 | label 'earthly' |
| 107 | } |
| 108 | |
| 109 | steps { |
| 110 | sh 'earthly --output +build.collection' |
| 111 | archiveArtifacts artifacts: 'dist/**' |
| 112 | } |
| 113 | } |
| 114 | |
| 115 | stage('images') { |
| 116 | agent { |
| 117 | label 'earthly' |
| 118 | } |
| 119 | |
| 120 | steps { |
| 121 | script { |
| 122 | if (env.BRANCH_NAME == 'main') { |
| 123 | docker.withRegistry('https://ghcr.io', 'github-packages-token') { |
| 124 | sh 'earthly --push +images' |
| 125 | } |
| 126 | } else { |
| 127 | sh 'earthly --push +images' |
| 128 | } |
| 129 | } |
| 130 | |
| 131 | sh 'earthly --output +pin-images' |
| 132 | sh 'earthly +scan-images' |
| 133 | stash name: 'src-with-pinned-images', includes: '**' |
| 134 | } |
| 135 | } |
| 136 | |
| 137 | stage('docs') { |
| 138 | agent { |
| 139 | label 'earthly' |
| 140 | } |
| 141 | |
| 142 | steps { |
| 143 | sh 'earthly +mkdocs-build' |
| 144 | } |
| 145 | } |
| 146 | } |
| 147 | } |
| 148 | |
| 149 | stage('integration') { |
| 150 | matrix { |
| 151 | axes { |
| 152 | axis { |
| 153 | name 'NETWORK_BACKEND' |
| 154 | values 'openvswitch', 'ovn' |
| 155 | } |
| 156 | } |
| 157 | |
| 158 | agent { |
| 159 | label 'jammy-16c-64g' |
| 160 | } |
| 161 | |
| 162 | environment { |
| 163 | ATMOSPHERE_DEBUG = "true" |
| 164 | ATMOSPHERE_NETWORK_BACKEND = "${NETWORK_BACKEND}" |
| 165 | } |
| 166 | |
| 167 | stages { |
| 168 | stage('molecule') { |
| 169 | steps { |
| 170 | // Checkout code with built/pinned images |
| 171 | unstash 'src-with-pinned-images' |
| 172 | |
| 173 | // Install dependencies |
| 174 | sh 'sudo apt-get install -y git python3-pip' |
| 175 | sh 'sudo pip install poetry' |
| 176 | |
| 177 | // Run tests |
| 178 | sh 'sudo poetry install --with dev' |
| 179 | sh 'sudo --preserve-env=ATMOSPHERE_DEBUG,ATMOSPHERE_NETWORK_BACKEND poetry run molecule test -s aio' |
| 180 | } |
| 181 | } |
| 182 | } |
| 183 | |
| 184 | post { |
| 185 | always { |
| 186 | // Kubernetes logs |
| 187 | sh "sudo ./build/fetch-kubernetes-logs.sh logs/${NETWORK_BACKEND}/kubernetes || true" |
| 188 | archiveArtifacts artifacts: 'logs/**', allowEmptyArchive: true |
| 189 | |
| 190 | // JUnit results for Tempest |
| 191 | sh "sudo ./build/fetch-junit-xml.sh tempest-${NETWORK_BACKEND}.xml || true" |
| 192 | junit "tempest-${NETWORK_BACKEND}.xml" |
| 193 | } |
| 194 | } |
| 195 | } |
| 196 | } |
| 197 | |
| 198 | // promote images |
| 199 | // release? |
| 200 | // todo: manual pin commit to main (avoiding loop) |
| 201 | } |
| 202 | } |