Skip to content

Commit dd3ff24

Browse files
committed
chore: initial setup
1 parent 74c5920 commit dd3ff24

8 files changed

Lines changed: 210 additions & 0 deletions

File tree

builders/selector/builder.toml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ description = "Builder for Renku frontends and environments."
5353
id = "paketo-buildpacks/miniconda"
5454
version = "0.11.5"
5555

56+
[[buildpacks]]
57+
uri = "docker://docker.io/paketobuildpacks/npm-install:2.3.18"
58+
id = "paketo-buildpacks/npm-install"
59+
version = "2.3.18"
60+
5661
[[buildpacks]]
5762
uri = "docker://docker.io/heroku/buildpack-deb-packages:0.2.0"
5863
id = "heroku/deb-packages"
@@ -66,6 +71,10 @@ description = "Builder for Renku frontends and environments."
6671
uri = "../../buildpacks/r-conda"
6772
version = "0.5.1"
6873

74+
[[buildpacks]]
75+
uri = "../../buildpacks/piagent"
76+
version = "0.5.1"
77+
6978
[[order]]
7079

7180
[[order.group]]
@@ -111,6 +120,11 @@ description = "Builder for Renku frontends and environments."
111120
id = "renku/init-scripts"
112121
version = "0.5.1"
113122
optional = true
123+
124+
[[order.group]]
125+
id = "renku/piagent"
126+
version = "0.5.1"
127+
optional = true
114128

115129
[[order]]
116130

@@ -149,6 +163,11 @@ description = "Builder for Renku frontends and environments."
149163
id = "renku/init-scripts"
150164
version = "0.5.1"
151165
optional = true
166+
167+
[[order.group]]
168+
id = "renku/piagent"
169+
version = "0.5.1"
170+
optional = true
152171

153172
[[order]]
154173

@@ -187,6 +206,11 @@ description = "Builder for Renku frontends and environments."
187206
id = "renku/init-scripts"
188207
version = "0.5.1"
189208
optional = true
209+
210+
[[order.group]]
211+
id = "renku/piagent"
212+
version = "0.5.1"
213+
optional = true
190214

191215
[[order]]
192216

@@ -228,6 +252,11 @@ description = "Builder for Renku frontends and environments."
228252
id = "renku/init-scripts"
229253
version = "0.5.1"
230254
optional = true
255+
256+
[[order.group]]
257+
id = "renku/piagent"
258+
version = "0.5.1"
259+
optional = true
231260

232261
[build]
233262
image = "index.docker.io/paketobuildpacks/ubuntu-noble-build:0.0.38"

buildpacks/piagent/bin/build

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
echo -e "=== 🔧 \033[1mRenku R buildpack\033[0m ==="
5+
6+
LAYERS_DIR="${1}"
7+
8+
log() { echo "-----> $*"; }
9+
info() { echo " $*"; }
10+
11+
read_meta() {
12+
grep -Po "(?<=^${2} = \")([^\"]+)" "${1}" 2>/dev/null || true
13+
}
14+
15+
R_VERSION="$(jq -r ".R.Version" "renv.lock" || true)"
16+
17+
# Conda package cache layer
18+
19+
PKG_CACHE_LAYER="${LAYERS_DIR}/r-conda-pkg-cache"
20+
mkdir -p "${PKG_CACHE_LAYER}"
21+
22+
cat >"${PKG_CACHE_LAYER}.toml" <<TOML
23+
[types]
24+
build = false
25+
launch = false
26+
cache = true
27+
TOML
28+
29+
# R layer
30+
31+
R_LAYER="${LAYERS_DIR}/r"
32+
mkdir -p "${R_LAYER}"
33+
34+
CACHED_R_VERSION="$(read_meta "${R_LAYER}.toml" "r_version")"
35+
36+
cat >"${R_LAYER}.toml" <<TOML
37+
[types]
38+
build = true
39+
launch = true
40+
cache = true
41+
42+
[metadata]
43+
r_version = "${R_VERSION}"
44+
TOML
45+
46+
if [[ "${CACHED_R_VERSION}" == "${R_VERSION}" && -x "${R_LAYER}/bin/R" ]]; then
47+
log "Reusing cached R ${R_VERSION}"
48+
else
49+
log "Installing R ${R_VERSION} via miniconda (using conda-forge channel only)..."
50+
51+
R_PACKAGE_NAME="r-base"
52+
if [[ -n "${R_VERSION}" ]]; then
53+
R_PACKAGE_NAME="r-base=${R_VERSION}"
54+
fi
55+
CONDA_PKGS_DIRS="$PKG_CACHE_LAYER" conda create \
56+
--prefix "${R_LAYER}" \
57+
--channel conda-forge \
58+
--channel nodefaults \
59+
--yes \
60+
"${R_PACKAGE_NAME}" \
61+
r-renv \
62+
openjdk \
63+
cairo \
64+
zlib \
65+
bzip2 \
66+
xz \
67+
hdf5 \
68+
libxml2 \
69+
libpng \
70+
libjpeg-turbo \
71+
libtiff \
72+
2>&1 | sed 's/^/ /'
73+
74+
info "R ${R_VERSION} installed to ${R_LAYER}"
75+
fi
76+
77+
# Environment — launch
78+
79+
ENV_LAUNCH="${R_LAYER}/env.launch"
80+
mkdir -p "${ENV_LAUNCH}"
81+
82+
printf '%s' "${R_LAYER}/bin" >"${ENV_LAUNCH}/PATH.prepend"
83+
printf ':' >"${ENV_LAUNCH}/PATH.delim"
84+
printf '%s' "${R_LAYER}/lib" >"${ENV_LAUNCH}/LD_LIBRARY_PATH.prepend"
85+
printf ':' >"${ENV_LAUNCH}/LD_LIBRARY_PATH.delim"
86+
printf '%s' "${R_LAYER}" >"${ENV_LAUNCH}/R_HOME.override"
87+
printf '%s' "${R_LAYER}/lib/R/library" >"${ENV_LAUNCH}/R_LIBS.override"
88+
89+
# Environment — build
90+
91+
ENV_BUILD="${R_LAYER}/env.build"
92+
mkdir -p "${ENV_BUILD}"
93+
94+
printf '%s' "${R_LAYER}/bin" >"${ENV_BUILD}/PATH.prepend"
95+
printf ':' >"${ENV_BUILD}/PATH.delim"
96+
printf '%s' "${R_LAYER}/lib" >"${ENV_BUILD}/LD_LIBRARY_PATH.prepend"
97+
printf ':' >"${ENV_BUILD}/LD_LIBRARY_PATH.delim"
98+
printf '%s' "${R_LAYER}" >"${ENV_BUILD}/R_HOME.override"
99+
printf '%s' "${R_LAYER}/lib/R/library" >"${ENV_BUILD}/R_LIBS.override"

buildpacks/piagent/bin/detect

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/usr/bin/env bash
2+
set -eo pipefail
3+
4+
plan_path="${CNB_BUILD_PLAN_PATH}"
5+
6+
cat >>"${plan_path}" <<EOL
7+
[[provides]]
8+
name = "piagent"
9+
10+
[[requires]]
11+
name = "node_modules" # provided by "paketo-buildpacks/npm-install"
12+
13+
[requires.metadata]
14+
build = true
15+
launch = false
16+
EOL

buildpacks/piagent/buildpack.toml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
api = "0.11"
2+
3+
[[targets]]
4+
arch = "amd64"
5+
os = "linux"
6+
7+
[[targets]]
8+
arch = "arm64"
9+
os = "linux"
10+
11+
[buildpack]
12+
id = "renku/piagent"
13+
name = "Piagent"
14+
version = "0.5.1"

buildpacks/piagent/package.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[buildpack]
2+
uri = "."

samples/piagent/project.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[_]
2+
schema-version = "0.2"
3+
4+
[[io.buildpacks.build.env]]
5+
name = "BP_RENKU_AI_AGENT"
6+
value = "piagent"

samples/piagent/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
flask

tests/e2e/buildpacks_test.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,4 +316,47 @@ var _ = Describe("Testing samples", Label("samples"), Ordered, func() {
316316
},
317317
Entry("using homebrew sample", "../../samples/homebrew"),
318318
)
319+
320+
FDescribeTableSubtree(
321+
"piagent",
322+
func(source string) {
323+
var image string
324+
var container string
325+
var port int
326+
BeforeAll(func(ctx SpecContext) {
327+
image = strings.ToLower(fmt.Sprintf("test-image-%s", getULID()))
328+
Expect(buildImage(ctx, builderImg, source, image, map[string]string{})).To(Succeed())
329+
port = getFreePortOrDie()
330+
envVars := []string{fmt.Sprintf("RENKU_SESSION_PORT=%d", port)}
331+
ports := map[int]int{port: port}
332+
container, err = runImage(ctx, client, image, envVars, ports)
333+
Expect(err).ToNot(HaveOccurred())
334+
})
335+
336+
AfterAll(func(ctx SpecContext) {
337+
if container != "" && client != nil {
338+
log.Println("Cleaning up container")
339+
err = removeContainer(ctx, client, container)
340+
if err != nil {
341+
log.Println(err)
342+
}
343+
}
344+
if image != "" && client != nil {
345+
log.Println("Cleaning up image")
346+
err = removeImage(ctx, client, image)
347+
if err != nil {
348+
log.Println(err)
349+
}
350+
}
351+
})
352+
353+
Context("when the container is running", func() {
354+
It("piagent should exist as a command in the container", func(ctx SpecContext) {
355+
_, err := execInContainer(ctx, client, container, []string{"launcher", "piagent", "--version"})
356+
Expect(err).ToNot(HaveOccurred())
357+
})
358+
})
359+
},
360+
Entry("using piagent sample", "../../samples/piagent"),
361+
)
319362
})

0 commit comments

Comments
 (0)