Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Checks the config on every pull request; on a `v*` tag, also builds the release tarball and publishes it.
# Release assets (same names in every release, so .../releases/latest/download/<name> always works):
# opencode-onyxia.tar.gz opencode-onyxia.tar.gz.sha256 onyxia-init.sh
name: release

on:
pull_request:
push:
tags: ["v*"]

permissions:
contents: read

jobs:
check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install opencode v2
run: |
curl -fsSL https://opencode.ai/v2/install | bash
for d in "$HOME/.opencode/bin" "$HOME/.local/bin"; do echo "$d" >> "$GITHUB_PATH"; done
- run: opencode --version
- run: python3 -I scripts/check_permissions.py
- run: python3 -I scripts/check_install.py

release:
if: startsWith(github.ref, 'refs/tags/v')
needs: check
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v4
- run: bash scripts/build_dist.sh "$GITHUB_REF_NAME" dist
- name: Publish the GitHub release
env:
GH_TOKEN: ${{ github.token }}
run: |
gh release create "$GITHUB_REF_NAME" --verify-tag --generate-notes \
dist/opencode-onyxia.tar.gz dist/opencode-onyxia.tar.gz.sha256 dist/onyxia-init.sh
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,4 @@ mlruns/
.DS_Store
Thumbs.db
*.swp
dist/
55 changes: 53 additions & 2 deletions INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,42 @@ source ~/.bashrc

## 4. Install the config globally

### Method 0 — Onyxia init script (recommended on SSP Cloud, no manual step)

Onyxia runs a *personal initialization script* at the start of every service. In Onyxia → **My account** →
**Services**, set:

| Field | Value |
|---|---|
| Initialization script | `https://raw.githubusercontent.com/inseefrlab/opencode-onyxia/main/onyxia-init.sh` |
| Arguments | e.g. `--version v1.0.0` (default: latest release), `--bare` (models only), `--claude` |

At start-up, `onyxia-init.sh`:
1. installs opencode v2 with the official installer, unless a v2 `opencode` is already on `PATH`;
2. downloads the release tarball `opencode-onyxia.tar.gz` and its `.sha256` from GitHub Releases, verifies the
checksum, and runs the bundled `install.sh` with your arguments (same result as Method A);
3. warns if `OPENAI_BASE_URL` / `OPENAI_API_KEY` are missing (on SSP Cloud the platform injects them).

It **never makes the service fail**. Every error is logged to `~/.cache/opencode-onyxia-init.log`, and the service
starts without the config.

Things to know:
- Onyxia fetches the script with `curl` **without `-L`**, so the URL must not redirect. Use the
`raw.githubusercontent.com` URL above. `github.com/.../releases/latest/download/onyxia-init.sh` redirects and
would run nothing. To pin the script itself, replace `main` with a tag.
- Pin `--version` for reproducible services. `latest` follows each new release.
- Onyxia accepts a single init script. If you already have one, call this script from it:
```bash
curl -fsSL https://raw.githubusercontent.com/inseefrlab/opencode-onyxia/main/onyxia-init.sh | bash -s -- --version v1.0.0
```
- Overrides: `OPENCODE_ONYXIA_REPO=<owner>/<repo>` (a fork's releases), `OPENCODE_ONYXIA_URL=<base url>` (any
location holding the two files, e.g. a MinIO bucket), `OPENCODE_ONYXIA_SKIP_OPENCODE=1`.
- The checksum guards against a corrupted or truncated download. It is fetched from the same release, so it does
not authenticate the publisher.

The tarball contains only the runtime files listed in `MANIFEST` (config, `AGENTS.md`, prompts, skills,
commands, `install.sh`, licenses) plus a `VERSION` file. No dev scripts or tests.

### Method A — provided script (recommended)

From the unpacked repository folder:
Expand Down Expand Up @@ -99,7 +135,7 @@ It installs **no** agents, permissions, policies, MCP servers, skills, commands,
are left in place and stay active; the script says so.
- Re-run `./install.sh --bare` after a `git pull` to pick up model changes. You still need `OPENAI_BASE_URL` and
`OPENAI_API_KEY` (step 3 above).
- `python3 -I scripts/check_install.py` tests what the full and the bare install write.
- `python3 -I scripts/check_install.py` tests the full and bare installs, the release tarball and `onyxia-init.sh`.

### Method B — manual

Expand Down Expand Up @@ -191,9 +227,24 @@ To update, review the upstream diff, bump the SHA in `UPSTREAM.lock`, re-run the
edit no longer applies) and update `THIRD_PARTY.md`. The DuckDB skills are adapted by hand: port upstream changes
manually and re-test the snippets.

## Publishing a release (maintainers)

```bash
python3 -I scripts/check_permissions.py && python3 -I scripts/check_install.py
git tag v1.2.0 && git push origin v1.2.0
```

`.github/workflows/release.yml` reruns both checks, then builds the tarball with `scripts/build_dist.sh` and
publishes a GitHub Release with `opencode-onyxia.tar.gz`, `opencode-onyxia.tar.gz.sha256` and `onyxia-init.sh`.
The same workflow runs the checks on every pull request. To ship a new file, add its path to `MANIFEST`: the build
fails on an untracked or misspelled path, and `check_install.py` compares the tarball with `MANIFEST`. Build
locally with `scripts/build_dist.sh v0.0.0-test` (output in `dist/`, git-ignored). Two builds of the same commit
produce identical bytes.

## Updating the global config

After a `git pull` of the repository, simply rerun:
With Method 0, new services pick up the release that `--version` points to (or the newest one, with `latest`).
With a clone, after a `git pull`, rerun:

```bash
./install.sh
Expand Down
12 changes: 12 additions & 0 deletions MANIFEST
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Runtime files shipped in the release tarball (read by scripts/build_dist.sh, tested by scripts/check_install.py).
# One tracked path per line (directory = everything tracked under it). Keep the .opencode/ layout: install.sh reads it.
# Dev-only material (scripts/, UPSTREAM.lock, README.md, INSTALL.md, onyxia-init.sh) stays out.
opencode.jsonc
AGENTS.md
install.sh
LICENSE
THIRD_PARTY.md
licenses
prompts
.opencode/skills
.opencode/commands
20 changes: 19 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,16 @@ opencode-onyxia/
├── opencode.jsonc # main config (native opencode v2): providers, models/variants, agents, permissions, MCP
├── AGENTS.md # Onyxia context shared by ALL agents (loaded automatically)
├── install.sh # GLOBAL install into ~/.config/opencode (all projects)
├── onyxia-init.sh # Onyxia personal init script: installs opencode + a released config at service start
├── MANIFEST # runtime files shipped in the release tarball
├── INSTALL.md # detailed install guide
├── .github/workflows/release.yml # checks on PRs; on a v* tag builds and publishes the release tarball
├── THIRD_PARTY.md UPSTREAM.lock # skills adapted from duckdb/duckdb-skills (MIT) and mlflow/skills (Apache-2.0)
├── licenses/ # upstream licenses
├── scripts/vendor_mlflow_skills.py# re-creates the vendored mlflow-* skills from the pinned upstream revision
├── scripts/check_permissions.py # model-free test of the permission rules (allow/ask/deny table)
├── scripts/check_install.py # tests what `install.sh` and `install.sh --bare` write
├── scripts/check_install.py # tests install.sh (full/--bare), the release tarball and onyxia-init.sh
├── scripts/build_dist.sh # builds dist/opencode-onyxia.tar.gz (+ .sha256) from MANIFEST
├── prompts/ # one system prompt per agent
│ ├── build.md plan.md python-ds.md r-ds.md mlops.md reviewer.md dataviz-vision.md
└── .opencode/
Expand All @@ -42,6 +46,20 @@ opencode-onyxia/
```

## Installation (summary — detailed guide in `INSTALL.md`)

**On SSP Cloud, the shortest route is the init script.** Under Onyxia → *My account* → *Services*, set the
initialization script and (optionally) its arguments:
```
URL https://raw.githubusercontent.com/inseefrlab/opencode-onyxia/main/onyxia-init.sh
args --version v1.0.0 # pin a release (default: latest); add --bare for the models only
```
Every new service then installs opencode v2 (if missing) and the released config, checksum-verified. The script
never makes the service fail: errors go to `~/.cache/opencode-onyxia-init.log`. The platform already injects
`OPENAI_BASE_URL` / `OPENAI_API_KEY`. If you already use another init script, add one line to it instead:
`curl -fsSL https://raw.githubusercontent.com/inseefrlab/opencode-onyxia/main/onyxia-init.sh | bash -s -- --version v1.0.0`.

Manual install from a clone:

1. **Install OpenCode v2** in the service (VSCode/Jupyter). This config is in the
*native v2 format* and cannot be read by OpenCode v1:
```bash
Expand Down
101 changes: 101 additions & 0 deletions onyxia-init.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
#!/usr/bin/env bash
# SSP Cloud / Onyxia init script: installs opencode v2 (if needed) and the opencode-onyxia config from a release.
#
# As your personal init script (Onyxia → My account → Services → Initialization script):
# URL https://raw.githubusercontent.com/inseefrlab/opencode-onyxia/main/onyxia-init.sh
# args e.g. --version v1.0.0 --bare
# (Onyxia runs `curl $URL | bash -s -- $ARGS` WITHOUT -L: use a raw.githubusercontent.com URL, never a
# github.com/.../releases/... one, which redirects and would run nothing.)
# From another init script (Onyxia takes only one):
# curl -fsSL https://raw.githubusercontent.com/inseefrlab/opencode-onyxia/main/onyxia-init.sh | bash -s -- --version v1.0.0
#
# Options: --version <tag> release to install (default: latest; env OPENCODE_ONYXIA_VERSION)
# anything else passed to install.sh (--bare, --claude)
# Env: OPENCODE_ONYXIA_REPO GitHub repo to download from (default inseefrlab/opencode-onyxia)
# OPENCODE_ONYXIA_URL base URL holding opencode-onyxia.tar.gz(.sha256): overrides repo/version
# OPENCODE_ONYXIA_SKIP_OPENCODE=1 do not install opencode itself
# OPENCODE_CONFIG_DIR target config dir (default ~/.config/opencode, handled by install.sh)
#
# Never makes the service fail: any error is logged (~/.cache/opencode-onyxia-init.log) and the script exits 0.
set -uo pipefail

LOG="${HOME}/.cache/opencode-onyxia-init.log"
mkdir -p "$(dirname "$LOG")" 2>/dev/null && exec > >(tee -a "$LOG") 2>&1
echo "=== opencode-onyxia init — $(date -Is) ==="

log() { echo "[opencode-onyxia] $*"; }
fail() { echo "[opencode-onyxia] ✗ $*" >&2; return 1; }

is_v2() { command -v opencode >/dev/null 2>&1 && opencode --version 2>/dev/null | head -n1 | grep -Eq '(^|v| )2\.'; }

ensure_path_line() { # $1 = directory to put on PATH in ~/.bashrc (idempotent)
local line="export PATH=\"$1:\$PATH\""
grep -qxF "$line" "$HOME/.bashrc" 2>/dev/null || echo "$line" >> "$HOME/.bashrc"
case ":$PATH:" in *":$1:"*) ;; *) export PATH="$1:$PATH" ;; esac
}

install_opencode() {
if [ "${OPENCODE_ONYXIA_SKIP_OPENCODE:-0}" = 1 ]; then log "skipping opencode install (OPENCODE_ONYXIA_SKIP_OPENCODE=1)"; return 0; fi
if is_v2; then log "opencode already installed: $(opencode --version 2>/dev/null | head -n1)"; return 0; fi
log "installing opencode v2…"
curl -fsSL https://opencode.ai/v2/install | bash || fail "opencode installer failed" || return 1
local d
for d in "$HOME/.opencode/bin" "$HOME/.local/bin"; do
[ -x "$d/opencode" ] && ensure_path_line "$d"
done
is_v2 || fail "opencode v2 not found on PATH after install" || return 1
log "opencode installed: $(opencode --version 2>/dev/null | head -n1)"
}

install_config() {
local version="${OPENCODE_ONYXIA_VERSION:-latest}" repo="${OPENCODE_ONYXIA_REPO:-inseefrlab/opencode-onyxia}"
local args=()
while [ $# -gt 0 ]; do
case "$1" in
--version) [ $# -ge 2 ] || { fail "--version needs a value"; return 1; }; version="$2"; shift 2 ;;
--version=*) version="${1#*=}"; shift ;;
*) args+=("$1"); shift ;;
esac
done

local base
if [ -n "${OPENCODE_ONYXIA_URL:-}" ]; then base="$OPENCODE_ONYXIA_URL"
elif [ "$version" = latest ]; then base="https://github.com/$repo/releases/latest/download"
else base="https://github.com/$repo/releases/download/$version"
fi

tmp="$(mktemp -d)" || return 1 # global: removed by the EXIT trap
log "downloading $base/opencode-onyxia.tar.gz"
curl -fsSL -o "$tmp/opencode-onyxia.tar.gz" "$base/opencode-onyxia.tar.gz" \
&& curl -fsSL -o "$tmp/opencode-onyxia.tar.gz.sha256" "$base/opencode-onyxia.tar.gz.sha256" \
|| { fail "download failed (version '$version' exists? network?)"; return 1; }
(cd "$tmp" && sha256sum -c --quiet opencode-onyxia.tar.gz.sha256) || { fail "checksum mismatch: not installing"; return 1; }

mkdir "$tmp/src" && tar -xzf "$tmp/opencode-onyxia.tar.gz" -C "$tmp/src" --strip-components=1 \
|| { fail "could not extract the tarball"; return 1; }
local installed
installed="$(cat "$tmp/src/VERSION" 2>/dev/null || echo unknown)"
log "installing config $installed ${args[*]:-}"
bash "$tmp/src/install.sh" "${args[@]}" || { fail "install.sh failed"; return 1; }

# When Onyxia runs this as root, hand the files back to the service user
local dest="${OPENCODE_CONFIG_DIR:-$HOME/.config/opencode}"
if [ "$(id -u)" = 0 ] && [ -n "${USERNAME:-}" ] && id "$USERNAME" >/dev/null 2>&1; then
chown -R "$USERNAME:$(id -gn "$USERNAME")" "$dest" "$HOME/.claude" 2>/dev/null || true
fi
log "✓ opencode-onyxia $installed installed in $dest"
}

check_env() {
if [ -z "${OPENAI_BASE_URL:-}" ] || [ -z "${OPENAI_API_KEY:-}" ]; then
log "⚠ OPENAI_BASE_URL / OPENAI_API_KEY not set: opencode cannot reach the models."
log " Create a key at https://llm.lab.sspcloud.fr (Settings → Account → API Keys), store it in Vault"
log " (My secrets) and inject it in your services; OPENAI_BASE_URL=https://llm.lab.sspcloud.fr/api"
fi
}

tmp=""
trap '[ -n "$tmp" ] && rm -rf "$tmp"' EXIT
install_opencode || log "continuing without a verified opencode v2"
if install_config "$@"; then check_env; else log "config NOT installed — see $LOG"; fi
exit 0
45 changes: 45 additions & 0 deletions scripts/build_dist.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/usr/bin/env bash
# Builds the release tarball: only the runtime files listed in MANIFEST (tracked by Git), under a versioned prefix.
#
# Usage: scripts/build_dist.sh <version> [out_dir] e.g. scripts/build_dist.sh v1.2.0
# Writes: <out_dir>/opencode-onyxia.tar.gz (asset name is the same in every release, so
# <out_dir>/opencode-onyxia.tar.gz.sha256 releases/latest/download/... always resolves)
# <out_dir>/onyxia-init.sh (attached to the release for reference)
#
# Content = the working-tree version of the files Git tracks under MANIFEST paths (untracked files, caches and
# local junk never get in). Reproducible: sorted entries, fixed mtime (last commit), root owner, gzip -n.
set -euo pipefail

VERSION="${1:?usage: scripts/build_dist.sh <version> [out_dir]}"
REPO="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
OUT="${2:-$REPO/dist}"
NAME="opencode-onyxia"
PREFIX="$NAME-$VERSION"

cd "$REPO"
mapfile -t paths < <(grep -v -e '^[[:space:]]*#' -e '^[[:space:]]*$' MANIFEST)
mapfile -t files < <(git ls-files -- "${paths[@]}")
for p in "${paths[@]}"; do # a typo or a removed path in MANIFEST must not silently ship an incomplete tarball
if ! printf '%s\n' "${files[@]}" | grep -q -e "^$p\$" -e "^$p/"; then
echo "✗ MANIFEST path not tracked by Git: $p" >&2
exit 1
fi
done

stage="$(mktemp -d)"
trap 'rm -rf "$stage"' EXIT
printf '%s\n' "$VERSION" > "$stage/VERSION"
mtime="@$(git log -1 --format=%ct)"
tar_opts=(--sort=name --mtime="$mtime" --owner=0 --group=0 --numeric-owner --mode='u+rw,go+r,go-w')

mkdir -p "$OUT"
{
tar -cf - "${tar_opts[@]}" --transform "s|^|$PREFIX/|" "${files[@]}"
} > "$stage/files.tar"
tar -rf "$stage/files.tar" "${tar_opts[@]}" -C "$stage" --transform "s|^|$PREFIX/|" VERSION
gzip -n -9 < "$stage/files.tar" > "$OUT/$NAME.tar.gz"
(cd "$OUT" && sha256sum "$NAME.tar.gz" > "$NAME.tar.gz.sha256")
cp -f "$REPO/onyxia-init.sh" "$OUT/onyxia-init.sh"

echo "✓ $OUT/$NAME.tar.gz ($PREFIX, ${#files[@]} files)"
cat "$OUT/$NAME.tar.gz.sha256"
Loading
Loading