summarylogtreecommitdiffstats
path: root/PKGBUILD
blob: bab9812bf83a0f0536d2cc424e191913b1265a65 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# Maintainer: enihcam <enihcam@noreply.gitcode.com>
pkgname=openjiuwen-sandbox
pkgver=0.1.8
pkgrel=4
pkgdesc="OpenJiuwen sandbox + gateway: code-execution sandbox server and gateway proxy"
arch=('x86_64')
url="https://gitcode.com/openJiuwen/agent-studio"
license=('Apache-2.0')
depends=(
    'python>=3.11.4'
    'python-fastapi>=0.124.0'
    'uvicorn>=0.38.0'
    'python-httpx>=0.28.0'
    'python-yaml'
    'python-dotenv'
    'python-libseccomp'
)
makedepends=(
    'python-build'
    'python-installer'
    'python-wheel'
    'python-setuptools'
)
optdepends=(
    'openjiuwen-server: backend that consumes this sandbox via CODE_SANDBOX_URL'
)
_srcdir_repo=agent-studio
source=("git+https://gitcode.com/openJiuwen/agent-studio.git#tag=v${pkgver}")
source+=("openjiuwen-sandbox.service")
source+=("openjiuwen-sandbox-gateway.service")
source+=("openjiuwen-sandbox.sysusers")
source+=("openjiuwen-sandbox.tmpfiles")
sha256sums=('SKIP')
sha256sums+=('SKIP')
sha256sums+=('SKIP')
sha256sums+=('SKIP')
sha256sums+=('SKIP')

prepare() {
    local srcdir_top="${srcdir}/${_srcdir_repo:-agent-studio}"
    # Upstream sandbox server.py imports the sibling `app` subpackage as a
    # top-level module:
    #   from app.sandbox import get_sandbox_class
    # but the wheel installs it nested as openjiuwen_sandbox_server.app.*,
    # so the import raises ModuleNotFoundError. Add the proper prefix so
    # the wheel imports cleanly without runtime PYTHONPATH hacks.
    #
    # gateway already uses the correct absolute import path; only the
    # sandbox worker needs this fix.
    local f="${srcdir_top}/sandbox_server/sandbox/openjiuwen_sandbox_server/server.py"
    if [ -f "${f}" ]; then
        sed -i 's/^from app\./from openjiuwen_sandbox_server.app./' "${f}"
    fi

    # bwrap.py does `import pyseccomp` and uses `pyseccomp.SyscallFilter`,
    # `pyseccomp.KILL`, `pyseccomp.ALLOW`. Arch's python-libseccomp ships
    # the SAME C extension under the module name `seccomp` (identical
    # public API — both wrap libseccomp). There is no separate python-
    # pyseccomp package, so rename the references to match the Arch module.
    local bwrap="${srcdir_top}/sandbox_server/sandbox/openjiuwen_sandbox_server/app/bwrap.py"
    if [ -f "${bwrap}" ]; then
        sed -i \
            -e 's/^import pyseccomp$/import seccomp/' \
            -e 's/\bpyseccomp\./seccomp./g' \
            "${bwrap}"
    fi
}

build() {
    local srcdir_top="${srcdir}/${_srcdir_repo:-agent-studio}"

    cd "${srcdir_top}/sandbox_server/sandbox"
    python -m build --wheel --no-isolation

    cd "${srcdir_top}/sandbox_server/gateway"
    python -m build --wheel --no-isolation
}

package() {
    local srcdir_top="${srcdir}/${_srcdir_repo:-agent-studio}"

    # Install both wheels into separate staging dirs, then merge. Using separate
    # dirs avoids installer failing with FileExistsError if a previous failed
    # build left stale files at ${srcdir}/staging (makepkg does not auto-clean
    # its workdir between runs without -C).
    local staging_s="${srcdir}/staging-sandbox"
    local staging_g="${srcdir}/staging-gateway"
    rm -rf "${staging_s}" "${staging_g}"
    install -dm755 "${staging_s}" "${staging_g}"
    python -m installer --destdir="${staging_s}" --compile-bytecode=1 \
        "${srcdir_top}/sandbox_server/sandbox/dist/"*.whl
    python -m installer --destdir="${staging_g}" --compile-bytecode=1 \
        "${srcdir_top}/sandbox_server/gateway/dist/"*.whl

    # Merge into one staging tree for the move into /opt
    local staging="${srcdir}/staging"
    rm -rf "${staging}"
    install -dm755 "${staging}"
    cp -a "${staging_s}/." "${staging}/"
    cp -a "${staging_g}/." "${staging}/"

    # Lay out /opt/openjiuwen-sandbox
    install -dm755 "${pkgdir}/opt/openjiuwen-sandbox/lib"
    cp -a "${staging}/usr/lib/python3"*/site-packages/. \
          "${pkgdir}/opt/openjiuwen-sandbox/lib/"

    # Runtime / state dirs
    install -dm750 "${pkgdir}/var/lib/openjiuwen-sandbox"
    install -dm755 "${pkgdir}/var/log/openjiuwen-sandbox"

    # Licenses
    install -Dm644 "${srcdir_top}/LICENSE" \
        "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE"

    # Systemd units (two services in one package)
    install -Dm644 "${srcdir}/openjiuwen-sandbox.service" \
        "${pkgdir}/usr/lib/systemd/system/openjiuwen-sandbox.service"
    install -Dm644 "${srcdir}/openjiuwen-sandbox-gateway.service" \
        "${pkgdir}/usr/lib/systemd/system/openjiuwen-sandbox-gateway.service"

    install -Dm644 "${srcdir}/openjiuwen-sandbox.sysusers" \
        "${pkgdir}/usr/lib/sysusers.d/openjiuwen-sandbox.conf"
    install -Dm644 "${srcdir}/openjiuwen-sandbox.tmpfiles" \
        "${pkgdir}/usr/lib/tmpfiles.d/openjiuwen-sandbox.conf"
}