|
| 1 | +name: Docker build and smoke test for apps |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + pull_request: |
| 6 | + branches: ["preview"] |
| 7 | + paths: |
| 8 | + - "apps/web/**" |
| 9 | + - "apps/space/**" |
| 10 | + - "apps/admin/**" |
| 11 | + - "apps/live/**" |
| 12 | + - "packages/**" |
| 13 | + - "turbo.json" |
| 14 | + - "pnpm-lock.yaml" |
| 15 | + - "pnpm-workspace.yaml" |
| 16 | + - "Dockerfile.node" |
| 17 | + - "Dockerfile.api" |
| 18 | + - "Dockerfile.aio" |
| 19 | + - "docker-bake.hcl" |
| 20 | + - ".github/workflows/docker-smoke.yml" |
| 21 | + push: |
| 22 | + branches: ["preview"] |
| 23 | + paths: |
| 24 | + - "apps/web/**" |
| 25 | + - "apps/space/**" |
| 26 | + - "apps/admin/**" |
| 27 | + - "apps/live/**" |
| 28 | + - "packages/**" |
| 29 | + - "turbo.json" |
| 30 | + - "pnpm-lock.yaml" |
| 31 | + - "pnpm-workspace.yaml" |
| 32 | + - "Dockerfile.node" |
| 33 | + - "Dockerfile.api" |
| 34 | + - "Dockerfile.aio" |
| 35 | + - "docker-bake.hcl" |
| 36 | + - ".github/workflows/docker-smoke.yml" |
| 37 | + |
| 38 | +jobs: |
| 39 | + determine-matrix: |
| 40 | + name: Determine matrix |
| 41 | + runs-on: ubuntu-latest |
| 42 | + outputs: |
| 43 | + matrix: ${{ steps.build-matrix.outputs.matrix }} |
| 44 | + aio_needed: ${{ steps.build-matrix.outputs.aio_needed }} |
| 45 | + steps: |
| 46 | + - name: Checkout repository |
| 47 | + uses: actions/checkout@v4 |
| 48 | + with: |
| 49 | + fetch-depth: 0 |
| 50 | + |
| 51 | + - name: Detect changed paths |
| 52 | + id: changes |
| 53 | + uses: dorny/paths-filter@v3 |
| 54 | + with: |
| 55 | + filters: | |
| 56 | + web: |
| 57 | + - 'apps/web/**' |
| 58 | + space: |
| 59 | + - 'apps/space/**' |
| 60 | + admin: |
| 61 | + - 'apps/admin/**' |
| 62 | + live: |
| 63 | + - 'apps/live/**' |
| 64 | + common: |
| 65 | + - 'packages/**' |
| 66 | + - 'turbo.json' |
| 67 | + - 'pnpm-lock.yaml' |
| 68 | + - 'pnpm-workspace.yaml' |
| 69 | + - 'Dockerfile.node' |
| 70 | + - 'Dockerfile.api' |
| 71 | + - 'Dockerfile.aio' |
| 72 | + - 'docker-bake.hcl' |
| 73 | + - '.github/workflows/docker-smoke.yml' |
| 74 | +
|
| 75 | + - name: Build matrix |
| 76 | + id: build-matrix |
| 77 | + uses: actions/github-script@v7 |
| 78 | + with: |
| 79 | + script: | |
| 80 | + const include = []; |
| 81 | + const anyCommon = '${{ steps.changes.outputs.common }}' === 'true'; |
| 82 | + const changed = { |
| 83 | + web: '${{ steps.changes.outputs.web }}' === 'true', |
| 84 | + space: '${{ steps.changes.outputs.space }}' === 'true', |
| 85 | + admin: '${{ steps.changes.outputs.admin }}' === 'true', |
| 86 | + live: '${{ steps.changes.outputs.live }}' === 'true', |
| 87 | + }; |
| 88 | + const add = (name, bake_target, image, container, port, path, env_flags = "") => |
| 89 | + include.push({ name, bake_target, image, container, host_port: port, path, env_flags }); |
| 90 | +
|
| 91 | + const buildAll = anyCommon || changed.web || changed.space || changed.admin || changed.live; |
| 92 | + if (buildAll || changed.web) add('web', 'web', 'plane-web:ci-smoke', 'plane-web-ci', 3001, '/'); |
| 93 | + if (buildAll || changed.space) add('space', 'space', 'plane-space:ci-smoke', 'plane-space-ci', 3002, '/spaces'); |
| 94 | + if (buildAll || changed.admin) add('admin', 'admin', 'plane-admin:ci-smoke', 'plane-admin-ci', 3003, '/god-mode'); |
| 95 | + if (buildAll || changed.live) add('live', 'live', 'plane-live:ci-smoke', 'plane-live-ci', 3005, '/live/health', '-e NODE_ENV=production -e LIVE_BASE_PATH=/live'); |
| 96 | +
|
| 97 | + if (include.length === 0) { |
| 98 | + // Default to web to keep job non-empty |
| 99 | + add('web', 'web', 'plane-web:ci-smoke', 'plane-web-ci', 3001, '/'); |
| 100 | + } |
| 101 | + // AIO is needed on the same condition we build all (common or any app changed) |
| 102 | + const aioNeeded = buildAll; |
| 103 | + core.setOutput('matrix', JSON.stringify({ include })); |
| 104 | + core.setOutput('aio_needed', String(aioNeeded)); |
| 105 | +
|
| 106 | + smoke: |
| 107 | + name: Build and smoke test ${{ matrix.name }} |
| 108 | + runs-on: ubuntu-latest |
| 109 | + needs: determine-matrix |
| 110 | + timeout-minutes: 25 |
| 111 | + |
| 112 | + strategy: |
| 113 | + fail-fast: false |
| 114 | + matrix: ${{ fromJSON(needs.determine-matrix.outputs.matrix) }} |
| 115 | + |
| 116 | + steps: |
| 117 | + - name: Checkout repository |
| 118 | + uses: actions/checkout@v4 |
| 119 | + with: |
| 120 | + fetch-depth: 0 |
| 121 | + |
| 122 | + - name: Prepare build environment |
| 123 | + run: echo "Using docker build (no buildx bake)" |
| 124 | + |
| 125 | + - name: Show Docker version |
| 126 | + run: | |
| 127 | + docker version |
| 128 | + docker info |
| 129 | +
|
| 130 | + - name: Build image (${{ matrix.name }}) |
| 131 | + shell: bash |
| 132 | + run: | |
| 133 | + set -euo pipefail |
| 134 | + name="${{ matrix.name }}" |
| 135 | + tag="${{ matrix.image }}" |
| 136 | + if [ "$name" = "live" ]; then |
| 137 | + # Determine repo root (supports layouts with or without 'plane/' prefix) |
| 138 | + ROOT="." |
| 139 | + if [ -f "plane/apps/live/Dockerfile.live" ]; then ROOT="plane"; fi |
| 140 | + docker build -f "$ROOT/apps/live/Dockerfile.live" -t "$tag" "$ROOT" |
| 141 | + else |
| 142 | + docker build -f "./Dockerfile.node" --target runtime --build-arg APP_SCOPE="$name" -t "$tag" "." |
| 143 | + fi |
| 144 | +
|
| 145 | + - name: Run container (${{ matrix.name }}) |
| 146 | + run: | |
| 147 | + docker run -d --name ${{ matrix.container }} -p ${{ matrix.host_port }}:3000 ${{ matrix.env_flags }} ${{ matrix.image }} |
| 148 | + docker ps -a |
| 149 | +
|
| 150 | + - name: Smoke test HTTP endpoint (${{ matrix.name }}) |
| 151 | + shell: bash |
| 152 | + run: | |
| 153 | + set -euo pipefail |
| 154 | + URL="http://localhost:${{ matrix.host_port }}${{ matrix.path }}" |
| 155 | + echo "Probing $URL ..." |
| 156 | + for i in {1..60}; do |
| 157 | + STATUS="$(curl -sS -o /dev/null -w "%{http_code}" -L "${URL}" || true)" |
| 158 | + if [ "${STATUS}" = "200" ]; then |
| 159 | + echo "Success: HTTP ${STATUS} from ${URL}" |
| 160 | + exit 0 |
| 161 | + fi |
| 162 | + echo "Attempt ${i}: HTTP ${STATUS} (waiting 2s)" |
| 163 | + sleep 2 |
| 164 | + done |
| 165 | + echo "Failed to get HTTP 200 from ${URL}" |
| 166 | + echo "::group::Container logs (${{ matrix.container }})" |
| 167 | + docker logs ${{ matrix.container }} || true |
| 168 | + echo "::endgroup::" |
| 169 | + exit 1 |
| 170 | +
|
| 171 | + - name: Cleanup container (${{ matrix.name }}) |
| 172 | + if: always() |
| 173 | + run: | |
| 174 | + docker rm -f ${{ matrix.container }} || true |
| 175 | +
|
| 176 | + aio_smoke: |
| 177 | + name: Build and smoke test AIO |
| 178 | + runs-on: ubuntu-latest |
| 179 | + needs: determine-matrix |
| 180 | + if: ${{ needs.determine-matrix.outputs.aio_needed == 'true' }} |
| 181 | + timeout-minutes: 30 |
| 182 | + |
| 183 | + steps: |
| 184 | + - name: Checkout repository |
| 185 | + uses: actions/checkout@v4 |
| 186 | + with: |
| 187 | + fetch-depth: 0 |
| 188 | + |
| 189 | + - name: Set up Docker Buildx |
| 190 | + uses: docker/setup-buildx-action@v3 |
| 191 | + |
| 192 | + - name: Build AIO image with bake |
| 193 | + run: | |
| 194 | + docker buildx bake -f "./docker-bake.hcl" aio |
| 195 | +
|
| 196 | + - name: Run AIO smoke |
| 197 | + run: | |
| 198 | + ROOT="." |
| 199 | + if [ -f "plane/scripts/smoke-aio.sh" ]; then ROOT="plane"; fi |
| 200 | + chmod +x "$ROOT/scripts/smoke-aio.sh" |
| 201 | + "$ROOT/scripts/smoke-aio.sh" |
0 commit comments