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

package: specfile #15

Merged
merged 13 commits into from
Dec 19, 2024
Merged

package: specfile #15

merged 13 commits into from
Dec 19, 2024

Conversation

schuellerf
Copy link
Contributor

This is a maybe controversial version of #14 which tries to avoid commiting vendor/ but patching source tar ball.
Prerequisite to testing osbuild/release-action#25

supakeen and others added 3 commits December 18, 2024 16:39
As we've now vendored our dependencies let's enable dependabot in the
same way we use it in our other Go projects.

Signed-off-by: Simon de Vlieger <supakeen@redhat.com>
Provide a spec file for `image-builder-cli`. The spec file is based on
`osbuild-composer`'s spec file except it is simplified as (some)
usecases would currently cloud the intent of the specfile. We can add
back RHEL conditionals when/if we start shipping and building for RHEL.

Some tools from `osbuild-composer` are also included; most notably the
one that generates bundled dependencies from vendored modules.

Signed-off-by: Simon de Vlieger <supakeen@redhat.com>
Supports to package `vendor/` directory
which is not part of the repository.
Copy link
Collaborator

@mvo5 mvo5 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! I really like this approach!

@thozza
Copy link
Member

thozza commented Dec 19, 2024

I'm sorry, but as far as I can tell, this won't work for releasing to Fedora, CS, and RHEL.

Once we start using GitHub action to push release tags, GH will generate the tarball for us, and it will miss the vendored packages. This PR solves only RPM builds in CI using Makefile using a full repo checkout, which won't work with downstream repositories. The problem that needs to be solved is that the release tarball attached to GH releases needs to contain all vendored code.

EDIT: OK, with the modified release action, this should work. Looking forward to see this work in action 🤔

@supakeen
Copy link
Member

I'm sorry, but as far as I can tell, this won't work for releasing to Fedora, CS, and RHEL.

Once we start using GitHub action to push release tags, GH will generate the tarball for us, and it will miss the vendored packages. This PR solves only RPM builds in CI using Makefile using a full repo checkout, which won't work with downstream repositories. The problem that needs to be solved is that the release tarball attached to GH releases needs to contain all vendored code.

EDIT: OK, with the modified release action, this should work. Looking forward to see this work in action 🤔

I'm still not fully on-board as I've had to deal with people excluding/including things in release tarballs way too often while packaging stuff. I'm not entirely up to date on the Go macros but do they use the actual release tarballs or do they check out the tag from git?

We'd also need to run make in PackIt right?

I prefer that a certain git checkout is always buildable.

Makefile Outdated

$(RPM_TARBALL):
mkdir -p $(CURDIR)/rpmbuild/SOURCES
git archive --prefix=image-builder-cli-$(COMMIT)/ --format=tar.gz HEAD > $(RPM_TARBALL)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably consider release tags v* so that our release tarballs have a nice filename that consists only of the name and version but no commit ref.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point - I'll align, how this repo will be versioned

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mvo5 @supakeen @thozza should I just manually set the tag v1 for now?

Makefile Outdated

RPM_TARBALL_UNCOMPRESSED=$(RPM_TARBALL:.tar.gz=.tar)

$(RPM_TARBALL):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tarball should ontain SPEC file with proper Provides for bundled code, so the commands executed in the $(RPM_SPECFILE) target should be executed also on the SPEC that ends up in the release tarball.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the hint!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it is a bug in our osbuild-composer tarball. We do not have proper provides for bundled code in CS/RHEL. :-/

Makefile Outdated
#

RPM_SPECFILE=rpmbuild/SPECS/image-builder-cli.spec
RPM_TARBALL=rpmbuild/SOURCES/image-builder-cli-$(COMMIT).tar.gz
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tarball should IMO contain also the release version, not just the commit.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll align with @mvo5 and @supakeen

@schuellerf
Copy link
Contributor Author

schuellerf commented Dec 19, 2024

@supakeen

We'd also need to run make in PackIt right?

Not necessarily, the action will take care, that the release contains the tarball with vendored stuff already.
( see https://github.com/osbuild/release-action/blob/staging/action.yml#L46 )

I prefer that a certain git checkout is always buildable.

It is - go.mod contains the versions anyway and will fetch when building…
So either fetch the source tarball with vendor stuff or just build with go

Makefile Outdated
# pre-fetched but evaluated at time of use.
#

VERSION := $(shell (cd "$(SRCDIR)" && grep "^Version:" image-builder-cli.spec | sed 's/[^[:digit:]]*\([[:digit:]]\+\).*/\1/'))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should take potential "dot" versions into consideration. Such as 12.1, since we use that for backporting. Moreover, this variable does not seem to be used anywhere at all.

@schuellerf
Copy link
Contributor Author

EDIT: OK, with the modified release action, this should work. Looking forward to see this work in action 🤔

me too 😄🎉

@supakeen
Copy link
Member

@supakeen

We'd also need to run make in PackIt right?

Not necessarily, the action will take care, that the release contains the tarball with vendored stuff already. ( see https://github.com/osbuild/release-action/blob/staging/action.yml#L46 )

PackIt builds from commits (and releases) but the vendor directory would not be there in commits?

I prefer that a certain git checkout is always buildable.

It is - go.mod contains the versions anyway and will fetch when building… So either fetch the source tarball with vendor stuff or just build with go

That works well when you have network access in your build environment. While I have that on my own workstation I don't have it everywhere.

@schuellerf
Copy link
Contributor Author

PackIt builds from commits (and releases) but the vendor directory would not be there in commits?

That's the point of this approach, that the release contains the vendor directory.

That works well when you have network access in your build environment. While I have that on my own workstation I don't have it everywhere.

So you'll just download the source tarball with vendored stuff

@supakeen
Copy link
Member

PackIt builds from commits (and releases) but the vendor directory would not be there in commits?

That's the point of this approach, that the release contains the vendor directory.

That works well when you have network access in your build environment. While I have that on my own workstation I don't have it everywhere.

So you'll just download the source tarball with vendored stuff

Which doesn't exist for each commit, only tagged releases?

Packit needs expects the archive path to be printed when specifying a
custom action to build the archive. See [0].

[0] https://packit.dev/docs/configuration/actions#create-archive

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
@thozza
Copy link
Member

thozza commented Dec 19, 2024

PackIt builds from commits (and releases) but the vendor directory would not be there in commits?

That's the point of this approach, that the release contains the vendor directory.

That works well when you have network access in your build environment. While I have that on my own workstation I don't have it everywhere.

So you'll just download the source tarball with vendored stuff

Which doesn't exist for each commit, only tagged releases?

The answer is YES, Packit will need to have a custom action to build the archive with vendored code for PRs.

For now, Packit should trigger COPR buils for PRs and merges to the
`main` branch.

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
schuellerf and others added 2 commits December 19, 2024 10:47
The release artifact should contain the spec file including the
bundle information.
Packit needs golang to be installed when we build SRPM, because we need
to vendor code to generate the archive.

Moreover, we need to vendor code to be able to modify SPEC port upstream
clone to include bundled code.

Signed-off-by: Tomáš Hozza <thozza@redhat.com>

actions:
get-current-version: bash -c "git describe --tags --abbrev=0 | sed 's|v||'"
post-upstream-clone: "./tools/rpm_spec_add_provides_bundle.sh"
post-upstream-clone: bash -c "go mod vendor && ./tools/rpm_spec_add_provides_bundle.sh"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️

@supakeen supakeen mentioned this pull request Dec 19, 2024
@supakeen
Copy link
Member

Let's undraft this one, I've closed #14 as efforts seem to be more focused on this PR and while I have my own opinions it's not really important enough if everyone else doesn't want /vendor.

I'd really like if we have RPMs shipping today :)

FWIW, I never get || and && correctly in Bash for the first time :D

Also handle the case then the repository does not contain any version
tags yet by defaulting to "1".

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
Comment on lines +16 to +20
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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was probably not changed when copied over from osbuild-composer. We should update it.

Comment on lines +35 to +37
BuildRequires: systemd
BuildRequires: krb5-devel
BuildRequires: python3-docutils
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if they are still relevant, because we do not interact with systemd or Koji (krb5) and I'm not sure about docs...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are likely leftovers from the copy :)

# Build requirements of 'github.com/containers/storage' package
BuildRequires: device-mapper-devel
%if 0%{?fedora}
BuildRequires: systemd-rpm-macros
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is, in my opinion, not needed because we do not enable/disable/start/stop/restart any services as part of the RPM installation process.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are likely leftovers from the copy :)

@thozza
Copy link
Member

thozza commented Dec 19, 2024

@schuellerf the sources archive should really be named image-builder-cli-${version_from_spec}.tar.gz. This is what the rpmbuild tooling expects and this is how things work on any of our other repositories.

see https://download.copr.fedorainfracloud.org/results/packit/osbuild-image-builder-cli-15/fedora-41-x86_64/08414991-image-builder-cli/builder-live.log.gz

+ /usr/lib/rpm/rpmuncompress -x /builddir/build/SOURCES/image-builder-cli-65b31cf96d13561bca0b30f455e48874ead1e196.tar.gz
+ STATUS=0
+ '[' 0 -ne 0 ']'
+ cd image-builder-cli-1
/var/tmp/rpm-tmp.vardlL: line 41: cd: image-builder-cli-1: No such file or directory

@schuellerf
Copy link
Contributor Author

@thozza

@schuellerf the sources archive should really be named image-builder-cli-${version_from_spec}.tar.gz. This is what the rpmbuild tooling expects and this is how things work on any of our other repositories.

Sound really reasonable, but why would this work with osbuild-composer then :-/
https://github.com/osbuild/osbuild-composer/blob/main/Makefile#L317

SPEC always uses the next version that will be released.

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
RPM tooling expects the source tarball to match the name of the
package, suffixed with the version in the SPEC file. Modify the Makefile
to comply with this expectation.

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
@schuellerf schuellerf marked this pull request as ready for review December 19, 2024 11:25
@thozza
Copy link
Member

thozza commented Dec 19, 2024

So, 33d65c2 fixed build in COPR (and would make things work in downstream distros), but it broke the make rpm use case. In COPR and build systems, we can't define commit when building (S)RPM. So we need to build the tarball conditionally with $(VERSION) or $(COMMIT) based on the use case.

@thozza
Copy link
Member

thozza commented Dec 19, 2024

@thozza

@schuellerf the sources archive should really be named image-builder-cli-${version_from_spec}.tar.gz. This is what the rpmbuild tooling expects and this is how things work on any of our other repositories.

Sound really reasonable, but why would this work with osbuild-composer then :-/ https://github.com/osbuild/osbuild-composer/blob/main/Makefile#L317

This would work only for CI or local invocations of rpmbuild with the commit variable defined. We can't do that in COPR and downstream build systems.

@ondrejbudai
Copy link
Member

For the record, cockpit does something similar for node_modules, so it's a viable method. :)

See:

@supakeen supakeen added this pull request to the merge queue Dec 19, 2024
Merged via the queue into osbuild:main with commit 1f94684 Dec 19, 2024
19 of 23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants