|
| 1 | +name: Build and Push Image to Docker Hub |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + image: |
| 7 | + description: Image to build |
| 8 | + required: true |
| 9 | + type: choice |
| 10 | + options: |
| 11 | + - inspect-computer-tool |
| 12 | + - inspect-web-browser-tool |
| 13 | + - inspect-tool-support |
| 14 | + tag: |
| 15 | + description: Tag to assign to the image |
| 16 | + required: true |
| 17 | + type: string |
| 18 | + default: latest |
| 19 | + platforms: |
| 20 | + description: Target platforms (comma-separated list) |
| 21 | + required: true |
| 22 | + type: string |
| 23 | + default: linux/amd64,linux/arm64 |
| 24 | + push: |
| 25 | + description: Push the image to Docker Hub |
| 26 | + required: true |
| 27 | + type: boolean |
| 28 | + default: true |
| 29 | + org: |
| 30 | + description: Docker Hub organization |
| 31 | + required: true |
| 32 | + type: string |
| 33 | + default: aisiuk |
| 34 | + |
| 35 | +jobs: |
| 36 | + build-and-push: |
| 37 | + runs-on: ubuntu-latest |
| 38 | + environment: docker |
| 39 | + steps: |
| 40 | + - name: Checkout repository |
| 41 | + uses: actions/checkout@v3 |
| 42 | + - name: Set build context path and image name |
| 43 | + run: | |
| 44 | + if [[ "${{ github.event.inputs.image }}" == "inspect-computer-tool" ]]; then |
| 45 | + echo "BUILD_CONTEXT=src/inspect_ai/tool/_tools/_computer/_resources" >> $GITHUB_ENV |
| 46 | + elif [[ "${{ github.event.inputs.image }}" == "inspect-web-browser-tool" ]]; then |
| 47 | + echo "BUILD_CONTEXT=src/inspect_ai/tool/_tools/_web_browser/_resources" >> $GITHUB_ENV |
| 48 | + elif [[ "${{ github.event.inputs.image }}" == "inspect-tool-support" ]]; then |
| 49 | + echo "BUILD_CONTEXT=src/inspect_tool_support" >> $GITHUB_ENV |
| 50 | + else |
| 51 | + echo "Invalid image name '${{ github.event.inputs.image }}'" |
| 52 | + exit 1 |
| 53 | + fi |
| 54 | + - name: Login to DockerHub |
| 55 | + uses: docker/login-action@v2 |
| 56 | + with: |
| 57 | + username: ${{ secrets.DOCKERHUB_USERNAME }} |
| 58 | + password: ${{ secrets.DOCKERHUB_TOKEN }} |
| 59 | + - name: Set up QEMU |
| 60 | + uses: docker/setup-qemu-action@v2 |
| 61 | + with: |
| 62 | + platforms: arm64,amd64 |
| 63 | + - name: Set up Docker Buildx |
| 64 | + id: buildx |
| 65 | + uses: docker/setup-buildx-action@v2 |
| 66 | + with: |
| 67 | + install: true |
| 68 | + - name: Build and (optionally) push multi-arch image |
| 69 | + uses: docker/build-push-action@v4 |
| 70 | + with: |
| 71 | + context: ${{ env.BUILD_CONTEXT }} |
| 72 | + push: ${{ github.event.inputs.push }} |
| 73 | + platforms: ${{ github.event.inputs.platforms }} |
| 74 | + tags: ${{ github.event.inputs.org }}/${{ github.event.inputs.image }}:${{ github.event.inputs.tag }} |
| 75 | + cache-from: type=gha |
| 76 | + cache-to: type=gha,mode=max |
0 commit comments