|
| 1 | +# This workflow is used to build and push one-off images for specific node types. This is useful |
| 2 | +# when deploying hotfixes or any time a change is not needed for all node roles. |
| 3 | +name: Build Node Docker Images |
| 4 | + |
| 5 | +on: |
| 6 | + workflow_dispatch: |
| 7 | + inputs: |
| 8 | + tag: |
| 9 | + type: string |
| 10 | + description: 'Git tag/commit' |
| 11 | + required: true |
| 12 | + docker_tag: |
| 13 | + type: string |
| 14 | + description: 'Docker tag' |
| 15 | + required: true |
| 16 | + # GHA doesn't support multi-selects, so simulating it with one boolean for each option |
| 17 | + build_access: |
| 18 | + type: boolean |
| 19 | + description: 'Access' |
| 20 | + required: false |
| 21 | + build_collection: |
| 22 | + type: boolean |
| 23 | + description: 'Collection' |
| 24 | + required: false |
| 25 | + build_consensus: |
| 26 | + type: boolean |
| 27 | + description: 'Consensus' |
| 28 | + required: false |
| 29 | + build_execution: |
| 30 | + type: boolean |
| 31 | + description: 'Execution' |
| 32 | + required: false |
| 33 | + build_verification: |
| 34 | + type: boolean |
| 35 | + description: 'Verification' |
| 36 | + required: false |
| 37 | + build_observer: |
| 38 | + type: boolean |
| 39 | + description: 'Observer' |
| 40 | + required: false |
| 41 | + include_without_netgo: |
| 42 | + type: boolean |
| 43 | + description: 'Build `without_netgo` images' |
| 44 | + required: false |
| 45 | + |
| 46 | +jobs: |
| 47 | + # matrix_builder generates a matrix that includes the roles selected in the input |
| 48 | + matrix_builder: |
| 49 | + name: Setup build jobs |
| 50 | + runs-on: ubuntu-latest |
| 51 | + outputs: |
| 52 | + matrix: ${{ steps.generate.outputs.matrix }} |
| 53 | + steps: |
| 54 | + - id: generate |
| 55 | + run: | |
| 56 | + roles=() |
| 57 | + if [[ "${{ inputs.build_access }}" = "true" ]]; then |
| 58 | + roles+=( "access" ) |
| 59 | + fi |
| 60 | + if [[ "${{ inputs.build_collection }}" = "true" ]]; then |
| 61 | + roles+=( "collection" ) |
| 62 | + fi |
| 63 | + if [[ "${{ inputs.build_consensus }}" = "true" ]]; then |
| 64 | + roles+=( "consensus" ) |
| 65 | + fi |
| 66 | + if [[ "${{ inputs.build_execution }}" = "true" ]]; then |
| 67 | + roles+=( "execution" ) |
| 68 | + fi |
| 69 | + if [[ "${{ inputs.build_verification }}" = "true" ]]; then |
| 70 | + roles+=( "verification" ) |
| 71 | + fi |
| 72 | + if [[ "${{ inputs.build_observer }}" = "true" ]]; then |
| 73 | + roles+=( "observer" ) |
| 74 | + fi |
| 75 | + rolesJSON=$(jq --compact-output --null-input '$ARGS.positional' --args -- "${roles[@]}") |
| 76 | + echo "matrix={\"role\":$(echo $rolesJSON)}" >> $GITHUB_OUTPUT |
| 77 | + docker-push: |
| 78 | + name: ${{ matrix.role }} images |
| 79 | + runs-on: ubuntu-latest |
| 80 | + needs: matrix_builder |
| 81 | + |
| 82 | + # setup jobs for each role |
| 83 | + strategy: |
| 84 | + fail-fast: false |
| 85 | + matrix: ${{ fromJson(needs.matrix_builder.outputs.matrix) }} |
| 86 | + |
| 87 | + steps: |
| 88 | + - name: Setup Go |
| 89 | + uses: actions/setup-go@v2 |
| 90 | + with: |
| 91 | + go-version: '1.19' |
| 92 | + - name: Checkout repo |
| 93 | + uses: actions/checkout@v2 |
| 94 | + with: |
| 95 | + ref: ${{ inputs.tag }} |
| 96 | + # Provide Google Service Account credentials to Github Action, allowing interaction with the Google Container Registry |
| 97 | + |
| 98 | + - name: Docker login |
| 99 | + uses: docker/login-action@v1 |
| 100 | + with: |
| 101 | + registry: gcr.io |
| 102 | + username: _json_key |
| 103 | + password: ${{ secrets.GCR_SERVICE_KEY }} |
| 104 | + |
| 105 | + - name: Build/Push ${{ matrix.role }} images |
| 106 | + env: |
| 107 | + IMAGE_TAG: ${{ inputs.docker_tag }} |
| 108 | + run: | |
| 109 | + make docker-build-${{ matrix.role }} docker-push-${{ matrix.role }} |
| 110 | +
|
| 111 | + - name: Build/Push ${{ matrix.role }} without_netgo images |
| 112 | + if: ${{ inputs.include_without_netgo }} |
| 113 | + env: |
| 114 | + IMAGE_TAG: ${{ inputs.docker_tag }} |
| 115 | + run: | |
| 116 | + make docker-build-${{ matrix.role }}-without-netgo docker-push-${{ matrix.role }}-without-netgo |
0 commit comments