Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add source for osbuild-deploy-container command #11

Merged
merged 15 commits into from
Nov 28, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/.idea
/output
/bin
10 changes: 6 additions & 4 deletions Containerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
FROM registry.fedoraproject.org/fedora:39 AS builder
RUN dnf install -y git-core golang gpgme-devel libassuan-devel
COPY build.sh .
RUN mkdir /build
COPY build.sh /build
COPY odc /build/odc
WORKDIR /build
RUN ./build.sh

FROM registry.fedoraproject.org/fedora:39
Expand All @@ -9,10 +12,9 @@ FROM registry.fedoraproject.org/fedora:39
# - https://github.com/osbuild/osbuild-deploy-container/issues/9
# - https://github.com/osbuild/osbuild/pull/1468
COPY ./group_osbuild-osbuild-fedora-39.repo /etc/yum.repos.d/
RUN dnf install -y osbuild osbuild-ostree && dnf clean all
COPY --from=builder images/osbuild-deploy-container /usr/bin/osbuild-deploy-container
RUN dnf install -y osbuild osbuild-ostree osbuild-depsolve-dnf && dnf clean all
COPY --from=builder /build/bin/osbuild-deploy-container /usr/bin/osbuild-deploy-container
COPY prepare.sh entrypoint.sh /
COPY --from=builder images/dnf-json .

ENTRYPOINT ["/entrypoint.sh"]
VOLUME /output
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ A simpler container for deploying bootable container images.

```
mkdir output
sudo podman run --rm -it --privileged --security-opt label=type:unconfined_t -v $(pwd)/output:/output ghcr.io/osbuild/osbuild-deploy-container -imageref quay.io/centos-boot/fedora-tier-1:eln
sudo podman run --rm -it --privileged --security-opt label=type:unconfined_t -v $(pwd)/output:/output ghcr.io/osbuild/osbuild-deploy-container quay.io/centos-boot/fedora-tier-1:eln

qemu-system-x86_64 -M accel=kvm -cpu host -smp 2 -m 4096 -bios /usr/share/OVMF/OVMF_CODE.fd -snapshot output/qcow2/disk.qcow2
```
Expand Down Expand Up @@ -40,5 +40,5 @@ Example of such a config:
Save this config as `output/config.json` and run:

```
sudo podman run --rm -it --privileged --security-opt label=type:unconfined_t -v $(pwd)/output:/output ghcr.io/osbuild/osbuild-deploy-container -imageref quay.io/centos-boot/fedora-tier-1:eln -config /output/config.json
sudo podman run --rm -it --privileged --security-opt label=type:unconfined_t -v $(pwd)/output:/output ghcr.io/osbuild/osbuild-deploy-container quay.io/centos-boot/fedora-tier-1:eln --config /output/config.json
```
6 changes: 2 additions & 4 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,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
cd odc
go build -o ../bin/osbuild-deploy-container ./cmd/osbuild-deploy-container
2 changes: 1 addition & 1 deletion entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
set -euo pipefail

./prepare.sh
/usr/bin/osbuild-deploy-container -store /store -rpmmd /rpmmd -output /output "$@"
/usr/bin/osbuild-deploy-container --store /store --rpmmd /rpmmd --output /output "$@"
58 changes: 58 additions & 0 deletions odc/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"
}
]
}
104 changes: 104 additions & 0 deletions odc/cmd/osbuild-deploy-container/image.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
package main

import (
"fmt"
"math/rand"

"github.com/osbuild/images/pkg/arch"
"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/platform"
"github.com/osbuild/images/pkg/rpmmd"
"github.com/osbuild/images/pkg/runner"
)

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

source := rand.NewSource(seed)

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

img, err := pipelines(imgref, config, architecture, 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(imgref string, config *BuildConfig, architecture arch.Arch, rng *rand.Rand) (image.ImageKind, error) {
if imgref == "" {
fail("pipeline: no base image defined")
}
ref := "ostree/1/1/0"
tlsVerify := true
containerSource := container.SourceSpec{
Source: imgref,
Name: imgref,
TLSVerify: &tlsVerify,
}

img := image.NewOSTreeDiskImageFromContainer(containerSource, ref)

var customizations *blueprint.Customizations
if config != nil && config.Blueprint != nil {
customizations = config.Blueprint.Customizations
}

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

img.SysrootReadOnly = true

switch architecture {
case arch.ARCH_X86_64:
img.Platform = &platform.X86{
BasePlatform: platform.BasePlatform{
ImageFormat: platform.FORMAT_QCOW2,
},
BIOS: true,
UEFIVendor: "fedora",
}
case arch.ARCH_AARCH64:
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 = &NullWorkload{}

basept, ok := partitionTables[architecture.String()]
if !ok {
fail(fmt.Sprintf("pipelines: no partition tables defined for %s", architecture))
}
size := uint64(10 * 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
Loading