Build powerful CI/CD pipelines using Ruby and Dagger instead of YAML configurations
A skill for building container-based CI/CD pipelines using DaggerRuby, the Ruby SDK for Dagger. Create powerful, programmable build and deployment workflows with Ruby code instead of YAML configurations.
Helps you build CI/CD pipelines using DaggerRuby by:
When the user requests help with DaggerRuby pipelines, follow these steps:
First, identify what the user needs:
Ask clarifying questions if requirements are unclear.
If working with an existing project:
Plan the pipeline using DaggerRuby patterns:
**Basic structure:**
```ruby
require 'dagger_ruby'
DaggerRuby.connection do |client|
# 1. Define source directories
# 2. Create containers with base images
# 3. Mount directories and caches
# 4. Execute build/test commands
# 5. Export artifacts or results
end
```
**Key patterns to use:**
Build the pipeline step-by-step:
**Container creation:**
```ruby
container = client.container.from("ruby:3.2-alpine")
```
**Mounting source code:**
```ruby
source = client.host.directory(".", exclude: ["node_modules", ".git"])
container = container.with_directory("/app", source)
```
**Adding cache volumes:**
```ruby
cache = client.cache_volume("bundle-cache")
container = container.with_mounted_cache("/usr/local/bundle", cache)
```
**Running commands:**
```ruby
container = container
.with_exec(["bundle", "install"])
.with_exec(["bundle", "exec", "rspec"])
```
**Exporting results:**
```ruby
container.stdout # Get command output
container.directory("/app/build").export("./dist") # Export directory
```
For sensitive data:
```ruby
secret = client.set_secret("api_token", ENV["API_TOKEN"])
container = container.with_secret_variable("API_TOKEN", secret)
```
For environment variables:
```ruby
container = container.with_env_variable("NODE_ENV", "production")
```
Wrap operations with error handling:
```ruby
begin
DaggerRuby.connection do |client|
# Pipeline operations
end
rescue DaggerRuby::GraphQLError => e
puts "GraphQL error: #{e.message}"
exit 1
rescue DaggerRuby::ConnectionError => e
puts "Connection error: #{e.message}"
exit 1
end
```
Apply caching strategies:
Before finalizing:
Provide clear documentation:
**Ruby application with tests:**
```ruby
DaggerRuby.connection do |client|
source = client.host.directory(".")
cache = client.cache_volume("bundle-cache")
output = client.container
.from("ruby:3.2")
.with_directory("/app", source)
.with_workdir("/app")
.with_mounted_cache("/usr/local/bundle", cache)
.with_exec(["bundle", "install"])
.with_exec(["bundle", "exec", "rspec"])
.stdout
puts output
end
```
**Node.js build with caching:**
```ruby
DaggerRuby.connection do |client|
source = client.host.directory(".", exclude: ["node_modules"])
npm_cache = client.cache_volume("npm-cache")
client.container
.from("node:18-alpine")
.with_directory("/src", source)
.with_workdir("/src")
.with_mounted_cache("/root/.npm", npm_cache)
.with_exec(["npm", "ci"])
.with_exec(["npm", "run", "build"])
.directory("/src/dist")
.export("./build")
end
```
**Git repository build:**
```ruby
DaggerRuby.connection do |client|
repo = client.git("https://github.com/user/repo.git")
.branch("main")
.tree
client.container
.from("golang:1.21")
.with_directory("/src", repo)
.with_workdir("/src")
.with_exec(["go", "build", "-o", "app"])
.file("/src/app")
.export("./app")
end
```
When creating new pipelines, typical structure:
```
project/
├── dagger.rb # Main pipeline script
├── Gemfile # Include dagger_ruby gem
├── .dockerignore # Exclude files from context
└── src/ # Source code
```
Leave a review
No reviews yet. Be the first to review this skill!
# Download SKILL.md from killerskills.ai/api/skills/daggerruby-cicd-pipeline-builder/raw