Skip to content
Open
Show file tree
Hide file tree
Changes from 4 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
27 changes: 27 additions & 0 deletions nginx-1.25/.github/workflows/example-nginx-stable.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Build and Test Nginx Example - Stable

on:
push:
branches: [add-nginx-latest]
pull_request:
branches: [add-nginx-latest]

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Install KraftKit
run: |
curl -sSf https://get.kraftkit.sh | sh

- name: Build Nginx Example
run: |
cd nginx
kraft build

- name: Test Nginx
run: |
curl http://localhost:8080
27 changes: 27 additions & 0 deletions nginx-1.25/.github/workflows/example-nginx-staging.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Build and Test Nginx Example - Staging

on:
push:
branches: [staging]
pull_request:
branches: [staging]

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Install KraftKit
run: |
curl -sSf https://get.kraftkit.sh | sh

- name: Build Nginx Example
run: |
cd nginx
kraft build

- name: Test Nginx
run: |
curl http://localhost:8080
File renamed without changes.
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions nginx-1.25/app-nginx
Submodule app-nginx added at e21185
17 changes: 17 additions & 0 deletions nginx-1.25/rootfs/wwwroot/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
body {
width: 35em;
margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif;
}
</style>
</head>
<body>
<h1>Hello from Unikraft + Nginx!</h1>
<h2>Hello World!</h2>
</body>
</html>
27 changes: 27 additions & 0 deletions nginx-1.27/.github/workflows/example-nginx-stable.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Build and Test Nginx Example - Stable

on:
push:
branches: [add-nginx-latest]
pull_request:
branches: [add-nginx-latest]

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Install KraftKit
run: |
curl -sSf https://get.kraftkit.sh | sh

- name: Build Nginx Example
run: |
cd nginx
kraft build

- name: Test Nginx
run: |
curl http://localhost:8080
27 changes: 27 additions & 0 deletions nginx-1.27/.github/workflows/example-nginx-staging.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Build and Test Nginx Example - Staging

on:
push:
branches: [staging]
pull_request:
branches: [staging]

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Install KraftKit
run: |
curl -sSf https://get.kraftkit.sh | sh

- name: Build Nginx Example
run: |
cd nginx
kraft build

- name: Test Nginx
run: |
curl http://localhost:8080
33 changes: 33 additions & 0 deletions nginx-1.27/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
FROM nginx:1.25.3-bookworm AS build

RUN set -xe; \
rm -f /var/log/nginx/access.log; \
rm -f /var/log/nginx/error.log; \
touch /var/log/nginx/access.log; \
touch /var/log/nginx/error.log \
;

FROM scratch

# Nginx binaries, modules, configuration, log and runtime files
COPY --from=build /usr/sbin/nginx /usr/bin/nginx
COPY --from=build /usr/lib/nginx /usr/lib/nginx
COPY --from=build /etc/nginx /etc/nginx
COPY --from=build /etc/passwd /etc/passwd
COPY --from=build /etc/group /etc/group
COPY --from=build /var/log/nginx /var/log/nginx
COPY --from=build /var/cache/nginx /var/cache/nginx
COPY --from=build /var/run /var/run

# Libraries
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/libpcre2-8.so.0 /lib/x86_64-linux-gnu/libpcre2-8.so.0
COPY --from=build /lib/x86_64-linux-gnu/libssl.so.3 /lib/x86_64-linux-gnu/libssl.so.3
COPY --from=build /lib/x86_64-linux-gnu/libcrypto.so.3 /lib/x86_64-linux-gnu/libcrypto.so.3
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/libc.so.6 /lib/x86_64-linux-gnu/libc.so.6
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

# Custom configuration files, including using a single process for Nginx
COPY ./rootfs/ /
12 changes: 12 additions & 0 deletions nginx-1.27/Kraftfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
spec: v0.6

runtime: index.unikraft.io/official/nginx:latest

labels:
cloud.unikraft.v1.instances/scale_to_zero.policy: "on"
cloud.unikraft.v1.instances/scale_to_zero.stateful: "false"
cloud.unikraft.v1.instances/scale_to_zero.cooldown_time_ms: 1000

rootfs: ./rootfs

cmd: ["/usr/bin/nginx", "-c", "/etc/nginx/nginx.conf"]
120 changes: 120 additions & 0 deletions nginx-1.27/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
# NGINX

This example uses [`Nginx`](https://nginx.org), one of the most popular web servers.
Nginx can be used with Unikraft / Unikraft Cloud to serve static web content.

To run this example, follow these steps:

1. Install the [`kraft` CLI tool](https://unikraft.org/docs/cli/install) and a container runtime engine, for example [Docker](https://docs.docker.com/engine/install/).

2. Clone the [`examples` repository](https://github.com/unikraft-cloud/examples) and `cd` into the `examples/nginx/` directory:

```bash
git clone https://github.com/unikraft-cloud/examples
cd examples/nginx/
Comment on lines +10 to +14
```

Make sure to log into Unikraft Cloud by setting your token and a [metro](https://unikraft.com/docs/platform/metros) close to you.
This guide uses `fra` (Frankfurt, 🇩🇪):

```bash
export UKC_TOKEN=token
# Set metro to Frankfurt, DE
export UKC_METRO=fra
```

When done, invoke the following command to deploy this app on Unikraft Cloud:

```bash
kraft cloud deploy -M 256 -p 443:8080 .
```

The output shows the instance address and other details:

```ansi
[●] Deployed successfully!
├────────── name: nginx-67zbu
├────────── uuid: 8a8bc1b9-0af6-420e-a426-190dc2da9eaa
├───────── state: running
├─────────── url: https://nameless-fog-0tvh1uov.fra.unikraft.app
├───────── image: nginx@sha256:f51ecc121c9ca34abb88a2bc6a69765501304f7893f7e85af15fbec3dc86e2bd
├───── boot time: 11.13ms
├──────── memory: 256 MiB
├─────── service: nameless-fog-0tvh1uov
├── private fqdn: nginx-67zbu.internal
├──── private ip: 172.16.3.3
└────────── args: /usr/bin/nginx -c /etc/nginx/nginx.conf
```

In this case, the instance name is `nginx-67zbu` and the address is `https://nameless-fog-0tvh1uov.fra.unikraft.app`.
They're different for each run.

Use `curl` to query the Unikraft Cloud instance of Nginx.

```bash
curl https://nameless-fog-0tvh1uov.fra.unikraft.app
```
```text
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
[...]
```

You can list information about the instance by running:

```bash
kraft cloud instance list
```
```ansi
NAME FQDN STATE STATUS IMAGE MEMORY VCPUS ARGS BOOT TIME
nginx-67zbu nameless-fog-0tvh1uov.fra.unikraft.app running 5 minutes ago nginx@sha256:f51ecc121c9ca34abb... 256 MiB 1 /usr/bin/nginx -c /etc/nginx/nginx.conf 11129us
```

When done, you can remove the instance:

```bash
kraft cloud instance remove nginx-67zbu
```

## Customize your app

To customize the Nginx app, update the files in the repository, listed below:

* `Kraftfile`: the Unikraft Cloud specification
* `rootfs/wwwroot/index.html`: the index page of the content served
* `rootfs/conf/nginx.conf`: the Nginx configuration file

Update the contents of the `rootfs/wwwroot/` directory to serve different static web content.
For example, you could change the contents of `rootfs/wwwroot/index.html` to:

```html
<!DOCTYPE html>
<html>
<head>
<title>Hello</title>
</head>
<body>
<h2>Hello, World!</h2>
</body>
</html>
```

After re-deploying the Nginx image on Unikraft Cloud, using `curl` or a browser to query it will present the new page contents.

Tools like [`Jekyll`](https://jekyllrb.com/) or [`Hugo`](https://gohugo.io/) can generate the static web content located in the `rootfs/wwwroot/` offline.

If required, you can also customize the configuration of Nginx in `rootfs/conf/nginx.conf`.
You can set a new webroot (different than `wwwroot`), or a different internal port, or a different index page, etc.

## Learn more

Use the `--help` option for detailed information on using Unikraft Cloud:

```bash
kraft cloud --help
```

Or visit the [CLI Reference](https://unikraft.com/docs/cli/overview).
1 change: 1 addition & 0 deletions nginx-1.27/app-nginx
Submodule app-nginx added at e21185
31 changes: 31 additions & 0 deletions nginx-1.27/rootfs/etc/nginx/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
worker_processes 1;
daemon off;
master_process off;
user root root;

events {
worker_connections 64;
}

http {
include mime.types;
default_type application/octet-stream;

open_file_cache max=10000 inactive=30s;
open_file_cache_min_uses 2;
open_file_cache_errors on;

error_log stderr error;
access_log off;

keepalive_timeout 10s;
keepalive_requests 10000;
send_timeout 10s;

server {
listen 8080;
server_name localhost;
root /wwwroot;
index index.html;
}
}
17 changes: 17 additions & 0 deletions nginx-1.27/rootfs/wwwroot/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
body {
width: 35em;
margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif;
}
</style>
</head>
<body>
<h1>Hello from Unikraft + Nginx!</h1>
<h2>Hello World!</h2>
</body>
</html>
25 changes: 0 additions & 25 deletions nginx/rootfs/wwwroot/index.html

This file was deleted.

Loading