Skip to content

Commit 421a061

Browse files
committed
feat(library) Introduce Ruby 3.4 library and workflow
Signed-off-by: adriannnv <guzunadrian.vasile@gmail.com>
1 parent fc9155c commit 421a061

File tree

6 files changed

+374
-1
lines changed

6 files changed

+374
-1
lines changed
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
name: library/ruby:3.4
2+
3+
on:
4+
repository_dispatch:
5+
types: [core_merge, elfloader_merge, libelf_merge, lwip_merge]
6+
7+
workflow_dispatch:
8+
9+
schedule:
10+
- cron: '45 1 * * *'
11+
12+
push:
13+
branches: [main]
14+
paths:
15+
- 'library/ruby/3.4/**'
16+
- '.github/workflows/library-ruby3.4.yaml'
17+
18+
pull_request:
19+
types: [opened, synchronize, reopened]
20+
branches: [main]
21+
paths:
22+
- 'library/ruby/3.4/**'
23+
- '.github/workflows/library-ruby3.4.yaml'
24+
25+
# Automatically cancel in-progress actions on the same branch
26+
concurrency:
27+
group: ${{ github.workflow }}-${{ github.event_name == 'pull_request_target' && github.head_ref || github.ref }}
28+
cancel-in-progress: true
29+
30+
jobs:
31+
build:
32+
strategy:
33+
fail-fast: false
34+
matrix:
35+
include:
36+
- plat: qemu
37+
arch: x86_64
38+
- plat: fc
39+
arch: x86_64
40+
41+
runs-on: ubuntu-latest
42+
43+
steps:
44+
- uses: actions/checkout@v4
45+
46+
- name: Build ruby3.4
47+
uses: unikraft/kraftkit@staging
48+
with:
49+
loglevel: debug
50+
workdir: library/ruby/3.4
51+
runtimedir: /github/workspace/.kraftkit
52+
plat: ${{ matrix.plat }}
53+
arch: ${{ matrix.arch }}
54+
push: false
55+
output: oci://index.unikraft.io/unikraft.org/ruby:3.4
56+
57+
- name: Archive OCI digests
58+
uses: actions/upload-artifact@v4
59+
with:
60+
name: oci-digests-${{ matrix.arch }}-${{ matrix.plat }}
61+
path: ${{ github.workspace }}/.kraftkit/oci/digests
62+
if-no-files-found: error
63+
64+
push:
65+
if: ${{ github.event_name == 'push' || github.event_name == 'schedule' }}
66+
needs: [ build ]
67+
runs-on: ubuntu-latest
68+
69+
steps:
70+
- uses: actions/checkout@v4
71+
72+
- name: Login to OCI registry
73+
uses: docker/login-action@v3
74+
with:
75+
registry: index.unikraft.io
76+
username: ${{ secrets.REG_USERNAME }}
77+
password: ${{ secrets.REG_TOKEN }}
78+
79+
- name: Retrieve, merge and push OCI digests
80+
uses: ./.github/actions/merge-oci-digests
81+
with:
82+
name: index.unikraft.io/unikraft.org/ruby:3.4
83+
push: true

library/ruby/3.2/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ kraft run --rm -M 256M -p 8080:8080 --plat qemu --arch x86_64 unikraft.org/ruby:
5454

5555
The commands so far used the pre-build Ruby image available in the Unikraft registry.
5656

57-
In oder to to build a local image, clone this repository and `cd` into this directory.
57+
In order to build a local image, clone this repository and `cd` into this directory.
5858
Then use `kraft` to build an image locally:
5959

6060
```bash

library/ruby/3.4/Dockerfile

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
FROM --platform=linux/x86_64 ruby:3.4-bookworm AS build
2+
3+
FROM alpine:3 AS sys
4+
5+
RUN set -xe; \
6+
mkdir -p /target/etc; \
7+
mkdir -p /blank; \
8+
apk --no-cache add \
9+
ca-certificates \
10+
tzdata \
11+
; \
12+
update-ca-certificates; \
13+
ln -sf ../usr/share/zoneinfo/Etc/UTC /target/etc/localtime; \
14+
echo "Etc/UTC" > /target/etc/timezone;
15+
16+
FROM scratch
17+
18+
COPY --from=sys /target/etc /etc
19+
COPY --from=sys /usr/share/zoneinfo/Etc/UTC /usr/share/zoneinfo/Etc/UTC
20+
COPY --from=sys /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
21+
COPY --from=sys /blank /tmp
22+
23+
# Ruby binary
24+
COPY --from=build /usr/local/bin/ruby /usr/bin/ruby
25+
26+
# Ruby libraries
27+
COPY --from=build /usr/local/lib/ruby /usr/local/lib/ruby
28+
29+
# System libraries
30+
COPY --from=build /usr/local/lib/libruby.so.3.4 /usr/local/lib/libruby.so.3.4
31+
COPY --from=build /lib/x86_64-linux-gnu/libz.so.1 /lib/x86_64-linux-gnu/libz.so.1
32+
COPY --from=build /lib/x86_64-linux-gnu/libgmp.so.10 /lib/x86_64-linux-gnu/libgmp.so.10
33+
COPY --from=build /lib/x86_64-linux-gnu/libcrypt.so.1 /lib/x86_64-linux-gnu/libcrypt.so.1
34+
COPY --from=build /lib/x86_64-linux-gnu/libm.so.6 /lib/x86_64-linux-gnu/libm.so.6
35+
COPY --from=build /lib/x86_64-linux-gnu/libc.so.6 /lib/x86_64-linux-gnu/libc.so.6
36+
COPY --from=build /lib/x86_64-linux-gnu/libgcc_s.so.1 /lib/x86_64-linux-gnu/libgcc_s.so.1
37+
COPY --from=build /lib64/ld-linux-x86-64.so.2 /lib64/ld-linux-x86-64.so.2
38+
COPY --from=build /etc/ld.so.cache /etc/ld.so.cache
39+
40+
# Simple Ruby HTTP server
41+
COPY ./server.rb /src/server.rb

library/ruby/3.4/Kraftfile

Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
spec: v0.6
2+
3+
name: ruby
4+
5+
rootfs: ./Dockerfile
6+
7+
cmd: ["/usr/bin/ruby", "/src/server.rb"]
8+
9+
template:
10+
source: https://github.com/unikraft/app-elfloader.git
11+
version: staging
12+
13+
unikraft:
14+
source: https://github.com/unikraft/unikraft.git
15+
version: staging
16+
kconfig:
17+
# Configurations options for app-elfloader
18+
# (they can't be part of the template atm)
19+
CONFIG_LIBPOSIX_PROCESS_ARCH_PRCTL: 'y'
20+
CONFIG_APPELFLOADER_BRK: 'y'
21+
CONFIG_APPELFLOADER_CUSTOMAPPNAME: 'y'
22+
CONFIG_APPELFLOADER_STACK_NBPAGES: 128
23+
CONFIG_APPELFLOADER_VFSEXEC_EXECBIT: 'n'
24+
CONFIG_APPELFLOADER_VFSEXEC: 'y'
25+
CONFIG_APPELFLOADER_HFS: 'y'
26+
CONFIG_APPELFLOADER_HFS_ETCRESOLVCONF: 'y'
27+
CONFIG_APPELFLOADER_HFS_ETCHOSTS: 'y'
28+
CONFIG_APPELFLOADER_HFS_ETCHOSTNAME: 'y'
29+
CONFIG_APPELFLOADER_HFS_REPLACEEXIST: 'y'
30+
# Unikraft options
31+
CONFIG_HAVE_PAGING_DIRECTMAP: 'y'
32+
CONFIG_HAVE_PAGING: 'y'
33+
CONFIG_I8042: 'y'
34+
CONFIG_LIBDEVFS_AUTOMOUNT: 'y'
35+
CONFIG_LIBDEVFS_DEV_NULL: 'y'
36+
CONFIG_LIBDEVFS_DEV_STDOUT: 'y'
37+
CONFIG_LIBDEVFS_DEV_ZERO: 'y'
38+
CONFIG_LIBDEVFS: 'y'
39+
CONFIG_LIBPOSIX_ENVIRON_ENVP0: "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
40+
CONFIG_LIBPOSIX_ENVIRON_ENVP1: "LD_LIBRARY_PATH=/usr/local/lib:/usr/lib:/lib"
41+
CONFIG_LIBPOSIX_ENVIRON_ENVP2: "HOME=/"
42+
CONFIG_LIBPOSIX_ENVIRON: 'y'
43+
CONFIG_LIBPOSIX_ENVIRON_LIBPARAM: 'y'
44+
CONFIG_LIBPOSIX_ENVIRON_LIBPARAM_MAXCOUNT: '64'
45+
CONFIG_LIBPOSIX_EVENTFD: 'y'
46+
CONFIG_LIBPOSIX_FDIO: 'y'
47+
CONFIG_LIBPOSIX_FDTAB: 'y'
48+
CONFIG_LIBPOSIX_FUTEX: 'y'
49+
CONFIG_LIBPOSIX_MMAP: 'y'
50+
CONFIG_LIBPOSIX_NETLINK: 'y'
51+
CONFIG_LIBPOSIX_PIPE: 'y'
52+
CONFIG_LIBPOSIX_POLL: 'y'
53+
CONFIG_LIBPOSIX_PROCESS: 'y'
54+
CONFIG_LIBPOSIX_PROCESS_MULTITHREADING: 'y'
55+
CONFIG_LIBPOSIX_SOCKET: 'y'
56+
CONFIG_LIBPOSIX_SYSINFO: 'y'
57+
CONFIG_LIBPOSIX_TIME: 'y'
58+
CONFIG_LIBPOSIX_TIMERFD: 'y'
59+
CONFIG_LIBPOSIX_UNIXSOCKET: 'y'
60+
CONFIG_LIBPOSIX_USER_GID: 0
61+
CONFIG_LIBPOSIX_USER_GROUPNAME: "root"
62+
CONFIG_LIBPOSIX_USER_UID: 0
63+
CONFIG_LIBPOSIX_USER_USERNAME: "root"
64+
CONFIG_LIBPOSIX_USER: 'y'
65+
CONFIG_LIBRAMFS: 'y'
66+
CONFIG_LIBSYSCALL_SHIM_HANDLER_ULTLS: 'y'
67+
CONFIG_LIBSYSCALL_SHIM_HANDLER: 'y'
68+
CONFIG_LIBSYSCALL_SHIM_LEGACY_VERBOSE: 'y'
69+
CONFIG_LIBSYSCALL_SHIM: 'y'
70+
CONFIG_LIBUKALLOCPOOL: 'y'
71+
CONFIG_LIBUKBLKDEV_MAXNBQUEUES: '1'
72+
CONFIG_LIBUKBLKDEV_DISPATCHERTHREADS: 'y'
73+
CONFIG_LIBUKBLKDEV_SYNC_IO_BLOCKED_WAITING: 'y'
74+
CONFIG_LIBUKBLKDEV: 'y'
75+
CONFIG_LIBUKBOOT_BANNER_MINIMAL: 'y'
76+
CONFIG_LIBUKBOOT_HEAP_BASE: '0x400000000'
77+
CONFIG_LIBUKBOOT_MAINTHREAD: 'y'
78+
CONFIG_LIBUKBOOT_SHUTDOWNREQ_HANDLER: 'y'
79+
CONFIG_LIBUKCPIO: 'y'
80+
CONFIG_LIBUKDEBUG_CRASH_SCREEN: 'y'
81+
CONFIG_LIBUKDEBUG_ENABLE_ASSERT: 'y'
82+
CONFIG_LIBUKDEBUG_PRINT_SRCNAME: 'n'
83+
CONFIG_LIBUKDEBUG_PRINT_TIME: 'y'
84+
CONFIG_LIBUKDEBUG_PRINTK_ERR: 'y'
85+
CONFIG_LIBUKDEBUG_PRINTK: 'y'
86+
CONFIG_LIBUKDEBUG: 'y'
87+
CONFIG_LIBUKFALLOC: 'y'
88+
CONFIG_LIBUKMPI: 'n'
89+
CONFIG_LIBUKSIGNAL: 'y'
90+
CONFIG_LIBUKRANDOM_DEVFS: 'y'
91+
CONFIG_LIBUKRANDOM: 'y'
92+
CONFIG_LIBUKRANDOM_GETRANDOM: 'y'
93+
CONFIG_LIBUKVMEM_DEFAULT_BASE: '0x0000001000000000'
94+
CONFIG_LIBUKVMEM_DEMAND_PAGE_IN_SIZE: 12
95+
CONFIG_LIBUKVMEM_PAGEFAULT_HANDLER_PRIO: 4
96+
CONFIG_LIBUKVMEM: 'y'
97+
CONFIG_LIBVFSCORE_AUTOMOUNT_CI: 'y'
98+
CONFIG_LIBVFSCORE_AUTOMOUNT_CI_EINITRD: 'y'
99+
CONFIG_LIBVFSCORE_AUTOMOUNT_UP: 'y'
100+
CONFIG_LIBVFSCORE_AUTOMOUNT: 'y'
101+
CONFIG_LIBVFSCORE_NONLARGEFILE: 'y'
102+
CONFIG_LIBVFSCORE: 'y'
103+
CONFIG_LIBUK9P: 'y'
104+
CONFIG_OPTIMIZE_DEADELIM: 'y'
105+
CONFIG_OPTIMIZE_LTO: 'y'
106+
CONFIG_PAGING: 'y'
107+
CONFIG_STACK_SIZE_PAGE_ORDER: 4 # 128 * 4K = 512K
108+
CONFIG_UKPLAT_MEMREGION_MAX_COUNT: 64
109+
CONFIG_LIBUKNETDEV_EINFO_LIBPARAM: 'y'
110+
111+
# Debug options
112+
# CONFIG_LIBUKDEBUG_PRINTD: 'y'
113+
# CONFIG_LIBUKDEBUG_PRINTK_INFO: 'y'
114+
# CONFIG_LIBSYSCALL_SHIM_STRACE: 'y'
115+
# CONFIG_LIBSYSCALL_SHIM_DEBUG: 'y'
116+
117+
libraries:
118+
lwip:
119+
source: https://github.com/unikraft/lib-lwip.git
120+
version: staging
121+
kconfig:
122+
CONFIG_LWIP_LOOPIF: 'y'
123+
CONFIG_LWIP_UKNETDEV: 'y'
124+
CONFIG_LWIP_LOOPBACK: 'y'
125+
CONFIG_LWIP_TCP: 'y'
126+
CONFIG_LWIP_UDP: 'y'
127+
CONFIG_LWIP_RAW: 'y'
128+
CONFIG_LWIP_WND_SCALE: 'y'
129+
CONFIG_LWIP_TCP_KEEPALIVE: 'y'
130+
CONFIG_LWIP_THREADS: 'y'
131+
CONFIG_LWIP_HEAP: 'y'
132+
CONFIG_LWIP_SOCKET: 'y'
133+
CONFIG_LWIP_AUTOIFACE: 'y'
134+
CONFIG_LWIP_IPV4: 'y'
135+
CONFIG_LWIP_DHCP: 'y'
136+
CONFIG_LWIP_DNS: 'y'
137+
CONFIG_LWIP_NUM_TCPCON: 64
138+
CONFIG_LWIP_NUM_TCPLISTENERS: 64
139+
CONFIG_LWIP_ICMP: 'y'
140+
libelf:
141+
source: https://github.com/unikraft/lib-libelf.git
142+
version: staging
143+
144+
targets:
145+
- fc/x86_64
146+
- qemu/x86_64

library/ruby/3.4/README.md

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
# Ruby
2+
3+
This directory contains the [Ruby](https://www.ruby-lang.org) runtime on Unikraft, in binary compatibility mode.
4+
It implements a simple HTTP server running on Unikraft that provides a simple response to each request.
5+
6+
## Run and Use
7+
8+
Use `kraft` to run the image and start a Unikraft instance:
9+
10+
```bash
11+
kraft run -M 256M -p 8080:8080 --plat qemu --arch x86_64 unikraft.org/ruby:3.2
12+
```
13+
14+
If the `--plat` argument is left out, it defaults to `qemu`.
15+
If the `--arch` argument is left out, it defaults to your system's CPU architecture.
16+
17+
Once executed, it will open port `8080` and wait for connections.
18+
To test it, you can use `curl`:
19+
20+
```bash
21+
curl localhost:8080
22+
```
23+
24+
You should see a "Hello, World!" message.
25+
26+
## Inspect and Close
27+
28+
To list information about the Unikraft instance, use:
29+
30+
```bash
31+
kraft ps -a
32+
```
33+
34+
```text
35+
NAME KERNEL ARGS CREATED STATUS MEM PORTS PLAT
36+
happy_gordo project://ruby:qemu/x86_64 /usr/bin/ruby /src/server.rb 46 seconds ago running 0MiB 0.0.0.0:8080->8080/tcp qemu/x86_64
37+
```
38+
39+
The instance name is `happy_gordo`.
40+
To close the Unikraft instance, use:
41+
42+
```bash
43+
kraft rm happy_gordo
44+
```
45+
46+
Note that closing the `kraft run` command (e.g., via `Ctrl+c`) does not kill the Unikraft instance.
47+
If you want the Unikraft instance closed when closing the `kraft run` command, use the `--rm` option:
48+
49+
```bash
50+
kraft run --rm -M 256M -p 8080:8080 --plat qemu --arch x86_64 unikraft.org/ruby:3.2
51+
```
52+
53+
## Build and Run Locally
54+
55+
The commands so far used the pre-build Ruby image available in the Unikraft registry.
56+
57+
In oder to to build a local image, clone this repository and `cd` into this directory.
58+
Then use `kraft` to build an image locally:
59+
60+
```bash
61+
kraft build --no-cache --no-update --plat qemu --arch x86_64
62+
```
63+
64+
Similar to the `kraft run` command, if the `--plat` argument is left out, it defaults to `qemu`.
65+
If the `--arch` argument is left out, it defaults to your system's CPU architecture.
66+
67+
In order to run the locally built image, use `.` (_dot_, the current directory) as the final argument to the `kraft run` command:
68+
69+
```bash
70+
kraft run -M 512M -p 8080:8080 --plat qemu --arch x86_64 .
71+
```
72+
73+
Same as above, it will open port `8080` and wait for connections.
74+
75+
## `kraft` and `sudo`
76+
77+
Mixing invocations of `kraft` and `sudo` can lead to unexpected behavior.
78+
Read more about how to start `kraft` without `sudo` at [https://unikraft.org/sudoless](https://unikraft.org/sudoless).
79+
80+
## Learn More
81+
82+
- [How to run unikernels locally](https://unikraft.org/docs/cli/running)
83+
- [How to build `Dockerfile` root filesystems with BuildKit](https://unikraft.org/docs/getting-started/integrations/buildkit)

library/ruby/3.4/server.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# https://dev.to/leandronsp/web-basics-a-simple-http-server-in-ruby-2jj4
2+
3+
require 'socket'
4+
5+
socket = TCPServer.new(8080)
6+
7+
loop do
8+
client = socket.accept
9+
10+
request = client.gets
11+
12+
response = "HTTP/1.1 200 OK\r\n" \
13+
"Content-type: text/html\r\n" \
14+
"Connection: close\r\n" \
15+
"\r\n" \
16+
"Hello, World!"
17+
client.puts(response)
18+
19+
client.close
20+
end

0 commit comments

Comments
 (0)