blob: f5f766b6596687183ae19c101f136c5ba60af16c [file] [log] [blame]
Mohammed Naser99a31652024-02-05 20:02:33 -05001def installDocker() {
2 sh 'curl -fsSL https://get.docker.com | sh'
3 sh 'sudo usermod -aG docker ubuntu'
4}
5
6def installEarthly() {
7 installDocker()
8
9 sh 'curl -fsSL https://github.com/earthly/earthly/releases/latest/download/earthly-linux-amd64 -o /usr/local/bin/earthly'
10 sh 'chmod +x /usr/local/bin/earthly'
11 sh 'earthly bootstrap'
12}
13
Mohammed Naser12207172024-02-05 18:49:35 -050014pipeline {
15 agent none
16
17 options {
18 disableConcurrentBuilds(abortPrevious: true);
19 }
20
21 // TODO: periodic multi-node jobs
22
23 environment {
24 TEST_REGISTRY = "registry.atmosphere.dev:5000/${env.BRANCH_NAME.toLowerCase()}"
25 PROD_REGISTRY = "ghcr.io/vexxhost/atmosphere"
26 REGISTRY = "${env.BRANCH_NAME == 'main' ? PROD_REGISTRY : TEST_REGISTRY}"
27
28 EARTHLY_CI = 'true'
29 EARTHLY_BUILD_ARGS = "REGISTRY=${REGISTRY}"
30 }
31
32 stages {
33 stage('lint') {
34 parallel {
35 stage('ansible-lint') {
36 agent {
Mohammed Naser99a31652024-02-05 20:02:33 -050037 label 'jammy-2c-4g'
Mohammed Naser12207172024-02-05 18:49:35 -050038 }
39
40 steps {
Mohammed Naser99a31652024-02-05 20:02:33 -050041 installEarthly()
Mohammed Naser12207172024-02-05 18:49:35 -050042 sh 'earthly --output +lint.ansible-lint'
43 }
44
45 post {
46 always {
47 junit testResults: 'ansible-lint.xml', allowEmptyResults: true
48 }
49 }
50 }
51
52 stage('helm') {
53 agent {
Mohammed Naser99a31652024-02-05 20:02:33 -050054 label 'jammy-2c-4g'
Mohammed Naser12207172024-02-05 18:49:35 -050055 }
56
57 steps {
Mohammed Naser99a31652024-02-05 20:02:33 -050058 installEarthly()
Mohammed Naser12207172024-02-05 18:49:35 -050059 sh 'earthly --output +lint.helm'
60 }
61
62 post {
63 always {
64 junit testResults: 'output/junit-helm-*.xml', allowEmptyResults: true
65 }
66 }
67 }
68
69 stage('markdownlint') {
70 agent {
Mohammed Naser99a31652024-02-05 20:02:33 -050071 label 'jammy-2c-4g'
Mohammed Naser12207172024-02-05 18:49:35 -050072 }
73
74 steps {
Mohammed Naser99a31652024-02-05 20:02:33 -050075 installEarthly()
Mohammed Naser12207172024-02-05 18:49:35 -050076 sh 'earthly --output +lint.markdownlint'
77 }
78
79 post {
80 always {
81 junit testResults: 'junit.xml', allowEmptyResults: true
82 }
83 }
84 }
85
86 stage('image-manifest') {
87 agent {
Mohammed Naser99a31652024-02-05 20:02:33 -050088 label 'jammy-2c-4g'
Mohammed Naser12207172024-02-05 18:49:35 -050089 }
90
91 steps {
Mohammed Naser99a31652024-02-05 20:02:33 -050092 installEarthly()
Mohammed Naser12207172024-02-05 18:49:35 -050093 sh 'earthly +lint.image-manifest'
94 }
95 }
96 }
97 }
98
99 stage('unit') {
100 parallel {
101 stage('go') {
102 agent {
Mohammed Naser99a31652024-02-05 20:02:33 -0500103 label 'jammy-2c-4g'
Mohammed Naser12207172024-02-05 18:49:35 -0500104 }
105
106 steps {
Mohammed Naser99a31652024-02-05 20:02:33 -0500107 installEarthly()
Mohammed Naser12207172024-02-05 18:49:35 -0500108 sh 'earthly --output +unit.go'
109 }
110
111 post {
112 always {
113 junit 'junit-go.xml'
114 }
115 }
116 }
117 }
118 }
119
120 stage('build') {
121 parallel {
122 stage('collection') {
123 agent {
Mohammed Naser99a31652024-02-05 20:02:33 -0500124 label 'jammy-2c-4g'
Mohammed Naser12207172024-02-05 18:49:35 -0500125 }
126
127 steps {
Mohammed Naser99a31652024-02-05 20:02:33 -0500128 installEarthly()
Mohammed Naser12207172024-02-05 18:49:35 -0500129 sh 'earthly --output +build.collection'
130 archiveArtifacts artifacts: 'dist/**'
131 }
132 }
133
134 stage('images') {
135 agent {
136 label 'earthly'
137 }
138
139 steps {
140 script {
141 if (env.BRANCH_NAME == 'main') {
142 docker.withRegistry('https://ghcr.io', 'github-packages-token') {
143 sh 'earthly --push +images'
144 }
145 } else {
146 sh 'earthly --push +images'
147 }
148 }
149
150 sh 'earthly --output +pin-images'
151 sh 'earthly +scan-images'
152 stash name: 'src-with-pinned-images', includes: '**'
153 }
154 }
155
156 stage('docs') {
157 agent {
Mohammed Naser99a31652024-02-05 20:02:33 -0500158 label 'jammy-2c-4g'
Mohammed Naser12207172024-02-05 18:49:35 -0500159 }
160
161 steps {
Mohammed Naser99a31652024-02-05 20:02:33 -0500162 installEarthly()
Mohammed Naser12207172024-02-05 18:49:35 -0500163 sh 'earthly +mkdocs-build'
164 }
165 }
166 }
167 }
168
169 stage('integration') {
170 matrix {
171 axes {
172 axis {
173 name 'NETWORK_BACKEND'
174 values 'openvswitch', 'ovn'
175 }
176 }
177
178 agent {
179 label 'jammy-16c-64g'
180 }
181
182 environment {
183 ATMOSPHERE_DEBUG = "true"
184 ATMOSPHERE_NETWORK_BACKEND = "${NETWORK_BACKEND}"
185 }
186
187 stages {
188 stage('molecule') {
189 steps {
190 // Checkout code with built/pinned images
191 unstash 'src-with-pinned-images'
192
193 // Install dependencies
194 sh 'sudo apt-get install -y git python3-pip'
195 sh 'sudo pip install poetry'
196
197 // Run tests
198 sh 'sudo poetry install --with dev'
199 sh 'sudo --preserve-env=ATMOSPHERE_DEBUG,ATMOSPHERE_NETWORK_BACKEND poetry run molecule test -s aio'
200 }
201 }
202 }
203
204 post {
205 always {
206 // Kubernetes logs
207 sh "sudo ./build/fetch-kubernetes-logs.sh logs/${NETWORK_BACKEND}/kubernetes || true"
208 archiveArtifacts artifacts: 'logs/**', allowEmptyArchive: true
209
210 // JUnit results for Tempest
211 sh "sudo ./build/fetch-junit-xml.sh tempest-${NETWORK_BACKEND}.xml || true"
212 junit "tempest-${NETWORK_BACKEND}.xml"
213 }
214 }
215 }
216 }
217
218 // promote images
219 // release?
220 // todo: manual pin commit to main (avoiding loop)
221 }
222}