diff --git a/.expeditor/config.yml b/.expeditor/config.yml index 5971a9ba..eccfa25f 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" diff --git a/.expeditor/run_windows_tests.ps1 b/.expeditor/run_windows_tests.ps1 index 2f80a4bc..a411276d 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" @@ -15,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 } +If ($lastexitcode -ne 0) { Exit $lastexitcode } \ No newline at end of file diff --git a/.github/workflows/unit.yml b/.github/workflows/unit.yml index 60583e9d..f289909a 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 diff --git a/.gitignore b/.gitignore index a8cef440..1f1475d0 100644 --- a/.gitignore +++ b/.gitignore @@ -15,6 +15,7 @@ /_yardoc/ /doc/ /rdoc/ +/vendor/ ## Environment normalisation: /.bundle/ diff --git a/Rakefile b/Rakefile index 2a6a2f6f..434d8668 100644 --- a/Rakefile +++ b/Rakefile @@ -1,7 +1,15 @@ require "bundler/gem_tasks" +require "fileutils" # Add this line 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" @@ -34,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 @@ -52,4 +72,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 diff --git a/dev/Dockerfile.linux b/dev/Dockerfile.linux new file mode 100644 index 00000000..983999a8 --- /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 00000000..2be62449 --- /dev/null +++ b/dev/Dockerfile.windows @@ -0,0 +1,37 @@ +# 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 +ENV BUNDLE_SILENCE_ROOT_WARNING=true \ + GIT_DISCOVERY_ACROSS_FILESYSTEM=true \ + chocolateyVersion="1.4.0" + +# When launched by user, default to PowerShell if no other command specified. +CMD ["powershell.exe", "-NoLogo", "-ExecutionPolicy", "Bypass"] + +# 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) + +# 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)'; + +# 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 new file mode 100644 index 00000000..c09bbf3a --- /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}:C:\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