Skip to content

Commit

Permalink
feat(library): Introduce Hugo 0.122 as library (#53)
Browse files Browse the repository at this point in the history
  • Loading branch information
razvand authored Mar 4, 2024
2 parents 839c699 + 2e33c31 commit c314cdc
Show file tree
Hide file tree
Showing 7 changed files with 285 additions and 11 deletions.
22 changes: 11 additions & 11 deletions .github/workflows/library-node18.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: library/node:18
name: library/hugo:0.122

on:
schedule:
Expand All @@ -7,17 +7,17 @@ on:
push:
branches: [main]
paths:
- 'library/node/18/**'
- '.github/workflows/library-node18.yaml'
- '!library/node/18/README.md'
- 'library/hugo/0.122/**'
- '.github/workflows/library-hugo0.122.yaml'
- '!library/hugo/0.122/README.md'

pull_request:
types: [opened, synchronize, reopened]
branches: [main]
paths:
- 'library/node/18/**'
- '.github/workflows/library-node18.yaml'
- '!library/node/18/README.md'
- 'library/hugo/0.122/**'
- '.github/workflows/library-hugo0.122.yaml'
- '!library/hugo/0.122/README.md'

jobs:
build:
Expand All @@ -35,16 +35,16 @@ jobs:
steps:
- uses: actions/checkout@v3

- name: Build node18
- name: Build hugo0.122
uses: unikraft/kraftkit@staging
with:
loglevel: debug
workdir: library/node/18
workdir: library/hugo/0.122
runtimedir: /github/workspace/.kraftkit
plat: ${{ matrix.plat }}
arch: ${{ matrix.arch }}
push: false
output: oci://index.unikraft.io/unikraft.org/node:18
output: oci://index.unikraft.io/unikraft.org/hugo:0.122

- name: Archive OCI digests
uses: actions/upload-artifact@v3
Expand All @@ -71,5 +71,5 @@ jobs:
- name: Retrieve, merge and push OCI digests
uses: ./.github/actions/merge-oci-digests
with:
name: index.unikraft.io/unikraft.org/node:18
name: index.unikraft.io/unikraft.org/hugo:0.122
push: true
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,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-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) |
| [![](https://github.com/unikraft/catalog/actions/workflows/library-nginx1.15.yaml/badge.svg)](https://github.com/unikraft/catalog/actions/workflows/library-nginx1.15.yaml) | [`unikraft.org/nginx:1.15`](library/nginx/1.15) |
Expand Down
3 changes: 3 additions & 0 deletions library/hugo/0.122/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/Makefile.uk
/.unikraft/
/.config*
3 changes: 3 additions & 0 deletions library/hugo/0.122/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/Makefile.uk
/.unikraft/
/.config*
54 changes: 54 additions & 0 deletions library/hugo/0.122/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
FROM golang:1.21.3-bookworm AS build

ARG HUGO_VERSION=v0.122.0

WORKDIR /src

RUN set -xe; \
CGO_ENABLED=1 \
go install \
-buildmode=pie \
-tags extended \
github.com/gohugoio/hugo@${HUGO_VERSION} \
;

WORKDIR /site

RUN set -xe; \
hugo new site .; \
git clone --depth 1 https://github.com/budparr/gohugo-theme-ananke.git themes/ananke; \
echo 'theme = "ananke"' >> hugo.toml \
;

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

# Binary executable
COPY --from=build /go/bin/hugo /usr/bin/hugo

# System libraries
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/libm.so.6 /lib/x86_64-linux-gnu/libm.so.6
COPY --from=build /lib/x86_64-linux-gnu/libstdc++.so.6 /lib/x86_64-linux-gnu/libstdc++.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

# Site
COPY --from=build /site /site
130 changes: 130 additions & 0 deletions library/hugo/0.122/Kraftfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
spec: v0.6

name: hugo

rootfs: ./Dockerfile

cmd: ["/usr/bin/hugo", "server", "--bind=0.0.0.0", "--source", "/site"]

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_AUTOGEN_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_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_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

# Debug options
# CONFIG_LIBUKDEBUG_PRINTD: 'y'
# CONFIG_LIBUKDEBUG_PRINTK_INFO: 'y'
# CONFIG_LIBSYSCALL_SHIM_STRACE: 'y'

libraries:
lwip:
source: https://github.com/unikraft/lib-lwip.git
version: staging
kconfig:
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_NUM_TCPCON: 64
CONFIG_LWIP_NUM_TCPLISTENERS: 64
CONFIG_LWIP_ICMP: 'y'
CONFIG_LWIP_DHCP: 'y'
CONFIG_LWIP_DNS: 'n'
libelf:
source: https://github.com/unikraft/lib-libelf.git
version: staging

targets:
- fc/x86_64
- qemu/x86_64
83 changes: 83 additions & 0 deletions library/hugo/0.122/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# Hugo

This directory contains the [Hugo](https://gohugo.io/) runtime on Unikraft, in binary compatibility mode.
It implements a simple HTTP server running on Unikraft that provides a simple response to each request.

## Run and Use

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

```bash
kraft run -M 512M -p 1313:1313 --plat qemu --arch x86_64 unikraft.org/hugo:0.122
```

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 `1313` and wait for connections.
To test it, you can use `curl`:

```bash
curl localhost:1313
```

You should the landing page used by Hugo.

## Inspect and Close

To list information about the Unikraft instance, use:

```bash
kraft ps -a
```

```text
NAME KERNEL ARGS CREATED STATUS MEM PORTS PLAT
elated_jack project://hugo:qemu/x86_64 /usr/bin/hugo server --bind=0.0.0.0 --source /site 1 minute ago running 0MiB 0.0.0.0:1313->1313/tcp qemu/x86_64
```

The instance name is `elated_jack`.
To close the Unikraft instance, use:

```bash
kraft rm elated_jack
```

Note that closing the `kraft run` command (e.g., via `Ctrl+c`) does not kill the Unikraft instance.
If you want the Unikraft instance closed when closing the `kraft run` command, use the `--rm` option:

```bash
kraft run --rm -M 512M -p 1313:1313 --plat qemu --arch x86_64 unikraft.org/hugo:0.122
```

## Build and Run Locally

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.
Then use `kraft` to build an image locally:

```bash
kraft build --no-cache --no-update --plat qemu --arch x86_64
```

Similar to the `kraft run` command, 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.

In order to run the locally built image, use `.` (_dot_, the current directory) as the final argument to the `kraft run` command:

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

Same as above, it will open port `1313` and wait for connections.

## `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)
- [How to build `Dockerfile` root filesystems with BuildKit](https://unikraft.org/docs/getting-started/integrations/buildkit)

0 comments on commit c314cdc

Please sign in to comment.