# Do not build with tests by default
# Pass --with tests to rpmbuild to override
%bcond_with tests
%bcond_with relax_requires

# The minimum required osbuild version
%global min_osbuild_version 129

%global goipath         github.com/osbuild/image-builder-cli

Version:        4

%gometa

%global common_description %{expand:
A service for building customized OS artifacts, such as VM images and OSTree
commits, that uses osbuild under the hood. Besides building images for local
usage, it can also upload images directly to cloud.

It is compatible with composer-cli and cockpit-composer clients.
}

Name:           image-builder-cli
Release:        1.20250116045907721124.pr60.19.g5305812%{?dist}
Summary:        An image building service based on osbuild
ExcludeArch:    i686 armv7hl

# Upstream license specification: Apache-2.0
License:        Apache-2.0
URL:            %{gourl}
Source0:        image-builder-cli-4.tar.gz


BuildRequires:  %{?go_compiler:compiler(go-compiler)}%{!?go_compiler:golang}
BuildRequires:  systemd
BuildRequires:  krb5-devel
BuildRequires:  python3-docutils
BuildRequires:  make
# Build requirements of 'theproglottis/gpgme' package
BuildRequires:  gpgme-devel
BuildRequires:  libassuan-devel
# Build requirements of 'github.com/containers/storage' package
BuildRequires:  device-mapper-devel
%if 0%{?fedora}
BuildRequires:  systemd-rpm-macros
BuildRequires:  git
# Build requirements of 'github.com/containers/storage' package
BuildRequires:  btrfs-progs-devel
# DO NOT REMOVE the BUNDLE_START and BUNDLE_END markers as they are used by 'tools/rpm_spec_add_provides_bundle.sh' to generate the Provides: bundled list
# BUNDLE_START
Provides: bundled(golang(dario.cat/mergo)) = 1.0.0
Provides: bundled(golang(github.com/BurntSushi/toml)) = 1.4.0
Provides: bundled(golang(github.com/Microsoft/go-winio)) = 0.6.2
Provides: bundled(golang(github.com/Microsoft/hcsshim)) = 0.12.5
Provides: bundled(golang(github.com/VividCortex/ewma)) = 1.2.0
Provides: bundled(golang(github.com/acarl005/stripansi)) = 5a71ef0
Provides: bundled(golang(github.com/asaskevich/govalidator)) = a9d515a
Provides: bundled(golang(github.com/containerd/cgroups/v3)) = 3.0.3
Provides: bundled(golang(github.com/containerd/errdefs)) = 0.1.0
Provides: bundled(golang(github.com/containerd/stargz-snapshotter/estargz)) = 0.15.1
Provides: bundled(golang(github.com/containers/common)) = 0.60.4
Provides: bundled(golang(github.com/containers/image/v5)) = 5.32.2
Provides: bundled(golang(github.com/containers/libtrust)) = c1716e8
Provides: bundled(golang(github.com/containers/ocicrypt)) = 1.2.0
Provides: bundled(golang(github.com/containers/storage)) = 1.55.0
Provides: bundled(golang(github.com/cyberphone/json-canonicalization)) = ba74d44
Provides: bundled(golang(github.com/cyphar/filepath-securejoin)) = 0.3.1
Provides: bundled(golang(github.com/davecgh/go-spew)) = d8f796a
Provides: bundled(golang(github.com/distribution/reference)) = 0.6.0
Provides: bundled(golang(github.com/docker/distribution)) = 2.8.3+incompatible
Provides: bundled(golang(github.com/docker/docker)) = 27.1.1+incompatible
Provides: bundled(golang(github.com/docker/docker-credential-helpers)) = 0.8.2
Provides: bundled(golang(github.com/docker/go-connections)) = 0.5.0
Provides: bundled(golang(github.com/docker/go-units)) = 0.5.0
Provides: bundled(golang(github.com/felixge/httpsnoop)) = 1.0.4
Provides: bundled(golang(github.com/go-jose/go-jose/v4)) = 4.0.2
Provides: bundled(golang(github.com/go-logr/logr)) = 1.4.2
Provides: bundled(golang(github.com/go-logr/stdr)) = 1.2.2
Provides: bundled(golang(github.com/go-openapi/analysis)) = 0.23.0
Provides: bundled(golang(github.com/go-openapi/errors)) = 0.22.0
Provides: bundled(golang(github.com/go-openapi/jsonpointer)) = 0.21.0
Provides: bundled(golang(github.com/go-openapi/jsonreference)) = 0.21.0
Provides: bundled(golang(github.com/go-openapi/loads)) = 0.22.0
Provides: bundled(golang(github.com/go-openapi/runtime)) = 0.28.0
Provides: bundled(golang(github.com/go-openapi/spec)) = 0.21.0
Provides: bundled(golang(github.com/go-openapi/strfmt)) = 0.23.0
Provides: bundled(golang(github.com/go-openapi/swag)) = 0.23.0
Provides: bundled(golang(github.com/go-openapi/validate)) = 0.24.0
Provides: bundled(golang(github.com/gobwas/glob)) = 0.2.3
Provides: bundled(golang(github.com/gogo/protobuf)) = 1.3.2
Provides: bundled(golang(github.com/golang/groupcache)) = 41bb18b
Provides: bundled(golang(github.com/golang/protobuf)) = 1.5.4
Provides: bundled(golang(github.com/google/go-containerregistry)) = 0.20.0
Provides: bundled(golang(github.com/google/go-intervals)) = 0.0.2
Provides: bundled(golang(github.com/google/uuid)) = 1.6.0
Provides: bundled(golang(github.com/gorilla/mux)) = 1.8.1
Provides: bundled(golang(github.com/hashicorp/errwrap)) = 1.1.0
Provides: bundled(golang(github.com/hashicorp/go-multierror)) = 1.1.1
Provides: bundled(golang(github.com/hashicorp/go-version)) = 1.7.0
Provides: bundled(golang(github.com/inconshreveable/mousetrap)) = 1.1.0
Provides: bundled(golang(github.com/josharian/intern)) = 1.0.0
Provides: bundled(golang(github.com/json-iterator/go)) = 1.1.12
Provides: bundled(golang(github.com/klauspost/compress)) = 1.17.9
Provides: bundled(golang(github.com/klauspost/pgzip)) = 1.2.6
Provides: bundled(golang(github.com/letsencrypt/boulder)) = 89b07f4
Provides: bundled(golang(github.com/mailru/easyjson)) = 0.7.7
Provides: bundled(golang(github.com/mattn/go-runewidth)) = 0.0.16
Provides: bundled(golang(github.com/mattn/go-sqlite3)) = 1.14.22
Provides: bundled(golang(github.com/miekg/pkcs11)) = 1.1.1
Provides: bundled(golang(github.com/mistifyio/go-zfs/v3)) = 3.0.1
Provides: bundled(golang(github.com/mitchellh/mapstructure)) = 1.5.0
Provides: bundled(golang(github.com/moby/docker-image-spec)) = 1.3.1
Provides: bundled(golang(github.com/moby/sys/mountinfo)) = 0.7.2
Provides: bundled(golang(github.com/moby/sys/user)) = 0.2.0
Provides: bundled(golang(github.com/modern-go/concurrent)) = bacd9c7
Provides: bundled(golang(github.com/modern-go/reflect2)) = 1.0.2
Provides: bundled(golang(github.com/oklog/ulid)) = 1.3.1
Provides: bundled(golang(github.com/opencontainers/go-digest)) = 1.0.0
Provides: bundled(golang(github.com/opencontainers/image-spec)) = 1.1.0
Provides: bundled(golang(github.com/opencontainers/runtime-spec)) = 1.2.0
Provides: bundled(golang(github.com/opencontainers/selinux)) = 1.11.0
Provides: bundled(golang(github.com/osbuild/images)) = 0.109.0
Provides: bundled(golang(github.com/ostreedev/ostree-go)) = 719684c
Provides: bundled(golang(github.com/pkg/errors)) = 0.9.1
Provides: bundled(golang(github.com/pmezard/go-difflib)) = 5d4384e
Provides: bundled(golang(github.com/proglottis/gpgme)) = 0.1.3
Provides: bundled(golang(github.com/rivo/uniseg)) = 0.4.7
Provides: bundled(golang(github.com/secure-systems-lab/go-securesystemslib)) = 0.8.0
Provides: bundled(golang(github.com/sigstore/fulcio)) = 1.4.5
Provides: bundled(golang(github.com/sigstore/rekor)) = 1.3.6
Provides: bundled(golang(github.com/sigstore/sigstore)) = 1.8.4
Provides: bundled(golang(github.com/sirupsen/logrus)) = 1.9.3
Provides: bundled(golang(github.com/spf13/cobra)) = 1.8.1
Provides: bundled(golang(github.com/spf13/pflag)) = 1.0.5
Provides: bundled(golang(github.com/stefanberger/go-pkcs11uri)) = 7828495
Provides: bundled(golang(github.com/stretchr/testify)) = 1.10.0
Provides: bundled(golang(github.com/sylabs/sif/v2)) = 2.18.0
Provides: bundled(golang(github.com/syndtr/gocapability)) = 42c35b4
Provides: bundled(golang(github.com/tchap/go-patricia/v2)) = 2.3.1
Provides: bundled(golang(github.com/titanous/rocacheck)) = afe7314
Provides: bundled(golang(github.com/ulikunitz/xz)) = 0.5.12
Provides: bundled(golang(github.com/vbatts/tar-split)) = 0.11.5
Provides: bundled(golang(github.com/vbauerster/mpb/v8)) = 8.7.5
Provides: bundled(golang(go.mongodb.org/mongo-driver)) = 1.14.0
Provides: bundled(golang(go.mozilla.org/pkcs7)) = 33d0574
Provides: bundled(golang(go.opencensus.io)) = 0.24.0
Provides: bundled(golang(go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp)) = 0.54.0
Provides: bundled(golang(go.opentelemetry.io/otel)) = 1.29.0
Provides: bundled(golang(go.opentelemetry.io/otel/metric)) = 1.29.0
Provides: bundled(golang(go.opentelemetry.io/otel/trace)) = 1.29.0
Provides: bundled(golang(golang.org/x/crypto)) = 0.31.0
Provides: bundled(golang(golang.org/x/exp)) = 8a7402a
Provides: bundled(golang(golang.org/x/net)) = 0.33.0
Provides: bundled(golang(golang.org/x/sync)) = 0.10.0
Provides: bundled(golang(golang.org/x/sys)) = 0.29.0
Provides: bundled(golang(golang.org/x/term)) = 0.27.0
Provides: bundled(golang(golang.org/x/text)) = 0.21.0
Provides: bundled(golang(google.golang.org/genproto/googleapis/rpc)) = e6fa225
Provides: bundled(golang(google.golang.org/grpc)) = 1.67.3
Provides: bundled(golang(google.golang.org/protobuf)) = 1.35.2
Provides: bundled(golang(gopkg.in/ini.v1)) = 1.67.0
Provides: bundled(golang(gopkg.in/yaml.v3)) = 3.0.1
# BUNDLE_END
%endif

%description
%{common_description}

%prep
%if 0%{?rhel}
%forgeautosetup -p1
%else
%goprep -k
%endif

%build
export GOFLAGS="-buildmode=pie"
%if 0%{?rhel}
GO_BUILD_PATH=$PWD/_build
install -m 0755 -vd $(dirname $GO_BUILD_PATH/src/%{goipath})
ln -fs $PWD $GO_BUILD_PATH/src/%{goipath}
cd $GO_BUILD_PATH/src/%{goipath}
install -m 0755 -vd _bin
export PATH=$PWD/_bin${PATH:+:$PATH}
export GOPATH=$GO_BUILD_PATH:%{gopath}
export GOFLAGS+=" -mod=vendor"
%endif

%if 0%{?fedora}
# Fedora disables Go modules by default, but we want to use them.
# Undefine the macro which disables it to use the default behavior.
%undefine gomodulesmode
%endif

# btrfs-progs-devel is not available on RHEL
%if 0%{?rhel}
GOTAGS="exclude_graphdriver_btrfs"
%endif

%gobuild ${GOTAGS:+-tags=$GOTAGS} -o %{gobuilddir}/bin/image-builder %{goipath}/cmd/image-builder

%install
install -m 0755 -vd                                 %{buildroot}%{_bindir}
install -m 0755 -vp %{gobuilddir}/bin/image-builder %{buildroot}%{_bindir}/

%check
export GOFLAGS="-buildmode=pie"
%if 0%{?rhel}
export GOFLAGS+=" -mod=vendor -tags=exclude_graphdriver_btrfs"
export GOPATH=$PWD/_build:%{gopath}
# cd inside GOPATH, otherwise go with GO111MODULE=off ignores vendor directory
cd $PWD/_build/src/%{goipath}
%gotest ./...
%else
%gocheck
%endif

%files
%license LICENSE
%doc README.md
%{_bindir}/image-builder

%changelog
# the changelog is distribution-specific, therefore there's just one entry
# to make rpmlint happy.

* Thu Jan 16 2025 Packit <hello@packit.dev> - 4-1.20250116045907721124.pr60.19.g5305812
- build(deps): bump github.com/osbuild/images in the go-deps group (dependabot[bot])
- spellcheck: ignore release_artifacts directory (Florian Schüller)
- ci: expand spellcheck (Simon de Vlieger)
- README: add blueprint example (Michael Vogt)
- main: add ostree integration (Michael Vogt)
- Makefile/packit: avoid duplicate implementation of "version" (Florian Schüller)
- manifestgen: pass missing repoConfig to preManifest.Serialize() (Michael Vogt)
- Makefile: fix packer version by using git tag (Florian Schüller)
- pre-commit: drop golangci-lint for now (Michael Vogt)
- cmd: drop TestListImagesOverrideDatadir (Michael Vogt)
- lint: fix whitespace/spelling in README (Michael Vogt)
- main: help golang-ci to find the "main" symbol in the tests (Michael Vogt)
- pre-commit: bump golangci-lint to v1.63.1 to fix crash when importing slices (Michael Vogt)
- workflow: switch to composite action to fix go/pytest (Michael Vogt)
- workflow: rename .yml -> .yaml (Michael Vogt)
- test: fix integration test (Michael Vogt)
- repos: lookup <buildin>, /{etc,usr/share}/image-builder/repositories (Michael Vogt)
- go.sum: update to latest images lib to get embeded repos (Michael Vogt)
- Post release version bump (schutzbot)

* Wed Sep 11 2019 Image Builder team <osbuilders@redhat.com> - 0-1
- On this day, this project was born.