github.com/hernad/nomad@v1.6.112/.github/workflows/build.yml (about) 1 name: build 2 3 on: 4 push: 5 branches: 6 - main 7 - release/** 8 workflow_dispatch: 9 inputs: 10 build-ref: 11 description: 'The git ref to build from' 12 type: string 13 default: '' 14 required: false 15 make-prerelease: 16 description: "Run prerelease to generate files" 17 type: "boolean" 18 required: false 19 default: true 20 21 env: 22 PKG_NAME: "nomad" 23 GO_TAGS: "release" 24 25 jobs: 26 get-go-version: 27 runs-on: ubuntu-20.04 28 outputs: 29 go-version: ${{ steps.get-go-version.outputs.go-version }} 30 steps: 31 - uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2 32 with: 33 ref: ${{ github.event.inputs.build-ref }} 34 - name: Determine Go version 35 id: get-go-version 36 # We use .go-version as our source of truth for current Go 37 # version, because "goenv" can react to it automatically. 38 run: |- 39 echo "Building with Go $(cat .go-version)" 40 echo "go-version=$(cat .go-version)" >> "$GITHUB_OUTPUT" 41 get-product-version: 42 runs-on: ubuntu-20.04 43 outputs: 44 product-version: ${{ steps.get-product-version.outputs.product-version }} 45 steps: 46 - uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2 47 with: 48 ref: ${{ github.event.inputs.build-ref }} 49 - name: get product version 50 id: get-product-version 51 run: |- 52 make version 53 echo "product-version=$(make version)" >> "$GITHUB_OUTPUT" 54 generate-metadata-file: 55 needs: get-product-version 56 runs-on: ubuntu-20.04 57 outputs: 58 filepath: ${{ steps.generate-metadata-file.outputs.filepath }} 59 steps: 60 - name: "Checkout directory" 61 uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2 62 with: 63 ref: ${{ github.event.inputs.build-ref }} 64 - name: Generate metadata file 65 id: generate-metadata-file 66 uses: hashicorp/actions-generate-metadata@v1.1.1 67 with: 68 version: ${{ needs.get-product-version.outputs.product-version }} 69 product: ${{ env.PKG_NAME }} 70 repositoryOwner: "hashicorp" 71 sha: ${{ github.event.inputs.build-ref }} 72 - uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # v3.1.2 73 with: 74 name: metadata.json 75 path: ${{ steps.generate-metadata-file.outputs.filepath }} 76 77 build-other: 78 needs: [get-go-version, get-product-version] 79 runs-on: [ custom, linux, xxl, 20.04 ] 80 strategy: 81 matrix: 82 goos: [windows] 83 goarch: ["amd64"] 84 fail-fast: true 85 86 name: Go ${{ needs.get-go-version.outputs.go-version }} ${{ matrix.goos }} ${{ matrix.goarch }} build 87 88 steps: 89 - uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2 90 with: 91 ref: ${{ github.event.inputs.build-ref }} 92 - name: Setup go 93 uses: actions/setup-go@4d34df0c2316fe8122ab82dc22947d607c0c91f9 # v4.0.0 94 with: 95 go-version: ${{ needs.get-go-version.outputs.go-version }} 96 97 - name: Build dependencies 98 run: make deps 99 100 - name: Setup node and yarn 101 uses: actions/setup-node@64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c # v3.6.0 102 with: 103 node-version: "18" 104 cache-dependency-path: "ui/yarn.lock" 105 106 - name: Install Yarn 107 run: | 108 npm install -g yarn 109 110 - name: Build prerelease 111 run: make prerelease 112 if: ${{ github.event_name != 'workflow_dispatch' || github.event.inputs.make-prerelease == 'true' }} 113 114 - name: Build 115 env: 116 GOOS: ${{ matrix.goos }} 117 GOARCH: ${{ matrix.goarch }} 118 GO_TAGS: ${{ env.GO_TAGS }} 119 CGO_ENABLED: 1 120 run: | 121 go clean -cache 122 make pkg/${{ matrix.goos }}_${{ matrix.goarch }}.zip 123 mv pkg/${{ matrix.goos }}_${{ matrix.goarch }}.zip ${{ env.PKG_NAME }}_${{ needs.get-product-version.outputs.product-version }}_${{ matrix.goos }}_${{ matrix.goarch }}.zip 124 - uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # v3.1.2 125 with: 126 name: ${{ env.PKG_NAME }}_${{ needs.get-product-version.outputs.product-version }}_${{ matrix.goos }}_${{ matrix.goarch }}.zip 127 path: ${{ env.PKG_NAME }}_${{ needs.get-product-version.outputs.product-version }}_${{ matrix.goos }}_${{ matrix.goarch }}.zip 128 129 build-linux: 130 needs: [get-go-version, get-product-version] 131 runs-on: [ custom, linux, xxl, 20.04 ] 132 strategy: 133 matrix: 134 goos: [linux] 135 goarch: ["arm", "arm64", "amd64"] 136 fail-fast: true 137 138 name: Go ${{ needs.get-go-version.outputs.go-version }} ${{ matrix.goos }} ${{ matrix.goarch }} build 139 140 steps: 141 - uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2 142 with: 143 ref: ${{ github.event.inputs.build-ref }} 144 - name: Setup go 145 uses: actions/setup-go@4d34df0c2316fe8122ab82dc22947d607c0c91f9 # v4.0.0 146 with: 147 go-version: ${{ needs.get-go-version.outputs.go-version }} 148 149 - name: Build dependencies 150 run: make deps 151 152 - name: Setup node and yarn 153 uses: actions/setup-node@64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c # v3.6.0 154 with: 155 node-version: "18" 156 cache-dependency-path: "ui/yarn.lock" 157 158 - name: Install Yarn 159 run: | 160 npm install -g yarn 161 162 - name: Build prerelease 163 run: make prerelease 164 if: ${{ github.event_name != 'workflow_dispatch' || github.event.inputs.make-prerelease == 'true' }} 165 166 - name: Install Linux build utilties 167 run: | 168 sudo apt-get update 169 sudo apt-get install -y software-properties-common 170 sudo apt-get update 171 sudo apt-get install -y \ 172 binutils-aarch64-linux-gnu \ 173 binutils-arm-linux-gnueabihf \ 174 gcc-aarch64-linux-gnu \ 175 gcc-arm-linux-gnueabihf \ 176 gcc-multilib-arm-linux-gnueabihf 177 178 - name: Set gcc 179 run: | 180 if [ "${{ matrix.goarch }}" == "arm" ]; then 181 echo "CC=arm-linux-gnueabihf-gcc" >> "$GITHUB_ENV" 182 elif [ "${{ matrix.goarch }}" == "arm64" ]; then 183 echo "CC=aarch64-linux-gnu-gcc" >> "$GITHUB_ENV" 184 fi 185 186 - name: Build 187 env: 188 GOOS: ${{ matrix.goos }} 189 GOARCH: ${{ matrix.goarch }} 190 GO_TAGS: ${{ env.GO_TAGS }} 191 CGO_ENABLED: 1 192 run: | 193 go clean -cache 194 make pkg/${{ matrix.goos }}_${{ matrix.goarch }}.zip 195 mv pkg/${{ matrix.goos }}_${{ matrix.goarch }}.zip ${{ env.PKG_NAME }}_${{ needs.get-product-version.outputs.product-version }}_${{ matrix.goos }}_${{ matrix.goarch }}.zip 196 - uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # v3.1.2 197 with: 198 name: ${{ env.PKG_NAME }}_${{ needs.get-product-version.outputs.product-version }}_${{ matrix.goos }}_${{ matrix.goarch }}.zip 199 path: ${{ env.PKG_NAME }}_${{ needs.get-product-version.outputs.product-version }}_${{ matrix.goos }}_${{ matrix.goarch }}.zip 200 201 - name: Package 202 uses: hashicorp/actions-packaging-linux@v1 203 with: 204 name: ${{ env.PKG_NAME }} 205 description: "Nomad is an easy-to-use, flexible, and performant workload orchestrator that can deploy a mix of microservice, batch, containerized, and non-containerized applications." 206 arch: ${{ matrix.goarch }} 207 version: ${{ needs.get-product-version.outputs.product-version }} 208 maintainer: "HashiCorp" 209 homepage: "https://github.com/hernad/nomad" 210 license: "MPL-2.0" 211 binary: "pkg/${{ matrix.goos }}_${{ matrix.goarch }}/${{ env.PKG_NAME }}" 212 deb_depends: "openssl" 213 rpm_depends: "openssl" 214 config_dir: ".release/linux/package/" 215 preinstall: ".release/linux/preinst" 216 postinstall: ".release/linux/postinst" 217 postremove: ".release/linux/postrm" 218 219 - name: Set Package Names 220 run: | 221 echo "RPM_PACKAGE=$(basename out/*.rpm)" >> "$GITHUB_ENV" 222 echo "DEB_PACKAGE=$(basename out/*.deb)" >> "$GITHUB_ENV" 223 224 - uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # v3.1.2 225 with: 226 name: ${{ env.RPM_PACKAGE }} 227 path: out/${{ env.RPM_PACKAGE }} 228 229 - uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # v3.1.2 230 with: 231 name: ${{ env.DEB_PACKAGE }} 232 path: out/${{ env.DEB_PACKAGE }} 233 234 build-darwin: 235 needs: [get-go-version, get-product-version] 236 runs-on: ${{ endsWith(github.repository, '-enterprise') && fromJSON('["self-hosted", "ondemand", "macos"]') || 'macos-latest' }} 237 strategy: 238 matrix: 239 goos: [darwin] 240 goarch: ["arm64", "amd64"] 241 fail-fast: true 242 243 name: Go ${{ needs.get-go-version.outputs.go-version }} ${{ matrix.goos }} ${{ matrix.goarch }} build 244 245 steps: 246 - uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2 247 with: 248 ref: ${{ github.event.inputs.build-ref }} 249 250 - uses: ./.github/actions/vault-secrets 251 with: 252 paths: |- 253 kv/data/github/hashicorp/nomad-enterprise/gha ELEVATED_GITHUB_TOKEN ; 254 - name: Git config token 255 if: endsWith(github.repository, '-enterprise') 256 run: git config --global url.'https://${{ env.ELEVATED_GITHUB_TOKEN }}@github.com'.insteadOf 'https://github.com' 257 258 - name: Setup go 259 uses: actions/setup-go@4d34df0c2316fe8122ab82dc22947d607c0c91f9 # v4.0.0 260 with: 261 go-version: ${{ needs.get-go-version.outputs.go-version }} 262 263 - name: Build dependencies 264 run: make deps 265 266 - name: Setup node and yarn 267 uses: actions/setup-node@64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c # v3.6.0 268 with: 269 node-version: "18" 270 cache-dependency-path: "ui/yarn.lock" 271 272 - name: Install Yarn 273 run: | 274 npm install -g yarn 275 276 - name: Build prerelease 277 run: make prerelease 278 if: ${{ github.event_name != 'workflow_dispatch' || github.event.inputs.make-prerelease == 'true' }} 279 280 - name: Build 281 env: 282 GOOS: ${{ matrix.goos }} 283 GOARCH: ${{ matrix.goarch }} 284 GO_TAGS: "${{ env.GO_TAGS }} netcgo" 285 CGO_ENABLED: 1 286 run: | 287 go clean -cache 288 make pkg/${{ matrix.goos }}_${{ matrix.goarch }}.zip 289 mv pkg/${{ matrix.goos }}_${{ matrix.goarch }}.zip ${{ env.PKG_NAME }}_${{ needs.get-product-version.outputs.product-version }}_${{ matrix.goos }}_${{ matrix.goarch }}.zip 290 - uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # v3.1.2 291 with: 292 name: ${{ env.PKG_NAME }}_${{ needs.get-product-version.outputs.product-version }}_${{ matrix.goos }}_${{ matrix.goarch }}.zip 293 path: ${{ env.PKG_NAME }}_${{ needs.get-product-version.outputs.product-version }}_${{ matrix.goos }}_${{ matrix.goarch }}.zip 294 295 build-docker: 296 name: Docker ${{ matrix.arch }} build 297 needs: 298 - get-product-version 299 - build-linux 300 runs-on: [ custom, linux, xxl, 20.04 ] 301 strategy: 302 matrix: 303 arch: ["arm64", "amd64"] 304 env: 305 version: ${{needs.get-product-version.outputs.product-version}} 306 revision: ${{github.sha}} 307 steps: 308 - uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2 309 - name: Set revision 310 if: "${{ github.event.inputs.build-ref != '' }}" 311 run: | 312 echo "revision=${{ github.event.inputs.build-ref }}" >> "$GITHUB_ENV" 313 - name: Docker Build (Action) 314 uses: hashicorp/actions-docker-build@v1 315 with: 316 smoke_test: | 317 TEST_VERSION="$(docker run "${IMAGE_NAME}" version | awk '/Nomad v/{print $2}')" 318 if [ "${TEST_VERSION}" != "v${version}" ]; then 319 echo "Test FAILED" 320 exit 1 321 fi 322 echo "Test PASSED" 323 version: ${{env.version}} 324 revision: ${{env.revision}} 325 target: release 326 arch: ${{matrix.arch}} 327 tags: | 328 docker.io/hashicorp/${{env.PKG_NAME}}:${{env.version}} 329 dev_tags: | 330 docker.io/hashicorppreview/${{ env.PKG_NAME }}:${{ env.version }}-dev 331 docker.io/hashicorppreview/${{ env.PKG_NAME }}:${{ env.version }}-${{env.revision}} 332 333 minimum-os: 334 name: OS Compatibility 335 # A quick smoke test of our binaries on our minimum target OS (RHEL 7). Why RHEL 7? Because the glibc version is that old (2.17). 336 needs: 337 - get-go-version 338 - get-product-version 339 - build-linux 340 runs-on: ubuntu-22.04 341 strategy: 342 fail-fast: false 343 # Note: Ideally we'd test all our target archs, unfortunately availability of containers of these OS's vary. 344 # For instance there is no ubi7 image for arm64 (there is on ubi8), RHBZ#1728771. And none at all for arm. 345 # So we have to settle for only being able to validate where we can, which is just amd64. 346 matrix: 347 goos: [linux] 348 goarch: [amd64] 349 steps: 350 - uses: actions/setup-go@4d34df0c2316fe8122ab82dc22947d607c0c91f9 # v4.0.0 351 with: 352 go-version: ${{needs.get-go-version.outputs.go-version}} 353 - uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2 354 with: 355 name: ${{ env.PKG_NAME }}_${{ needs.get-product-version.outputs.product-version }}_${{ matrix.goos }}_${{ matrix.goarch }}.zip 356 - name: Test binary 357 env: 358 artifact_name: ${{ env.PKG_NAME }}_${{ needs.get-product-version.outputs.product-version }}_${{ matrix.goos }}_${{ matrix.goarch }}.zip 359 run: | 360 echo "::group::Unpack and Prep" 361 docker pull registry.access.redhat.com/ubi7/ubi-minimal:7.9-1057 362 unzip "$artifact_name" 363 echo "::group::Diagnostics" 364 echo "CGO related build information:" 365 go version -m ./nomad | grep CGO 366 echo "GLIBC links:" 367 go tool nm ./nomad | grep -i glibc | cut -d @ -f 2-3 | sort --version-sort | uniq 368 echo "::group::Smoke test binary" 369 docker run --rm -v "$PWD:/src" registry.access.redhat.com/ubi7/ubi-minimal:7.9-1057 /src/nomad version 370 371 permissions: 372 contents: read 373 id-token: write