|
| 1 | +# ═══════════════════════════════════════════════════════════ |
| 2 | +# LocalPibox Devstack — CI/CD Build & Publish |
| 3 | +# ═══════════════════════════════════════════════════════════ |
| 4 | +# Builds on GitHub (fast connection) → publishes to GHCR |
| 5 | +# Extensions update at runtime via pi update --extensions |
| 6 | +# |
| 7 | +# Triggers: |
| 8 | +# - Push to main (Dockerfile, support/, lpb.stack.env, lpb.conf.env) |
| 9 | +# - Weekly cron (Monday 3am UTC) — keep image fresh |
| 10 | +# - Manual dispatch |
| 11 | +# |
| 12 | +# Images built: |
| 13 | +# ghcr.io/localpibox/devstack:cli — Base dev environment + Pi CLI |
| 14 | +# ghcr.io/localpibox/devstack:web — Extends cli + VSCodium server |
| 15 | +# |
| 16 | +# Actions: all latest major versions (Node.js 24 native) |
| 17 | +# actions/checkout@v6 · docker/build-push-action@v7 |
| 18 | +# docker/setup-buildx-action@v4 · docker/setup-qemu-action@v4 |
| 19 | +# docker/login-action@v4 · docker/metadata-action@v6 |
| 20 | +# actions/upload-artifact@v7 |
| 21 | + |
| 22 | +name: Build & Publish Devstack |
| 23 | + |
| 24 | +on: |
| 25 | + push: |
| 26 | + branches: [main] |
| 27 | + paths: |
| 28 | + - 'Dockerfile' |
| 29 | + - 'support/**' |
| 30 | + - 'lpb.stack.env' |
| 31 | + - 'lpb.conf.env' |
| 32 | + - '.github/workflows/*.yml' |
| 33 | + - 'scripts/**' |
| 34 | + pull_request: |
| 35 | + branches: [main] |
| 36 | + paths: |
| 37 | + - 'Dockerfile' |
| 38 | + - 'support/**' |
| 39 | + - 'lpb.stack.env' |
| 40 | + - 'lpb.conf.env' |
| 41 | + - '.github/workflows/*.yml' |
| 42 | + - 'scripts/**' |
| 43 | + schedule: |
| 44 | + - cron: '0 3 * * 1' |
| 45 | + workflow_dispatch: |
| 46 | + inputs: |
| 47 | + publish_latest: |
| 48 | + description: 'Publish as :latest tag' |
| 49 | + type: boolean |
| 50 | + default: true |
| 51 | + no_cache: |
| 52 | + description: 'Full rebuild with no cache (pick up fork-branch changes)' |
| 53 | + type: boolean |
| 54 | + default: false |
| 55 | + |
| 56 | +permissions: |
| 57 | + contents: read |
| 58 | + packages: write |
| 59 | + |
| 60 | +env: |
| 61 | + IMAGE_NAME: ghcr.io/localpibox/devstack |
| 62 | + |
| 63 | +jobs: |
| 64 | + test-lpb: |
| 65 | + name: Run lpb.py unit tests |
| 66 | + runs-on: ubuntu-latest |
| 67 | + steps: |
| 68 | + - name: Checkout |
| 69 | + uses: actions/checkout@v6 |
| 70 | + |
| 71 | + - name: Run test suite |
| 72 | + run: | |
| 73 | + python3 scripts/test_lpb.py |
| 74 | + python3 scripts/test_localpibox.py |
| 75 | +
|
| 76 | + build-cli: |
| 77 | + name: Build & publish cli image |
| 78 | + runs-on: ubuntu-latest |
| 79 | + timeout-minutes: 45 |
| 80 | + needs: [test-lpb] |
| 81 | + steps: |
| 82 | + - name: Checkout |
| 83 | + uses: actions/checkout@v6 |
| 84 | + |
| 85 | + - name: Set up QEMU |
| 86 | + uses: docker/setup-qemu-action@v4 |
| 87 | + |
| 88 | + - name: Set up buildx |
| 89 | + uses: docker/setup-buildx-action@v4 |
| 90 | + |
| 91 | + - name: Login to GHCR |
| 92 | + uses: docker/login-action@v4 |
| 93 | + with: |
| 94 | + registry: ghcr.io |
| 95 | + username: ${{ github.actor }} |
| 96 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 97 | + |
| 98 | + - name: Load stack config |
| 99 | + id: config |
| 100 | + run: | |
| 101 | + set -a |
| 102 | + source lpb.stack.env |
| 103 | + set +a |
| 104 | + echo "PI_FORK=$LPB_PI_FORK" >> "$GITHUB_OUTPUT" |
| 105 | + echo "PI_REF=$LPB_PI_REF" >> "$GITHUB_OUTPUT" |
| 106 | + echo "CONFIG_FORK=$LPB_CONFIG_FORK" >> "$GITHUB_OUTPUT" |
| 107 | + echo "CONFIG_REF=$LPB_CONFIG_REF" >> "$GITHUB_OUTPUT" |
| 108 | + echo "NODE_VERSION=$LPB_NODE_VERSION" >> "$GITHUB_OUTPUT" |
| 109 | + echo "VSCODIUM_VERSION=$LPB_VSCODIUM_VERSION" >> "$GITHUB_OUTPUT" |
| 110 | + echo "LPB_VERSION=$(cat VERSION 2>/dev/null || echo unknown)" >> "$GITHUB_OUTPUT" |
| 111 | + MAX_TOKENS=$(grep -E '^LPB_MAX_TOKENS_CONTEXT_RATIO=' lpb.conf.env | cut -d= -f2- | tr -d '"' 2>/dev/null || true) |
| 112 | + echo "MAX_TOKENS=${MAX_TOKENS:-0.06}" >> "$GITHUB_OUTPUT" |
| 113 | + sha=$(git ls-remote "$LPB_PI_FORK" "refs/heads/$LPB_PI_REF" | awk '{print $1}') |
| 114 | + # Read stack version from config repo |
| 115 | + cfg_repo=$(echo "$LPB_CONFIG_FORK" | sed -E 's#https://github.com/([^/]+)/([^./]+)\.git#\1/\2#') |
| 116 | + stack_ver=$(curl -sf "https://raw.githubusercontent.com/$cfg_repo/$LPB_CONFIG_REF/VERSION" 2>/dev/null || echo "unknown") |
| 117 | + echo "sha=${sha:-unknown}" >> "$GITHUB_OUTPUT" |
| 118 | + echo "stack_version=${stack_ver}" >> "$GITHUB_OUTPUT" |
| 119 | +
|
| 120 | + - name: Build & push cli |
| 121 | + uses: docker/build-push-action@v7 |
| 122 | + with: |
| 123 | + context: . |
| 124 | + file: ./Dockerfile |
| 125 | + target: cli |
| 126 | + push: ${{ github.event_name != 'pull_request' }} |
| 127 | + cache-from: type=gha |
| 128 | + cache-to: type=gha,mode=max |
| 129 | + build-args: | |
| 130 | + PI_FORK=${{ steps.config.outputs.PI_FORK }} |
| 131 | + PI_REF=${{ steps.config.outputs.PI_REF }} |
| 132 | + CONFIG_FORK=${{ steps.config.outputs.CONFIG_FORK }} |
| 133 | + CONFIG_REF=${{ steps.config.outputs.CONFIG_REF }} |
| 134 | + NODE_VERSION=${{ steps.config.outputs.NODE_VERSION }} |
| 135 | + VSCODIUM_VERSION=${{ steps.config.outputs.VSCODIUM_VERSION }} |
| 136 | + PI_HEAD_SHA=${{ steps.config.outputs.sha }} |
| 137 | + LPB_VERSION=${{ steps.config.outputs.LPB_VERSION }} |
| 138 | + LPB_MAX_TOKENS_CONTEXT_RATIO=${{ steps.config.outputs.MAX_TOKENS }} |
| 139 | + no-cache: ${{ github.event.inputs.no_cache == 'true' }} |
| 140 | + tags: | |
| 141 | + ${{ env.IMAGE_NAME }}:cli |
| 142 | + ${{ env.IMAGE_NAME }}:main-cli |
| 143 | + ${{ env.IMAGE_NAME }}:${{ github.sha }}-cli |
| 144 | + ${{ env.IMAGE_NAME }}:${{ steps.config.outputs.stack_version }}-cli |
| 145 | + ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' && format('{0}:latest', env.IMAGE_NAME) || '' }} |
| 146 | + ${{ github.event.inputs.publish_latest && format('{0}:latest', env.IMAGE_NAME) || '' }} |
| 147 | + ${{ github.event_name == 'schedule' && format('{0}:weekly-cli', env.IMAGE_NAME) || '' }} |
| 148 | + provenance: false |
| 149 | + platforms: linux/amd64 |
| 150 | + |
| 151 | + build-web: |
| 152 | + name: Build & publish web image |
| 153 | + runs-on: ubuntu-latest |
| 154 | + timeout-minutes: 45 |
| 155 | + needs: [build-cli] |
| 156 | + steps: |
| 157 | + - name: Checkout |
| 158 | + uses: actions/checkout@v6 |
| 159 | + |
| 160 | + - name: Set up QEMU |
| 161 | + uses: docker/setup-qemu-action@v4 |
| 162 | + |
| 163 | + - name: Set up buildx |
| 164 | + uses: docker/setup-buildx-action@v4 |
| 165 | + |
| 166 | + - name: Login to GHCR |
| 167 | + uses: docker/login-action@v4 |
| 168 | + with: |
| 169 | + registry: ghcr.io |
| 170 | + username: ${{ github.actor }} |
| 171 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 172 | + |
| 173 | + - name: Load stack config |
| 174 | + id: config |
| 175 | + run: | |
| 176 | + set -a |
| 177 | + source lpb.stack.env |
| 178 | + set +a |
| 179 | + echo "PI_FORK=$LPB_PI_FORK" >> "$GITHUB_OUTPUT" |
| 180 | + echo "PI_REF=$LPB_PI_REF" >> "$GITHUB_OUTPUT" |
| 181 | + echo "CONFIG_FORK=$LPB_CONFIG_FORK" >> "$GITHUB_OUTPUT" |
| 182 | + echo "CONFIG_REF=$LPB_CONFIG_REF" >> "$GITHUB_OUTPUT" |
| 183 | + echo "NODE_VERSION=$LPB_NODE_VERSION" >> "$GITHUB_OUTPUT" |
| 184 | + echo "VSCODIUM_VERSION=$LPB_VSCODIUM_VERSION" >> "$GITHUB_OUTPUT" |
| 185 | + echo "LPB_VERSION=$(cat VERSION 2>/dev/null || echo unknown)" >> "$GITHUB_OUTPUT" |
| 186 | + MAX_TOKENS=$(grep -E '^LPB_MAX_TOKENS_CONTEXT_RATIO=' lpb.conf.env | cut -d= -f2- | tr -d '"' 2>/dev/null || true) |
| 187 | + echo "MAX_TOKENS=${MAX_TOKENS:-0.06}" >> "$GITHUB_OUTPUT" |
| 188 | + sha=$(git ls-remote "$LPB_PI_FORK" "refs/heads/$LPB_PI_REF" | awk '{print $1}') |
| 189 | + # Read stack version from config repo |
| 190 | + cfg_repo=$(echo "$LPB_CONFIG_FORK" | sed -E 's#https://github.com/([^/]+)/([^./]+)\.git#\1/\2#') |
| 191 | + stack_ver=$(curl -sf "https://raw.githubusercontent.com/$cfg_repo/$LPB_CONFIG_REF/VERSION" 2>/dev/null || echo "unknown") |
| 192 | + echo "sha=${sha:-unknown}" >> "$GITHUB_OUTPUT" |
| 193 | + echo "stack_version=${stack_ver}" >> "$GITHUB_OUTPUT" |
| 194 | +
|
| 195 | + - name: Build & push web |
| 196 | + uses: docker/build-push-action@v7 |
| 197 | + with: |
| 198 | + context: . |
| 199 | + file: ./Dockerfile |
| 200 | + target: web |
| 201 | + push: ${{ github.event_name != 'pull_request' }} |
| 202 | + cache-from: type=gha |
| 203 | + cache-to: type=gha,mode=max |
| 204 | + build-args: | |
| 205 | + PI_FORK=${{ steps.config.outputs.PI_FORK }} |
| 206 | + PI_REF=${{ steps.config.outputs.PI_REF }} |
| 207 | + CONFIG_FORK=${{ steps.config.outputs.CONFIG_FORK }} |
| 208 | + CONFIG_REF=${{ steps.config.outputs.CONFIG_REF }} |
| 209 | + NODE_VERSION=${{ steps.config.outputs.NODE_VERSION }} |
| 210 | + VSCODIUM_VERSION=${{ steps.config.outputs.VSCODIUM_VERSION }} |
| 211 | + PI_HEAD_SHA=${{ steps.config.outputs.sha }} |
| 212 | + LPB_VERSION=${{ steps.config.outputs.LPB_VERSION }} |
| 213 | + LPB_MAX_TOKENS_CONTEXT_RATIO=${{ steps.config.outputs.MAX_TOKENS }} |
| 214 | + no-cache: ${{ github.event.inputs.no_cache == 'true' }} |
| 215 | + tags: | |
| 216 | + ${{ env.IMAGE_NAME }}:web |
| 217 | + ${{ env.IMAGE_NAME }}:main-web |
| 218 | + ${{ env.IMAGE_NAME }}:${{ github.sha }}-web |
| 219 | + ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' && format('{0}:latest-web', env.IMAGE_NAME) || '' }} |
| 220 | + ${{ github.event.inputs.publish_latest && format('{0}:latest-web', env.IMAGE_NAME) || '' }} |
| 221 | + ${{ github.event_name == 'schedule' && format('{0}:weekly-web', env.IMAGE_NAME) || '' }} |
| 222 | + provenance: false |
| 223 | + platforms: linux/amd64 |
| 224 | + |
| 225 | + status: |
| 226 | + name: Build status |
| 227 | + needs: [build-cli, build-web] |
| 228 | + if: always() |
| 229 | + runs-on: ubuntu-latest |
| 230 | + steps: |
| 231 | + - run: | |
| 232 | + if [ "${{ needs.build-cli.result }}" != "success" ] || [ "${{ needs.build-web.result }}" != "success" ]; then |
| 233 | + echo "Build failed!" |
| 234 | + exit 1 |
| 235 | + fi |
| 236 | + echo "Build complete — both cli and web images pushed" |
0 commit comments