| name: Build and Push Elizabeth Images | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| tag: | |
| description: Optional additional tag (e.g., 0.1.0) | |
| required: false | |
| type: string | |
| push: | |
| branches: [ main ] | |
| tags: [ 'v*', 'release-*' ] | |
| env: | |
| REGISTRY: docker.io | |
| REPO_OWNER: ${{ secrets.DOCKERHUB_USERNAME }} | |
| jobs: | |
| build-and-push: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| packages: write | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| include: | |
| - name: serve | |
| dockerfile: docker/serve/Dockerfile | |
| imagename: elizabeth-serve | |
| - name: train | |
| dockerfile: docker/train/Dockerfile | |
| imagename: elizabeth-train | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Login to Docker Hub | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ${{ env.REGISTRY }} | |
| username: ${{ secrets.DOCKERHUB_USERNAME }} | |
| password: ${{ secrets.DOCKERHUB_TOKEN }} | |
| - name: Login to GHCR | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Compute tags (Docker Hub + GHCR) | |
| id: meta | |
| run: | | |
| IMAGE_DH=${{ env.REGISTRY }}/${{ env.REPO_OWNER }}/${{ matrix.imagename }} | |
| IMAGE_GHCR=ghcr.io/${{ github.repository_owner }}/${{ matrix.imagename }} | |
| SHA_TAG=${GITHUB_SHA::12} | |
| echo "image_dh=${IMAGE_DH}" >> $GITHUB_OUTPUT | |
| echo "image_ghcr=${IMAGE_GHCR}" >> $GITHUB_OUTPUT | |
| TAGS="${IMAGE_DH}:latest,${IMAGE_DH}:${SHA_TAG},${IMAGE_GHCR}:latest,${IMAGE_GHCR}:${SHA_TAG}" | |
| if [[ "${{ github.ref }}" == refs/tags/* ]]; then | |
| REF_TAG="${GITHUB_REF##*/}" | |
| TAGS+=" ,${IMAGE_DH}:${REF_TAG} ,${IMAGE_GHCR}:${REF_TAG}" | |
| fi | |
| if [[ -n "${{ inputs.tag }}" ]]; then | |
| TAGS+=" ,${IMAGE_DH}:${{ inputs.tag }} ,${IMAGE_GHCR}:${{ inputs.tag }}" | |
| fi | |
| echo "tags=${TAGS}" >> $GITHUB_OUTPUT | |
| - name: Build and push ${{ matrix.name }} | |
| uses: docker/build-push-action@v5 | |
| with: | |
| context: . | |
| file: ${{ matrix.dockerfile }} | |
| push: true | |
| tags: ${{ steps.meta.outputs.tags }} | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max | |