Skip to content

Commit

Permalink
feat(dockerfile-llb-frontend): Add the initial LLB frontend code.
Browse files Browse the repository at this point in the history
This code results in a working LLB plugin that can then be consumed with
docker to build a unikraft app.

Includes unit tests for the core build part, end-to-end tests suites for
BuildKit and Docker, and a comprehensive readme.

The end to end tests build the app-helloworld.

The BuildKit test suite is skipped by default as the docker one
does the same test of correctness. Its usefulness is mostly for local
debugging.

Add a GitHub Action to build and push the kraftkit.sh/llb image.

GitHub-Fixes: #707
GitHub-Fixes: #708

Signed-off-by: Jakub Ciolek <jakub@ciolek.dev>
  • Loading branch information
jake-ciolek committed Aug 10, 2023
1 parent 8a562d8 commit 0722a65
Show file tree
Hide file tree
Showing 14 changed files with 2,686 additions and 0 deletions.
36 changes: 36 additions & 0 deletions .github/workflows/dockerfile-llb-frontend.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: tools/dockerfile-llb-frontend

on:
push:
branches: [stable]
paths:
- 'tools/dockerfile-llb-frontend/**'
- '.github/workflows/dockerfile-llb-frontend.yaml'

jobs:
plugin-push:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

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

- name: Build OCI image for the LLB plugin
uses: docker/build-push-action@v4
with:
context: ./tools/dockerfile-llb-frontend
file: ./tools/dockerfile-llb-frontend/Dockerfile
tags: index.unikraft.io/kraftkit.sh/llb:latest
push: true
platforms: linux/amd64
cache-from: type=gha
cache-to: type=gha,mode=max
12 changes: 12 additions & 0 deletions tools/dockerfile-llb-frontend/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
*/.vscode*
test/
*_test.go
*.bak
*.swp
*.idea
*.orig
.DS_Store
*.md
.git/
.gitignore
Dockerfile
9 changes: 9 additions & 0 deletions tools/dockerfile-llb-frontend/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM golang:1.20 AS builder

WORKDIR /src
COPY . ./
RUN CGO_ENABLED=0 go build -o /kraft-llb-plugin --ldflags "-s -w"

FROM scratch
COPY --from=builder /kraft-llb-plugin /bin/kraft-llb-plugin
ENTRYPOINT ["/bin/kraft-llb-plugin"]
97 changes: 97 additions & 0 deletions tools/dockerfile-llb-frontend/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
# KraftKit LLB Plugin

This KraftKit LLB Plugin enables running Unikraft builds using Docker commands.

It eliminates the need for installing KraftKit or Unikraft-specific dependencies on your machine by executing builds in containers.

The result is a Unikraft image saved in your local Docker registry.

**Please note:** If you are unfamiliar with Unikraft, KraftKit, or unikernels, kindly refer to the [Unikraft Documentation](https://unikraft.org/docs/getting-started/).

## Prerequisites

- Docker with BuildKit enabled (this is the default setting from Docker v23.0 onwards)
- Go v1.20 or later

## Usage

There are two ways to use the LLB plugin:

### 1. Docker-based Usage

Build the Docker image containing the plugin:

```sh
docker build . -t kraftkit.sh/llb
```

Modify your Kraftfile file by adding the following line at the top:

```yaml
#syntax=kraftkit.sh/llb:latest
```

Now, run the Docker build:

```sh
docker build -f test/apps/app-helloworld/kraft.yaml test/apps/app-helloworld
```

See [Docker docs about dynamic frontends](https://docs.docker.com/build/dockerfile/frontend/) for more information.

### 2. Direct Binary Usage (Debug Mode)

In this mode, you can output the LLB graph for inspection with buildkit.

First, build the project:

```sh
go build .
```

Then, run the built binary from within a Unikraft app directory:

```sh
dockerfile-llb-frontend --llb-stdout=true | buildctl debug dump-llb
```

To learn more about this, see this [BuildKit doc](https://github.com/moby/buildkit/blob/master/examples/README.md).

## Contributing

We warmly welcome contributions in the form of tests, bug reports, and feature requests.

For discussions or queries, join us on Discord: https://bit.ly/UnikraftDiscord

### Testing

The project has unit tests for the core build part (./build/build_test.go) and end-to-end
tests suites in the test/apps directory, one for BuildKit and one for Docker.

The Docker suite calls the docker-backing BuildKit daemon so in a way the BuildKit tests
are redundant, thus we omit them from the CI flow. They come in handy if you want to
run a BuildKit daemon with a debugger.

To run these tests:

Docker:

```sh
go test ./test/docker -v
```

BuildKit (you have to run buildkit daemon):

To spawn a BuildKit daemon, run:

```sh
buildkitd
```

Then run the test suite:

```sh
go test ./test/buildkit -v
```

The -v option gives you the output of the BuildKit or Docker runs.
Loading

0 comments on commit 0722a65

Please sign in to comment.