Skip to content
Open
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
58 changes: 58 additions & 0 deletions .github/workflows/dagger-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: Dagger CI

on:
push:
branches: [ main, master ]
pull_request:
branches: [ main, master ]

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '20'

- name: Install Dagger dependencies
working-directory: dagger
run: npm install

- name: Run Dagger Pipeline
working-directory: dagger
run: npm run pipeline

- name: Upload artifacts
uses: actions/upload-artifact@v3
if: always()
with:
name: build-artifacts
path: |
build/
dist/
coverage/
retention-days: 7

security-scan:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Run Trivy vulnerability scanner
uses: aquasecurity/trivy-action@master
with:
scan-type: 'fs'
scan-ref: '.'
format: 'sarif'
output: 'trivy-results.sarif'

- name: Upload Trivy scan results to GitHub Security tab
uses: github/codeql-action/upload-sarif@v2
if: always()
with:
sarif_file: 'trivy-results.sarif'
65 changes: 65 additions & 0 deletions dagger/ci.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { Client, connect } from "@dagger.io/dagger";

export default async function pipeline() {
const client = await connect();

try {
// Get source directory
const source = client.host().directory(".", {
exclude: ["node_modules", ".git", "dist", "build", ".next", "coverage", "dagger"]
});

// Build container using Nixpacks approach
const container = client
.container()
.from("alpine:latest")
.withExec(["apk", "add", "--no-cache", "bash", "curl", "git"])
.withDirectory("/app", source)
.withWorkdir("/app");

// Run project-specific commands
const tested = await runTests(client, container);

// Build final image
const image = tested.withLabel("built-by", "dagger");

// Publish to registry (using ttl.sh for demo)
const imageRef = await image.publish(`ttl.sh/agentic-rag-knowledge-graph:1h`);
console.log(`Published image: ${imageRef}`);

return imageRef;
} finally {
await client.close();
}
}

async function runTests(client: Client, container: any) {
// Detect and run tests based on project type
const projectFiles = await client.host().directory(".").entries();

if (projectFiles.includes("package.json")) {
return container
.withExec(["sh", "-c", "command -v npm || (apk add --no-cache nodejs npm)"])
.withExec(["npm", "install", "--no-fund", "--no-audit"])
.withExec(["npm", "test", "||", "echo", "No tests found"]);
} else if (projectFiles.includes("requirements.txt")) {
return container
.withExec(["sh", "-c", "command -v python3 || apk add --no-cache python3 py3-pip"])
.withExec(["pip", "install", "-r", "requirements.txt", "||", "echo", "No requirements"])
.withExec(["python", "-m", "pytest", "||", "echo", "No tests found"]);
} else if (projectFiles.includes("go.mod")) {
return container
.withExec(["sh", "-c", "command -v go || apk add --no-cache go"])
.withExec(["go", "test", "./...", "||", "echo", "No tests found"]);
}

return container;
}

// Run the pipeline
if (require.main === module) {
pipeline().catch((e) => {
console.error(e);
process.exit(1);
});
}
14 changes: 14 additions & 0 deletions dagger/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "dagger-pipeline",
"version": "1.0.0",
"type": "module",
"scripts": {
"pipeline": "tsx ci.ts"
},
"devDependencies": {
"@dagger.io/dagger": "^0.9.0",
"@types/node": "^20.0.0",
"tsx": "^4.0.0",
"typescript": "^5.0.0"
}
}
Loading