|
| 1 | +name: Build and push docker image to registry |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + push: |
| 6 | + branches: |
| 7 | + - 'main' |
| 8 | + tags: |
| 9 | + - 'v*' |
| 10 | + pull_request: |
| 11 | + paths: |
| 12 | + - ".github/workflows/build.yaml" |
| 13 | + - ".github/workflows/matrix.json" |
| 14 | + - "integration-tests/**" |
| 15 | + - "backends/**" |
| 16 | + - "core/**" |
| 17 | + - "router/**" |
| 18 | + - "Cargo.lock" |
| 19 | + - "rust-toolchain.toml" |
| 20 | + - "Dockerfile" |
| 21 | + branches: |
| 22 | + - 'main' |
| 23 | + |
| 24 | +jobs: |
| 25 | + matrix: |
| 26 | + runs-on: ubuntu-latest |
| 27 | + outputs: |
| 28 | + matrix: ${{ steps.set-matrix.outputs.matrix }} |
| 29 | + steps: |
| 30 | + - name: Checkout repository |
| 31 | + uses: actions/checkout@v3 |
| 32 | + |
| 33 | + - id: set-matrix |
| 34 | + run: | |
| 35 | + branchName=$(echo '${{ github.ref }}' | sed 's,refs/heads/,,g') |
| 36 | + matrix=$(jq --arg branchName "$branchName" 'map(. | select((.runOn==$branchName) or (.runOn=="always")) )' .github/workflows/matrix.json) |
| 37 | + echo "{\"include\":$(echo $matrix)}" |
| 38 | + echo ::set-output name=matrix::{\"include\":$(echo $matrix)}\" |
| 39 | +
|
| 40 | + build-and-push-image: |
| 41 | + needs: matrix |
| 42 | + strategy: |
| 43 | + matrix: ${{fromJson(needs.matrix.outputs.matrix)}} |
| 44 | + concurrency: |
| 45 | + group: ${{ github.workflow }}-${{ github.job }}-${{matrix.name}}-${{ github.head_ref || github.run_id }} |
| 46 | + cancel-in-progress: true |
| 47 | + runs-on: |
| 48 | + group: aws-r7i-8xlarge-priv |
| 49 | + permissions: |
| 50 | + contents: write |
| 51 | + packages: write |
| 52 | + # This is used to complete the identity challenge |
| 53 | + # with sigstore/fulcio when running outside of PRs. |
| 54 | + id-token: write |
| 55 | + security-events: write |
| 56 | + steps: |
| 57 | + - name: Checkout repository |
| 58 | + uses: actions/checkout@v4 |
| 59 | + |
| 60 | + - name: Initialize Docker Buildx |
| 61 | + uses: docker/setup-buildx-action@v3 |
| 62 | + with: |
| 63 | + install: true |
| 64 | + buildkitd-config-inline: | |
| 65 | + [registry."docker.io"] |
| 66 | + mirrors = ["registry-us-east-1.prod.aws.ci.huggingface.tech"] |
| 67 | +
|
| 68 | + - name: Configure sccache |
| 69 | + uses: actions/github-script@v6 |
| 70 | + with: |
| 71 | + script: | |
| 72 | + core.exportVariable('ACTIONS_CACHE_URL', process.env.ACTIONS_CACHE_URL || ''); |
| 73 | + core.exportVariable('ACTIONS_RUNTIME_TOKEN', process.env.ACTIONS_RUNTIME_TOKEN || ''); |
| 74 | +
|
| 75 | + - name: Inject slug/short variables |
| 76 | + uses: rlespinasse/github-slug-action@v4 |
| 77 | + |
| 78 | + - name: Login to internal Container Registry |
| 79 | + if: github.event_name != 'pull_request' |
| 80 | + uses: docker/login-action@v3 |
| 81 | + with: |
| 82 | + username: ${{ secrets.REGISTRY_USERNAME }} |
| 83 | + password: ${{ secrets.REGISTRY_PASSWORD }} |
| 84 | + registry: registry.internal.huggingface.tech |
| 85 | + |
| 86 | + - name: Login to GitHub Container Registry |
| 87 | + if: github.event_name != 'pull_request' |
| 88 | + uses: docker/login-action@v3 |
| 89 | + with: |
| 90 | + registry: ghcr.io |
| 91 | + username: ${{ github.actor }} |
| 92 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 93 | + |
| 94 | + - name: Extract metadata (tags, labels) for Docker |
| 95 | + id: meta |
| 96 | + uses: docker/metadata-action@v5 |
| 97 | + with: |
| 98 | + images: | |
| 99 | + registry.internal.huggingface.tech/api-inference/text-embeddings-inference |
| 100 | + ghcr.io/huggingface/text-embeddings-inference |
| 101 | + flavor: | |
| 102 | + latest=false |
| 103 | + tags: | |
| 104 | + type=semver,pattern=${{ matrix.imageNamePrefix }}{{version}} |
| 105 | + type=semver,pattern=${{ matrix.imageNamePrefix }}{{major}}.{{minor}} |
| 106 | + type=raw,value=${{ matrix.imageNamePrefix }}latest |
| 107 | + type=raw,value=${{ matrix.imageNamePrefix }}sha-${{ env.GITHUB_SHA_SHORT }} |
| 108 | +
|
| 109 | + - name: Build and push Docker image |
| 110 | + id: build-and-push |
| 111 | + uses: docker/build-push-action@v6 |
| 112 | + with: |
| 113 | + context: . |
| 114 | + file: ${{ matrix.dockerfile }} |
| 115 | + push: ${{ github.event_name != 'pull_request' }} |
| 116 | + platforms: 'linux/amd64' |
| 117 | + build-args: | |
| 118 | + SCCACHE_GHA_ENABLED=${{ matrix.sccache }} |
| 119 | + ACTIONS_CACHE_URL=${{ env.ACTIONS_CACHE_URL }} |
| 120 | + ACTIONS_RUNTIME_TOKEN=${{ env.ACTIONS_RUNTIME_TOKEN }} |
| 121 | + CUDA_COMPUTE_CAP=${{ matrix.cudaComputeCap }} |
| 122 | + GIT_SHA=${{ env.GITHUB_SHA }} |
| 123 | + DOCKER_LABEL=sha-${{ env.GITHUB_SHA_SHORT }} |
| 124 | + ${{matrix.extraBuildArgs}} |
| 125 | + tags: ${{ steps.meta.outputs.tags }} |
| 126 | + labels: ${{ steps.meta.outputs.labels }} |
| 127 | + cache-from: type=s3,region=us-east-1,bucket=ci-docker-buildx-cache,name=text-embeddings-inference-cache-${{matrix.name}},access_key_id=${{ secrets.S3_CI_DOCKER_BUILDX_CACHE_ACCESS_KEY_ID }},secret_access_key=${{ secrets.S3_CI_DOCKER_BUILDX_CACHE_SECRET_ACCESS_KEY }},mode=max |
| 128 | + cache-to: type=s3,region=us-east-1,bucket=ci-docker-buildx-cache,name=text-embeddings-inference-cache-${{matrix.name}},access_key_id=${{ secrets.S3_CI_DOCKER_BUILDX_CACHE_ACCESS_KEY_ID }},secret_access_key=${{ secrets.S3_CI_DOCKER_BUILDX_CACHE_SECRET_ACCESS_KEY }},mode=max |
| 129 | + |
| 130 | + - name: Extract metadata (tags, labels) for Docker |
| 131 | + id: meta-grpc |
| 132 | + uses: docker/metadata-action@v5 |
| 133 | + with: |
| 134 | + images: | |
| 135 | + registry.internal.huggingface.tech/api-inference/text-embeddings-inference |
| 136 | + ghcr.io/huggingface/text-embeddings-inference |
| 137 | + flavor: | |
| 138 | + latest=false |
| 139 | + tags: | |
| 140 | + type=semver,pattern=${{ matrix.imageNamePrefix }}{{version}}-grpc |
| 141 | + type=semver,pattern=${{ matrix.imageNamePrefix }}{{major}}.{{minor}}-grpc |
| 142 | + type=raw,value=${{ matrix.imageNamePrefix }}latest-grpc |
| 143 | + type=raw,value=${{ matrix.imageNamePrefix }}sha-${{ env.GITHUB_SHA_SHORT }}-grpc |
| 144 | +
|
| 145 | + - name: Build and push Docker image |
| 146 | + id: build-and-push-grpc |
| 147 | + uses: docker/build-push-action@v6 |
| 148 | + with: |
| 149 | + context: . |
| 150 | + target: grpc |
| 151 | + file: Dockerfile-cuda |
| 152 | + push: ${{ github.event_name != 'pull_request' }} |
| 153 | + platforms: 'linux/amd64' |
| 154 | + build-args: | |
| 155 | + SCCACHE_GHA_ENABLED=${{ matrix.sccache }} |
| 156 | + ACTIONS_CACHE_URL=${{ env.ACTIONS_CACHE_URL }} |
| 157 | + ACTIONS_RUNTIME_TOKEN=${{ env.ACTIONS_RUNTIME_TOKEN }} |
| 158 | + CUDA_COMPUTE_CAP=${{ matrix.cudaComputeCap }} |
| 159 | + GIT_SHA=${{ env.GITHUB_SHA }} |
| 160 | + DOCKER_LABEL=sha-${{ env.GITHUB_SHA_SHORT }} |
| 161 | + ${{matrix.extraBuildArgs}} |
| 162 | + tags: ${{ steps.meta-grpc.outputs.tags }} |
| 163 | + labels: ${{ steps.meta-grpc.outputs.labels }} |
| 164 | + cache-from: type=s3,region=us-east-1,bucket=ci-docker-buildx-cache,name=text-embeddings-inference-cache-${{matrix.name}},access_key_id=${{ secrets.S3_CI_DOCKER_BUILDX_CACHE_ACCESS_KEY_ID }},secret_access_key=${{ secrets.S3_CI_DOCKER_BUILDX_CACHE_SECRET_ACCESS_KEY }},mode=max |
0 commit comments