Simplify workflow: build CLI only in GitHub Actions, image built by Portainer

- Removed Docker build job from workflow (image built when deploying)
- Updated paths filter to only trigger on opencode/** changes
- Added artifact cleanup to keep only latest CLI build
- Added multi-stage Dockerfile to build CLI from source during Docker build
- Simplified permissions (removed packages write)
This commit is contained in:
southseact-3d
2026-02-10 13:44:03 +00:00
parent 25d23d8dd1
commit e8f89ae111
2 changed files with 91 additions and 182 deletions

View File

@@ -1,4 +1,4 @@
name: Build OpenCode CLI and Docker Image
name: Build OpenCode CLI
on:
push:
@@ -7,34 +7,16 @@ on:
- master
paths:
- opencode/**
- Dockerfile
- .github/workflows/build-opencode-cli-docker.yml
workflow_dispatch:
inputs:
image_name:
description: "Docker image name (including registry if desired)"
required: false
push_image:
description: "Push the image to the registry"
type: boolean
default: false
permissions:
contents: read
packages: write
actions: read
jobs:
build-cli:
name: Build OpenCode CLI (${{ matrix.arch }})
runs-on: ${{ matrix.runner }}
strategy:
fail-fast: false
matrix:
include:
- arch: amd64
runner: ubuntu-24.04
cli_dir: opencode-linux-x64
name: Build OpenCode CLI (x86_64)
runs-on: ubuntu-24.04
steps:
- name: Checkout
uses: actions/checkout@v4
@@ -55,118 +37,30 @@ jobs:
- name: Upload CLI artifact
uses: actions/upload-artifact@v4
with:
name: opencode-cli-${{ matrix.arch }}
path: opencode/packages/opencode/dist/${{ matrix.cli_dir }}
name: opencode-cli-x86_64
path: opencode/packages/opencode/dist/opencode-linux-x64
retention-days: 1
build-image:
name: Build Docker image
needs: build-cli
runs-on: ubuntu-24.04
env:
IMAGE_NAME: ${{ inputs.image_name || format('ghcr.io/{0}/shopify-ai-builder', github.repository_owner) }}
PUSH_IMAGE: ${{ inputs.push_image || false }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Download CLI artifacts
uses: actions/download-artifact@v4
with:
pattern: opencode-cli-*
path: opencode/packages/opencode/dist
merge-multiple: true
- name: Verify artifact structure
run: |
echo "Contents of dist directory:"
ls -la opencode/packages/opencode/dist/
echo "Looking for opencode binary..."
find opencode/packages/opencode/dist -name "opencode" -type f 2>/dev/null || echo "Binary not found"
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
driver-opts: |
image=moby/buildkit:latest
buildkitd-flags: --debug
- name: Cache Docker layers
uses: actions/cache@v4
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
- name: Login to GHCR
if: ${{ env.PUSH_IMAGE == 'true' }}
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build image (amd64 push)
if: ${{ env.PUSH_IMAGE == 'true' }}
run: |
docker buildx build \
--platform linux/amd64 \
--cache-from type=local,src=/tmp/.buildx-cache \
--cache-to type=local,dest=/tmp/.buildx-cache-new,mode=max \
-t "$IMAGE_NAME" \
--push \
.
- name: Move cache
if: ${{ env.PUSH_IMAGE == 'true' }}
run: |
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
- name: Build image (amd64) and verify CLI
if: ${{ env.PUSH_IMAGE != 'true' }}
run: |
docker buildx build \
--platform linux/amd64 \
--cache-from type=local,src=/tmp/.buildx-cache \
--cache-to type=local,dest=/tmp/.buildx-cache-new,mode=max \
-t "$IMAGE_NAME" \
--load \
.
docker run --rm "$IMAGE_NAME" opencode --version
- name: Move cache
if: ${{ env.PUSH_IMAGE != 'true' }}
run: |
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
- name: Cleanup old package versions
if: ${{ env.PUSH_IMAGE == 'true' && github.event_name == 'push' }}
- name: Cleanup old CLI artifacts
uses: actions/github-script@v7
with:
script: |
const packageName = 'shopify-ai-builder';
const packageType = 'container';
// List all versions of the package
const { data: versions } = await github.rest.packages.getAllPackageVersionsForPackageOwnedByOrg({
package_type: packageType,
package_name: packageName,
org: context.repo.owner,
per_page: 100
const artifactName = 'opencode-cli-x86_64';
const { data: artifacts } = await github.rest.actions.listArtifactsForRepo({
owner: context.repo.owner,
repo: context.repo.repo,
name: artifactName,
per_page: 10
});
// Keep only the most recent version, delete the rest
if (versions.length > 1) {
const versionsToDelete = versions.slice(1);
for (const version of versionsToDelete) {
await github.rest.packages.deletePackageVersionForOrg({
package_type: packageType,
package_name: packageName,
org: context.repo.owner,
package_version_id: version.id
if (artifacts.length > 1) {
const artifactsToDelete = artifacts.slice(1);
for (const artifact of artifactsToDelete) {
await github.rest.actions.deleteArtifact({
owner: context.repo.owner,
repo: context.repo.repo,
artifact_id: artifact.id
});
console.log(`Deleted package version ${version.id}`);
console.log(`Deleted old artifact: ${artifact.id}`);
}
}