Skip to content

Commit

Permalink
WIP: Merge osbuildbootc into here, use osbuild/images PR
Browse files Browse the repository at this point in the history
- Take the code from https://github.com/achilleas-k/images/tree/bifrost-image/cmd/osbuild-deploy-container
  and merge it into this repository, using the code from osbuild/images#243
  as a `replace`
- Also merge in osbuildbootc
  • Loading branch information
cgwalters committed Nov 13, 2023
1 parent e228594 commit 7a6bbd5
Show file tree
Hide file tree
Showing 2,386 changed files with 811,556 additions and 1,907 deletions.
4 changes: 2 additions & 2 deletions Containerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
FROM quay.io/fedora/fedora:39 as builder
FROM registry.fedoraproject.org/fedora:39 AS builder
RUN dnf -y install golang make
COPY . /src
RUN cd /src && make && make install DESTDIR=/instroot

FROM quay.io/fedora/fedora:39
COPY --from=builder /instroot /
RUN /usr/lib/osbuildbootc/installdeps.sh
ENTRYPOINT ["osbuildbootc"]
ENTRYPOINT ["osbuildbootc"]
6 changes: 3 additions & 3 deletions Containerfile.orig → Containerfile.odc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
FROM registry.fedoraproject.org/fedora:39 AS builder
RUN dnf install -y git-core golang gpgme-devel libassuan-devel
COPY build.sh .
RUN ./build.sh
RUN dnf -y install golang make
COPY . /src
RUN cd /src && make && make install DESTDIR=/instroot

FROM registry.fedoraproject.org/fedora:39
RUN dnf install -y osbuild osbuild-ostree && dnf clean all
Expand Down
9 changes: 9 additions & 0 deletions Containerfile.osbuildbootc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM quay.io/fedora/fedora:39 as builder
RUN dnf -y install golang make
COPY . /src
RUN cd /src && make && make install DESTDIR=/instroot

FROM quay.io/fedora/fedora:39
COPY --from=builder /instroot /
RUN /usr/lib/osbuildbootc/installdeps.sh
ENTRYPOINT ["osbuildbootc"]
13 changes: 8 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ GONAMESPACE := github.com/cgwalters/osbuildbootc
PREFIX ?= /usr
DESTDIR ?=

.PHONY: all bin/osbuildbootc install clean vendor
all: bin/osbuildbootc
BINARIES := osbuildbootc osbuild-deploy-container

.PHONY: all bin install clean vendor
all: bin

src:=$(shell find src -maxdepth 1 -type f -executable -print)
GOARCH:=$(shell uname -m)
Expand All @@ -13,8 +15,9 @@ else ifeq ($(GOARCH),aarch64)
GOARCH="arm64"
endif

bin/osbuildbootc:
cd cmd && go build -mod vendor -o ../$@
bin:
(cd cmd && go build -mod vendor -o ../bin/osbuildbootc)
(top=$$(pwd); cd cmd/osbuild-deploy-container && go build -mod vendor -o $${top}/bin/osbuild-deploy-container)

check:
(cd cmd && go test -mod=vendor)
Expand All @@ -26,7 +29,7 @@ clean:
install:
install -d $(DESTDIR)$(PREFIX)/lib/osbuildbootc
install -D -t $(DESTDIR)$(PREFIX)/lib/osbuildbootc $$(find src/ -maxdepth 1 -type f)
install -D -t $(DESTDIR)$(PREFIX)/bin bin/osbuildbootc
install -D -t $(DESTDIR)$(PREFIX)/bin $(addprefix bin/,$(BINARIES))

vendor:
@go mod vendor
Expand Down
53 changes: 53 additions & 0 deletions README-osbuildbootc.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@

# osbuildbootc

## Usage

This tool can be invoked as a pre-built container image, and it can also be installed
as a standalone tool inside another environment. The implementation uses qemu+KVM.

Example invocation for the container image:

```bash
podman run --rm -ti --security-opt label=disable --device /dev/kvm -v $(pwd):/srv -w /srv ghcr.io/cgwalters/osbuildbootc:latest build-qcow2 -I quay.io/cgwalters/ostest example.qcow2
```

Explanation of podman arguments:

- `--security-opt label=disable`: This is necessary to bind mount in host paths at all
- `--device /dev/kvm`: Pass the KVM device into the container image
- `-v $(pwd):/srv -w /srv`: Pass the current directory as `/srv` into the container

Note that by default KVM is required. You can set the `OSBUILD_NO_KVM` environment variable
to use full qemu emulation if necessary.

### Take a container image from remote registry, output a qcow2

```bash
osbuildbootc build-qcow2 quay.io/centos-boot/fedora-boot-cloud:eln fedora-boot-cloud.qcow2
```

### Take a container image stored in local OCI directory

In some scenarios it may be desirable to have local disk caches of container images,
instead of fetching from a registry every time.

Note here we need to specify the *target* image after installtion to ensure that
the machine will fetch updates from the registry.

```bash
osbuildbootc build-qcow2 --transport oci oci:cgwalters-ostest -I -t quay.io/cgwalters/ostest foo.qcow2
```

## Development

This project is mostly in Go. However, it also has some shell script because
some nontrivial code was inherited from [coreos-assembler](https://github.com/coreos/coreos-assembler/).

It's recommended to use e.g. [a toolbox](https://github.com/containers/toolbox/) for development:

```bash
make && sudo make install
```

Then you can run `osbuildbootc`.
54 changes: 8 additions & 46 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,52 +1,14 @@
# osbuildbootc
# Tooling for generating disk images from bootc images

## Usage
This project currently merges two tools with unrelated history, called
`osbuild-deploy-container` and `osbuildbootc`.

This tool can be invoked as a pre-built container image, and it can also be installed
as a standalone tool inside another environment. The implementation uses qemu+KVM.
For more on bootc, see [its upstream repository](https://github.com/containers/bootc).

Example invocation for the container image:
## osbuild-deploy-container

```bash
podman run --rm -ti --security-opt label=disable --device /dev/kvm -v $(pwd):/srv -w /srv ghcr.io/cgwalters/osbuildbootc:latest build-qcow2 -I quay.io/cgwalters/ostest example.qcow2
```
See [README.md.osbuild-deploy-container](README.md.osbuild-deploy-container)

Explanation of podman arguments:
## osbuildbootc

- `--security-opt label=disable`: This is necessary to bind mount in host paths at all
- `--device /dev/kvm`: Pass the KVM device into the container image
- `-v $(pwd):/srv -w /srv`: Pass the current directory as `/srv` into the container

Note that by default KVM is required. You can set the `OSBUILD_NO_KVM` environment variable
to use full qemu emulation if necessary.

### Take a container image from remote registry, output a qcow2

```bash
osbuildbootc build-qcow2 quay.io/centos-boot/fedora-boot-cloud:eln fedora-boot-cloud.qcow2
```

### Take a container image stored in local OCI directory

In some scenarios it may be desirable to have local disk caches of container images,
instead of fetching from a registry every time.

Note here we need to specify the *target* image after installtion to ensure that
the machine will fetch updates from the registry.

```bash
osbuildbootc build-qcow2 --transport oci oci:cgwalters-ostest -I -t quay.io/cgwalters/ostest foo.qcow2
```

## Development

This project is mostly in Go. However, it also has some shell script because
some nontrivial code was inherited from [coreos-assembler](https://github.com/coreos/coreos-assembler/).

It's recommended to use e.g. [a toolbox](https://github.com/containers/toolbox/) for development:

```bash
make && sudo make install
```

Then you can run `osbuildbootc`.
See [README.md.osbuildbootc](README.md.osbuildbootc)
File renamed without changes.
1 change: 0 additions & 1 deletion build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,5 @@
set -euo pipefail


git clone --branch bifrost-image --depth 1 https://github.com/achilleas-k/images.git
cd images
go build ./cmd/osbuild-deploy-container
58 changes: 58 additions & 0 deletions cmd/osbuild-deploy-container/fedora-eln.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{
"aarch64": [
{
"baseurl": "https://odcs.fedoraproject.org/composes/production/latest-Fedora-ELN/compose/BaseOS/aarch64/os/",
"name": "baseos"
},
{
"baseurl": "https://odcs.fedoraproject.org/composes/production/latest-Fedora-ELN/compose/AppStream/aarch64/os/",
"name": "appstream"
},
{
"baseurl": "https://odcs.fedoraproject.org/composes/production/latest-Fedora-ELN/compose/CRB/aarch64/os/",
"name": "crb"
}
],
"ppc64le": [
{
"baseurl": "https://odcs.fedoraproject.org/composes/production/latest-Fedora-ELN/compose/BaseOS/ppc64le/os/",
"name": "baseos"
},
{
"baseurl": "https://odcs.fedoraproject.org/composes/production/latest-Fedora-ELN/compose/AppStream/ppc64le/os/",
"name": "appstream"
},
{
"baseurl": "https://odcs.fedoraproject.org/composes/production/latest-Fedora-ELN/compose/CRB/ppc64le/os/",
"name": "crb"
}
],
"s390x": [
{
"baseurl": "https://odcs.fedoraproject.org/composes/production/latest-Fedora-ELN/compose/BaseOS/s390x/os/",
"name": "baseos"
},
{
"baseurl": "https://odcs.fedoraproject.org/composes/production/latest-Fedora-ELN/compose/AppStream/s390x/os/",
"name": "appstream"
},
{
"baseurl": "https://odcs.fedoraproject.org/composes/production/latest-Fedora-ELN/compose/CRB/s390x/os/",
"name": "crb"
}
],
"x86_64": [
{
"baseurl": "https://odcs.fedoraproject.org/composes/production/latest-Fedora-ELN/compose/BaseOS/x86_64/os/",
"name": "baseos"
},
{
"baseurl": "https://odcs.fedoraproject.org/composes/production/latest-Fedora-ELN/compose/AppStream/x86_64/os/",
"name": "appstream"
},
{
"baseurl": "https://odcs.fedoraproject.org/composes/production/latest-Fedora-ELN/compose/CRB/x86_64/os/",
"name": "crb"
}
]
}
113 changes: 113 additions & 0 deletions cmd/osbuild-deploy-container/image.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
package main

import (
"fmt"
"math/rand"

"github.com/osbuild/images/internal/common"
"github.com/osbuild/images/internal/users"
"github.com/osbuild/images/internal/workload"
"github.com/osbuild/images/pkg/blueprint"
"github.com/osbuild/images/pkg/container"
"github.com/osbuild/images/pkg/disk"
"github.com/osbuild/images/pkg/image"
"github.com/osbuild/images/pkg/manifest"
"github.com/osbuild/images/pkg/ostree"
"github.com/osbuild/images/pkg/platform"
"github.com/osbuild/images/pkg/rpmmd"
"github.com/osbuild/images/pkg/runner"
)

func Manifest(imageref string, config *BuildConfig, repos []rpmmd.RepoConfig, arch string, seed int64) (*manifest.Manifest, error) {

source := rand.NewSource(seed)

// math/rand is good enough in this case
/* #nosec G404 */
rng := rand.New(source)

baseImage := &ostree.ImageOptions{
Container: imageref,
TLSVerify: common.ToPtr(true),
}

img, err := pipelines(baseImage, config, arch, rng)
if err != nil {
fail(err.Error())
}
mf := manifest.New()
mf.Distro = manifest.DISTRO_FEDORA
runner := &runner.Fedora{Version: 39}
_, err = img.InstantiateManifest(&mf, repos, runner, rng)

return &mf, err
}

func pipelines(baseImage *ostree.ImageOptions, config *BuildConfig, arch string, rng *rand.Rand) (image.ImageKind, error) {
if baseImage == nil {
fail("pipeline: no base image defined")
}
ref := "ostree/1/1/0"
containerSource := container.SourceSpec{
Source: baseImage.Container,
Name: baseImage.Container,
TLSVerify: baseImage.TLSVerify,
}

img := image.NewOSTreeContainerDiskImage(containerSource, ref)

var customizations *blueprint.Customizations
if config != nil && config.Blueprint != nil {
customizations = config.Blueprint.Customizations
}
img.Users = users.UsersFromBP(customizations.GetUsers())
img.Groups = users.GroupsFromBP(customizations.GetGroups())

img.KernelOptionsAppend = []string{
"rw",
"console=tty0",
"console=ttyS0",
}

img.SysrootReadOnly = true

switch arch {
case platform.ARCH_X86_64.String():
img.Platform = &platform.X86{
BasePlatform: platform.BasePlatform{
ImageFormat: platform.FORMAT_QCOW2,
},
BIOS: true,
UEFIVendor: "fedora",
}
case platform.ARCH_AARCH64.String():
img.Platform = &platform.Aarch64{
UEFIVendor: "fedora",
BasePlatform: platform.BasePlatform{
ImageFormat: platform.FORMAT_QCOW2,
QCOW2Compat: "1.1",
},
}
}

img.OSName = "default"

if kopts := customizations.GetKernel(); kopts != nil && kopts.Append != "" {
img.KernelOptionsAppend = append(img.KernelOptionsAppend, kopts.Append)
}

img.Workload = &workload.Custom{}

basept, ok := partitionTables[arch]
if !ok {
fail(fmt.Sprintf("pipelines: no partition tables defined for %s", arch))
}
size := uint64(10 * common.GibiByte)
pt, err := disk.NewPartitionTable(&basept, nil, size, disk.RawPartitioningMode, nil, rng)
check(err)
img.PartitionTable = pt

img.Filename = "disk.qcow2"

return img, nil
}
Loading

0 comments on commit 7a6bbd5

Please sign in to comment.