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