Skip to content
Open
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
83 changes: 83 additions & 0 deletions .github/workflows/library-ruby3.4.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
name: library/ruby:3.4

on:
repository_dispatch:
types: [core_merge, elfloader_merge, libelf_merge, lwip_merge]

workflow_dispatch:

schedule:
- cron: '45 1 * * *'

push:
branches: [main]
paths:
- 'library/ruby/3.4/**'
- '.github/workflows/library-ruby3.4.yaml'

pull_request:
types: [opened, synchronize, reopened]
branches: [main]
paths:
- 'library/ruby/3.4/**'
- '.github/workflows/library-ruby3.4.yaml'

# Automatically cancel in-progress actions on the same branch
concurrency:
group: ${{ github.workflow }}-${{ github.event_name == 'pull_request_target' && github.head_ref || github.ref }}
cancel-in-progress: true

jobs:
build:
strategy:
fail-fast: false
matrix:
include:
- plat: qemu
arch: x86_64
- plat: fc
arch: x86_64

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Build ruby3.4
uses: unikraft/kraftkit@staging
with:
loglevel: debug
workdir: library/ruby/3.4
runtimedir: /github/workspace/.kraftkit
plat: ${{ matrix.plat }}
arch: ${{ matrix.arch }}
push: false
output: oci://index.unikraft.io/unikraft.org/ruby:3.4

- name: Archive OCI digests
uses: actions/upload-artifact@v4
with:
name: oci-digests-${{ matrix.arch }}-${{ matrix.plat }}
path: ${{ github.workspace }}/.kraftkit/oci/digests
if-no-files-found: error

push:
if: ${{ github.event_name == 'push' || github.event_name == 'schedule' }}
needs: [ build ]
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Login to OCI registry
uses: docker/login-action@v3
with:
registry: index.unikraft.io
username: ${{ secrets.REG_USERNAME }}
password: ${{ secrets.REG_TOKEN }}

- name: Retrieve, merge and push OCI digests
uses: ./.github/actions/merge-oci-digests
with:
name: index.unikraft.io/unikraft.org/ruby:3.4
push: true
1 change: 1 addition & 0 deletions examples/httpserver-ruby3.4-base/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/.unikraft/
1 change: 1 addition & 0 deletions examples/httpserver-ruby3.4-base/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/.unikraft/
41 changes: 41 additions & 0 deletions examples/httpserver-ruby3.4-base/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
FROM --platform=linux/x86_64 ruby:3.4-bookworm AS build

FROM alpine:3 AS sys

RUN set -xe; \
mkdir -p /target/etc; \
mkdir -p /blank; \
apk --no-cache add \
ca-certificates \
tzdata \
; \
update-ca-certificates; \
ln -sf ../usr/share/zoneinfo/Etc/UTC /target/etc/localtime; \
echo "Etc/UTC" > /target/etc/timezone;

FROM scratch

COPY --from=sys /target/etc /etc
COPY --from=sys /usr/share/zoneinfo/Etc/UTC /usr/share/zoneinfo/Etc/UTC
COPY --from=sys /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
COPY --from=sys /blank /tmp

# Ruby binary
COPY --from=build /usr/local/bin/ruby /usr/bin/ruby

# Ruby libraries
COPY --from=build /usr/local/lib/ruby /usr/local/lib/ruby

# System libraries
COPY --from=build /usr/local/lib/libruby.so.3.4 /usr/local/lib/libruby.so.3.4
COPY --from=build /lib/x86_64-linux-gnu/libz.so.1 /lib/x86_64-linux-gnu/libz.so.1
COPY --from=build /lib/x86_64-linux-gnu/libgmp.so.10 /lib/x86_64-linux-gnu/libgmp.so.10
COPY --from=build /lib/x86_64-linux-gnu/libcrypt.so.1 /lib/x86_64-linux-gnu/libcrypt.so.1
COPY --from=build /lib/x86_64-linux-gnu/libm.so.6 /lib/x86_64-linux-gnu/libm.so.6
COPY --from=build /lib/x86_64-linux-gnu/libc.so.6 /lib/x86_64-linux-gnu/libc.so.6
COPY --from=build /lib/x86_64-linux-gnu/libgcc_s.so.1 /lib/x86_64-linux-gnu/libgcc_s.so.1
COPY --from=build /lib64/ld-linux-x86-64.so.2 /lib64/ld-linux-x86-64.so.2
COPY --from=build /etc/ld.so.cache /etc/ld.so.cache

# Simple Ruby HTTP server
COPY ./server.rb /src/server.rb
9 changes: 9 additions & 0 deletions examples/httpserver-ruby3.4-base/Kraftfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
spec: v0.6

name: httpserver-ruby3.4-base

runtime: base:latest

rootfs: ./Dockerfile

cmd: ["/usr/bin/ruby", "/src/server.rb"]
64 changes: 64 additions & 0 deletions examples/httpserver-ruby3.4-base/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# Ruby Web Server

This directory contains a [Ruby](https://www.ruby-lang.org/en/) web server running on Unikraft.

## Set Up

To run this example, [install Unikraft's companion command-line toolchain `kraft`](https://unikraft.org/docs/cli), clone this repository and `cd` into this directory.

## Run and Use

Use `kraft` to run the image and start a Unikraft instance:

```bash
kraft run --rm -p 8080:8080 --plat qemu --arch x86_64 -M 512M .
```

If the `--plat` argument is left out, it defaults to `qemu`.
If the `--arch` argument is left out, it defaults to your system's CPU architecture.

Once executed, it will open port `8080` and wait for connections.
To test it, you can use `curl`:

```bash
curl localhost:8080
```

You should see a "Bye, World!" message.

## Inspect and Close

To list information about the Unikraft instance, use:

```bash
kraft ps
```

```text
NAME KERNEL ARGS CREATED STATUS MEM PORTS PLAT
zealous_ramu oci://unikraft.org/ruby:3.4 /usr/bin/ruby /src/server.rb 14 minutes ago running 488M 0.0.0.0:8080->8080/tcp qemu/x86_64
```

The instance name is `zealous_ramu`.
To close the Unikraft instance, close the `kraft` process (e.g., via `Ctrl+c`) or run:

```bash
kraft rm zealous_ramu
```

Note that depending on how you modify this example your instance **may** need more memory to run.
To do so, use the `kraft run`'s `-M` flag, for example:

```bash
kraft run --rm -p 8080:8080 --plat qemu --arch x86_64 -M 1024M .
```

## `kraft` and `sudo`

Mixing invocations of `kraft` and `sudo` can lead to unexpected behavior.
Read more about how to start `kraft` without `sudo` at [https://unikraft.org/sudoless](https://unikraft.org/sudoless).

## Learn More

- [How to run unikernels locally](https://unikraft.org/docs/cli/running)
- [Building `Dockerfile` Images with `BuildKit`](https://unikraft.org/guides/building-dockerfile-images-with-buildkit)
20 changes: 20 additions & 0 deletions examples/httpserver-ruby3.4-base/server.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# https://dev.to/leandronsp/web-basics-a-simple-http-server-in-ruby-2jj4

require 'socket'

socket = TCPServer.new(8080)

loop do
client = socket.accept

request = client.gets

response = "HTTP/1.1 200 OK\r\n" \
"Content-type: text/html\r\n" \
"Connection: close\r\n" \
"\r\n" \
"Bye, World!"
client.puts(response)

client.close
end
1 change: 1 addition & 0 deletions examples/httpserver-ruby3.4/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/.unikraft/
1 change: 1 addition & 0 deletions examples/httpserver-ruby3.4/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/.unikraft/
4 changes: 4 additions & 0 deletions examples/httpserver-ruby3.4/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
FROM unikraft.org/ruby:3.4

# Simple Ruby HTTP server
COPY ./server.rb /src/server.rb
9 changes: 9 additions & 0 deletions examples/httpserver-ruby3.4/Kraftfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
spec: v0.6

name: httpserver-ruby3.4

runtime: ruby:3.4

rootfs: ./Dockerfile

cmd: ["/usr/bin/ruby", "/src/server.rb"]
64 changes: 64 additions & 0 deletions examples/httpserver-ruby3.4/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# Ruby Web Server

This directory contains a [Ruby](https://www.ruby-lang.org/en/) web server running on Unikraft.

## Set Up

To run this example, [install Unikraft's companion command-line toolchain `kraft`](https://unikraft.org/docs/cli), clone this repository and `cd` into this directory.

## Run and Use

Use `kraft` to run the image and start a Unikraft instance:

```bash
kraft run --rm -p 8080:8080 --plat qemu --arch x86_64 -M 512M .
```

If the `--plat` argument is left out, it defaults to `qemu`.
If the `--arch` argument is left out, it defaults to your system's CPU architecture.

Once executed, it will open port `8080` and wait for connections.
To test it, you can use `curl`:

```bash
curl localhost:8080
```

You should see a "Bye, World!" message.

## Inspect and Close

To list information about the Unikraft instance, use:

```bash
kraft ps
```

```text
NAME KERNEL ARGS CREATED STATUS MEM PORTS PLAT
zealous_ramu oci://unikraft.org/ruby:3.4 /usr/bin/ruby /src/server.rb 14 minutes ago running 488M 0.0.0.0:8080->8080/tcp qemu/x86_64
```

The instance name is `zealous_ramu`.
To close the Unikraft instance, close the `kraft` process (e.g., via `Ctrl+c`) or run:

```bash
kraft rm zealous_ramu
```

Note that depending on how you modify this example your instance **may** need more memory to run.
To do so, use the `kraft run`'s `-M` flag, for example:

```bash
kraft run --rm -p 8080:8080 --plat qemu --arch x86_64 -M 1024M .
```

## `kraft` and `sudo`

Mixing invocations of `kraft` and `sudo` can lead to unexpected behavior.
Read more about how to start `kraft` without `sudo` at [https://unikraft.org/sudoless](https://unikraft.org/sudoless).

## Learn More

- [How to run unikernels locally](https://unikraft.org/docs/cli/running)
- [Building `Dockerfile` Images with `BuildKit`](https://unikraft.org/guides/building-dockerfile-images-with-buildkit)
20 changes: 20 additions & 0 deletions examples/httpserver-ruby3.4/server.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# https://dev.to/leandronsp/web-basics-a-simple-http-server-in-ruby-2jj4

require 'socket'

socket = TCPServer.new(8080)

loop do
client = socket.accept

request = client.gets

response = "HTTP/1.1 200 OK\r\n" \
"Content-type: text/html\r\n" \
"Connection: close\r\n" \
"\r\n" \
"Bye, World!"
client.puts(response)

client.close
end
2 changes: 1 addition & 1 deletion library/ruby/3.2/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ kraft run --rm -M 256M -p 8080:8080 --plat qemu --arch x86_64 unikraft.org/ruby:

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

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

```bash
Expand Down
41 changes: 41 additions & 0 deletions library/ruby/3.4/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
FROM --platform=linux/x86_64 ruby:3.4-bookworm AS build

FROM alpine:3 AS sys

RUN set -xe; \
mkdir -p /target/etc; \
mkdir -p /blank; \
apk --no-cache add \
ca-certificates \
tzdata \
; \
update-ca-certificates; \
ln -sf ../usr/share/zoneinfo/Etc/UTC /target/etc/localtime; \
echo "Etc/UTC" > /target/etc/timezone;

FROM scratch

COPY --from=sys /target/etc /etc
COPY --from=sys /usr/share/zoneinfo/Etc/UTC /usr/share/zoneinfo/Etc/UTC
COPY --from=sys /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
COPY --from=sys /blank /tmp

# Ruby binary
COPY --from=build /usr/local/bin/ruby /usr/bin/ruby

# Ruby libraries
COPY --from=build /usr/local/lib/ruby /usr/local/lib/ruby

# System libraries
COPY --from=build /usr/local/lib/libruby.so.3.4 /usr/local/lib/libruby.so.3.4
COPY --from=build /lib/x86_64-linux-gnu/libz.so.1 /lib/x86_64-linux-gnu/libz.so.1
COPY --from=build /lib/x86_64-linux-gnu/libgmp.so.10 /lib/x86_64-linux-gnu/libgmp.so.10
COPY --from=build /lib/x86_64-linux-gnu/libcrypt.so.1 /lib/x86_64-linux-gnu/libcrypt.so.1
COPY --from=build /lib/x86_64-linux-gnu/libm.so.6 /lib/x86_64-linux-gnu/libm.so.6
COPY --from=build /lib/x86_64-linux-gnu/libc.so.6 /lib/x86_64-linux-gnu/libc.so.6
COPY --from=build /lib/x86_64-linux-gnu/libgcc_s.so.1 /lib/x86_64-linux-gnu/libgcc_s.so.1
COPY --from=build /lib64/ld-linux-x86-64.so.2 /lib64/ld-linux-x86-64.so.2
COPY --from=build /etc/ld.so.cache /etc/ld.so.cache

# Simple Ruby HTTP server
COPY ./server.rb /src/server.rb
Loading