Skip to content
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
4 changes: 2 additions & 2 deletions .github/workflows/pytest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
- name: Install lint dependencies
run: sudo apt install -y yamllint aspell pre-commit
- name: Install project dependencies
run: sudo apt install -y libgpgme-dev libbtrfs-dev
run: sudo apt install -y libgpgme-dev libbtrfs-dev libvirt-dev
- name: "Clone Repository"
uses: actions/checkout@v5
- name: Set up Python
Expand All @@ -33,7 +33,7 @@ jobs:
- name: Install integration test env
run: |
sudo apt update
sudo apt install -y python3-pytest golang
sudo apt install -y python3-pytest golang libvirt-dev
- name: Install cross build dependencies
run: sudo apt install -y qemu-user-static

Expand Down
3 changes: 3 additions & 0 deletions cmd/image-builder/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,9 @@ operating systems like Fedora, CentOS and RHEL with easy customizations support.
uploadCmd.Flags().String("aws-ami-name", "", "name for the AMI in AWS (only for type=ami)")
uploadCmd.Flags().String("aws-bucket", "", "target S3 bucket name for intermediate storage when creating AMI (only for type=ami)")
uploadCmd.Flags().String("aws-region", "", "target region for AWS uploads (only for type=ami)")
uploadCmd.Flags().String("libvirt-connection", "", "connection URI (only for type=libvirt)")
uploadCmd.Flags().String("libvirt-pool", "", "pool name (only for type=libvirt)")
uploadCmd.Flags().String("libvirt-volume", "", "volume name (only for type=libvirt)")
uploadCmd.Flags().String("arch", "", "upload for the given architecture")
rootCmd.AddCommand(uploadCmd)

Expand Down
23 changes: 22 additions & 1 deletion cmd/image-builder/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/osbuild/images/pkg/arch"
"github.com/osbuild/images/pkg/cloud"
"github.com/osbuild/images/pkg/cloud/awscloud"
"github.com/osbuild/images/pkg/cloud/libvirt"
"github.com/osbuild/images/pkg/platform"
)

Expand All @@ -29,6 +30,7 @@ var ErrUploadConfigNotProvided = errors.New("missing all upload configuration")
var ErrUploadTypeUnsupported = errors.New("unsupported type")

var awscloudNewUploader = awscloud.NewUploader
var libvirtNewUploader = libvirt.NewUploader

func uploadImageWithProgress(uploader cloud.Uploader, imagePath string) error {
f, err := os.Open(imagePath)
Expand All @@ -42,14 +44,15 @@ func uploadImageWithProgress(uploader cloud.Uploader, imagePath string) error {
if err != nil {
return fmt.Errorf("cannot stat upload: %v", err)
}
size := uint64(st.Size())
pbar := pb.New64(st.Size())
pbar.Set(pb.Bytes, true)
pbar.SetWriter(osStdout)
r := pbar.NewProxyReader(f)
pbar.Start()
defer pbar.Finish()

return uploader.UploadAndRegister(r, 0, osStderr)
return uploader.UploadAndRegister(r, size, osStderr)
}

func uploaderCheckWithProgress(pbar progress.ProgressBar, uploader cloud.Uploader) error {
Expand All @@ -69,6 +72,8 @@ func uploaderFor(cmd *cobra.Command, typeOrCloud string, targetArch string, boot
switch typeOrCloud {
case "ami", "server-ami", "aws":
return uploaderForCmdAWS(cmd, targetArch, bootMode)
case "libvirt":
return uploaderForLibvirt(cmd, targetArch, bootMode)
default:
return nil, fmt.Errorf("%w: %q", ErrUploadTypeUnsupported, typeOrCloud)
}
Expand Down Expand Up @@ -129,6 +134,22 @@ func uploaderForCmdAWS(cmd *cobra.Command, targetArchStr string, bootMode *platf
return awscloudNewUploader(region, bucketName, amiName, opts)
}

func uploaderForLibvirt(cmd *cobra.Command, targetArchStr string, bootMode *platform.BootMode) (cloud.Uploader, error) {
connection, err := cmd.Flags().GetString("libvirt-connection")
if err != nil {
return nil, err
}
pool, err := cmd.Flags().GetString("libvirt-pool")
if err != nil {
return nil, err
}
volume, err := cmd.Flags().GetString("libvirt-volume")
if err != nil {
return nil, err
}
return libvirtNewUploader(connection, pool, volume)
}

func detectArchFromImagePath(imagePath string) string {
// This detection is currently rather naive, we just look for
// the file name and try to infer from that. We could extend
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -138,4 +138,5 @@ require (
google.golang.org/grpc v1.74.2 // indirect
google.golang.org/protobuf v1.36.7 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
libvirt.org/go/libvirt v1.11006.0 // indirect
)
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -499,5 +499,7 @@ gotest.tools/v3 v3.5.2 h1:7koQfIKdy+I8UTetycgUqXWSDwpgv193Ka+qRsmBY8Q=
gotest.tools/v3 v3.5.2/go.mod h1:LtdLGcnqToBH83WByAAi/wiwSFCArdFIUV/xxN4pcjA=
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
libvirt.org/go/libvirt v1.11006.0 h1:xzF87ptj/7cp1h4T62w1ZMBVY8m0mQukSCstMgeiVLs=
libvirt.org/go/libvirt v1.11006.0/go.mod h1:1WiFE8EjZfq+FCVog+rvr1yatKbKZ9FaFMZgEqxEJqQ=
sigs.k8s.io/yaml v1.5.0 h1:M10b2U7aEUY6hRtU870n2VTPgR5RZiL/I6Lcc2F4NUQ=
sigs.k8s.io/yaml v1.5.0/go.mod h1:wZs27Rbxoai4C0f8/9urLZtZtF3avA3gKvGyPdDqTO4=
2 changes: 2 additions & 0 deletions image-builder.spec
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ BuildRequires: libassuan-devel
# Build requirements of 'github.com/containers/storage' package
BuildRequires: device-mapper-devel
BuildRequires: libxcrypt-devel
# Build requiremets of 'github.com/osbuild/images' package
BuildRequires: libvirt-devel
%if 0%{?fedora}
# Build requirements of 'github.com/containers/storage' package
BuildRequires: btrfs-progs-devel
Expand Down
Loading