|
| 1 | +name: Build envd Base Image |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + paths: |
| 6 | + - 'docker/Dockerfile.cube-base' |
| 7 | + - 'docker/cube-entrypoint.sh' |
| 8 | + - '.github/workflows/build-envd-base-image.yml' |
| 9 | + pull_request: |
| 10 | + paths: |
| 11 | + - 'docker/Dockerfile.cube-base' |
| 12 | + - 'docker/cube-entrypoint.sh' |
| 13 | + - '.github/workflows/build-envd-base-image.yml' |
| 14 | + workflow_dispatch: |
| 15 | + inputs: |
| 16 | + envd_ref: |
| 17 | + description: 'Upstream e2b-dev/infra ref (tag/branch/SHA) to compile envd from' |
| 18 | + required: false |
| 19 | + default: '2026.16' |
| 20 | + |
| 21 | +env: |
| 22 | + ENVD_REF_DEFAULT: '2026.16' |
| 23 | + IMAGE_NAME: ghcr.io/tencentcloud/cubesandbox-base |
| 24 | + BASE_OS_TAG_SUFFIX: ubuntu22.04 |
| 25 | + |
| 26 | +concurrency: |
| 27 | + group: build-envd-base-image-${{ github.ref }}-${{ github.event.inputs.envd_ref || 'default' }} |
| 28 | + cancel-in-progress: false |
| 29 | + |
| 30 | +jobs: |
| 31 | + build: |
| 32 | + runs-on: ubuntu-latest |
| 33 | + permissions: |
| 34 | + contents: read |
| 35 | + packages: write |
| 36 | + |
| 37 | + steps: |
| 38 | + - name: Checkout |
| 39 | + uses: actions/checkout@v4 |
| 40 | + |
| 41 | + - name: Resolve envd ref |
| 42 | + id: meta_ref |
| 43 | + run: | |
| 44 | + envd_ref="${{ github.event.inputs.envd_ref || env.ENVD_REF_DEFAULT }}" |
| 45 | + echo "envd_ref=${envd_ref}" >> "${GITHUB_OUTPUT}" |
| 46 | + echo "Compiling envd from e2b-dev/infra@${envd_ref}" |
| 47 | +
|
| 48 | + - name: Set up Docker Buildx |
| 49 | + uses: docker/setup-buildx-action@v3 |
| 50 | + |
| 51 | + - name: Log in to GitHub Container Registry |
| 52 | + if: github.repository == 'TencentCloud/CubeSandbox' && github.ref == 'refs/heads/master' |
| 53 | + uses: docker/login-action@v3 |
| 54 | + with: |
| 55 | + registry: ghcr.io |
| 56 | + username: ${{ github.actor }} |
| 57 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 58 | + |
| 59 | + - name: Extract image metadata |
| 60 | + id: meta |
| 61 | + uses: docker/metadata-action@v5 |
| 62 | + with: |
| 63 | + images: ${{ env.IMAGE_NAME }} |
| 64 | + tags: | |
| 65 | + type=raw,value=${{ steps.meta_ref.outputs.envd_ref }},enable=${{ github.repository == 'TencentCloud/CubeSandbox' && github.ref == 'refs/heads/master' }} |
| 66 | + type=raw,value=${{ steps.meta_ref.outputs.envd_ref }}-${{ env.BASE_OS_TAG_SUFFIX }},enable=${{ github.repository == 'TencentCloud/CubeSandbox' && github.ref == 'refs/heads/master' }} |
| 67 | + type=raw,value=latest,enable=${{ github.repository == 'TencentCloud/CubeSandbox' && github.ref == 'refs/heads/master' }} |
| 68 | + type=sha,prefix=sha-,format=short |
| 69 | + labels: | |
| 70 | + io.cubesandbox.envd.ref=${{ steps.meta_ref.outputs.envd_ref }} |
| 71 | +
|
| 72 | + - name: Build image (load locally for smoke test) |
| 73 | + uses: docker/build-push-action@v6 |
| 74 | + with: |
| 75 | + context: docker |
| 76 | + file: docker/Dockerfile.cube-base |
| 77 | + platforms: linux/amd64 |
| 78 | + push: false |
| 79 | + load: true |
| 80 | + tags: cubesandbox-base:ci-smoke |
| 81 | + labels: ${{ steps.meta.outputs.labels }} |
| 82 | + build-args: | |
| 83 | + ENVD_REF=${{ steps.meta_ref.outputs.envd_ref }} |
| 84 | + cache-from: type=gha |
| 85 | + cache-to: type=gha,mode=max |
| 86 | + |
| 87 | + - name: Smoke test envd /health |
| 88 | + run: | |
| 89 | + set -euo pipefail |
| 90 | + cid="$(docker run -d --rm cubesandbox-base:ci-smoke)" |
| 91 | + trap 'docker rm -f "${cid}" >/dev/null 2>&1 || true' EXIT |
| 92 | +
|
| 93 | + ok="" |
| 94 | + for attempt in 1 2 3 4 5 6 7 8 9 10; do |
| 95 | + code="$(docker exec "${cid}" curl -s -o /dev/null -w "%{http_code}" \ |
| 96 | + http://127.0.0.1:49983/health || true)" |
| 97 | + echo "attempt ${attempt}: envd /health => ${code}" |
| 98 | + if [ "${code}" = "204" ]; then |
| 99 | + ok="yes" |
| 100 | + break |
| 101 | + fi |
| 102 | + sleep 1 |
| 103 | + done |
| 104 | +
|
| 105 | + if [ -z "${ok}" ]; then |
| 106 | + echo "envd /health probe never returned 204" >&2 |
| 107 | + docker exec "${cid}" cat /var/log/envd.log >&2 || true |
| 108 | + exit 1 |
| 109 | + fi |
| 110 | +
|
| 111 | + echo "envd inside container:" |
| 112 | + docker exec "${cid}" /usr/bin/envd -version |
| 113 | + docker exec "${cid}" /usr/bin/envd -commit |
| 114 | +
|
| 115 | + - name: Push image |
| 116 | + if: github.repository == 'TencentCloud/CubeSandbox' && github.ref == 'refs/heads/master' |
| 117 | + uses: docker/build-push-action@v6 |
| 118 | + with: |
| 119 | + context: docker |
| 120 | + file: docker/Dockerfile.cube-base |
| 121 | + platforms: linux/amd64 |
| 122 | + push: true |
| 123 | + tags: ${{ steps.meta.outputs.tags }} |
| 124 | + labels: ${{ steps.meta.outputs.labels }} |
| 125 | + build-args: | |
| 126 | + ENVD_REF=${{ steps.meta_ref.outputs.envd_ref }} |
| 127 | + cache-from: type=gha |
| 128 | + cache-to: type=gha,mode=max |
0 commit comments