|
| 1 | +# This workflow builds and publishes the ODH operator image for pushes and pull requests to the dev branch. |
| 2 | +name: ODH-Build-And-Publish-Operator-Image |
| 3 | + |
| 4 | +on: |
| 5 | + push: |
| 6 | + branches: |
| 7 | + - dev |
| 8 | + tags: |
| 9 | + - '**' |
| 10 | + pull_request: |
| 11 | + branches: |
| 12 | + - dev |
| 13 | + |
| 14 | +jobs: |
| 15 | + build-and-publish-operator: |
| 16 | + name: Build and (or) Publish Image |
| 17 | + runs-on: ubuntu-latest |
| 18 | + env: |
| 19 | + GOPATH: ${{ github.workspace }}/go |
| 20 | + REPO_NAME: ${{ vars.QUAY_REPO_NAME || 'opendatahub' }} |
| 21 | + steps: |
| 22 | + - name: Environment dump |
| 23 | + shell: bash |
| 24 | + run: | |
| 25 | + echo "GOPATH = ${GOPATH}" |
| 26 | + echo "REPO_NAME = ${REPO_NAME}" |
| 27 | + echo "Event name = ${{ github.event_name }}" |
| 28 | + echo "Branch input = ${{ github.event.inputs.branch }}" |
| 29 | + echo "Push images input = ${{ github.event.inputs.push_images }}" |
| 30 | + echo "Custom tag input = ${{ github.event.inputs.image_tag }}" |
| 31 | +
|
| 32 | + - name: Checkout |
| 33 | + uses: actions/checkout@v4 |
| 34 | + with: |
| 35 | + ref: ${{ github.event.inputs.branch || github.ref }} |
| 36 | + |
| 37 | + - name: Set up Go |
| 38 | + uses: actions/setup-go@v5 |
| 39 | + with: |
| 40 | + go-version-file: go.mod |
| 41 | + |
| 42 | + - name: Run go mod |
| 43 | + shell: bash |
| 44 | + run: | |
| 45 | + go mod download |
| 46 | +
|
| 47 | + # Build operators inside the gh runner vm directly and then copy the go binaries to docker images using the Dockerfile.multiarch |
| 48 | + - name: Build linux/amd64 operator binary |
| 49 | + env: |
| 50 | + CGO_ENABLED: 1 |
| 51 | + GOOS: linux |
| 52 | + GOARCH: amd64 |
| 53 | + shell: bash |
| 54 | + run: | |
| 55 | + go build -tags strictfipsruntime -a -o manager-$GOARCH cmd/trainer-controller-manager/main.go |
| 56 | +
|
| 57 | + - name: Build linux/arm64 operator binary |
| 58 | + env: |
| 59 | + CC: aarch64-linux-gnu-gcc |
| 60 | + CGO_ENABLED: 1 |
| 61 | + GOOS: linux |
| 62 | + GOARCH: arm64 |
| 63 | + shell: bash |
| 64 | + run: | |
| 65 | + sudo apt-get update |
| 66 | + sudo apt-get install -y gcc-aarch64-linux-gnu libc6-dev-arm64-cross |
| 67 | + go build -tags strictfipsruntime -a -o manager-$GOARCH cmd/trainer-controller-manager/main.go |
| 68 | +
|
| 69 | + - name: Add docker tags |
| 70 | + id: meta |
| 71 | + uses: docker/metadata-action@v5 |
| 72 | + with: |
| 73 | + images: quay.io/${{ env.REPO_NAME }}/trainer |
| 74 | + tags: | |
| 75 | + type=raw,latest |
| 76 | + type=ref,event=pr |
| 77 | + type=sha,prefix=v2-odh- |
| 78 | + type=ref,enable=true,priority=600,prefix=,suffix=,event=tag |
| 79 | + type=raw,value=${{ github.event.inputs.image_tag }},enable=${{ github.event.inputs.image_tag != '' }} |
| 80 | +
|
| 81 | + - name: Build image |
| 82 | + id: build-image |
| 83 | + uses: redhat-actions/buildah-build@v2 |
| 84 | + with: |
| 85 | + image: quay.io/${{ env.REPO_NAME }}/trainer |
| 86 | + tags: ${{ steps.meta.outputs.tags }} |
| 87 | + labels: ${{ steps.meta.outputs.labels }} |
| 88 | + platforms: linux/amd64,linux/arm64 |
| 89 | + containerfiles: | |
| 90 | + cmd/trainer-controller-manager/Dockerfile.multiarch |
| 91 | + extra-args: | |
| 92 | + --pull |
| 93 | +
|
| 94 | + # Check if image is build |
| 95 | + - name: Check images created |
| 96 | + shell: bash |
| 97 | + run: buildah images | grep 'quay.io/${{ env.REPO_NAME }}/trainer' |
| 98 | + |
| 99 | + - name: Check image manifest |
| 100 | + shell: bash |
| 101 | + run: | |
| 102 | + buildah manifest inspect ${{ steps.build-image.outputs.image }}:latest |
| 103 | +
|
| 104 | +
|
| 105 | + - name: Check image metadata |
| 106 | + shell: bash |
| 107 | + run: | |
| 108 | + buildah inspect ${{ steps.build-image.outputs.image-with-tag }} | jq '.OCIv1.config.Labels."org.opencontainers.image.title"' |
| 109 | + buildah inspect ${{ steps.build-image.outputs.image-with-tag }} | jq '.OCIv1.config.Labels."org.opencontainers.image.description"' |
| 110 | + buildah inspect ${{ steps.build-image.outputs.image-with-tag }} | jq '.Docker.config.Labels."org.opencontainers.image.title"' |
| 111 | + buildah inspect ${{ steps.build-image.outputs.image-with-tag }} | jq '.Docker.config.Labels."org.opencontainers.image.description"' |
| 112 | +
|
| 113 | + - name: Login to Quay.io |
| 114 | + id: podman-login-quay |
| 115 | + # Trigger step only for specific branch (master, v.*-branch) or tag (v.*), or when manually triggered with push_images=true. |
| 116 | + if: (github.ref == 'refs/heads/dev' || (startsWith(github.ref, 'refs/heads/v') && endsWith(github.ref, '-branch')) || startsWith(github.ref, 'refs/tags/v')) || (github.event_name == 'workflow_dispatch' && github.event.inputs.push_images == 'true') |
| 117 | + shell: bash |
| 118 | + run: | |
| 119 | + podman login --username ${{ secrets.QUAY_USERNAME }} --password ${{ secrets.QUAY_TOKEN }} quay.io |
| 120 | +
|
| 121 | + - name: Push to Quay.io |
| 122 | + if: always() && steps.podman-login-quay.outcome == 'success' |
| 123 | + id: push-to-quay |
| 124 | + uses: redhat-actions/push-to-registry@v2 |
| 125 | + with: |
| 126 | + image: ${{ steps.build-image.outputs.image }} |
| 127 | + tags: ${{ steps.build-image.outputs.tags }} |
| 128 | + |
| 129 | + - name: Print image url |
| 130 | + if: steps.push-to-quay.outcome == 'success' |
| 131 | + shell: bash |
| 132 | + run: echo "Image pushed to ${{ steps.push-to-quay.outputs.registry-paths }}" |
| 133 | + |
| 134 | + - name: Logout from Quay.io |
| 135 | + if: always() && steps.podman-login-quay.outcome == 'success' |
| 136 | + run: | |
| 137 | + podman logout quay.io |
0 commit comments