ghcr-runtime.yml 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. name: Build Publish and Test Runtime Image
  2. concurrency:
  3. group: ${{ github.workflow }}-${{ github.ref }}
  4. cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
  5. on:
  6. push:
  7. branches:
  8. - main
  9. tags:
  10. - '*'
  11. pull_request:
  12. workflow_dispatch:
  13. inputs:
  14. reason:
  15. description: 'Reason for manual trigger'
  16. required: true
  17. default: ''
  18. jobs:
  19. ghcr_build_runtime:
  20. runs-on: ubuntu-latest
  21. outputs:
  22. tags: ${{ steps.capture-tags.outputs.tags }}
  23. permissions:
  24. contents: read
  25. packages: write
  26. strategy:
  27. matrix:
  28. image: ["od_runtime"]
  29. base_image: ["ubuntu:22.04"]
  30. platform: ["amd64", "arm64"]
  31. steps:
  32. - name: Checkout
  33. uses: actions/checkout@v4
  34. - name: Free Disk Space (Ubuntu)
  35. uses: jlumbroso/free-disk-space@main
  36. with:
  37. # this might remove tools that are actually needed,
  38. # if set to "true" but frees about 6 GB
  39. tool-cache: true
  40. # all of these default to true, but feel free to set to
  41. # "false" if necessary for your workflow
  42. android: true
  43. dotnet: true
  44. haskell: true
  45. large-packages: true
  46. docker-images: false
  47. swap-storage: true
  48. - name: Set up QEMU
  49. uses: docker/setup-qemu-action@v3
  50. - name: Set up Docker Buildx
  51. id: buildx
  52. uses: docker/setup-buildx-action@v3
  53. - name: Install poetry via pipx
  54. run: pipx install poetry
  55. - name: Set up Python
  56. uses: actions/setup-python@v5
  57. with:
  58. python-version: "3.11"
  59. cache: "poetry"
  60. - name: Install Python dependencies using Poetry
  61. run: make install-python-dependencies
  62. - name: Create source distribution and Dockerfile
  63. run: poetry run python3 opendevin/runtime/utils/runtime_build.py --base_image ${{ matrix.base_image }} --build_folder containers/runtime
  64. - name: Build and export image
  65. id: build
  66. run: ./containers/build.sh ${{ matrix.image }} ${{ github.repository_owner }} ${{ matrix.platform }}
  67. - name: Capture tags
  68. id: capture-tags
  69. run: |
  70. tags=$(cat tags.txt)
  71. echo "tags=$tags"
  72. echo "tags=$tags" >> $GITHUB_OUTPUT
  73. - name: Upload Docker image as artifact
  74. uses: actions/upload-artifact@v4
  75. with:
  76. name: ${{ matrix.image }}-docker-image-${{ matrix.platform }}
  77. path: /tmp/${{ matrix.image }}_image_${{ matrix.platform }}.tar
  78. test-for-runtime:
  79. name: Test for Runtime
  80. runs-on: ubuntu-latest
  81. needs: ghcr_build_runtime
  82. env:
  83. PERSIST_SANDBOX: "false"
  84. steps:
  85. - uses: actions/checkout@v4
  86. - name: Free Disk Space (Ubuntu)
  87. uses: jlumbroso/free-disk-space@main
  88. with:
  89. # this might remove tools that are actually needed,
  90. # when set to "true" but frees about 6 GB
  91. tool-cache: true
  92. # all of these default to true, but feel free to set to
  93. # "false" if necessary for your workflow
  94. android: true
  95. dotnet: true
  96. haskell: true
  97. large-packages: true
  98. swap-storage: true
  99. - name: Install poetry via pipx
  100. run: pipx install poetry
  101. - name: Set up Python
  102. uses: actions/setup-python@v5
  103. with:
  104. python-version: "3.11"
  105. cache: "poetry"
  106. - name: Install Python dependencies using Poetry
  107. run: make install-python-dependencies
  108. - name: Download Runtime Docker image
  109. uses: actions/download-artifact@v4
  110. with:
  111. name: od_runtime-docker-image-amd64
  112. path: /tmp/
  113. - name: Load Runtime image and run runtime tests
  114. run: |
  115. # Load the Docker image and capture the output
  116. output=$(docker load -i /tmp/od_runtime_image_amd64.tar)
  117. # Extract the first image name from the output
  118. image_name=$(echo "$output" | grep -oP 'Loaded image: \K.*' | head -n 1)
  119. # Print the full name of the image
  120. echo "Loaded Docker image: $image_name"
  121. SANDBOX_CONTAINER_IMAGE=$image_name TEST_IN_CI=true poetry run pytest --cov=agenthub --cov=opendevin --cov-report=xml -s ./tests/unit/test_runtime.py
  122. - name: Upload coverage to Codecov
  123. uses: codecov/codecov-action@v4
  124. env:
  125. CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
  126. ghcr_push:
  127. runs-on: ubuntu-latest
  128. # don't push if runtime tests fail
  129. needs: [ghcr_build_runtime, test-for-runtime]
  130. if: github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/')
  131. env:
  132. tags: ${{ needs.ghcr_build_runtime.outputs.tags }}
  133. permissions:
  134. contents: read
  135. packages: write
  136. strategy:
  137. matrix:
  138. image: ["od_runtime"]
  139. platform: ["amd64", "arm64"]
  140. steps:
  141. - name: Checkout code
  142. uses: actions/checkout@v4
  143. - name: Login to GHCR
  144. uses: docker/login-action@v2
  145. with:
  146. registry: ghcr.io
  147. username: ${{ github.repository_owner }}
  148. password: ${{ secrets.GITHUB_TOKEN }}
  149. - name: Download Docker images
  150. uses: actions/download-artifact@v4
  151. with:
  152. name: ${{ matrix.image }}-docker-image-${{ matrix.platform }}
  153. path: /tmp/${{ matrix.platform }}
  154. - name: Load images and push to registry
  155. run: |
  156. mv /tmp/${{ matrix.platform }}/${{ matrix.image }}_image_${{ matrix.platform }}.tar .
  157. loaded_image=$(docker load -i ${{ matrix.image }}_image_${{ matrix.platform }}.tar | grep "Loaded image:" | head -n 1 | awk '{print $3}')
  158. echo "loaded image = $loaded_image"
  159. tags=$(echo ${tags} | tr ' ' '\n')
  160. image_name=$(echo "ghcr.io/${{ github.repository_owner }}/${{ matrix.image }}" | tr '[:upper:]' '[:lower:]')
  161. echo "image name = $image_name"
  162. for tag in $tags; do
  163. echo "tag = $tag"
  164. docker tag $loaded_image $image_name:${tag}_${{ matrix.platform }}
  165. docker push $image_name:${tag}_${{ matrix.platform }}
  166. done
  167. create_manifest:
  168. runs-on: ubuntu-latest
  169. needs: [ghcr_build_runtime, ghcr_push]
  170. if: github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/')
  171. env:
  172. tags: ${{ needs.ghcr_build_runtime.outputs.tags }}
  173. strategy:
  174. matrix:
  175. image: ["od_runtime"]
  176. permissions:
  177. contents: read
  178. packages: write
  179. steps:
  180. - name: Checkout code
  181. uses: actions/checkout@v4
  182. - name: Login to GHCR
  183. uses: docker/login-action@v2
  184. with:
  185. registry: ghcr.io
  186. username: ${{ github.repository_owner }}
  187. password: ${{ secrets.GITHUB_TOKEN }}
  188. - name: Create and push multi-platform manifest
  189. run: |
  190. image_name=$(echo "ghcr.io/${{ github.repository_owner }}/${{ matrix.image }}" | tr '[:upper:]' '[:lower:]')
  191. echo "image name = $image_name"
  192. tags=$(echo ${tags} | tr ' ' '\n')
  193. for tag in $tags; do
  194. echo 'tag = $tag'
  195. docker buildx imagetools create --tag $image_name:$tag \
  196. $image_name:${tag}_amd64 \
  197. $image_name:${tag}_arm64
  198. done