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

Gem won't install on Windows 2019 Server Core with JRuby #62

Closed
chadlwilson opened this issue Sep 10, 2022 · 10 comments
Closed

Gem won't install on Windows 2019 Server Core with JRuby #62

chadlwilson opened this issue Sep 10, 2022 · 10 comments

Comments

@chadlwilson
Copy link

chadlwilson commented Sep 10, 2022

Hi there - it seems the current approach for unzipping is not very portable across Windows systems due to the use of cscript/vbascript to unzip the binary.

It works fine on Windows 10/11, however on Windows 2019 Server Core (e.g container mcr.microsoft.com/windows/servercore:ltsc2019), it fails to install without any feedback.

fetch https://github.com/sass/dart-sass-embedded/releases/download/1.54.9/sass_embedded-1.54.9-windows-x64.zip
cscript unzip.vbs //B //Nologo sass_embedded-1.54.9-windows-x64.zip .
rake aborted!
sass_embedded/dart-sass-embedded not found

By removing the //B argument to cscript (suppresses all errors) you now get feedback on the failure:

fetch https://github.com/sass/dart-sass-embedded/releases/download/1.54.9/sass_embedded-1.54.9-windows-x64.zip
cscript unzip.vbs //Nologo sass_embedded-1.54.9-windows-x64.zip .
C:\go\pipelines\test\ext\sass\unzip.vbs(10, 1) (null): Unspecified error 

rake aborted!
sass_embedded/dart-sass-embedded not found
C:/go/pipelines/test/ext/sass/Rakefile:28:in `block in <top (required)>'
Tasks: TOP => default => install => embedded.rb
(See full trace by running task with --trace)
rm sass_embedded-1.54.9-windows-x64.zip

Line 10 is
https://github.com/ntkme/sass-embedded-host-ruby/blob/81177507031b58175dfd6e7ecc9f133a7d2303fb/ext/sass/unzip.vbs#L10

The reason this doesn't work is that the NameSpace logic here seems to rely upon some kind of Compressed Folders feature of the Windows shell/explorer that makes zips easy to work with. This feature is so old, that it seems difficult to find information about, but is hinted at here.

In addition, this method will NOT work if Compressed Folders is disabled. In that situation, you will get this message:
Path\to\script.vbs(line number, char number) (null): Unspecified error
It is simple to Google how to enable/disable Compressed Folders.

Maybe was simple to google in 2011, but not so much now? 😅 I am inferring that this is not enabled by default on server variants especially Core which omits many features of full fledged windows. These core variants are common to use to run as build agents (we use Windows 2019 Server Core containers to build). I'm not even sure how to enable whatever is needed when building a docker image to try and resolve this, but will keep playing around.

Would you consider going back to a more standard approach here, using Powershell 5? I don't have context on why it was replaced in 778c61a but it seems this would be more robust to me, rather than depending on weird Windows Shell options like Compressed Folders?

@ntkme
Copy link
Member

ntkme commented Sep 10, 2022

Have you tried the pre-built ones which does not require vbscript for unzipping? E.g.
1.54.9 - September 08, 2022 x64-mingw-ucrt (3.04 MB)
1.54.9 - September 08, 2022 x64-mingw32 (3.04 MB)
1.54.9 - September 08, 2022 x86-mingw32 (14.2 MB)

@ntkme
Copy link
Member

ntkme commented Sep 10, 2022

I guess you're on JRuby? I can put back the powershell version.

@chadlwilson
Copy link
Author

Yeah, on JRuby. I don't follow all the way this works but I understand all the challenges with platform detection (the same ones that cause me issues with sassc and libsass trying to compile on Windows) causes it to "build the native extension" i.e download and unzip in this case.

@chadlwilson chadlwilson changed the title Gem won't install on Windows 2019 Server Core Gem won't install on Windows 2019 Server Core with JRuby Sep 10, 2022
@ntkme
Copy link
Member

ntkme commented Sep 10, 2022

@chadlwilson I don't have access to windows. If possible can you please see if the main branch works?

gem 'sass-embedded', github: 'ntkme/sass-embedded-host-ruby'

@chadlwilson
Copy link
Author

Thanks! 🙏 Switched in gocd/gocd#10796

4724a84 seems to be working fine on both Windows 2019 Server Core and Windows 11 (with appropriate Set-ExecutionPolicy, one of these annoying Powershell things, I guess 🤔).

Windows 11

Fetching https://github.com/ntkme/sass-embedded-host-ruby.git
Using sass-embedded 1.54.9 from https://github.com/ntkme/sass-embedded-host-ruby.git (at main@4724a84)

gem_make.out via JRuby

current directory: C:/gocd/server/src/main/webapp/WEB-INF/rails/gems/jruby/2.6.0/bundler/gems/sass-embedded-host-ruby-4724a844b7cd/ext/sass
C:/gocd/server/scripts/jruby.bat -Iuri:classloader:/META-INF/jruby.home/lib/ruby/stdlib -rrubygems C:/gocd/server/src/main/webapp/WEB-INF/rails/gems/jruby/2.6.0/gems/rake-13.0.6/exe/rake RUBYARCHDIR\=C:/gocd/server/src/main/webapp/WEB-INF/rails/gems/jruby/2.6.0/bundler/gems/extensions/universal-java-17/2.6.0/sass-embedded-host-ruby-4724a844b7cd RUBYLIBDIR\=C:/gocd/server/src/main/webapp/WEB-INF/rails/gems/jruby/2.6.0/bundler/gems/extensions/universal-java-17/2.6.0/sass-embedded-host-ruby-4724a844b7cd
fetch https://github.com/sass/dart-sass-embedded/releases/download/1.54.9/sass_embedded-1.54.9-windows-x64.zip
powershell -NoLogo -NoProfile -NonInteractive -File unzip.ps1 -Archive sass_embedded-1.54.9-windows-x64.zip -DestinationPath .
rm sass_embedded-1.54.9-windows-x64.zip
fetch https://github.com/sass/embedded-protocol/raw/1.1.0/embedded_sass.proto
fetch https://repo.maven.apache.org/maven2/com/google/protobuf/protoc/3.21.5/protoc-3.21.5-windows-x86_64.exe
chmod a+x protoc.exe
./protoc.exe --proto_path=. --ruby_out=. embedded_sass.proto

Windows 2019 Server Core

Fetching https://github.com/ntkme/sass-embedded-host-ruby.git
Using sass-embedded 1.54.9 from https://github.com/ntkme/sass-embedded-host-ruby.git (at main@4724a84)

@ntkme
Copy link
Member

ntkme commented Sep 10, 2022

I just pushed a Java based unzip solution. It should work better for JRuby on Windows as neither powershell nor vbscript is required.

@chadlwilson
Copy link
Author

OK, I can give it a go tomorrow 🙏

@chadlwilson
Copy link
Author

Working fine on Windows 11.

current directory: C:/gocd/server/src/main/webapp/WEB-INF/rails/gems/jruby/2.6.0/bundler/gems/sass-embedded-host-ruby-0d103fd1936a/ext/sass
C:/gocd/server/scripts/jruby.bat -Iuri:classloader:/META-INF/jruby.home/lib/ruby/stdlib -rrubygems C:/gocd/server/src/main/webapp/WEB-INF/rails/gems/jruby/2.6.0/gems/rake-13.0.6/exe/rake RUBYARCHDIR\=C:/gocd/server/src/main/webapp/WEB-INF/rails/gems/jruby/2.6.0/bundler/gems/extensions/universal-java-17/2.6.0/sass-embedded-host-ruby-0d103fd1936a RUBYLIBDIR\=C:/gocd/server/src/main/webapp/WEB-INF/rails/gems/jruby/2.6.0/bundler/gems/extensions/universal-java-17/2.6.0/sass-embedded-host-ruby-0d103fd1936a
fetch https://github.com/sass/dart-sass-embedded/releases/download/1.54.9/sass_embedded-1.54.9-windows-x64.zip
Archive:  sass_embedded-1.54.9-windows-x64.zip
  inflating: sass_embedded/src/LICENSE
  inflating: sass_embedded/src/dart.exe
  inflating: sass_embedded/src/dart-sass-embedded.snapshot
  inflating: sass_embedded/dart-sass-embedded.bat
rm sass_embedded-1.54.9-windows-x64.zip
fetch https://github.com/sass/embedded-protocol/raw/1.1.0/embedded_sass.proto
fetch https://repo.maven.apache.org/maven2/com/google/protobuf/protoc/3.21.5/protoc-3.21.5-windows-x86_64.exe
chmod a+x protoc.exe
./protoc.exe --proto_path=. --ruby_out=. embedded_sass.proto

And on Windows 2019 Server Core (don't have easy access to gem_make.out here)

> Task :server:initializeRailsGems
Using environment variables
CLASSPATH='C:\Users\ContainerAdministrator\.gradle\caches\modules-2\files-2.1\org.jruby\jruby-complete\9.3.7.0\92b318807fd957ace836078a1df5810e5471f42\jruby-complete-9.3.7.0.jar' \
 GEM_HOME='C:\go\pipelines\build-windows\server\src\main\webapp\WEB-INF\rails\gems\jruby\2.6.0' \
 GEM_PATH='C:\go\pipelines\build-windows\server\src\main\webapp\WEB-INF\rails\gems\jruby\2.6.0' \
     PATH='C:\go\pipelines\build-windows\server\scripts;C:\go\pipelines\build-windows\server\src\main\webapp\WEB-INF\rails\gems\jruby\2.6.0\bin;C:\tools\ruby31\bin;C:\Program Files\Eclipse Adoptium\jdk-17.0.4.101-hotspot\bin;C:\Python310\Scripts\;C:\Python310\;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\ProgramData\chocolatey\bin;C:\Program Files\nodejs\;C:\Program Files (x86)\nant-0.92\bin;C:\Program Files (x86)\Yarn\bin\;C:\Program Files (x86)\Subversion\bin;C:\Program Files\Git\cmd;C:\Program Files\Perforce\;C:\Program Files (x86)\GNU\GnuPG\pub;C:\Program Files (x86)\Windows Kits\8.1\Windows Performance Toolkit\;C:\Program Files\Amazon\AWSCLIV2\;C:\Program Files\\Perforce\\bin;C:\Users\ContainerAdministrator\AppData\Local\Microsoft\WindowsApps;C:\Users\ContainerAdministrator\AppData\Roaming\npm;C:\Program Files\Mercurial\;C:\Users\ContainerAdministrator\AppData\Local\Yarn\bin' \
     RUBY='C:/go/pipelines/build-windows/server/scripts/jruby.bat' \
[C:\go\pipelines\build-windows\server\src\main\webapp\WEB-INF\rails]$ java -Djruby.home=uri:classloader://META-INF/jruby.home -XX:+TieredCompilation -XX:TieredStopAtLevel=1 -Xss2048k -client --add-opens=java.base/sun.nio.ch=ALL-UNNAMED --add-opens=java.base/java.io=ALL-UNNAMED -Xmx1g -Dfile.encoding=windows-1252 -Duser.country=US -Duser.language=en -Duser.variant -cp C:\Users\ContainerAdministrator\.gradle\caches\modules-2\files-2.1\org.jruby\jruby-complete\9.3.7.0\92b318807fd957ace836078a1df5810e5471f42\jruby-complete-9.3.7.0.jar org.jruby.Main org.jruby.Main -S bundle install

# ... snip

Fetching https://github.com/sass/sassc-ruby.git
Fetching https://github.com/ntkme/sass-embedded-host-ruby.git
Using sassc 2.4.0 from https://github.com/sass/sassc-ruby.git (at refs/pull/233/head@244d3dc)
Using sass-embedded 1.54.9 from https://github.com/ntkme/sass-embedded-host-ruby.git (at main@0d103fd)
Fetching sassc-embedded 1.54.0
Installing sassc-embedded 1.54.0
Fetching sassc-rails 2.1.2
Installing sassc-rails 2.1.2

# ... snip

Bundle complete! 14 Gemfile dependencies, 72 gems now installed.
Bundled gems are installed into `./gems`

And then works fine after that with the assets pipeline :-)

@chadlwilson
Copy link
Author

Hello @ntkme - are you planning to publish a 1.59 patch release with these enhancements soon? It would be useful so I can switch back to proper rubygems releases rather than using main in order to have things working on Windows.

@ntkme
Copy link
Member

ntkme commented Sep 21, 2022

Dart Sass 1.55.0 (sass/dart-sass#1806) will be released soon, and I will cut a matching release once 1.55.0 is out.

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

2 participants