Skip to content

Commit

Permalink
[wip] main: enable containers-storage
Browse files Browse the repository at this point in the history
Enable the ability to use local containers from containers-storage
rather than pulling containers from a remote registry.
  • Loading branch information
kingsleyzissou committed Jan 15, 2024
1 parent 7b37cde commit 00fe987
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
4 changes: 2 additions & 2 deletions Containerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
FROM registry.fedoraproject.org/fedora:39 AS builder
RUN dnf install -y git-core golang gpgme-devel libassuan-devel && mkdir -p /build/bib
RUN dnf install -y git-core golang gpgme-devel libassuan-devel device-mapper-devel btrfs-progs-devel && mkdir -p /build/bib
COPY bib/go.mod bib/go.sum /build/bib
RUN cd /build/bib && go mod download
COPY build.sh /build
Expand All @@ -14,11 +14,11 @@ FROM registry.fedoraproject.org/fedora:39
# - 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 osbuild-depsolve-dnf && dnf clean all

COPY --from=builder /build/bin/bootc-image-builder /usr/bin/bootc-image-builder
COPY entrypoint.sh /

ENTRYPOINT ["/entrypoint.sh"]
VOLUME /output
VOLUME /store
VOLUME /rpmmd

9 changes: 9 additions & 0 deletions bib/cmd/bootc-image-builder/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ type ManifestConfig struct {

// TLSVerify specifies whether HTTPS and a valid TLS certificate are required
TLSVerify bool

// Use a local container from the host rather than a repository
Local bool
}

func Manifest(c *ManifestConfig) (*manifest.Manifest, error) {
Expand Down Expand Up @@ -84,6 +87,12 @@ func pipelinesForDiskImage(c *ManifestConfig, rng *rand.Rand) (image.ImageKind,
TLSVerify: &c.TLSVerify,
}

if c.Local {
transport := "containers-storage"
containerSource.ContainersTransport = &transport
containerSource.TLSVerify = nil
}

img := image.NewOSTreeDiskImageFromContainer(containerSource, ref)
img.ContainerBuildable = true

Expand Down
15 changes: 11 additions & 4 deletions bib/cmd/bootc-image-builder/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,12 @@ func loadConfig(path string) BuildConfig {
return conf
}

func makeManifest(c *ManifestConfig, cacheRoot string) (manifest.OSBuildManifest, error) {
manifest, err := Manifest(c)
func makeManifest(config *ManifestConfig, cacheRoot string) (manifest.OSBuildManifest, error) {
manifest, err := Manifest(config)
check(err)

// depsolve packages
solver := dnfjson.NewSolver(modulePlatformID, releaseVersion, c.Architecture.String(), distroName, cacheRoot)
solver := dnfjson.NewSolver(modulePlatformID, releaseVersion, config.Architecture.String(), distroName, cacheRoot)
depsolvedSets := make(map[string][]rpmmd.PackageSpec)
for name, pkgSet := range manifest.GetPackageSetChains() {
res, err := solver.Depsolve(pkgSet)
Expand All @@ -119,10 +119,14 @@ func makeManifest(c *ManifestConfig, cacheRoot string) (manifest.OSBuildManifest
}

// resolve container
resolver := container.NewResolver(c.Architecture.String())
resolver := container.NewResolver(config.Architecture.String())
containerSpecs := make(map[string][]container.Spec)
for plName, sourceSpecs := range manifest.GetContainerSourceSpecs() {
for _, c := range sourceSpecs {
// if config.Local {
// transport := "containers-storage"
// c.ContainersTransport = &transport
// }
resolver.Add(c)
}
containerSpecs[plName], err = resolver.Finish()
Expand Down Expand Up @@ -171,6 +175,7 @@ func build(cmd *cobra.Command, args []string) {
configFile, _ := cmd.Flags().GetString("config")
imgType, _ := cmd.Flags().GetString("type")
tlsVerify, _ := cmd.Flags().GetBool("tls-verify")
localContainer, _ := cmd.Flags().GetBool("local")

if err := os.MkdirAll(outputDir, 0777); err != nil {
fail(fmt.Sprintf("failed to create target directory: %s", err.Error()))
Expand Down Expand Up @@ -221,6 +226,7 @@ func build(cmd *cobra.Command, args []string) {
Repos: repos,
Architecture: hostArch,
TLSVerify: tlsVerify,
Local: localContainer,
}
mf, err := makeManifest(manifestConfig, rpmCacheRoot)
check(err)
Expand Down Expand Up @@ -279,6 +285,7 @@ func main() {
buildCmd.Flags().String("aws-region", "", "target region for AWS uploads (only for type=ami)")
buildCmd.Flags().String("aws-bucket", "", "target S3 bucket name for intermediate storage when creating AMI (only for type=ami)")
buildCmd.Flags().String("aws-ami-name", "", "name for the AMI in AWS (only for type=ami)")
buildCmd.Flags().Bool("local", false, "use a local container rather than a container from a registry")

// flag rules
check(buildCmd.MarkFlagDirname("output"))
Expand Down

0 comments on commit 00fe987

Please sign in to comment.