From afd4053bd69a11d32cda907aac45c403d278c4dc Mon Sep 17 00:00:00 2001 From: Sean Simmons Date: Tue, 11 Feb 2025 16:51:56 -0500 Subject: [PATCH 1/6] enabling the public build again Signed-off-by: Sean Simmons --- .expeditor/config.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.expeditor/config.yml b/.expeditor/config.yml index 5971a9b..eccfa25 100644 --- a/.expeditor/config.yml +++ b/.expeditor/config.yml @@ -64,6 +64,7 @@ subscriptions: pipelines: - verify: description: Pull Request validation tests + public: true - habitat/build: env: - HAB_NONINTERACTIVE: "true" From 5695218352203999731d70952dda48c9c889c7f3 Mon Sep 17 00:00:00 2001 From: Sean Simmons Date: Tue, 11 Feb 2025 17:05:05 -0500 Subject: [PATCH 2/6] updating runner, as 1804 is gone Signed-off-by: Sean Simmons --- .github/workflows/unit.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/unit.yml b/.github/workflows/unit.yml index 60583e9..f289909 100644 --- a/.github/workflows/unit.yml +++ b/.github/workflows/unit.yml @@ -12,7 +12,7 @@ on: jobs: coverage-test: name: Coverage - runs-on: ubuntu-18.04 + runs-on: ubuntu-22.04 steps: - uses: actions/checkout@v2 - name: Set up ruby 3.1 From cb71483782367cde5a9219fac4888c345556d008 Mon Sep 17 00:00:00 2001 From: Sean Simmons Date: Wed, 12 Feb 2025 13:32:15 -0500 Subject: [PATCH 3/6] adding in a dev container process for windows and linux this is for local testing only Signed-off-by: Sean Simmons --- dev/Dockerfile.linux | 9 ++++ dev/Dockerfile.windows | 24 ++++++++++ dev/readme.md | 100 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 133 insertions(+) create mode 100644 dev/Dockerfile.linux create mode 100644 dev/Dockerfile.windows create mode 100644 dev/readme.md diff --git a/dev/Dockerfile.linux b/dev/Dockerfile.linux new file mode 100644 index 0000000..983999a --- /dev/null +++ b/dev/Dockerfile.linux @@ -0,0 +1,9 @@ +# Use official Ruby image from Docker Hub +# Update if you need to use a different version of ruby. source: https://hub.docker.com/_/ruby/tags +FROM ruby:3.1.2 + +# Set working directory +WORKDIR /workspace + +# Default command to keep container running +CMD ["sleep", "infinity"] diff --git a/dev/Dockerfile.windows b/dev/Dockerfile.windows new file mode 100644 index 0000000..ee27a5a --- /dev/null +++ b/dev/Dockerfile.windows @@ -0,0 +1,24 @@ +# Use Windows Server Core LTSC 2022 +FROM mcr.microsoft.com/windows/servercore:ltsc2022 + +# Set default Ruby version (overridable at runtime) +# this is a choco package list +ARG rubyVersion=3.1.2.1 +ENV RUBY_VERSION=${rubyVersion} + +# Install Chocolatey (Windows package manager) +RUN powershell -Command Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1')) +# Install Ruby via Chocolatey using the environment variable +RUN powershell -Command "choco install ruby --version=$env:RUBY_VERSION -y" + +# Add Ruby to PATH +ENV PATH="C:\\tools\\ruby${RUBY_VERSION}\\bin;${PATH}" + +# # Verify Ruby installation +# RUN ruby --version + +# Set working directory +WORKDIR C:\\workspace + +# Default command to keep container running +CMD ["powershell", "-Command", "Start-Sleep -Seconds 86400"] diff --git a/dev/readme.md b/dev/readme.md new file mode 100644 index 0000000..3c6bd95 --- /dev/null +++ b/dev/readme.md @@ -0,0 +1,100 @@ +# Ruby Development Environment with Docker +--- + +# **Ruby Development with Docker (Linux & Windows Containers)** + +## **Overview** +This project provides **Docker containers** for Ruby development on both **Linux** and **Windows** environments. + +- 🐧 **Linux Container**: Uses the official [`ruby:3.1.2`](https://hub.docker.com/_/ruby) Docker image for a lightweight setup. +- 🖥️ **Windows Container**: Based on **Windows Server Core LTSC 2022**, installing Ruby via **Chocolatey**. + +--- + +## **System Requirements** +### **For Linux/macOS users (WSL2 or native Linux/macOS)** +✅ Docker Desktop with **Linux containers enabled** +✅ macOS/Linux terminal (or WSL2 for Windows users) + +### **For Windows users** +✅ Docker Desktop with **Windows containers enabled** +✅ Windows 10/11 (Pro, Enterprise, or Education) + +--- + +## **How to Build the Containers** + +### **Building the Linux Container** +```sh +docker build -t ruby-linux -f Dockerfile.linux . +``` + +### **Building the Windows Container** +```powershell +docker build -t ruby-windows -f Dockerfile.windows . +``` + +To specify a **different Ruby version**, use `--build-arg`: +```sh +docker build --build-arg rubyVersion=3.2.0 -t ruby-linux -f Dockerfile.linux . +``` +```powershell +docker build --build-arg rubyVersion=3.2.0 -t ruby-windows -f Dockerfile.windows . +``` + +--- + +## **How to Run the Containers** + +### **Running the Linux Container** +```sh +docker run -it --rm -v $(pwd):/workspace ruby-linux bash +``` +- Mounts the current project directory to `/workspace` inside the container. +- Starts an interactive shell session. + +### **Running the Windows Container** +```powershell +docker run -it --rm -v ${PWD}:/workspace ruby-windows powershell +``` +- Mounts the project directory as `C:\workspace`. +- Starts an interactive PowerShell session. + +--- + +## **Switching Between Windows and Linux Containers** +⚠ **IMPORTANT:** Docker **cannot run both Linux and Windows containers simultaneously**. If you're switching between them: + +### **Switch to Linux Containers** +1. Open **Docker Desktop**. +2. Click the **Settings** ⚙️ icon. +3. Under **General**, check **"Use the WSL 2 based engine"**. +4. Right-click the Docker icon in the system tray → **Switch to Linux containers**. + +### **Switch to Windows Containers** +1. Right-click the **Docker Desktop** icon in the system tray. +2. Select **"Switch to Windows containers"**. + +--- + +## **Verifying Ruby Installation** +Once inside a running container, check the installed Ruby version: +```sh +ruby -v +``` + +--- + +## **Troubleshooting** +❌ **Issue:** "Cannot switch to Windows/Linux containers" +✅ **Solution:** Restart **Docker Desktop** and try again. + +❌ **Issue:** "Mounting volume fails on Windows" +✅ **Solution:** Ensure **file sharing** is enabled in Docker settings under **Resources > File Sharing**. + +❌ **Issue:** "Exception calling "DownloadString" with "1" argument(s): "The remote name could not be resolved: 'community.chocolatey.org'" +✅ **Solution:** Ensure **Docker network ls** is using the correct network. + - docker network ls + - docker network inspect "name" + - use the right network: docker build --network="NameOfNetwork" -t ruby-windows -f +--- \ No newline at end of file From 9120e6176d83b4b9ad614b539eafa6a41f18d03d Mon Sep 17 00:00:00 2001 From: Sean Simmons Date: Fri, 14 Feb 2025 10:49:40 -0500 Subject: [PATCH 4/6] testing in container fixed missing a microsoft dev pacakges, running a quick temp fix to address the immediate need Signed-off-by: Sean Simmons --- .expeditor/run_windows_tests.ps1 | 5 +++- .gitignore | 1 + dev/Dockerfile.windows | 43 +++++++++++++++++++++----------- dev/readme.md | 2 +- 4 files changed, 34 insertions(+), 17 deletions(-) diff --git a/.expeditor/run_windows_tests.ps1 b/.expeditor/run_windows_tests.ps1 index 2f80a4b..34a5375 100644 --- a/.expeditor/run_windows_tests.ps1 +++ b/.expeditor/run_windows_tests.ps1 @@ -1,6 +1,9 @@ # Stop script execution when a non-terminating error occurs $ErrorActionPreference = "Stop" +## temp fix for docker container ## +choco install vcredist140 -y + # This will run ruby test on windows platform Write-Output "--- Bundle install" @@ -18,4 +21,4 @@ If ($lastexitcode -ne 0) { Exit $lastexitcode } Write-Output "--- Bundle Execute" bundle exec rake -If ($lastexitcode -ne 0) { Exit $lastexitcode } +If ($lastexitcode -ne 0) { Exit $lastexitcode } \ No newline at end of file diff --git a/.gitignore b/.gitignore index a8cef44..1f1475d 100644 --- a/.gitignore +++ b/.gitignore @@ -15,6 +15,7 @@ /_yardoc/ /doc/ /rdoc/ +/vendor/ ## Environment normalisation: /.bundle/ diff --git a/dev/Dockerfile.windows b/dev/Dockerfile.windows index ee27a5a..2be6244 100644 --- a/dev/Dockerfile.windows +++ b/dev/Dockerfile.windows @@ -3,22 +3,35 @@ FROM mcr.microsoft.com/windows/servercore:ltsc2022 # Set default Ruby version (overridable at runtime) # this is a choco package list -ARG rubyVersion=3.1.2.1 -ENV RUBY_VERSION=${rubyVersion} +ENV BUNDLE_SILENCE_ROOT_WARNING=true \ + GIT_DISCOVERY_ACROSS_FILESYSTEM=true \ + chocolateyVersion="1.4.0" -# Install Chocolatey (Windows package manager) -RUN powershell -Command Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1')) -# Install Ruby via Chocolatey using the environment variable -RUN powershell -Command "choco install ruby --version=$env:RUBY_VERSION -y" - -# Add Ruby to PATH -ENV PATH="C:\\tools\\ruby${RUBY_VERSION}\\bin;${PATH}" +# When launched by user, default to PowerShell if no other command specified. +CMD ["powershell.exe", "-NoLogo", "-ExecutionPolicy", "Bypass"] -# # Verify Ruby installation -# RUN ruby --version +# Install Chocolatey (Windows package manager) +RUN powershell Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1')) && \ + C:\ProgramData\Chocolatey\bin\refreshenv && \ + choco feature enable -n=allowGlobalConfirmation && \ + choco config set cacheLocation C:\chococache && \ + choco install git && \ + choco install vcredist140 && \ + rmdir /q /s C:\chococache && \ + echo Chocolatey install complete -- closing out layer (this can take awhile) -# Set working directory -WORKDIR C:\\workspace +# Install Ruby + Devkit +RUN powershell -Command \ + $ErrorActionPreference = 'Stop'; \ + Write-Output 'Downloading Ruby + DevKit'; \ + [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; \ + (New-Object System.Net.WebClient).DownloadFile('https://github.com/oneclick/rubyinstaller2/releases/download/RubyInstaller-3.1.1-1/rubyinstaller-devkit-3.1.1-1-x64.exe', 'c:\\rubyinstaller-devkit-3.1.1-1-x64.exe'); \ + Write-Output 'Installing Ruby + DevKit'; \ + Start-Process c:\rubyinstaller-devkit-3.1.1-1-x64.exe -ArgumentList '/verysilent /dir=C:\\ruby31' -Wait ; \ + Write-Output 'Cleaning up installation'; \ + Remove-Item c:\rubyinstaller-devkit-3.1.1-1-x64.exe -Force; \ + Write-Output 'Closing out the layer (this can take awhile)'; -# Default command to keep container running -CMD ["powershell", "-Command", "Start-Sleep -Seconds 86400"] +# permissions junk +RUN powershell -Command "git config --global --add safe.directory "*"" +# RUN icacls "C:\workspace\" /grant "Everyone:(F)" /t diff --git a/dev/readme.md b/dev/readme.md index 3c6bd95..c09bbf3 100644 --- a/dev/readme.md +++ b/dev/readme.md @@ -55,7 +55,7 @@ docker run -it --rm -v $(pwd):/workspace ruby-linux bash ### **Running the Windows Container** ```powershell -docker run -it --rm -v ${PWD}:/workspace ruby-windows powershell +docker run -it --rm -v ${PWD}:C:\workspace ruby-windows powershell ``` - Mounts the project directory as `C:\workspace`. - Starts an interactive PowerShell session. From 72d497157c4de70bb83d48abe2073f9bc0db6a13 Mon Sep 17 00:00:00 2001 From: Sean Simmons Date: Fri, 14 Feb 2025 13:29:30 -0500 Subject: [PATCH 5/6] testing with privileged Signed-off-by: Sean Simmons --- .expeditor/run_windows_tests.ps1 | 2 +- .expeditor/verify.pipeline.yml | 1 + Rakefile | 9 ++++++++- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/.expeditor/run_windows_tests.ps1 b/.expeditor/run_windows_tests.ps1 index 34a5375..a411276 100644 --- a/.expeditor/run_windows_tests.ps1 +++ b/.expeditor/run_windows_tests.ps1 @@ -18,7 +18,7 @@ If ($lastexitcode -ne 0) { Exit $lastexitcode } bundle install --jobs=7 --retry=3 If ($lastexitcode -ne 0) { Exit $lastexitcode } -Write-Output "--- Bundle Execute" +Write-Output "--- Bundle Execute rake" bundle exec rake If ($lastexitcode -ne 0) { Exit $lastexitcode } \ No newline at end of file diff --git a/.expeditor/verify.pipeline.yml b/.expeditor/verify.pipeline.yml index 53fa4a1..f96c39f 100644 --- a/.expeditor/verify.pipeline.yml +++ b/.expeditor/verify.pipeline.yml @@ -25,6 +25,7 @@ steps: expeditor: executor: docker: + privileged: true host_os: windows shell: ["powershell", "-Command"] image: rubydistros/windows-2019:3.1 diff --git a/Rakefile b/Rakefile index 2a6a2f6..01882e2 100644 --- a/Rakefile +++ b/Rakefile @@ -2,6 +2,13 @@ require "bundler/gem_tasks" WINDOWS_PLATFORM = /mswin|win32|mingw/.freeze unless defined? WINDOWS_PLATFORM +# def elevated_permissions? +# return true if RUBY_PLATFORM !~ WINDOWS_PLATFORM +# require "win32ole" +# shell = WIN32OLE.new("Shell.Application") +# shell.IsUserAnAdmin +# end + # Style Tests begin require "chefstyle" @@ -52,4 +59,4 @@ end # test or the default task runs spec, features, style desc "run all tests" task default: %i{coverage features style} -task test: :default +task test: :default \ No newline at end of file From 77705ff4d0b440385cc04d5e98dfd000fd89d440 Mon Sep 17 00:00:00 2001 From: Sean Simmons Date: Fri, 14 Feb 2025 15:18:30 -0500 Subject: [PATCH 6/6] removing option Signed-off-by: Sean Simmons --- .expeditor/verify.pipeline.yml | 1 - Rakefile | 15 ++++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/.expeditor/verify.pipeline.yml b/.expeditor/verify.pipeline.yml index f96c39f..53fa4a1 100644 --- a/.expeditor/verify.pipeline.yml +++ b/.expeditor/verify.pipeline.yml @@ -25,7 +25,6 @@ steps: expeditor: executor: docker: - privileged: true host_os: windows shell: ["powershell", "-Command"] image: rubydistros/windows-2019:3.1 diff --git a/Rakefile b/Rakefile index 01882e2..434d866 100644 --- a/Rakefile +++ b/Rakefile @@ -1,4 +1,5 @@ require "bundler/gem_tasks" +require "fileutils" # Add this line WINDOWS_PLATFORM = /mswin|win32|mingw/.freeze unless defined? WINDOWS_PLATFORM @@ -41,11 +42,23 @@ rescue LoadError task :spec end +# Ensure no file access conflicts +desc "Ensure no file access conflicts" +task :ensure_file_access do + files_to_check = ["admin.pem", "config.rb"] # Add any other files that need to be checked + files_to_check.each do |file| + while File.exist?(file) && File.open(file) { |f| f.flock(File::LOCK_EX | File::LOCK_NB) } == false + puts "Waiting for #{file} to be available..." + sleep 1 + end + end +end + # Feature Tests begin require "cucumber" require "cucumber/rake/task" - Cucumber::Rake::Task.new(:features) do |t| + Cucumber::Rake::Task.new(:features => :ensure_file_access) do |t| # Add dependency on :ensure_file_access if RUBY_PLATFORM =~ WINDOWS_PLATFORM || RUBY_PLATFORM =~ /darwin/ t.cucumber_opts = "--tags 'not @not-windows'" end