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

enabling the public build again #435

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .expeditor/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ subscriptions:
pipelines:
- verify:
description: Pull Request validation tests
public: true
- habitat/build:
env:
- HAB_NONINTERACTIVE: "true"
Expand Down
7 changes: 5 additions & 2 deletions .expeditor/run_windows_tests.ps1
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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 }
2 changes: 1 addition & 1 deletion .github/workflows/unit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
/_yardoc/
/doc/
/rdoc/
/vendor/

## Environment normalisation:
/.bundle/
Expand Down
24 changes: 22 additions & 2 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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
Expand All @@ -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
9 changes: 9 additions & 0 deletions dev/Dockerfile.linux
Original file line number Diff line number Diff line change
@@ -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"]
37 changes: 37 additions & 0 deletions dev/Dockerfile.windows
Original file line number Diff line number Diff line change
@@ -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
100 changes: 100 additions & 0 deletions dev/readme.md
Original file line number Diff line number Diff line change
@@ -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
---
Loading