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

Synthesize .npmrc from Makefile; Fix bsdtar on older Debian/Ubuntu/macOS #15256

Closed

Conversation

CL-Jeremy
Copy link
Contributor

@CL-Jeremy CL-Jeremy commented Apr 2, 2021

Summary on bsdtar:

  • Arch/Fedora and derivatives use latest bsdtar (3.3.x+) and, when SELinux is enabled (by default on Fedora), requires --no-xattrs or a --format flag with similar effect
  • Debian and derivatives use an older bsdtar (3.1.x/3.2.x) until recently (Debian 10/Ubuntu 20.04), which does not support --no-xattrs, but supports --format=gnutar which is largely the same:
    • GNU Tar is based on a draft version of PAX, which is what is used by bsdtar/libarchive by default, but uses a different style for storing extended attributes (disabled by default for compatibility)
    • using the gnutar writer of libarchive will ignore them
    • GNU Tar reads both GNU and PAX formats (sans extended attributes for the latter) just fine, so there are no compatibility issues
  • macOS < 10.15 uses an ancient bsdtar from 2010 (2.8.3) which by default doesn't store extended attributes at all (unless --format=pax is passed), so no flag is needed at all
    • macOS 10.15+, on the other hand, uses bsdtar 3.3.x+, which is functionally equivalent to Linux distros shipping this version and thus handled as case 1

Note that bsdtar is achieving better compression (among other benefits) even with --format=gnutar enabled
Bildschirmfoto von 2021-04-02 22-37-20

Summary on changes to Makefile:

  • .npmrc is now synthesized right before initial npm install (but will be included in the tarball), so edits of npm configs should now take place in Makefile (these files are added to .gitignore)
    • this is a better solution, by far, than a pre-commit hook (aborting commit and displaying a warning message if .npm-cache is present), or git update-index --skip-worktree (decoupling the file from working tree if it has uncommitted changes, breaking all kinds of stuff)
  • printf is leveraged instead of tr to avoid expansion partially, reducing console output

Fix: #15251

Edit: Refer to comment for details on the merged fix: CL-Jeremy#7 (comment)

Edit 2: Reference regarding TAR/libarchive features and effectiveness of --format=gnutar option: libarchive/libarchive#242 http://cdrtools.sourceforge.net/private/portability-of-tar-features.html

@silverwind
Copy link
Member

Some related concerns:

  • Will this break with npm 7?
  • Do we really need bsdtar? Standard tar is ubiquotous and stable.

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Apr 2, 2021
@lunny lunny added the topic/build PR changes how Gitea is built, i.e. regarding Docker or the Makefile label Apr 3, 2021
@CL-Jeremy
Copy link
Contributor Author

* Will this break with npm 7?

Yes, but it was already broken. A fix has been pushed after quite some testing. Should at least be an improvement to this PR (if not the best solution to the issues).

* Do we really need `bsdtar`? Standard `tar` is ubiquotous and stable.

No, not really. It was more for formal consistency across platforms. GNU Tar is indeed more conservative with options hidden behind flags. The summary in OP may look scary and seemingly prone to breakages, but the solution is rather uncomplicated. As for using bsdtar in CI, it's partly because I have no access to the actual CI recipes for me to actually test things privately. AFAICT the only way to test this fix is still to merge it and see what happens, making the test period longer than needed. I'm fine with excluding bsdtar in CI (while leaving it when it's installed) if you insist. I just don't think of it as an issue either way.

This was referenced Apr 3, 2021
@CL-Jeremy
Copy link
Contributor Author

Sorry for not posting this in #14578 as I was informed that commenting on closed PR is bad practice. I did refer to the first patch in OP and thought that would be enough.

Comment on lines +17 to +20
TAR := $(shell hash bsdtar > /dev/null 2>&1 && echo "bsdtar" || echo "tar" )
ifneq ($(shell $(TAR) --version | grep "bsdtar 3"),)
TAR += --format=gnutar
endif
Copy link
Contributor

Choose a reason for hiding this comment

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

I vote we do not have any more bsdtar stuff here. By all means allow bsdtar users to set an environment variable to use it like this:

Suggested change
TAR := $(shell hash bsdtar > /dev/null 2>&1 && echo "bsdtar" || echo "tar" )
ifneq ($(shell $(TAR) --version | grep "bsdtar 3"),)
TAR += --format=gnutar
endif
TAR ?= tar

So that if you run: TAR="bsdtar --no-xattrs --format=gnutar" make ... you use it.

I'd even state that this:

$(eval EXCL := --exclude=$(shell [ ! "$(TAR)" = "tar" ] && echo "^" )./)

needs to go too but I'm not averse to hacks like detecting if the provided tar is bsdtar e.g.

$(eval EXCL := --exclude=$(shell [ "$(TAR)" = bsdtar* ] && echo "^" )./)

Why are we even still going through this - what are the real benefits to using bsdtar? if you're going to use the --format=gnutar does it even have any improvement anymore?

Copy link
Contributor Author

@CL-Jeremy CL-Jeremy Apr 3, 2021

Choose a reason for hiding this comment

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

It started because macOS doesn't ship GNU Tar and aliases bsdtar as tar, so the original script led to wrong files being included (which your new fix doesn't handle). The last PR was very close to a good solution already. I'm not against removing it from .drone.yml anyway.

bsdtar/libarchive still comes with all the benefits with file handling and compression and the like when using a different output stream writer, and as stated the (good) compatibility of these archives are documented clearly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Cf. relevant change suggested to #15273 for fixing Mac issue singularly.

rm -rf .npm-cache
$(eval ESBUILD_VERSION := $(shell node -p "require('./package-lock.json').dependencies.esbuild.version"))
npm config --userconfig=.npmrc set cache=.npm-cache
$(eval ESBUILD_PLATFORMS := darwin-64 $(foreach arch,arm arm64 32 64,linux-${arch}) $(foreach arch,32 64,windows-${arch}))
Copy link
Contributor

Choose a reason for hiding this comment

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

Seriously just use the foreach again here to append the ESBUILD_VERSION

Suggested change
$(eval ESBUILD_PLATFORMS := darwin-64 $(foreach arch,arm arm64 32 64,linux-${arch}) $(foreach arch,32 64,windows-${arch}))
$(eval ESBUILD_PLATFORMS := darwin-64 $(foreach arch,arm arm64 32 64,linux-${arch}) $(foreach arch,32 64,windows-${arch}))
$(eval ESBUILD_BUILDS := $(foreach platform, $(ESBUILD_PLATFORMS), esbuild-@$(ESBUILD_VERSION)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As stated in OP, that'll mean these stuff gets output to the console. I'm not a fan of overly long lines either in source or log. Using xargs wouldn't have an impact on performance AFAICT.

npm config --userconfig=$(FOMANTIC_WORK_DIR)/.npmrc set cache=../../.npm-cache
echo $(foreach build, darwin-64 $(foreach arch,arm arm64 32 64,linux-${arch}) $(foreach arch,32 64,windows-${arch}), esbuild-${build}@$(ESBUILD_VERSION)) | tr " " "\n" | xargs -n 1 -P 4 npm cache add
rm -rf $(FOMANTIC_WORK_DIR)/node_modules
echo $(ESBUILD_PLATFORMS) | xargs printf "esbuild-%s@$(ESBUILD_VERSION)\n" | xargs -n 1 -P 4 npm cache add
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
echo $(ESBUILD_PLATFORMS) | xargs printf "esbuild-%s@$(ESBUILD_VERSION)\n" | xargs -n 1 -P 4 npm cache add
echo $(ESBUILD_BUILDS) | xargs -n 1 -P 4 npm cache add

@CL-Jeremy
Copy link
Contributor Author

@lunny Probably other Mac-focused users could share their thoughts.

@silverwind
Copy link
Member

silverwind commented Apr 4, 2021

Not really happy with the .npmrc removal. Disabling audit speeds up package installation and the exact saving is also useful to enforce in there for package installation.

I'll see what can be done for #14578 (comment). I much prefer to keep things simple and not support UI rebuilds from tarballs.

@silverwind
Copy link
Member

Alternative: #15273

silverwind added a commit to silverwind/gitea that referenced this pull request Apr 8, 2021
- Don't package node_modules in tarballs, they are not cross-platform
  anymore and npm cache should not be messed with directly. Instead,
  require an internet connection to rebuild the UI, which is not necessary
  in the general use case because prebuilt UI files are shipped in the
  public directory.
- Simplify the fomantic build and make the target phony. We don't need
  anything more for something that is rarely ran.
- Use regular tar again to build tarballs and add variable for excludes
- Disable annoying npm update notifications

Fixes: go-gitea#14578
Fixes: go-gitea#15256
Fixes: go-gitea#15262
techknowlogick pushed a commit that referenced this pull request Apr 9, 2021
- Don't package node_modules in tarballs, they are not cross-platform
  anymore and npm cache should not be messed with directly. Instead,
  require an internet connection to rebuild the UI, which is not necessary
  in the general use case because prebuilt UI files are shipped in the
  public directory.
- Simplify the fomantic build and make the target phony. We don't need
  anything more for something that is rarely ran.
- Use regular tar again to build tarballs and add variable for excludes
- Disable annoying npm update notifications

Fixes: #14578
Fixes: #15256
Fixes: #15262

Co-authored-by: 6543 <6543@obermui.de>
@go-gitea go-gitea locked and limited conversation to collaborators May 13, 2021
AbdulrhmnGhanem pushed a commit to kitspace/gitea that referenced this pull request Aug 10, 2021
- Don't package node_modules in tarballs, they are not cross-platform
  anymore and npm cache should not be messed with directly. Instead,
  require an internet connection to rebuild the UI, which is not necessary
  in the general use case because prebuilt UI files are shipped in the
  public directory.
- Simplify the fomantic build and make the target phony. We don't need
  anything more for something that is rarely ran.
- Use regular tar again to build tarballs and add variable for excludes
- Disable annoying npm update notifications

Fixes: go-gitea#14578
Fixes: go-gitea#15256
Fixes: go-gitea#15262

Co-authored-by: 6543 <6543@obermui.de>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. topic/build PR changes how Gitea is built, i.e. regarding Docker or the Makefile
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants