github.com/anth0d/nomad@v0.0.0-20221214183521-ae3a0a2cad06/.circleci/config.yml (about) 1 version: 2.1 2 3 references: 4 # environment specific references - aim to avoid conflicts 5 go-machine-image: &go_machine_image 6 ubuntu-2004:202111-02 7 go-windows-image: &go_windows_image 8 windows-server-2019-vs2019:stable 9 10 # common references 11 common_envs: &common_envs 12 NOMAD_SLOW_TEST: 1 13 GOTESTSUM_JUNITFILE: /tmp/test-reports/results.xml 14 GOTESTSUM_JSONFILE: /tmp/test-reports/testjsonfile.json 15 # disable implicit git paging. CircleCI runs commands with in a tty 16 # making git assume it's an interactive session. 17 PAGER: cat 18 GIT_PAGER: cat 19 20 commands: 21 install-buf: 22 steps: 23 - run: 24 name: install buf 25 command: | 26 sudo ./scripts/vagrant-linux-priv-buf.sh 27 install-vault: 28 parameters: 29 version: 30 type: string 31 default: 1.2.4 32 steps: 33 - run: 34 name: Install Vault 35 command: | 36 set -x 37 38 case "${OSTYPE}" in 39 linux*) os="linux" ;; 40 darwin*) os="darwin" ;; 41 msys*) os="windows" ;; 42 *) echo "unknown os: ${OSTYPE}"; exit 1 ;; 43 esac 44 45 curl -SL --fail -o /tmp/vault.zip https://releases.hashicorp.com/vault/"<< parameters.version >>"/vault_"<< parameters.version >>"_"${os}"_amd64.zip 46 47 if [[ "${os}" != "windows" ]]; then 48 sudo unzip -d /usr/local/bin /tmp/vault.zip 49 rm -rf /tmp/vault* 50 else 51 rm -rf c:\Windows\vault.exe 52 unzip /tmp/vault.zip -d "/c/Windows" 53 rm -rf /tmp/vault* 54 fi 55 install-consul: 56 parameters: 57 version: 58 type: string 59 default: 1.8.3 60 steps: 61 - run: 62 name: Install Consul << parameters.version >> 63 command: | 64 curl -SL --fail -o /tmp/consul.zip https://releases.hashicorp.com/consul/<< parameters.version >>/consul_<< parameters.version >>_linux_amd64.zip 65 sudo unzip -d /usr/local/bin /tmp/consul.zip 66 rm -rf /tmp/consul* 67 install-golang: 68 parameters: 69 target_directory: 70 type: string 71 default: /usr/local 72 steps: 73 - run: 74 name: Install golang 75 command: | 76 set -x 77 78 echo installing golang ${GOLANG_VERSION} 79 80 case "${OSTYPE}" in 81 linux*) os="linux" ;; 82 darwin*) os="darwin" ;; 83 msys*) os="windows" ;; 84 *) echo "unknown os: ${OSTYPE}"; exit 1 ;; 85 esac 86 87 if [[ "${os}" != "windows" ]] 88 then 89 sudo rm -rf << parameters.target_directory >>/go 90 sudo mkdir -p << parameters.target_directory >> 91 curl -SL --fail -o /tmp/golang.tar.gz https://dl.google.com/go/go${GOLANG_VERSION}.${os}-amd64.tar.gz 92 sudo tar -C << parameters.target_directory >> -xzf /tmp/golang.tar.gz 93 rm -rf /tmp/golang.tar.gz 94 else 95 rm -rf << parameters.target_directory >>/go 96 mkdir -p <<parameters.target_directory >> 97 curl -SL --fail -o /tmp/go.zip https://dl.google.com/go/go${GOLANG_VERSION}.windows-amd64.zip 98 unzip -q -o /tmp/go.zip -d << parameters.target_directory >> 99 rm -rf /tmp/go.zip 100 fi 101 102 install-circleci-local-cli: 103 parameters: 104 version: 105 type: string 106 default: 0.1.5879 107 108 sha256: 109 type: string 110 default: f178ea62c781aec06267017404f87983c87f171fd0e66ef3737916246ae66dd6 111 steps: 112 - run: 113 name: Install CircleCI CLI << parameters.version >> 114 command: | 115 CCI_VERSION="<< parameters.version >>" 116 CCI_SHA256="<< parameters.sha256 >>" 117 118 URL="https://github.com/CircleCI-Public/circleci-cli/releases/download/v${CCI_VERSION}/circleci-cli_${CCI_VERSION}_linux_amd64.tar.gz" 119 120 mkdir -p /tmp/circleci-cli/ 121 curl --fail --show-error --location \ 122 -o /tmp/circleci-cli/cli.tar.gz "${URL}" 123 124 echo "$CCI_SHA256 /tmp/circleci-cli/cli.tar.gz" | sha256sum -c 125 126 tar -xz --strip-components=1 \ 127 -C /tmp/circleci-cli \ 128 -f /tmp/circleci-cli/cli.tar.gz \ 129 "circleci-cli_${CCI_VERSION}_linux_amd64/circleci" 130 131 sudo cp /tmp/circleci-cli/circleci /usr/bin/circleci-local-cli 132 133 circleci-local-cli version 134 run-tests: 135 steps: 136 - run: 137 name: Running Nomad Tests 138 no_output_timeout: 20m 139 command: | 140 if [ -z $GOTEST_PKGS_EXCLUDE ]; 141 then 142 unset GOTEST_PKGS_EXCLUDE 143 else 144 unset GOTEST_PKGS 145 fi 146 147 if [ ! -z $GOTESTARCH ]; then 148 export GOARCH="$GOTESTARCH"; 149 fi 150 151 mkdir -p /tmp/test-reports 152 sudo -E PATH="$GOPATH/bin:/usr/local/go/bin:$PATH" make generate-structs 153 154 if [ ! -z $GOTEST_MOD ]; then 155 sudo -E PATH="$GOPATH/bin:/usr/local/go/bin:$PATH" make test-nomad-module 156 else 157 sudo -E PATH="$GOPATH/bin:/usr/local/go/bin:$PATH" make test-nomad 158 fi 159 160 jobs: 161 test-windows: 162 executor: go-windows 163 164 steps: 165 - run: git config --global core.autocrlf false 166 - checkout 167 - run: 168 name: Setup 169 command: | 170 mkdir -p $GOBIN 171 mkdir -p $GOTESTSUM_PATH 172 - install-golang: 173 target_directory: "c:" 174 - run: 175 name: Show installed Go version 176 command: | 177 export PATH=/c/go/bin:/c/gopath/bin:$PATH 178 go version 179 - install-vault: 180 version: $VAULT_VERSION 181 - run: vault version 182 - run: choco install make 183 - run: 184 name: Install golang dependencies 185 command: | 186 export PATH=/c/go/bin:/c/gopath/bin:$PATH 187 make deps 188 - run: 189 name: Pre-download docker test image 190 command: docker pull docker.mirror.hashicorp.services/hashicorpdev/busybox-windows:server2016-0.1 191 - run: 192 name: Build nomad 193 command: | 194 export PATH=/c/go/bin:/c/gopath/bin:$PATH 195 go build -o $GOBIN\nomad.exe 196 - run: 197 name: Run tests with gotestsum 198 command: | 199 # Only test docker driver tests for now 200 export PATH=/c/go/bin:/c/gopath/bin:$PATH 201 gotestsum --format=short-verbose \ 202 --junitfile $GOTESTSUM_PATH/results.xml \ 203 github.com/hashicorp/nomad/drivers/docker \ 204 github.com/hashicorp/nomad/client/lib/fifo \ 205 github.com/hashicorp/nomad/client/logmon 206 207 - store_test_results: 208 path: c:\tmp\test-reports 209 - store_artifacts: 210 path: c:\tmp\test-reports 211 test-ui: 212 docker: 213 - image: docker.mirror.hashicorp.services/circleci/node:14-browsers 214 environment: 215 # See https://git.io/vdao3 for details. 216 JOBS: 2 217 steps: 218 - checkout 219 - restore_cache: 220 keys: 221 - v3-deps-{{ checksum "ui/yarn.lock" }} 222 - run: 223 name: yarn install 224 command: cd ui && yarn install --frozen-lockfile 225 - save_cache: 226 key: v3-deps-{{ checksum "ui/yarn.lock" }} 227 paths: 228 - ./ui/node_modules 229 - run: 230 name: lint:js 231 command: cd ui && yarn run lint:js 232 - run: 233 name: lint:hbs 234 command: cd ui && yarn run lint:hbs 235 - run: 236 name: Ember tests 237 command: mkdir -p /tmp/test-reports && cd ui && yarn test 238 - store_test_results: 239 path: /tmp/test-reports 240 - store_artifacts: 241 path: /tmp/test-reports 242 test-machine: 243 executor: "<< parameters.executor >>" 244 parameters: 245 test_packages: 246 type: string 247 default: "" 248 test_module: 249 type: string 250 default: "" 251 exclude_packages: 252 type: string 253 default: "" 254 executor: 255 type: string 256 default: "go-machine" 257 goarch: 258 type: string 259 default: "amd64" 260 enable_race_testing: 261 type: boolean 262 default: false 263 environment: 264 GOTEST_PKGS_EXCLUDE: "<< parameters.exclude_packages >>" 265 GOTEST_PKGS: "<< parameters.test_packages >>" 266 GOTEST_MOD: "<< parameters.test_module >>" 267 GOTESTARCH: "<< parameters.goarch >>" 268 ENABLE_RACE: "<<# parameters.enable_race_testing >>TRUE<</ parameters.enable_race_testing >>" 269 steps: 270 - checkout 271 - install-golang 272 - install-buf 273 - install-consul 274 - install-vault 275 - run: 276 name: Install 32bit gcc libs 277 command: | 278 if [ ! -z $GOTESTARCH ] && [ $GOTESTARCH == "386" ]; then 279 sudo apt-get update 280 sudo apt-get install -y gcc-multilib 281 else 282 echo "Skipping 32bit lib installation while building for not 386" 283 fi 284 - run: PATH="$GOPATH/bin:/usr/local/go/bin:$PATH" make bootstrap 285 - run-tests 286 - store_test_results: 287 path: /tmp/test-reports 288 - store_artifacts: 289 path: /tmp/test-reports 290 test-e2e: 291 executor: go 292 steps: 293 - checkout 294 - run: apt-get update; apt-get install -y sudo unzip 295 # e2e tests require privileged mount/umount permissions when running as root 296 # TODO: switch to using machine executor and run as root to test e2e path 297 - run: 298 name: prepare non-root user 299 command: | 300 groupadd --gid 3434 circleci 301 useradd --uid 3434 --gid circleci --shell /bin/bash --create-home circleci 302 echo 'circleci ALL=NOPASSWD: ALL' >> /etc/sudoers.d/50-circleci 303 echo 'Defaults env_keep += "DEBIAN_FRONTEND"' >> /etc/sudoers.d/env_keep 304 chown -R circleci:circleci /go 305 306 # configure git and ssh for the user 307 cp -r ~/.ssh /home/circleci/.ssh 308 chown -R circleci:circleci /home/circleci/.ssh 309 sudo -H -u circleci git config --global url."ssh://git@github.com".insteadOf "https://github.com" 310 311 - run: sudo -E -H -u circleci PATH=${PATH} make deps 312 - run: sudo -E -H -u circleci PATH=${PATH} make integration-test 313 - run: sudo -E -H -u circleci PATH=${PATH} make e2e-test 314 test-container: 315 executor: go 316 parameters: 317 test_packages: 318 type: string 319 default: "" 320 exclude_packages: 321 type: string 322 default: "" 323 goarch: 324 type: string 325 default: "amd64" 326 environment: 327 GOTEST_PKGS: "<< parameters.test_packages >>" 328 GOTEST_PKGS_EXCLUDE: "<< parameters.exclude_packages >>" 329 GOTESTARCH: "<< parameters.goarch >>" 330 steps: 331 - checkout 332 - run: apt-get update; apt-get install -y shellcheck sudo unzip 333 - run: make deps 334 - install-buf 335 - install-consul 336 - install-vault 337 - run-tests 338 - store_test_results: 339 path: /tmp/test-reports 340 - store_artifacts: 341 path: /tmp/test-reports 342 lint-go: 343 executor: go 344 steps: 345 - checkout 346 - run: apt-get update; apt-get install -y shellcheck sudo unzip 347 - install-buf 348 - install-circleci-local-cli 349 - run: make deps lint-deps 350 - run: make check 351 - run: make checkscripts 352 - run: mkdir -p ui/dist && make generate-all static-assets 353 build-darwin-binaries: 354 executor: go-macos 355 steps: 356 - checkout 357 - run: 358 name: configure PATH 359 command: 360 echo 'export PATH="${GOPATH}/bin:${HOME}/goinstall/go/bin:$PATH"' >> ${BASH_ENV} 361 362 - install-golang: 363 target_directory: ~/goinstall 364 - run: source ${BASH_ENV} && make deps 365 - run: PATH="$GOPATH/bin:${HOME}/goinstall/go/bin:$PATH" make generate-structs 366 367 - run: 368 name: prepare ui cache 369 command: git log -n 1 --pretty=format:%H ui > /tmp/ui-sha 370 371 - restore_cache: 372 name: restore compiled ui assets 373 keys: 374 - v1-binary-ui-assets-darwin-{{ checksum "/tmp/ui-sha" }} 375 - run: 376 name: prepare ui 377 command: | 378 if [[ -f ~/caches/ui-assets/bindata_assetfs.go ]]; then 379 cp ~/caches/ui-assets/bindata_assetfs.go ./command/agent/bindata_assetfs.go 380 exit 0 381 fi 382 383 ./scripts/vagrant-linux-unpriv-ui.sh 384 385 export PATH="$GOPATH/bin:/usr/local/go/bin:$PATH" 386 387 source ${BASH_ENV} 388 . ~/.nvm/nvm.sh 389 cd ui && yarn install --frozen-lockfile && cd .. 390 JOBS=2 make ember-dist static-assets 391 392 mkdir -p ~/caches/ui-assets 393 cp ./command/agent/bindata_assetfs.go ~/caches/ui-assets/bindata_assetfs.go 394 - save_cache: 395 name: save compiled ui assets 396 key: v1-binary-ui-assets-darwin-{{ checksum "/tmp/ui-sha" }} 397 paths: 398 - ~/caches/ui-assets 399 - run: 400 name: build binaries 401 command: | 402 source ${BASH_ENV} 403 export GO_TAGS="ui $(grep -e '^GO_TAGS ?=' ./GNUmakefile | cut -d= -f2)" 404 make pkg/darwin_amd64.zip 405 - store_artifacts: 406 path: pkg/darwin_amd64.zip 407 destination: /builds/nomad_darwin_amd64.zip 408 build-binaries: 409 executor: go 410 steps: 411 - checkout 412 - run: apt-get update; apt-get install -y sudo unzip zip 413 - run: make deps 414 - install-buf 415 - run: sudo -E PATH="$GOPATH/bin:/usr/local/go/bin:$PATH" make generate-structs 416 417 - run: 418 name: prepare ui cache 419 command: git log -n 1 --pretty=format:%H ui > /tmp/ui-sha 420 421 - restore_cache: 422 name: restore compiled ui assets 423 keys: 424 - v1-binary-ui-assets-linux-{{ checksum "/tmp/ui-sha" }} 425 - run: 426 name: prepare ui 427 command: | 428 if [[ -f /tmp/ui-assets/bindata_assetfs.go ]]; then 429 cp /tmp/ui-assets/bindata_assetfs.go ./command/agent/bindata_assetfs.go 430 exit 0 431 fi 432 433 ./scripts/vagrant-linux-unpriv-ui.sh 434 435 export PATH="$HOME/.yarn/bin:$HOME/.config/yarn/global/node_modules/.bin:$PATH" 436 export PATH="$GOPATH/bin:/usr/local/go/bin:$PATH" 437 . ~/.nvm/nvm.sh 438 cd ui && yarn install --frozen-lockfile && cd .. 439 JOBS=2 make ember-dist static-assets 440 441 mkdir -p /tmp/ui-assets 442 cp ./command/agent/bindata_assetfs.go /tmp/ui-assets/bindata_assetfs.go 443 444 - save_cache: 445 name: save compiled ui assets 446 key: v1-binary-ui-assets-linux-{{ checksum "/tmp/ui-sha" }} 447 paths: 448 - /tmp/ui-assets 449 - run: 450 name: build binaries 451 command: | 452 export GO_TAGS="ui $(grep -e '^GO_TAGS ?=' ./GNUmakefile | cut -d= -f2)" 453 make pkg/windows_amd64.zip pkg/linux_amd64.zip 454 - store_artifacts: 455 path: pkg 456 destination: /builds 457 - store_artifacts: 458 path: /tmp/ui-assets 459 destination: /ui-assets 460 executors: 461 go: 462 working_directory: /go/src/github.com/hashicorp/nomad 463 docker: 464 - image: docker.mirror.hashicorp.services/golang:1.19.3 465 resource_class: medium 466 environment: 467 <<: *common_envs 468 GOPATH: /go 469 470 go-machine: 471 working_directory: ~/go/src/github.com/hashicorp/nomad 472 machine: 473 image: *go_machine_image 474 resource_class: large 475 environment: &machine_env 476 <<: *common_envs 477 GOLANG_VERSION: 1.19.3 478 479 go-macos: 480 working_directory: ~/go/src/github.com/hashicorp/nomad 481 macos: 482 xcode: 13.4.1 483 environment: 484 <<: *common_envs 485 GOPATH: /Users/distiller/go 486 GOLANG_VERSION: 1.19.3 487 488 go-windows: 489 machine: 490 image: *go_windows_image 491 resource_class: windows.medium 492 shell: bash --login -eo pipefail 493 working_directory: c:\gopath\src\github.com\hashicorp\nomad 494 environment: 495 GOPATH: c:\gopath 496 GOBIN: c:\gopath\bin 497 GOTESTSUM_PATH: c:\tmp\test-reports 498 GOLANG_VERSION: 1.19.3 499 GOTESTSUM_VERSION: 1.7.0 500 VAULT_VERSION: 1.4.1 501 502 workflows: 503 build-test: 504 jobs: 505 - build-binaries: 506 # almost always build binaries as they may be needed 507 # for e2e tests 508 filters: 509 branches: 510 ignore: 511 - stable-website 512 513 - lint-go: 514 # check branches are almost all the backend branches 515 filters: &backend_check_branches_filter 516 branches: 517 ignore: 518 - /^.-ui\b.*/ 519 - /^docs-.*/ 520 - /^backport/docs-.*/ 521 - stable-website 522 523 - test-e2e: 524 filters: *backend_check_branches_filter 525 526 - test-ui: 527 filters: 528 branches: 529 ignore: 530 - stable-website 531 - /^docs-.*/ 532 - /^backport/docs-.*/ 533 - /^e2e-.*/ 534 535 # Note: comment-out this job in ENT 536 - test-windows: 537 filters: 538 branches: 539 ignore: 540 - /^.-ui\b.*/ 541 - /^docs-.*/ 542 - /^backport/docs-.*/ 543 - /^e2e-.*/ 544 - stable-website