From 8d20819f7c2c146c3a39b78823044ffb6347b649 Mon Sep 17 00:00:00 2001 From: Hamza Chandad Date: Sat, 30 Mar 2024 16:32:23 +0000 Subject: [PATCH] feat(library): Add httpbingo service as library Introduce the https://httpbingo.org service as a library A golang port of the httpbin.org HTTP request & response testing service. Signed-off-by: Hamza Chandad --- .../workflows/library-httpbingo2.13.4.yaml | 80 ++++++++++ README.md | 1 + library/httpbingo/2.13.4/Dockerfile | 24 +++ library/httpbingo/2.13.4/Kraftfile | 143 ++++++++++++++++++ library/httpbingo/2.13.4/README.md | 87 +++++++++++ 5 files changed, 335 insertions(+) create mode 100644 .github/workflows/library-httpbingo2.13.4.yaml create mode 100644 library/httpbingo/2.13.4/Dockerfile create mode 100644 library/httpbingo/2.13.4/Kraftfile create mode 100644 library/httpbingo/2.13.4/README.md diff --git a/.github/workflows/library-httpbingo2.13.4.yaml b/.github/workflows/library-httpbingo2.13.4.yaml new file mode 100644 index 00000000..55dac70a --- /dev/null +++ b/.github/workflows/library-httpbingo2.13.4.yaml @@ -0,0 +1,80 @@ +name: library/httpbingo:2.13.4 + +on: + repository_dispatch: + types: [core_merge] + + workflow_dispatch: + + schedule: + - cron: '0 0 * * *' # Everyday at 12AM + + push: + branches: [main] + paths: + - 'library/httpbingo/2.13.4/**' + - '.github/workflows/library-httpbingo2.13.4.yaml' + - '!library/httpbingo/2.13.4/README.md' + + pull_request: + types: [opened, synchronize, reopened] + branches: [main] + paths: + - 'library/httpbingo/2.13.4/**' + - '.github/workflows/library-httpbingo2.13.4.yaml' + - '!library/httpbingo/2.13.4/README.md' + +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@v3 + + - name: Build httpbingo2.13.4 + uses: unikraft/kraftkit@staging + with: + loglevel: debug + workdir: library/httpbingo/2.13.4 + runtimedir: /github/workspace/.kraftkit + plat: ${{ matrix.plat }} + arch: ${{ matrix.arch }} + push: false + output: oci://index.unikraft.io/unikraft.org/httpbingo:2.13.4 + + - name: Archive OCI digests + uses: actions/upload-artifact@v3 + 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@v3 + + - name: Login to OCI registry + uses: docker/login-action@v2 + 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/httpbingo:2.13.4 + push: true diff --git a/README.md b/README.md index 1b992966..073cd922 100644 --- a/README.md +++ b/README.md @@ -42,6 +42,7 @@ kraft pkg ls --apps --update | [![](https://github.com/unikraft/catalog/actions/workflows/library-base.yaml/badge.svg)](https://github.com/unikraft/catalog/actions/workflows/library-base.yaml) | [`unikraft.org/base:latest`](library/base) | | [![](https://github.com/unikraft/catalog/actions/workflows/library-caddy2.7.yaml/badge.svg)](https://github.com/unikraft/catalog/actions/workflows/library-caddy2.7.yaml) | [`unikraft.org/caddy:2.7`](library/caddy/2.7) | | [![](https://github.com/unikraft/catalog/actions/workflows/library-helloworld.yaml/badge.svg)](https://github.com/unikraft/catalog/actions/workflows/library-helloworld.yaml) | [`unikraft.org/helloworld:latest`](library/helloworld) | +| [![](https://github.com/unikraft/catalog/actions/workflows/library-httpbingo2.13.4.yaml/badge.svg)](https://github.com/unikraft/catalog/actions/workflows/library-httpbingo2.13.4.yaml) | [`unikraft.org/httpbingo:2.13.4`](library/httpbingo/2.13.4) | | [![](https://github.com/unikraft/catalog/actions/workflows/library-hugo0.122.yaml/badge.svg)](https://github.com/unikraft/catalog/actions/workflows/library-hugo0.122.yaml) | [`unikraft.org/hugo:0.122`](library/hugo/0.122) | | [![](https://github.com/unikraft/catalog/actions/workflows/library-lua5.4.4.yaml/badge.svg)](https://github.com/unikraft/catalog/actions/workflows/library-lua5.4.4.yaml) | [`unikraft.org/lua:5.4.4`](library/lua/5.4.4) | | [![](https://github.com/unikraft/catalog/actions/workflows/library-lua5.4.yaml/badge.svg)](https://github.com/unikraft/catalog/actions/workflows/library-lua5.4.yaml) | [`unikraft.org/lua:5.4`](library/lua/5.4) | diff --git a/library/httpbingo/2.13.4/Dockerfile b/library/httpbingo/2.13.4/Dockerfile new file mode 100644 index 00000000..98ec43ab --- /dev/null +++ b/library/httpbingo/2.13.4/Dockerfile @@ -0,0 +1,24 @@ +FROM golang:1.21 as build + +ARG VERSION=2.13.4 + +WORKDIR /go/src/github.com/mccutchen/go-httpbin + +RUN --mount=type=cache,target=/root/go/pkg/mod \ + --mount=type=cache,target=/root/.cache/go-build \ + set -xe; \ + apt-get update; \ + apt-get install -y --no-install-recommends \ + git \ + ca-certificates; \ + git clone --depth=1 --branch v${VERSION} https://github.com/mccutchen/go-httpbin.git .; \ + mkdir -p dist; \ + CGO_ENABLED=1 go build \ + -buildmode=pie \ + -ldflags="-linkmode external -extldflags -static-pie" \ + -tags netgo\ + -o dist/go-httpbin ./cmd/go-httpbin + +FROM scratch + +COPY --from=build /go/src/github.com/mccutchen/go-httpbin/dist/go-httpbin /bin/ diff --git a/library/httpbingo/2.13.4/Kraftfile b/library/httpbingo/2.13.4/Kraftfile new file mode 100644 index 00000000..284a5dc4 --- /dev/null +++ b/library/httpbingo/2.13.4/Kraftfile @@ -0,0 +1,143 @@ +spec: v0.6 + +name: go-httpbin + +rootfs: Dockerfile + +cmd: ["/bin/go-httpbin"] + +template: + source: https://github.com/unikraft/app-elfloader.git + version: staging + +unikraft: + source: https://github.com/unikraft/unikraft.git + version: staging + kconfig: + # Configurations options for app-elfloader + # (they can't be part of the template atm) + CONFIG_APPELFLOADER_ARCH_PRCTL: 'y' + CONFIG_APPELFLOADER_BRK: 'y' + CONFIG_APPELFLOADER_CUSTOMAPPNAME: 'y' + CONFIG_APPELFLOADER_STACK_NBPAGES: 128 + CONFIG_APPELFLOADER_VFSEXEC_EXECBIT: 'n' + CONFIG_APPELFLOADER_VFSEXEC: 'y' + CONFIG_APPELFLOADER_HFS: 'y' + CONFIG_APPELFLOADER_HFS_ETCRESOLVCONF: 'y' + CONFIG_APPELFLOADER_HFS_ETCHOSTS: 'y' + CONFIG_APPELFLOADER_HFS_ETCHOSTNAME: 'y' + CONFIG_APPELFLOADER_HFS_REPLACEEXIST: 'y' + # Unikraft options + CONFIG_HAVE_PAGING_DIRECTMAP: 'y' + CONFIG_HAVE_PAGING: 'y' + CONFIG_I8042: 'y' + CONFIG_LIBDEVFS_AUTOMOUNT: 'y' + CONFIG_LIBDEVFS_DEV_NULL: 'y' + CONFIG_LIBDEVFS_DEV_STDOUT: 'y' + CONFIG_LIBDEVFS_DEV_ZERO: 'y' + CONFIG_LIBDEVFS: 'y' + CONFIG_LIBPOSIX_ENVIRON_ENVP0: "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" + CONFIG_LIBPOSIX_ENVIRON_ENVP1: "LD_LIBRARY_PATH=/usr/local/lib:/usr/lib:/lib" + CONFIG_LIBPOSIX_ENVIRON_ENVP2: "HOME=/" + CONFIG_LIBPOSIX_ENVIRON: 'y' + CONFIG_LIBPOSIX_ENVIRON_LIBPARAM: 'y' + CONFIG_LIBPOSIX_ENVIRON_LIBPARAM_MAXCOUNT: '64' + CONFIG_LIBPOSIX_EVENTFD: 'y' + CONFIG_LIBPOSIX_FDIO: 'y' + CONFIG_LIBPOSIX_FDTAB: 'y' + CONFIG_LIBPOSIX_FUTEX: 'y' + CONFIG_LIBPOSIX_MMAP: 'y' + CONFIG_LIBPOSIX_NETLINK: 'y' + CONFIG_LIBPOSIX_PIPE: 'y' + CONFIG_LIBPOSIX_POLL: 'y' + CONFIG_LIBPOSIX_PROCESS_CLONE: 'y' + CONFIG_LIBPOSIX_SOCKET: 'y' + CONFIG_LIBPOSIX_SYSINFO: 'y' + CONFIG_LIBPOSIX_TIME: 'y' + CONFIG_LIBPOSIX_TIMERFD: 'y' + CONFIG_LIBPOSIX_UNIXSOCKET: 'y' + CONFIG_LIBPOSIX_USER_GID: 0 + CONFIG_LIBPOSIX_USER_GROUPNAME: "root" + CONFIG_LIBPOSIX_USER_UID: 0 + CONFIG_LIBPOSIX_USER_USERNAME: "root" + CONFIG_LIBPOSIX_USER: 'y' + CONFIG_LIBRAMFS: 'y' + CONFIG_LIBSYSCALL_SHIM_HANDLER_ULTLS: 'y' + CONFIG_LIBSYSCALL_SHIM_HANDLER: 'y' + CONFIG_LIBSYSCALL_SHIM_LEGACY_VERBOSE: 'y' + CONFIG_LIBSYSCALL_SHIM: 'y' + CONFIG_LIBUKALLOCPOOL: 'y' + CONFIG_LIBUKBLKDEV_MAXNBQUEUES: '1' + CONFIG_LIBUKBLKDEV_DISPATCHERTHREADS: 'y' + CONFIG_LIBUKBLKDEV_SYNC_IO_BLOCKED_WAITING: 'y' + CONFIG_LIBUKBLKDEV: 'y' + CONFIG_LIBUKBOOT_BANNER_MINIMAL: 'y' + CONFIG_LIBUKBOOT_HEAP_BASE: '0x400000000' + CONFIG_LIBUKBOOT_MAINTHREAD: 'y' + CONFIG_LIBUKBOOT_SHUTDOWNREQ_HANDLER: 'y' + CONFIG_LIBUKCPIO: 'y' + CONFIG_LIBUKDEBUG_CRASH_SCREEN: 'y' + CONFIG_LIBUKDEBUG_ENABLE_ASSERT: 'y' + CONFIG_LIBUKDEBUG_PRINT_SRCNAME: 'n' + CONFIG_LIBUKDEBUG_PRINT_TIME: 'y' + CONFIG_LIBUKDEBUG_PRINTK_ERR: 'y' + CONFIG_LIBUKDEBUG_PRINTK: 'y' + CONFIG_LIBUKDEBUG: 'y' + CONFIG_LIBUKFALLOC: 'y' + CONFIG_LIBUKMPI: 'n' + CONFIG_LIBUKSIGNAL: 'y' + CONFIG_LIBUKSWRAND_DEVFS: 'y' + CONFIG_LIBUKSWRAND: 'y' + CONFIG_LIBUKVMEM_DEFAULT_BASE: '0x0000001000000000' + CONFIG_LIBUKVMEM_DEMAND_PAGE_IN_SIZE: 12 + CONFIG_LIBUKVMEM_PAGEFAULT_HANDLER_PRIO: 4 + CONFIG_LIBUKVMEM: 'y' + CONFIG_LIBVFSCORE_AUTOMOUNT_CI: 'y' + CONFIG_LIBVFSCORE_AUTOMOUNT_CI_EINITRD: 'y' + CONFIG_LIBVFSCORE_AUTOMOUNT_UP: 'y' + CONFIG_LIBVFSCORE_AUTOMOUNT: 'y' + CONFIG_LIBVFSCORE_NONLARGEFILE: 'y' + CONFIG_LIBVFSCORE: 'y' + CONFIG_OPTIMIZE_DEADELIM: 'y' + CONFIG_OPTIMIZE_LTO: 'y' + CONFIG_PAGING: 'y' + CONFIG_STACK_SIZE_PAGE_ORDER: 4 # 128 * 4K = 512K + CONFIG_UKPLAT_MEMREGION_MAX_COUNT: 64 + CONFIG_LIBUKNETDEV_EINFO_LIBPARAM: 'y' + + # Debug options + # CONFIG_LIBUKDEBUG_PRINTD: 'y' + # CONFIG_LIBUKDEBUG_PRINTK_INFO: 'y' + # CONFIG_LIBSYSCALL_SHIM_STRACE: 'y' + # CONFIG_LIBSYSCALL_SHIM_DEBUG: 'y' + +libraries: + lwip: + source: https://github.com/unikraft/lib-lwip.git + version: staging + kconfig: + CONFIG_LWIP_LOOPIF: 'y' + CONFIG_LWIP_UKNETDEV: 'y' + CONFIG_LWIP_LOOPBACK: 'y' + CONFIG_LWIP_TCP: 'y' + CONFIG_LWIP_UDP: 'y' + CONFIG_LWIP_RAW: 'y' + CONFIG_LWIP_WND_SCALE: 'y' + CONFIG_LWIP_TCP_KEEPALIVE: 'y' + CONFIG_LWIP_THREADS: 'y' + CONFIG_LWIP_HEAP: 'y' + CONFIG_LWIP_SOCKET: 'y' + CONFIG_LWIP_AUTOIFACE: 'y' + CONFIG_LWIP_IPV4: 'y' + CONFIG_LWIP_DHCP: 'y' + CONFIG_LWIP_DNS: 'y' + CONFIG_LWIP_NUM_TCPCON: 64 + CONFIG_LWIP_NUM_TCPLISTENERS: 64 + CONFIG_LWIP_ICMP: 'y' + libelf: + source: https://github.com/unikraft/lib-libelf.git + version: staging + +targets: +- qemu/x86_64 +- fc/x86_64 diff --git a/library/httpbingo/2.13.4/README.md b/library/httpbingo/2.13.4/README.md new file mode 100644 index 00000000..3f5e275e --- /dev/null +++ b/library/httpbingo/2.13.4/README.md @@ -0,0 +1,87 @@ +# go-httpbin + +This directory contains the build definition for the [httpbingo](https://httpbingo.org/) image, an HTTP request & response testing service. + +## 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 unikraft.org/httpbingo:2.13.4 +``` + +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, visit `http://localhost:8080` to see all available endpoints + +Next try it out + +Using curl +```bash +$ curl -I http://localhost:8080/status/418 +HTTP/1.1 418 I'm a teapot +Access-Control-Allow-Credentials: true +Access-Control-Allow-Origin: * +Content-Type: text/plain; charset=utf-8 +X-More-Info: http://tools.ietf.org/html/rfc2324 +Date: Sat, 30 Mar 2024 15:59:44 GMT +``` + +Using [httpie](https://github.com/httpie/cli) +```bash +$ http http://localhost:8080/get?foo=bar +HTTP/1.1 200 OK +Access-Control-Allow-Credentials: true +Access-Control-Allow-Origin: * +Content-Length: 392 +Content-Type: application/json; charset=utf-8 +Date: Sat, 30 Mar 2024 15:58:45 GMT + +{ + "args": { + "foo": [ + "bar" + ] + }, + "headers": { + "Accept": [ + "*/*" + ], + "Accept-Encoding": [ + "gzip, deflate" + ], + "Connection": [ + "keep-alive" + ], + "Host": [ + "localhost:8080" + ], + "User-Agent": [ + "HTTPie/3.2.2" + ] + }, + "method": "GET", + "origin": "10.0.2.2:55852", + "url": "http://localhost:8080/get?foo=bar" +} +``` + +## Build and Run Locally + +To build the image locally, clone this repository and cd into this directory. Then run: + +```bash +kraft build --no-cache . +``` + +To run the locally built image, use: + +```bash +kraft run -p 8080:8080 . +``` + +## Learn More + +- [How to run unikernels locally](https://unikraft.org/docs/cli/running) +- [How to build `Dockerfile` root filesystems with BuildKit](https://unikraft.org/guides/building-dockerfile-images-with-buildkit)