|
| 1 | +name: Publish Head |
| 2 | +on: |
| 3 | + push: |
| 4 | + branches: |
| 5 | + - main |
| 6 | + - release/v* |
| 7 | +permissions: |
| 8 | + contents: write |
| 9 | +env: |
| 10 | + REGISTRY: docker.io |
| 11 | + REPO: rancher |
| 12 | +jobs: |
| 13 | + build: |
| 14 | + name: build and package |
| 15 | + runs-on: ubuntu-latest |
| 16 | + strategy: |
| 17 | + matrix: |
| 18 | + arch: |
| 19 | + - amd64 |
| 20 | + - arm64 |
| 21 | + steps: |
| 22 | + - name : Checkout repository |
| 23 | + uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 |
| 24 | + - name: Setup Go |
| 25 | + uses: actions/setup-go@44694675825211faa026b3c33043df3e48a5fa00 # v6.0.0 |
| 26 | + with: |
| 27 | + go-version-file: 'go.mod' |
| 28 | + - name: Build and package |
| 29 | + run: | |
| 30 | + ./scripts/build |
| 31 | + mkdir -p dist/artifacts |
| 32 | + cp bin/webhook dist/artifacts/webhook-linux-${{ matrix.arch }} |
| 33 | + env: |
| 34 | + ARCH: "${{ matrix.arch}}" |
| 35 | + GOARCH: "${{ matrix.arch}}" |
| 36 | + - name: Upload artifacts |
| 37 | + uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 |
| 38 | + with: |
| 39 | + name: webhook-artifacts-${{ matrix.arch }} |
| 40 | + path: | |
| 41 | + dist/artifacts/webhook-linux-${{ matrix.arch }} |
| 42 | + image: |
| 43 | + permissions: |
| 44 | + contents: read |
| 45 | + id-token: write |
| 46 | + strategy: |
| 47 | + matrix: |
| 48 | + arch: |
| 49 | + - amd64 |
| 50 | + - arm64 |
| 51 | + name: Build and push Webhook images |
| 52 | + runs-on: ubuntu-latest |
| 53 | + needs: build |
| 54 | + steps: |
| 55 | + - name : Checkout repository |
| 56 | + uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 |
| 57 | + - name: Download the artifacts |
| 58 | + uses: actions/download-artifact@634f93cb2916e3fdff6788551b99b062d0335ce0 # v5.0.0 |
| 59 | + with: |
| 60 | + name: webhook-artifacts-${{ matrix.arch }} |
| 61 | + path: dist/artifacts |
| 62 | + - name: Move binary to bin/ |
| 63 | + run: | |
| 64 | + mkdir -p bin/ |
| 65 | + cp -v dist/artifacts/webhook-linux-${{ matrix.arch }} bin/webhook |
| 66 | + chmod +x bin/webhook |
| 67 | + - name: "Read vault secrets" |
| 68 | + uses: rancher-eio/read-vault-secrets@main |
| 69 | + with: |
| 70 | + secrets: | |
| 71 | + secret/data/github/repo/${{ github.repository }}/dockerhub/rancher/credentials username | DOCKER_USERNAME ; |
| 72 | + secret/data/github/repo/${{ github.repository }}/dockerhub/rancher/credentials password | DOCKER_PASSWORD |
| 73 | + - name: Set up QEMU |
| 74 | + uses: docker/setup-qemu-action@29109295f81e9208d7d86ff1c6c12d2833863392 # v3.6.0 |
| 75 | + - name: Set up Docker Buildx |
| 76 | + uses: docker/setup-buildx-action@e468171a9de216ec08956ac3ada2f0791b6bd435 # v3.11.1 |
| 77 | + - name: Log in to the Container registry |
| 78 | + uses: docker/login-action@184bdaa0721073962dff0199f1fb9940f07167d1 # v3.5.0 |
| 79 | + with: |
| 80 | + registry: ${{ env.REGISTRY }} |
| 81 | + username: ${{ env.DOCKER_USERNAME }} |
| 82 | + password: ${{ env.DOCKER_PASSWORD }} |
| 83 | + - name: Build and push the webhook image |
| 84 | + id: build |
| 85 | + uses: docker/build-push-action@263435318d21b8e681c14492fe198d362a7d2c83 # v6.18.0 |
| 86 | + with: |
| 87 | + context: . |
| 88 | + file: ./package/Dockerfile |
| 89 | + platforms: "linux/${{ matrix.arch }}" |
| 90 | + outputs: type=image,name=${{ env.REPO }}/rancher-webhook,push-by-digest=true,name-canonical=true,push=true |
| 91 | + - name: Export digest |
| 92 | + run: | |
| 93 | + mkdir -p /tmp/digests |
| 94 | + digest="${{ steps.build.outputs.digest }}" |
| 95 | + touch "/tmp/digests/${digest#sha256:}" |
| 96 | + - name: Upload digest |
| 97 | + uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 |
| 98 | + with: |
| 99 | + name: digests-${{ matrix.arch }} |
| 100 | + path: /tmp/digests/* |
| 101 | + if-no-files-found: error |
| 102 | + retention-days: 1 |
| 103 | + merge: |
| 104 | + permissions: |
| 105 | + id-token: write |
| 106 | + runs-on: ubuntu-latest |
| 107 | + needs: image |
| 108 | + steps: |
| 109 | + - name: Download digests |
| 110 | + uses: actions/download-artifact@634f93cb2916e3fdff6788551b99b062d0335ce0 # v5.0.0 |
| 111 | + with: |
| 112 | + path: /tmp/digests |
| 113 | + pattern: digests-* |
| 114 | + merge-multiple: true |
| 115 | + - name: Set up Docker Buildx |
| 116 | + uses: docker/setup-buildx-action@e468171a9de216ec08956ac3ada2f0791b6bd435 # v3.11.1 |
| 117 | + - name: "Read vault secrets" |
| 118 | + uses: rancher-eio/read-vault-secrets@main |
| 119 | + with: |
| 120 | + secrets: | |
| 121 | + secret/data/github/repo/${{ github.repository }}/dockerhub/rancher/credentials username | DOCKER_USERNAME ; |
| 122 | + secret/data/github/repo/${{ github.repository }}/dockerhub/rancher/credentials password | DOCKER_PASSWORD |
| 123 | + - name: Log in to the Container registry |
| 124 | + uses: docker/login-action@184bdaa0721073962dff0199f1fb9940f07167d1 # v3.5.0 |
| 125 | + with: |
| 126 | + registry: ${{ env.REGISTRY }} |
| 127 | + username: ${{ env.DOCKER_USERNAME }} |
| 128 | + password: ${{ env.DOCKER_PASSWORD }} |
| 129 | + - name: Generate tag |
| 130 | + run: | |
| 131 | + if [[ "${{ github.ref }}" == "refs/heads/main" ]]; then |
| 132 | + echo "TAG=head" >> $GITHUB_ENV |
| 133 | + else |
| 134 | + VERSION=$(echo "${{ github.ref }}" | sed -E -n 's|refs/heads/release/v(.*)|\1|p') |
| 135 | + echo "TAG=v${VERSION}-${{ github.sha }}-head" >> $GITHUB_ENV |
| 136 | + fi |
| 137 | + - name: Create manifest list and push |
| 138 | + working-directory: /tmp/digests |
| 139 | + run: | |
| 140 | + docker buildx imagetools create -t ${{ env.REGISTRY }}/${{ env.REPO }}/rancher-webhook:${{ env.TAG }} \ |
| 141 | + $(printf '${{ env.REPO }}/rancher-webhook@sha256:%s ' *) |
0 commit comments