|
| 1 | + name: Build and push Cuda Turing 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_75.yaml" |
| 13 | +# - "integration-tests/**" |
| 14 | + - "backends/**" |
| 15 | + - "core/**" |
| 16 | + - "router/**" |
| 17 | + - "Cargo.lock" |
| 18 | + - "rust-toolchain.toml" |
| 19 | + - "Dockerfile" |
| 20 | + branches: |
| 21 | + - 'main' |
| 22 | + |
| 23 | + jobs: |
| 24 | + start-runner: |
| 25 | + name: Start self-hosted EC2 runner |
| 26 | + runs-on: ubuntu-latest |
| 27 | + env: |
| 28 | + AWS_REGION: us-east-1 |
| 29 | + EC2_AMI_ID: ami-03cfed9ea28f4b002 |
| 30 | + EC2_INSTANCE_TYPE: r5.8xlarge |
| 31 | + EC2_SUBNET_ID: subnet-931b34f5,subnet-ecb993cd,subnet-943dc2d8,subnet-45371f1a,subnet-ee93e0df,subnet-fddc3dfc |
| 32 | + EC2_SECURITY_GROUP: sg-030175c435ac141d6 |
| 33 | + outputs: |
| 34 | + label: ${{ steps.start-ec2-runner.outputs.label }} |
| 35 | + ec2-instance-id: ${{ steps.start-ec2-runner.outputs.ec2-instance-id }} |
| 36 | + steps: |
| 37 | + - name: Configure AWS credentials |
| 38 | + uses: aws-actions/configure-aws-credentials@v1 |
| 39 | + with: |
| 40 | + aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} |
| 41 | + aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} |
| 42 | + aws-region: ${{ env.AWS_REGION }} |
| 43 | + - name: Start EC2 runner |
| 44 | + id: start-ec2-runner |
| 45 | + uses: philschmid/philschmid-ec2-github-runner@main |
| 46 | + with: |
| 47 | + mode: start |
| 48 | + github-token: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }} |
| 49 | + ec2-image-id: ${{ env.EC2_AMI_ID }} |
| 50 | + ec2-instance-type: ${{ env.EC2_INSTANCE_TYPE }} |
| 51 | + subnet-id: ${{ env.EC2_SUBNET_ID }} |
| 52 | + security-group-id: ${{ env.EC2_SECURITY_GROUP }} |
| 53 | + aws-resource-tags: > # optional, requires additional permissions |
| 54 | + [ |
| 55 | + {"Key": "Name", "Value": "ec2-tei-github-runner"}, |
| 56 | + {"Key": "GitHubRepository", "Value": "${{ github.repository }}"} |
| 57 | + ] |
| 58 | +
|
| 59 | + build-and-push-image: |
| 60 | + concurrency: |
| 61 | + group: ${{ github.workflow }}-${{ github.job }}-75-${{ github.head_ref || github.run_id }} |
| 62 | + cancel-in-progress: true |
| 63 | + needs: start-runner # required to start the main job when the runner is ready |
| 64 | + runs-on: ${{ needs.start-runner.outputs.label }} # run the job on the newly created runner |
| 65 | + permissions: |
| 66 | + contents: write |
| 67 | + packages: write |
| 68 | + # This is used to complete the identity challenge |
| 69 | + # with sigstore/fulcio when running outside of PRs. |
| 70 | + id-token: write |
| 71 | + security-events: write |
| 72 | + steps: |
| 73 | + - name: Checkout repository |
| 74 | + uses: actions/checkout@v3 |
| 75 | + - name: Initialize Docker Buildx |
| 76 | + uses: docker/setup-buildx-action@v2.0.0 |
| 77 | + with: |
| 78 | + install: true |
| 79 | + - name: Configure sccache |
| 80 | + uses: actions/github-script@v6 |
| 81 | + with: |
| 82 | + script: | |
| 83 | + core.exportVariable('ACTIONS_CACHE_URL', process.env.ACTIONS_CACHE_URL || ''); |
| 84 | + core.exportVariable('ACTIONS_RUNTIME_TOKEN', process.env.ACTIONS_RUNTIME_TOKEN || ''); |
| 85 | + - name: Inject slug/short variables |
| 86 | + uses: rlespinasse/github-slug-action@v4.4.1 |
| 87 | + - name: Tailscale |
| 88 | + uses: tailscale/github-action@7bd8039bf25c23c4ab1b8d6e2cc2da2280601966 |
| 89 | + with: |
| 90 | + authkey: ${{ secrets.TAILSCALE_AUTHKEY }} |
| 91 | + - name: Login to GitHub Container Registry |
| 92 | + if: github.event_name != 'pull_request' |
| 93 | + uses: docker/login-action@v2 |
| 94 | + with: |
| 95 | + registry: ghcr.io |
| 96 | + username: ${{ github.actor }} |
| 97 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 98 | + - name: Login to internal Container Registry |
| 99 | + uses: docker/login-action@v2.1.0 |
| 100 | + with: |
| 101 | + username: ${{ secrets.TAILSCALE_DOCKER_USERNAME }} |
| 102 | + password: ${{ secrets.TAILSCALE_DOCKER_PASSWORD }} |
| 103 | + registry: registry.internal.huggingface.tech |
| 104 | + - name: Extract metadata (tags, labels) for Docker |
| 105 | + id: meta-75 |
| 106 | + uses: docker/metadata-action@v4.3.0 |
| 107 | + with: |
| 108 | + images: | |
| 109 | + registry.internal.huggingface.tech/api-inference/text-embeddings-inference |
| 110 | + ghcr.io/huggingface/text-embeddings-inference |
| 111 | + tags: | |
| 112 | + type=semver,pattern=turing-{{version}} |
| 113 | + type=semver,pattern=turing-{{major}}.{{minor}} |
| 114 | + type=raw,value=turing-latest,enable=${{ github.ref == format('refs/heads/{0}', github.event.repository.default_branch) }} |
| 115 | + type=raw,value=turing-sha-${{ env.GITHUB_SHA_SHORT }} |
| 116 | + - name: Build and push Docker image |
| 117 | + id: build-and-push-75 |
| 118 | + uses: docker/build-push-action@v4 |
| 119 | + with: |
| 120 | + context: . |
| 121 | + file: Dockerfile-cuda |
| 122 | + push: ${{ github.event_name != 'pull_request' }} |
| 123 | + platforms: 'linux/amd64' |
| 124 | + build-args: | |
| 125 | + SCCACHE_GHA_ENABLED=on |
| 126 | + ACTIONS_CACHE_URL=${{ env.ACTIONS_CACHE_URL }} |
| 127 | + ACTIONS_RUNTIME_TOKEN=${{ env.ACTIONS_RUNTIME_TOKEN }} |
| 128 | + CUDA_COMPUTE_CAP=75 |
| 129 | + GIT_SHA=${{ env.GITHUB_SHA }} |
| 130 | + DOCKER_LABEL=sha-${{ env.GITHUB_SHA_SHORT }} |
| 131 | + tags: ${{ steps.meta-75.outputs.tags }} |
| 132 | + labels: ${{ steps.meta-75.outputs.labels }} |
| 133 | + cache-from: type=registry,ref=registry.internal.huggingface.tech/api-inference/text-embeddings-inference:cache-75,mode=max |
| 134 | + cache-to: type=registry,ref=registry.internal.huggingface.tech/api-inference/text-embeddings-inference:cache-75,mode=max |
| 135 | + |
| 136 | + stop-runner: |
| 137 | + name: Stop self-hosted EC2 runner |
| 138 | + needs: |
| 139 | + - start-runner |
| 140 | + - build-and-push-image |
| 141 | + runs-on: ubuntu-latest |
| 142 | + env: |
| 143 | + AWS_REGION: us-east-1 |
| 144 | + if: ${{ always() }} # required to stop the runner even if the error happened in the previous jobs |
| 145 | + steps: |
| 146 | + - name: Configure AWS credentials |
| 147 | + uses: aws-actions/configure-aws-credentials@v1 |
| 148 | + with: |
| 149 | + aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} |
| 150 | + aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} |
| 151 | + aws-region: ${{ env.AWS_REGION }} |
| 152 | + - name: Stop EC2 runner |
| 153 | + uses: philschmid/philschmid-ec2-github-runner@main |
| 154 | + with: |
| 155 | + mode: stop |
| 156 | + github-token: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }} |
| 157 | + label: ${{ needs.start-runner.outputs.label }} |
| 158 | + ec2-instance-id: ${{ needs.start-runner.outputs.ec2-instance-id }} |
0 commit comments