docker.yaml 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. # Ultralytics YOLO 🚀, AGPL-3.0 license
  2. # Builds ultralytics/ultralytics:latest images on DockerHub https://hub.docker.com/r/ultralytics
  3. name: Publish Docker Images
  4. on:
  5. push:
  6. branches: [main]
  7. workflow_dispatch:
  8. inputs:
  9. dockerfile:
  10. type: choice
  11. description: Select Dockerfile
  12. options:
  13. - Dockerfile-arm64
  14. - Dockerfile-jetson
  15. - Dockerfile-python
  16. - Dockerfile-cpu
  17. - Dockerfile
  18. push:
  19. type: boolean
  20. description: Push image to Docker Hub
  21. default: true
  22. jobs:
  23. docker:
  24. if: github.repository == 'ultralytics/ultralytics'
  25. name: Push
  26. runs-on: ubuntu-latest
  27. strategy:
  28. fail-fast: false
  29. max-parallel: 5
  30. matrix:
  31. include:
  32. - dockerfile: "Dockerfile-arm64"
  33. tags: "latest-arm64"
  34. platforms: "linux/arm64"
  35. - dockerfile: "Dockerfile-jetson"
  36. tags: "latest-jetson"
  37. platforms: "linux/arm64"
  38. - dockerfile: "Dockerfile-python"
  39. tags: "latest-python"
  40. platforms: "linux/amd64"
  41. - dockerfile: "Dockerfile-cpu"
  42. tags: "latest-cpu"
  43. platforms: "linux/amd64"
  44. - dockerfile: "Dockerfile"
  45. tags: "latest"
  46. platforms: "linux/amd64"
  47. steps:
  48. - name: Checkout repo
  49. uses: actions/checkout@v3
  50. - name: Set up QEMU
  51. uses: docker/setup-qemu-action@v2
  52. - name: Set up Docker Buildx
  53. uses: docker/setup-buildx-action@v2
  54. - name: Login to Docker Hub
  55. uses: docker/login-action@v2
  56. with:
  57. username: ${{ secrets.DOCKERHUB_USERNAME }}
  58. password: ${{ secrets.DOCKERHUB_TOKEN }}
  59. - name: Retrieve Ultralytics version
  60. id: get_version
  61. run: |
  62. VERSION=$(grep "^__version__ =" ultralytics/__init__.py | awk -F"'" '{print $2}')
  63. echo "Retrieved Ultralytics version: $VERSION"
  64. echo "version=$VERSION" >> $GITHUB_OUTPUT
  65. VERSION_TAG=$(echo "${{ matrix.tags }}" | sed "s/latest/${VERSION}/")
  66. echo "Intended version tag: $VERSION_TAG"
  67. echo "version_tag=$VERSION_TAG" >> $GITHUB_OUTPUT
  68. - name: Check if version tag exists on DockerHub
  69. id: check_tag
  70. run: |
  71. RESPONSE=$(curl -s https://hub.docker.com/v2/repositories/ultralytics/ultralytics/tags/$VERSION_TAG)
  72. MESSAGE=$(echo $RESPONSE | jq -r '.message')
  73. if [[ "$MESSAGE" == "null" ]]; then
  74. echo "Tag $VERSION_TAG already exists on DockerHub."
  75. echo "exists=true" >> $GITHUB_OUTPUT
  76. elif [[ "$MESSAGE" == *"404"* ]]; then
  77. echo "Tag $VERSION_TAG does not exist on DockerHub."
  78. echo "exists=false" >> $GITHUB_OUTPUT
  79. else
  80. echo "Unexpected response from DockerHub. Please check manually."
  81. echo "exists=false" >> $GITHUB_OUTPUT
  82. fi
  83. env:
  84. VERSION_TAG: ${{ steps.get_version.outputs.version_tag }}
  85. - name: Build Image
  86. if: github.event_name == 'push' || github.event.inputs.dockerfile == matrix.dockerfile
  87. run: |
  88. docker build --platform ${{ matrix.platforms }} -f docker/${{ matrix.dockerfile }} \
  89. -t ultralytics/ultralytics:${{ matrix.tags }} \
  90. -t ultralytics/ultralytics:${{ steps.get_version.outputs.version_tag }} .
  91. - name: Run Tests
  92. if: (github.event_name == 'push' || github.event.inputs.dockerfile == matrix.dockerfile) && matrix.platforms == 'linux/amd64' # arm64 images not supported on GitHub CI runners
  93. run: docker run ultralytics/ultralytics:${{ matrix.tags }} /bin/bash -c "pip install pytest && pytest tests"
  94. - name: Run Benchmarks
  95. # WARNING: Dockerfile (GPU) error on TF.js export 'module 'numpy' has no attribute 'object'.
  96. if: (github.event_name == 'push' || github.event.inputs.dockerfile == matrix.dockerfile) && matrix.platforms == 'linux/amd64' && matrix.dockerfile != 'Dockerfile' # arm64 images not supported on GitHub CI runners
  97. run: docker run ultralytics/ultralytics:${{ matrix.tags }} yolo benchmark model=yolov8n.pt imgsz=160 verbose=0.26
  98. - name: Push Docker Image with Ultralytics version tag
  99. if: (github.event_name == 'push' || (github.event.inputs.dockerfile == matrix.dockerfile && github.event.inputs.push == 'true')) && steps.check_tag.outputs.exists == 'false'
  100. run: |
  101. docker push ultralytics/ultralytics:${{ steps.get_version.outputs.version_tag }}
  102. - name: Push Docker Image with latest tag
  103. if: github.event_name == 'push' || (github.event.inputs.dockerfile == matrix.dockerfile && github.event.inputs.push == 'true')
  104. run: |
  105. docker push ultralytics/ultralytics:${{ matrix.tags }}
  106. - name: Notify on failure
  107. if: github.event_name == 'push' && failure() # do not notify on cancelled() as cancelling is performed by hand
  108. uses: slackapi/slack-github-action@v1.24.0
  109. with:
  110. payload: |
  111. {"text": "<!channel> GitHub Actions error for ${{ github.workflow }} ❌\n\n\n*Repository:* https://github.com/${{ github.repository }}\n*Action:* https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}\n*Author:* ${{ github.actor }}\n*Event:* ${{ github.event_name }}\n"}
  112. env:
  113. SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL_YOLO }}