|
| 1 | +name: Build and Publish Docker Image |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [ main ] |
| 6 | + tags: [ 'v*.*.*' ] |
| 7 | + pull_request: |
| 8 | + branches: [ main ] |
| 9 | + workflow_dispatch: |
| 10 | + inputs: |
| 11 | + embedding_model: |
| 12 | + description: 'Embedding model to use' |
| 13 | + required: false |
| 14 | + default: 'multi-qa-MiniLM-L6-cos-v1' |
| 15 | + tokenizer_model: |
| 16 | + description: 'Tokenizer model to use' |
| 17 | + required: false |
| 18 | + default: 'sentence-transformers/multi-qa-MiniLM-L6-cos-v1' |
| 19 | + |
| 20 | +env: |
| 21 | + REGISTRY: ghcr.io |
| 22 | + IMAGE_NAME: ${{ github.repository }} |
| 23 | + |
| 24 | +jobs: |
| 25 | + build-and-push: |
| 26 | + runs-on: ubuntu-latest |
| 27 | + permissions: |
| 28 | + contents: read |
| 29 | + packages: write |
| 30 | + id-token: write |
| 31 | + |
| 32 | + steps: |
| 33 | + - name: Checkout repository |
| 34 | + uses: actions/checkout@v4 |
| 35 | + |
| 36 | + - name: Set up Docker Buildx |
| 37 | + uses: docker/setup-buildx-action@v3 |
| 38 | + |
| 39 | + - name: Log into registry ${{ env.REGISTRY }} |
| 40 | + if: github.event_name != 'pull_request' |
| 41 | + uses: docker/login-action@v3 |
| 42 | + with: |
| 43 | + registry: ${{ env.REGISTRY }} |
| 44 | + username: ${{ github.actor }} |
| 45 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 46 | + |
| 47 | + - name: Extract Docker metadata |
| 48 | + id: meta |
| 49 | + uses: docker/metadata-action@v5 |
| 50 | + with: |
| 51 | + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} |
| 52 | + tags: | |
| 53 | + type=ref,event=branch |
| 54 | + type=ref,event=pr |
| 55 | + type=semver,pattern={{version}} |
| 56 | + type=semver,pattern={{major}}.{{minor}} |
| 57 | + type=semver,pattern={{major}} |
| 58 | + type=sha,prefix=sha- |
| 59 | + type=raw,value=latest,enable={{is_default_branch}} |
| 60 | +
|
| 61 | + - name: Set build args |
| 62 | + id: build-args |
| 63 | + run: | |
| 64 | + if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then |
| 65 | + echo "EMBEDDING_MODEL=${{ github.event.inputs.embedding_model }}" >> $GITHUB_ENV |
| 66 | + echo "TOKENIZER_MODEL=${{ github.event.inputs.tokenizer_model }}" >> $GITHUB_ENV |
| 67 | + else |
| 68 | + echo "EMBEDDING_MODEL=multi-qa-MiniLM-L6-cos-v1" >> $GITHUB_ENV |
| 69 | + echo "TOKENIZER_MODEL=sentence-transformers/multi-qa-MiniLM-L6-cos-v1" >> $GITHUB_ENV |
| 70 | + fi |
| 71 | +
|
| 72 | + - name: Build and push Docker image |
| 73 | + id: build-and-push |
| 74 | + uses: docker/build-push-action@v5 |
| 75 | + with: |
| 76 | + context: . |
| 77 | + push: ${{ github.event_name != 'pull_request' }} |
| 78 | + load: ${{ github.event_name == 'pull_request' }} |
| 79 | + tags: ${{ steps.meta.outputs.tags }} |
| 80 | + labels: ${{ steps.meta.outputs.labels }} |
| 81 | + build-args: | |
| 82 | + EMBEDDING_MODEL=${{ env.EMBEDDING_MODEL }} |
| 83 | + TOKENIZER_MODEL=${{ env.TOKENIZER_MODEL }} |
| 84 | + cache-from: type=gha |
| 85 | + cache-to: type=gha,mode=max |
| 86 | + platforms: linux/amd64 |
| 87 | + |
| 88 | + - name: Generate artifact attestation |
| 89 | + if: github.event_name != 'pull_request' |
| 90 | + uses: actions/attest-build-provenance@v1 |
| 91 | + with: |
| 92 | + subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} |
| 93 | + subject-digest: ${{ steps.build-and-push.outputs.digest }} |
| 94 | + push-to-registry: true |
0 commit comments