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

Feature: support variable naming in pkg_deb #53

Closed
zegl opened this issue Feb 20, 2019 · 20 comments
Closed

Feature: support variable naming in pkg_deb #53

zegl opened this issue Feb 20, 2019 · 20 comments

Comments

@zegl
Copy link

zegl commented Feb 20, 2019

Description of the problem / feature request:

pkg_deb takes a version parameter for setting the version of the version of the generated deb-package.

It would be appreciated if this parameter would support "stamping", so that an external script (--workspace_status_command) can dynamically generate this version.

Similar to how the container_push rule supports stamping in it's tag parameter.

Feature requests: what underlying problem are you trying to solve with this feature?

Simplify creation of pkg_debs, if this was supported I wouldn't need to save the version to a file and use the version_file parameter.

What's the output of bazel info release?

release 0.22.0
@aiuto
Copy link
Collaborator

aiuto commented Feb 21, 2019

Whatever mechism designed must work for pkg_rpm() as well.
What we do internally at Google is allow $var substitutions in the version strings and then provide those variables in the builds that make distributable versions.

Doing this well probabl requires some design. Open questions:

  • should we jus allow variable substitution from the environment?
  • should it only be from workspace_status_command?
  • What do people even want as paramaterizable version numbers? Is a date/time based substitution sufficient if you want it automatic? If not, why is it better to parametirize it than to update the BUILD file?

@aiuto aiuto transferred this issue from bazelbuild/bazel Jul 11, 2019
@ashi009
Copy link

ashi009 commented Oct 9, 2019

I think there are already some mechanisms to stamp the packages yielded, say using a dynamically generated version_file which consumes workspace_status. However, doing so means we have to write such genrule everywhere. It would be nice to have it integrated in the pkg rules directly.

Whatever mechism designed must work for pkg_rpm() as well.
What we do internally at Google is allow $var substitutions in the version strings and then provide those variables in the builds that make distributable versions.

Doing this well probabl requires some design. Open questions:

  • should we jus allow variable substitution from the environment?

Personally, I don't like it. Setting environment variables is not as obvious as a flag passed to bazel.

  • should it only be from workspace_status_command?

Keep it consistent with other rules using variables from workspace_status_command would be great.

  • What do people even want as paramaterizable version numbers? Is a date/time based substitution sufficient if you want it automatic? If not, why is it better to parametirize it than to update the BUILD file?

Updating BUILD file on every release sounds like toil. Also introducing changes to codebase during the release is problematic -- consider the case where a cherry-pick is needed for an old release branch, such change on the BUILD file may prevent the cherry-picked patch from being applied.

@aiuto
Copy link
Collaborator

aiuto commented May 19, 2020

What I could see is a shared attribute env_vars:string_list.

If you set that on any rule you get the dependency on stable_status and enable the lookup, but only for those variable listed. That nicely documents that the rule depends on something outside the BUILD file (perhaps a default can be specified there). I could also see this variable expansion extend into the template and spec files.

This needs a better design with some examples before implementing it. Any implementation should also cover all the rules, not just one package type.

@aiuto aiuto added help wanted P3 An issue that we are not working on but will review quarterly labels May 19, 2020
@prashantv
Copy link

Indirectly related to this, when a debian package is created, it's currently named with the version,

out_deb = "%s_%s_%s.deb" % (package, version, architecture)

There are tools that assume that the file is named in this way, e.g., in dak:
https://github.com/Debian/dak/blob/master/daklib/regexes.py#L126-L128
https://github.com/Debian/dak/blob/master/dak/import.py#L116-L124

If the version isn't known till build time, then it can't be used as part of the output file. Ideally, there would be a way to output a tar file with the files named correctly based on version as well.

@aiuto
Copy link
Collaborator

aiuto commented Jul 24, 2020

More flexibility in output file naming is part of #193, #143, and #101. The solution to that proposed in #198 will also handle this stamp case.

@terinjokes
Copy link

#198 was merged, but it's not possible to use the functionality with pkg_deb

@aiuto
Copy link
Collaborator

aiuto commented Dec 8, 2020 via email

@terinjokes
Copy link

terinjokes commented Dec 8, 2020

I ended up calling out to dpkg-name as part of my releases pipeline, so I was running into the normal issues with the version not being available at analysis time.

@aiuto
Copy link
Collaborator

aiuto commented Dec 8, 2020 via email

@jheaff1
Copy link

jheaff1 commented Jan 2, 2021

I too am interested in this functionality, specifically being able to produce a tar file that contains version info provided by the workspace status. Eg: my-tarball-1.2.3.tar.gz

@aiuto aiuto changed the title Feature: support stamp in pkg_deb Feature: support variable naming in pkg_deb May 4, 2021
@aiuto
Copy link
Collaborator

aiuto commented May 4, 2021

I'm going to declare this fixed. It was not about "stamping" as the other bazel rules use it (time stamping of the artifacts). This was about injecting variable names into the output artifact name.
The examples in https://github.com/bazelbuild/rules_pkg/tree/main/examples/naming_package_files
show how you can inject a variable from the command line into the names.

The original request was to extract variables form the workspace status output. I'm not going to build that because it is impossible to do it well. You have to parse the file during the execution phase, while the techniques we already have let you get the variable values at analysis time. Having it at analysis time lets us pass the information up in providers so other rules can act on the output sensibly.

Part of this discussion talked about time stamping, which is a different need. #288 adds an implmentation of --stamp and the stamp attribute for pkg_tar. As soon as that is in I can add it for the others.

@aiuto aiuto removed P3 An issue that we are not working on but will review quarterly help wanted labels May 4, 2021
@aiuto aiuto closed this as completed May 4, 2021
@alokpr
Copy link

alokpr commented Jul 13, 2021

If package version is available in workspace-status files, using pkg_deb is still too cumbersome unless I am missing something. I need to provide the same version string via two mechanisms:

  1. version_file
  2. package_file_name + PackageVariablesInfo

If it is possible for pkg_deb to get the version number from version_file when constructing the package_file_name, it would make the most common use-case very convenient.

@aiuto
Copy link
Collaborator

aiuto commented Jul 13, 2021

It is not possible to get elements of the file name from the version_file. That would require reading the file at analysis time. The way we will have to work this is to generate the version_file from PackageVariablesInfo, or from attributes in the rule instance.

@alokpr
Copy link

alokpr commented Jul 13, 2021

Thanks for the quick response!

Would it be possible to provide an example for how to use pkg_deb if version is available in workspace-status files? Most (if not all) use-cases do not need fully custom file names. We just need a properly named output file.

@aiuto
Copy link
Collaborator

aiuto commented Jul 13, 2021 via email

@alokpr
Copy link

alokpr commented Jul 13, 2021

I think it is pretty common to use --workspace_status_command to generate version number based on git tags:

bazel build --workspace_status_command="echo STABLE_PKG_VERSION $(git describe)"

Generating a version file is trivial using a genrule. I guess you are suggesting a custom rule instead of the genrule that would do both - provide PackageVariablesInfo and generate version file?

@aiuto
Copy link
Collaborator

aiuto commented Jul 13, 2021

workspace_status is probably the worst way to pass build time variables like the package name. Put them on the command line as string flags. That makes them available during analysis instead of execution time.

@alokpr
Copy link

alokpr commented Jul 13, 2021

The nice thing about workspace_status is that it can be added to workspace bazelrc which works for both - developers and CI - without any additional setup. I am not sure if CLI flags can be made to work without a wrapper script around bazel.

If it is not possible to produce a properly-named deb file, I guess another option is to rename the file before uploading to the apt repository. I will look into adding this step to the upload script.

@aiuto
Copy link
Collaborator

aiuto commented Jul 13, 2021 via email

@alokpr
Copy link

alokpr commented Jul 13, 2021

Understood - thanks for the pointers!

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

No branches or pull requests

7 participants