ghcr.yml 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432
  1. # Workflow that builds, tests and then pushes the docker images to the ghcr.io repository
  2. name: Build Publish and Test Runtime Image
  3. # Only run one workflow of the same group at a time.
  4. # There can be at most one running and one pending job in a concurrency group at any time.
  5. concurrency:
  6. group: ${{ github.workflow }}-${{ github.ref }}
  7. cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
  8. on:
  9. push:
  10. branches:
  11. - main
  12. tags:
  13. - '*'
  14. pull_request:
  15. workflow_dispatch:
  16. inputs:
  17. reason:
  18. description: 'Reason for manual trigger'
  19. required: true
  20. default: ''
  21. jobs:
  22. # Builds the OpenDevin Docker images
  23. ghcr_build:
  24. runs-on: ubuntu-latest
  25. outputs:
  26. tags: ${{ steps.capture-tags.outputs.tags }}
  27. permissions:
  28. contents: read
  29. packages: write
  30. strategy:
  31. matrix:
  32. image: ['opendevin']
  33. platform: ['amd64', 'arm64']
  34. steps:
  35. - name: Checkout
  36. uses: actions/checkout@v4
  37. - name: Free Disk Space (Ubuntu)
  38. uses: jlumbroso/free-disk-space@main
  39. with:
  40. # this might remove tools that are actually needed,
  41. # if set to "true" but frees about 6 GB
  42. tool-cache: true
  43. # all of these default to true, but feel free to set to
  44. # "false" if necessary for your workflow
  45. android: true
  46. dotnet: true
  47. haskell: true
  48. large-packages: true
  49. docker-images: false
  50. swap-storage: true
  51. - name: Set up QEMU
  52. uses: docker/setup-qemu-action@v3
  53. - name: Set up Docker Buildx
  54. id: buildx
  55. uses: docker/setup-buildx-action@v3
  56. - name: Build and export image
  57. id: build
  58. run: ./containers/build.sh ${{ matrix.image }} ${{ github.repository_owner }} ${{ matrix.platform }}
  59. - name: Capture tags
  60. id: capture-tags
  61. run: |
  62. tags=$(cat tags.txt)
  63. echo "tags=$tags"
  64. echo "tags=$tags" >> $GITHUB_OUTPUT
  65. - name: Upload Docker image as artifact
  66. uses: actions/upload-artifact@v4
  67. with:
  68. name: ${{ matrix.image }}-docker-image-${{ matrix.platform }}
  69. path: /tmp/${{ matrix.image }}_image_${{ matrix.platform }}.tar
  70. retention-days: 14
  71. # Builds the runtime Docker images
  72. ghcr_build_runtime:
  73. runs-on: ubuntu-latest
  74. outputs:
  75. tags: ${{ steps.capture-tags.outputs.tags }}
  76. permissions:
  77. contents: read
  78. packages: write
  79. strategy:
  80. matrix:
  81. image: ['od_runtime']
  82. base_image: ['nikolaik/python-nodejs:python3.11-nodejs22']
  83. platform: ['amd64', 'arm64']
  84. steps:
  85. - name: Checkout
  86. uses: actions/checkout@v4
  87. - name: Free Disk Space (Ubuntu)
  88. uses: jlumbroso/free-disk-space@main
  89. with:
  90. # this might remove tools that are actually needed,
  91. # if set to "true" but frees about 6 GB
  92. tool-cache: true
  93. # all of these default to true, but feel free to set to
  94. # "false" if necessary for your workflow
  95. android: true
  96. dotnet: true
  97. haskell: true
  98. large-packages: true
  99. docker-images: false
  100. swap-storage: true
  101. - name: Set up QEMU
  102. uses: docker/setup-qemu-action@v3
  103. - name: Set up Docker Buildx
  104. id: buildx
  105. uses: docker/setup-buildx-action@v3
  106. - name: Install poetry via pipx
  107. run: pipx install poetry
  108. - name: Set up Python
  109. uses: actions/setup-python@v5
  110. with:
  111. python-version: '3.11'
  112. cache: 'poetry'
  113. - name: Install Python dependencies using Poetry
  114. run: make install-python-dependencies
  115. - name: Create source distribution and Dockerfile
  116. run: poetry run python3 opendevin/runtime/utils/runtime_build.py --base_image ${{ matrix.base_image }} --build_folder containers/runtime --force_rebuild
  117. - name: Build and export image
  118. id: build
  119. run: |
  120. if [ -f 'containers/runtime/Dockerfile' ]; then
  121. echo 'Dockerfile detected, building runtime image...'
  122. ./containers/build.sh ${{ matrix.image }} ${{ github.repository_owner }} ${{ matrix.platform }}
  123. else
  124. echo 'No Dockerfile detected which means an exact image is already built. Pulling the image and saving it to a tar file...'
  125. source containers/runtime/config.sh
  126. echo "$DOCKER_IMAGE_TAG $DOCKER_IMAGE_HASH_TAG" >> tags.txt
  127. echo "Pulling image $DOCKER_IMAGE/$DOCKER_IMAGE_HASH_TAG to /tmp/${{ matrix.image }}_image_${{ matrix.platform }}.tar"
  128. docker pull $DOCKER_IMAGE:$DOCKER_IMAGE_HASH_TAG
  129. docker save $DOCKER_IMAGE:$DOCKER_IMAGE_HASH_TAG -o /tmp/${{ matrix.image }}_image_${{ matrix.platform }}.tar
  130. fi
  131. - name: Capture tags
  132. id: capture-tags
  133. run: |
  134. tags=$(cat tags.txt)
  135. echo "tags=$tags"
  136. echo "tags=$tags" >> $GITHUB_OUTPUT
  137. - name: Upload Docker image as artifact
  138. uses: actions/upload-artifact@v4
  139. with:
  140. name: ${{ matrix.image }}-docker-image-${{ matrix.platform }}
  141. path: /tmp/${{ matrix.image }}_image_${{ matrix.platform }}.tar
  142. retention-days: 14
  143. # Run unit tests with the EventStream and Server runtime Docker images
  144. test_runtime:
  145. name: Test Runtime
  146. runs-on: ubuntu-latest
  147. needs: [ghcr_build_runtime, ghcr_build]
  148. strategy:
  149. matrix:
  150. runtime_type: ['eventstream']
  151. steps:
  152. - uses: actions/checkout@v4
  153. - name: Free Disk Space (Ubuntu)
  154. uses: jlumbroso/free-disk-space@main
  155. with:
  156. # this might remove tools that are actually needed,
  157. # when set to "true" but frees about 6 GB
  158. tool-cache: true
  159. # all of these default to true, but feel free to set to
  160. # "false" if necessary for your workflow
  161. android: true
  162. dotnet: true
  163. haskell: true
  164. large-packages: true
  165. swap-storage: true
  166. - name: Install poetry via pipx
  167. run: pipx install poetry
  168. - name: Set up Python
  169. uses: actions/setup-python@v5
  170. with:
  171. python-version: '3.11'
  172. cache: 'poetry'
  173. - name: Install Python dependencies using Poetry
  174. run: make install-python-dependencies
  175. - name: Download Runtime Docker image
  176. if: matrix.runtime_type == 'eventstream'
  177. uses: actions/download-artifact@v4
  178. with:
  179. name: od_runtime-docker-image-amd64
  180. path: /tmp/
  181. - name: Download Sandbox Docker image
  182. if: matrix.runtime_type == 'server'
  183. uses: actions/download-artifact@v4
  184. with:
  185. name: sandbox-docker-image-amd64
  186. path: /tmp/
  187. - name: Load Runtime image and run runtime tests
  188. run: |
  189. # Load the Docker image and capture the output
  190. if [ "${{ matrix.runtime_type }}" == "eventstream" ]; then
  191. output=$(docker load -i /tmp/od_runtime_image_amd64.tar)
  192. else
  193. output=$(docker load -i /tmp/sandbox_image_amd64.tar)
  194. fi
  195. # Extract the first image name from the output
  196. image_name=$(echo "$output" | grep -oP 'Loaded image: \K.*' | head -n 1)
  197. # Print the full name of the image
  198. echo "Loaded Docker image: $image_name"
  199. TEST_RUNTIME=${{ matrix.runtime_type }} SANDBOX_USER_ID=$(id -u) 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
  200. - name: Upload coverage to Codecov
  201. uses: codecov/codecov-action@v4
  202. env:
  203. CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
  204. # Run integration tests with the eventstream runtime Docker image
  205. runtime_integration_tests_on_linux:
  206. name: Runtime Integration Tests on Linux
  207. runs-on: ubuntu-latest
  208. needs: [ghcr_build_runtime]
  209. strategy:
  210. fail-fast: false
  211. matrix:
  212. python-version: ['3.11']
  213. # server is tested in a separate workflow
  214. runtime_type: ['eventstream']
  215. steps:
  216. - uses: actions/checkout@v4
  217. - name: Install poetry via pipx
  218. run: pipx install poetry
  219. - name: Set up Python
  220. uses: actions/setup-python@v5
  221. with:
  222. python-version: ${{ matrix.python-version }}
  223. cache: 'poetry'
  224. - name: Install Python dependencies using Poetry
  225. run: make install-python-dependencies
  226. - name: Download Runtime Docker image
  227. uses: actions/download-artifact@v4
  228. with:
  229. name: od_runtime-docker-image-amd64
  230. path: /tmp/
  231. - name: Load runtime image and run integration tests
  232. run: |
  233. # Load the Docker image and capture the output
  234. if [ "${{ matrix.runtime_type }}" == "eventstream" ]; then
  235. output=$(docker load -i /tmp/od_runtime_image_amd64.tar)
  236. else
  237. echo "No Runtime Docker image to load"
  238. exit 1
  239. fi
  240. # Extract the first image name from the output
  241. image_name=$(echo "$output" | grep -oP 'Loaded image: \K.*' | head -n 1)
  242. # Print the full name of the image
  243. echo "Loaded Docker image: $image_name"
  244. TEST_RUNTIME=${{ matrix.runtime_type }} SANDBOX_USER_ID=$(id -u) SANDBOX_CONTAINER_IMAGE=$image_name TEST_IN_CI=true TEST_ONLY=true ./tests/integration/regenerate.sh
  245. - name: Upload coverage to Codecov
  246. uses: codecov/codecov-action@v4
  247. env:
  248. CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
  249. # Push the OpenDevin and sandbox Docker images to the ghcr.io repository
  250. ghcr_push:
  251. runs-on: ubuntu-latest
  252. needs: [ghcr_build]
  253. if: github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/')
  254. env:
  255. tags: ${{ needs.ghcr_build.outputs.tags }}
  256. permissions:
  257. contents: read
  258. packages: write
  259. strategy:
  260. matrix:
  261. image: ['opendevin']
  262. platform: ['amd64', 'arm64']
  263. steps:
  264. - name: Checkout code
  265. uses: actions/checkout@v4
  266. - name: Login to GHCR
  267. uses: docker/login-action@v2
  268. with:
  269. registry: ghcr.io
  270. username: ${{ github.repository_owner }}
  271. password: ${{ secrets.GITHUB_TOKEN }}
  272. - name: Download Docker images
  273. uses: actions/download-artifact@v4
  274. with:
  275. name: ${{ matrix.image }}-docker-image-${{ matrix.platform }}
  276. path: /tmp/${{ matrix.platform }}
  277. - name: Load images and push to registry
  278. run: |
  279. mv /tmp/${{ matrix.platform }}/${{ matrix.image }}_image_${{ matrix.platform }}.tar .
  280. loaded_image=$(docker load -i ${{ matrix.image }}_image_${{ matrix.platform }}.tar | grep "Loaded image:" | head -n 1 | awk '{print $3}')
  281. echo "loaded image = $loaded_image"
  282. tags=$(echo ${tags} | tr ' ' '\n')
  283. image_name=$(echo "ghcr.io/${{ github.repository_owner }}/${{ matrix.image }}" | tr '[:upper:]' '[:lower:]')
  284. echo "image name = $image_name"
  285. for tag in $tags; do
  286. echo "tag = $tag"
  287. docker tag $loaded_image $image_name:${tag}_${{ matrix.platform }}
  288. docker push $image_name:${tag}_${{ matrix.platform }}
  289. done
  290. # Push the runtime Docker images to the ghcr.io repository
  291. ghcr_push_runtime:
  292. runs-on: ubuntu-latest
  293. needs: [ghcr_build_runtime, test_runtime, runtime_integration_tests_on_linux]
  294. if: github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/')
  295. env:
  296. RUNTIME_TAGS: ${{ needs.ghcr_build_runtime.outputs.tags }}
  297. permissions:
  298. contents: read
  299. packages: write
  300. strategy:
  301. matrix:
  302. image: ['od_runtime']
  303. platform: ['amd64', 'arm64']
  304. steps:
  305. - name: Checkout code
  306. uses: actions/checkout@v4
  307. - name: Free Disk Space (Ubuntu)
  308. uses: jlumbroso/free-disk-space@main
  309. with:
  310. tool-cache: true
  311. android: true
  312. dotnet: true
  313. haskell: true
  314. large-packages: true
  315. docker-images: false
  316. swap-storage: true
  317. - name: Login to GHCR
  318. uses: docker/login-action@v2
  319. with:
  320. registry: ghcr.io
  321. username: ${{ github.repository_owner }}
  322. password: ${{ secrets.GITHUB_TOKEN }}
  323. - name: Download Docker images
  324. uses: actions/download-artifact@v4
  325. with:
  326. name: ${{ matrix.image }}-docker-image-${{ matrix.platform }}
  327. path: /tmp/${{ matrix.platform }}
  328. - name: List downloaded files
  329. run: |
  330. ls -la /tmp/${{ matrix.platform }}
  331. file /tmp/${{ matrix.platform }}/*
  332. - name: Load images and push to registry
  333. run: |
  334. mv /tmp/${{ matrix.platform }}/${{ matrix.image }}_image_${{ matrix.platform }}.tar ./${{ matrix.image }}_image_${{ matrix.platform }}.tar
  335. if ! loaded_image=$(docker load -i ${{ matrix.image }}_image_${{ matrix.platform }}.tar | grep "Loaded image:" | head -n 1 | awk '{print $3}'); then
  336. echo "Failed to load Docker image"
  337. exit 1
  338. fi
  339. echo "loaded image = $loaded_image"
  340. image_name=$(echo "ghcr.io/${{ github.repository_owner }}/${{ matrix.image }}" | tr '[:upper:]' '[:lower:]')
  341. echo "image name = $image_name"
  342. echo "$RUNTIME_TAGS" | tr ' ' '\n' | while read -r tag; do
  343. echo "tag = $tag"
  344. if [ -n "$image_name" ] && [ -n "$tag" ]; then
  345. docker tag $loaded_image $image_name:${tag}_${{ matrix.platform }}
  346. docker push $image_name:${tag}_${{ matrix.platform }}
  347. else
  348. echo "Skipping tag and push due to empty image_name or tag"
  349. fi
  350. done
  351. # Creates and pushes the OpenDevin and sandbox Docker image manifests
  352. create_manifest:
  353. runs-on: ubuntu-latest
  354. needs: [ghcr_build, ghcr_push]
  355. if: github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/')
  356. env:
  357. tags: ${{ needs.ghcr_build.outputs.tags }}
  358. strategy:
  359. matrix:
  360. image: ['opendevin']
  361. permissions:
  362. contents: read
  363. packages: write
  364. steps:
  365. - name: Checkout code
  366. uses: actions/checkout@v4
  367. - name: Login to GHCR
  368. uses: docker/login-action@v2
  369. with:
  370. registry: ghcr.io
  371. username: ${{ github.repository_owner }}
  372. password: ${{ secrets.GITHUB_TOKEN }}
  373. - name: Create and push multi-platform manifest
  374. run: |
  375. image_name=$(echo "ghcr.io/${{ github.repository_owner }}/${{ matrix.image }}" | tr '[:upper:]' '[:lower:]')
  376. echo "image name = $image_name"
  377. tags=$(echo ${tags} | tr ' ' '\n')
  378. for tag in $tags; do
  379. echo 'tag = $tag'
  380. docker buildx imagetools create --tag $image_name:$tag \
  381. $image_name:${tag}_amd64 \
  382. $image_name:${tag}_arm64
  383. done
  384. # Creates and pushes the runtime Docker image manifest
  385. create_manifest_runtime:
  386. runs-on: ubuntu-latest
  387. needs: [ghcr_build_runtime, ghcr_push_runtime]
  388. if: github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/')
  389. env:
  390. tags: ${{ needs.ghcr_build_runtime.outputs.tags }}
  391. strategy:
  392. matrix:
  393. image: ['od_runtime']
  394. permissions:
  395. contents: read
  396. packages: write
  397. steps:
  398. - name: Checkout code
  399. uses: actions/checkout@v4
  400. - name: Login to GHCR
  401. uses: docker/login-action@v2
  402. with:
  403. registry: ghcr.io
  404. username: ${{ github.repository_owner }}
  405. password: ${{ secrets.GITHUB_TOKEN }}
  406. - name: Create and push multi-platform manifest
  407. run: |
  408. image_name=$(echo "ghcr.io/${{ github.repository_owner }}/${{ matrix.image }}" | tr '[:upper:]' '[:lower:]')
  409. echo "image name = $image_name"
  410. tags=$(echo ${tags} | tr ' ' '\n')
  411. for tag in $tags; do
  412. echo 'tag = $tag'
  413. docker buildx imagetools create --tag $image_name:$tag \
  414. $image_name:${tag}_amd64 \
  415. $image_name:${tag}_arm64
  416. done