1. ํ์ ์ฌ์ ์๊ฑด & ์์คํ ์๊ตฌ์ฌ์ (Prerequisites & System Requirements)
Dagger๋ Docker์ ์ฐฝ์์์ธ ์๋ก๋ชฌ ํ์ต์ค(Solomon Hykes)์ ์ด๊ธฐ Docker ํ์ด ๊ฐ๋ฐํ **์ฐจ์ธ๋ ์คํ์์ค ํ๋ก๊ทธ๋๋จธ๋ธ CI/CD ์์ง(Programmable CI/CD Engine)**์ ๋๋ค.
๊ธฐ์กด CI/CD ๋๊ตฌ(GitHub Actions, GitLab CI, Jenkins)์ ๊ณ ์ง์ ์ธ ๋ฌธ์ ์๋ โ์๋ฐฑ ์ค์ ์ฝ๊ธฐ ์ด๋ ค์ด YAML ํ์ผโ, โ๋ก์ปฌ์์๋ ํ
์คํธํ ์ ์์ด ์ปค๋ฐ๊ณผ ํธ์(git commit -m 'fix ci 47')๋ฅผ ๋ฌดํ ๋ฐ๋ณตํด์ผ ํ๋ ๋ญ๋นโ, **โCI ์๋น์ค๋ง๋ค ๋ฌธ๋ฒ๊ณผ ํ๊ฒฝ์ด ๋ฌ๋ผ ๋ฐ์ํ๋ ๋ฒค๋ ์ข
์์ฑโ**์ ์์ ํ ํด๊ฒฐํฉ๋๋ค.
Dagger๋ ํ์ดํ๋ผ์ธ์ ๊ฐ๋ฐ์์๊ฒ ๊ฐ์ฅ ์ต์ํ ๋ฒ์ฉ ํ๋ก๊ทธ๋๋ฐ ์ธ์ด(TypeScript, Go, Python)๋ก ์์ฑํ๋ฉฐ, ๋ชจ๋ ๋จ๊ณ๋ฅผ BuildKit ๊ธฐ๋ฐ์ ๊ฒฝ๋ ์ปจํ ์ด๋ ๊ฒฉ๋ฆฌ ํ๊ฒฝ์์ ์คํํ๋ฏ๋ก ๊ฐ๋ฐ์์ ๋ก์ปฌ ๋ ธํธ๋ถ๊ณผ ํด๋ผ์ฐ๋ CI ์๋ฒ ๊ฐ 100% ๋์ผํ ์คํ ๊ฒฐ๊ณผ๋ฅผ ๋ณด์ฅํฉ๋๋ค.
๐ป ์์คํ ์ค์น ๋ฐ ์คํ ์๊ตฌ์ฌ์ (System Requirements)
| ํญ๋ชฉ | ์ต์ ์ฌ์ (Minimum) | ๊ถ์ฅ ์ฌ์ (Recommended) | ์ฐธ๊ณ ๋ฐ ๋น๊ณ |
|---|---|---|---|
| ์ด์์ฒด์ (OS) | Linux (Ubuntu 20.04+, RHEL 8+), macOS 12+, Windows 10/11 (WSL2 ํ์) | Linux (Ubuntu 22.04/24.04 LTS) ๋๋ macOS 14+ (Apple Silicon) | OCI ์ปจํ ์ด๋ ๋ฐํ์ ์ง์ ํ๊ฒฝ |
| CPU | 2 ์ฝ์ด ์ด์ (x86_64, ARM64) | 4 ์ฝ์ด ~ 8 ์ฝ์ด ์ด์ | ์ปจํ ์ด๋ ๋น๋ ๋ฐ ๋ณ๋ ฌ ํ ์คํธ ํ์ดํ๋ผ์ธ ์ปดํ์ผ |
| ๋ฉ๋ชจ๋ฆฌ (RAM) | 4 GB ์ด์ | 8 GB ~ 16 GB ์ด์ | Dagger Engine(BuildKit) ์ปจํ ์ด๋ ๋ฐ ์บ์ ๋ณผ๋ฅจ ์์ฃผ |
| ๋์คํฌ (Storage) | 10 GB ์ด์์ ์ฌ์ ๊ณต๊ฐ | 30 GB ~ 50 GB ์ด์์ ๊ณ ์ NVMe SSD | OCI ์ปจํ ์ด๋ ์ด๋ฏธ์ง ๋ ์ด์ด ๋ฐ ๋น๋ ์บ์ ๋ณผ๋ฅจ ์คํ ๋ฆฌ์ง |
| ๋คํธ์ํฌ / ๋ฐํ์ | Docker Engine 24+ ๋๋ Podman 4.5+ / Containerd, Dagger CLI v0.15+ | Docker Desktop 4.30+ ๋๋ OrbStack (macOS), Node.js 20+ / Go 1.22+ / Python 3.11+ | ์์๋ฐ์ด๋ ์ธํฐ๋ท (Docker Hub ๋ฐ Daggerverse ๋ชจ๋ ๋ค์ด๋ก๋ 443 ํฌํธ) |
[!IMPORTANT] ์ Dagger์ธ๊ฐ? (Dev is CI, CI is Dev)
- 100% ๋ก์ปฌ ์ฌํ์ฑ: CI ์๋ฒ์ ํธ์ํ์ง ์๊ณ ๋ ๋ก์ปฌ ํฐ๋ฏธ๋์์
dagger call testํ ์ค๋ก ํ๋ก๋์ CI์ ์์ ํ ๋์ผํ ํ๊ฒฝ์ 0.1์ด ๋ง์ ์คํ ๋ฐ ๊ฒ์ฆํฉ๋๋ค.- BuildKit ๊ธฐ๋ฐ ์ด๊ณ ์ DAG ์บ์ฑ: ๋น๋ ๊ทธ๋ํ์ ๊ฐ ๋จ๊ณ๋ฅผ ๋ฐ์ดํธ ๋จ์๋ก ๋ถ์ํ์ฌ ๋ณ๊ฒฝ๋์ง ์์ ๋ ์ด์ด(npm ๋ชจ๋, Go ํจํค์ง ๋ฑ)๋ฅผ ์ฆ๊ฐ ์บ์ ํํธ(Cache Hit) ์ฒ๋ฆฌํฉ๋๋ค.
- ํ์ ์์ ํ ํจ์ํ ๋ชจ๋ (Daggerverse): ๋ณต์กํ Bash ์คํฌ๋ฆฝํธ ๋์ ์ธ์(Arguments), ๋ฐํ ํ์ , ๋ฌธ์ํ๊ฐ ์๋ฒฝํ ์ง์๋๋ ํ๋ก๊ทธ๋๋ฐ ์ธ์ด์ ํจ์(Functions)๋ก ํ์ดํ๋ผ์ธ์ ์กฐ๋ฆฝํฉ๋๋ค.
- ์ค์๊ฐ ์ธํฐ๋ํฐ๋ธ ๋๋ฒ๊น (
--interactive): ํ์ดํ๋ผ์ธ์ด ์คํจํ๋ฉด ๋ธ๋ผ์ฐ์ ๋ก๊ทธ๋ฅผ ๊ธฐ๋ค๋ฆด ํ์ ์์ด, ์ค๋ฅ๊ฐ ๋ฐ์ํ ๋ฐ๋ก ๊ทธ ์ปจํ ์ด๋ ์ ๋ด๋ถ๋ก ์ฆ์ ์ง์ ํ์ฌ ๋ฌธ์ ๋ฅผ ์ง๋จํ ์ ์์ต๋๋ค.
๐ฆ OS๋ณ Dagger CLI ์ค์น ๋ฐฉ๋ฒ
Dagger CLI๋ ๋จ์ผ ์คํ ๋ฐ์ด๋๋ฆฌ๋ก ์ ๊ณต๋๋ฉฐ, ์คํ ์ ๋ก์ปฌ Docker ๋ฐ๋ชฌ ์์ dagger-engine ์ปจํ
์ด๋๋ฅผ ์๋์ผ๋ก ํ๋ก๋น์ ๋ํฉ๋๋ค.
# ๐ 1. macOS (Homebrew)
brew install dagger/tap/dagger
# ๐ง 2. Linux (๊ณต์ ์ค์น ์
ธ ์คํฌ๋ฆฝํธ)
curl -fsSL https://dl.dagger.io/dagger/install.sh | BIN_DIR=/usr/local/bin sh
# ๐ช 3. Windows (WSL2 Ubuntu ํฐ๋ฏธ๋ ๊ถ์ฅ)
# WSL2 Ubuntu ์ ๋ด๋ถ์์ ์ Linux ์คํฌ๋ฆฝํธ๋ฅผ ์คํํ๊ฑฐ๋, PowerShell์์ ๋ฐ์ด๋๋ฆฌ ๋ค์ด๋ก๋:
# winget install Dagger.Dagger
# ์ค์น ํ์ธ
dagger version
์์ ์ฝ์ ์ถ๋ ฅ:
dagger v0.15.3 (c4961bf) linux/amd64
2. ์ง๊ด์ ์ธ ๋ฉํ ๋ชจ๋ธ (Mental Model & Architecture Diagram)
Dagger๋ ํด๋ผ์ด์ธํธ CLI/SDK์ ๋ฐฑ๊ทธ๋ผ์ด๋์์ ์ปจํ ์ด๋๋ฅผ ์ค์ผ์คํธ๋ ์ด์ ํ๋ Dagger Engine(BuildKit) ๊ฐ์ ํด๋ผ์ด์ธํธ-์๋ฒ ๊ตฌ์กฐ๋ก ๋์ํฉ๋๋ค.
+---------------------------------------------------------------------------------------------------+
| Dagger Programmable CI/CD Architecture |
+---------------------------------------------------------------------------------------------------+
| |
| [ ์ฌ์ฉ์ ํ๊ฒฝ ] (Developer Laptop / GitHub Actions / GitLab CI Runner) |
| - ๋ช
๋ น: `dagger call test`, `dagger call build` |
| โ |
| โผ |
| โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ |
| โ ๐ป Dagger Client Code (Go, TypeScript, Python) โ |
| โ - ์ต์ํ ํ๋ก๊ทธ๋๋ฐ ์ธ์ด๋ก ํ์ดํ๋ผ์ธ ์์ฑ (๋ฃจํ, ์กฐ๊ฑด๋ฌธ, ์ ๊ท์, ์ธ๋ถ ๋ผ์ด๋ธ๋ฌ๋ฆฌ ํ์ฉ) โ |
| โ - dag.container().from("node:20-alpine").withMountedDirectory(...) โ |
| โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ |
| โ gRPC over UNIX Socket / mTLS |
| โผ |
| [ Dagger Engine ๊ณ์ธต ] (BuildKit ๊ธฐ๋ฐ ์ปจํ
์ด๋ ๋ฐํ์: `dagger-engine`) |
| โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ |
| โ โ๏ธ Dagger Engine Server โ |
| โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ |
| โ โ ๐ GraphQL API Core (๋ชจ๋ ํด๋ผ์ด์ธํธ ํธ์ถ์ GraphQL ์ฐ์ฐ์ผ๋ก ์ถ์ํ) โ โ |
| โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ |
| โ โ DAG (Directed Acyclic Graph) ์คํ ๊ทธ๋ํ ๋ถ์โ |
| โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ |
| โ โ โก BuildKit Engine โ โ |
| โ โ - ๋ณ๋ ฌ ์ปจํ
์ด๋ ์คํ (Parallel Container Spawning) โ โ |
| โ โ - ๋ ์ด์ด ๋จ์ ์ปจํ
์ธ ์ฃผ์ ์ง์ ์บ์ (Content-Addressable Layer Caching) โ โ |
| โ โ - Cache Volumes (npm/maven/go ์์กด์ฑ ์๊ตฌ ๋ณด์กด) โ โ |
| โ โ - Secret Masking (๋ฉ๋ชจ๋ฆฌ ๊ฒฉ๋ฆฌ ๋น๋ฐ์ ๋ณด ๋ณดํธ) โ โ |
| โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ |
| โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ |
| โ ๊ฒฉ๋ฆฌ๋ ์ปจํ
์ด๋ ์คํ |
| โผ |
| [ ํ์ดํ๋ผ์ธ ์ฐ์ถ๋ฌผ ] |
| - ๐งช ๋จ์/ํตํฉ ํ
์คํธ ๊ฒฐ๊ณผ (JUnit XML, ์ปค๋ฒ๋ฆฌ์ง ๋ฆฌํฌํธ) |
| - ๐ฆ OCI ์ปจํ
์ด๋ ์ด๋ฏธ์ง (Docker Hub, AWS ECR, GitHub Packages ํธ์) |
| - ๐ ๋น๋ ๋ฐ์ด๋๋ฆฌ ๋ฐ ์ ์ ์์
(ํธ์คํธ ๋จธ์ `./dist` ๋๋ ํ ๋ฆฌ๋ก ์์ ํ๊ฒ ๋ด๋ณด๋ด๊ธฐ) |
+---------------------------------------------------------------------------------------------------+
โ๏ธ Dagger vs ๊ธฐ์กด CI ๋๊ตฌ ๊ธฐ์ ๋น๊ต
| ๋น๊ต ํญ๋ชฉ | Dagger | GitHub Actions | GitLab CI | Jenkins |
|---|---|---|---|---|
| ํ์ดํ๋ผ์ธ ์ธ์ด | TypeScript, Go, Python (์์ ํ ์ฝ๋) | YAML DSL | YAML DSL | Groovy (Jenkinsfile) |
| ๋ก์ปฌ ์คํ ๋ฐ ๋๋ฒ๊น | 100% ๋์ผ ์คํ & ์ค์๊ฐ ๋ํํ ์(-i) | ๋ถ๊ฐ๋ฅ (act ๋๊ตฌ๋ ๋ถ์์ ์๋ฎฌ๋ ์ด์
) | ๋ถ์์ (gitlab-runner exec ์ ํ์ ) | ๋ก์ปฌ ๋ง์คํฐ/์์ด์ ํธ ๋ณ๋ ์ธํ ํ์ |
| ์บ์ฑ ์ํคํ ์ฒ | BuildKit ๊ธฐ๋ฐ ๋ฐ์ดํธ ๋จ์ ์ ๋ฐ DAG ์บ์ | tar.gz ์์ถ ๊ธฐ๋ฐ ์๋ actions/cache | tarball ๊ธฐ๋ฐ ๋ถ์ฐ ์บ์ | ํ๋ฌ๊ทธ์ธ ์์กด ๋๋ ์์ ๊ณต๊ฐ ๊ณต์ |
| ๋ชจ๋ ์ฌ์ฌ์ฉ์ฑ | Daggerverse (ํ์ ๊ฒ์ฆ๋ ํจ์ ํธ์ถ) | ๋ณต์กํ Composite Action / ์ ธ ์คํฌ๋ฆฝํธ | include ๊ธฐ๋ฐ YAML ๋ณํฉ | ๊ณต์ ๋ผ์ด๋ธ๋ฌ๋ฆฌ(Shared Library) |
| CI ํ๋ซํผ ์ข ์์ฑ | ์ ๋ก (Zero Lock-in): ์ด๋์๋ dagger call | GitHub Actions์ ๊ฐํ๊ฒ ์ข ์ | GitLab์ ๊ฐํ๊ฒ ์ข ์ | Jenkins ํ๊ฒฝ์ ๊ฐํ๊ฒ ์ข ์ |
3. [์ด๋ณด์ 1๋จ๊ณ] ํฌ๋ก์๋: Dagger CLI ์ค์น์ ์ฒซ ๋ฒ์งธ ๋ชจ๋ ์คํ
๐ 1. ์ ๊ท Dagger ๋ชจ๋ ์ด๊ธฐํ (dagger init)
ํ๋ก์ ํธ ๋ฃจํธ ๋๋ ํ ๋ฆฌ์์ ์ํ๋ SDK ์ธ์ด๋ฅผ ์ ํํ์ฌ Dagger ๋ชจ๋์ ์ด๊ธฐํํฉ๋๋ค.
# 1. ํ
์คํธ์ฉ ํ๋ก์ ํธ ๋๋ ํ ๋ฆฌ ์์ฑ
mkdir my-dagger-pipeline && cd my-dagger-pipeline
# 2. TypeScript SDK๋ก Dagger ๋ชจ๋ ์ด๊ธฐํ (๋๋ --sdk=go, --sdk=python)
dagger init --name=my-pipeline --sdk=typescript
# ์์ฑ๋ ๋๋ ํ ๋ฆฌ ๊ตฌ์กฐ ํ์ธ
ls -la
์์ฑ๋ ํ์ค ๋๋ ํ ๋ฆฌ ๊ตฌ์กฐ:
my-dagger-pipeline/
โโโ dagger.json # Dagger ๋ชจ๋ ๋ฉํ๋ฐ์ดํฐ ๋ฐ ์์กด์ฑ ๋ช
์ธ
โโโ src/
โ โโโ index.ts # TypeScript SDK๋ก ์์ฑํ๋ ์ค์ ํ์ดํ๋ผ์ธ ํจ์ ์ฝ๋
โโโ package.json # TypeScript SDK ์์กด์ฑ (@dagger.io/dagger)
โโโ tsconfig.json # TypeScript ์ค์
โโโ .git/
๐ 2. ํฌ๋ก์๋ ํจ์ ์์ฑ (src/index.ts)
src/index.ts์ ๊ฐ๋จํ ์ปจํ
์ด๋ ์คํ ํจ์๋ฅผ ์ ์ํฉ๋๋ค. @object()์ @func() ๋ฐ์ฝ๋ ์ดํฐ๋ฅผ ์ฌ์ฉํ๋ฉด Dagger CLI๊ฐ ์๋์ผ๋ก ์ด๋ฅผ ๊ฐ์งํ์ฌ CLI ๋ช
๋ น์ด ํํ๋ก ๋
ธ์ถํฉ๋๋ค.
// src/index.ts
import { dag, Container, Directory, object, func } from "@dagger.io/dagger";
@object()
export class MyPipeline {
/**
* ๊ฒฝ๋ Alpine ์ปจํ
์ด๋๋ฅผ ๋์ ์ ๋ฌ๋ฐ์ ๋ฉ์์ง๋ฅผ ์ถ๋ ฅํ๋ ํฌ๋ก์๋ ํจ์
* @param message ์ถ๋ ฅํ ๋ฌธ์์ด ๋ฉ์์ง (๊ธฐ๋ณธ๊ฐ: 'Hello, Dagger World!')
*/
@func()
async hello(message: string = "Hello, Dagger World!"): Promise<string> {
return await dag
.container()
.from("alpine:latest")
.withExec(["echo", message])
.stdout();
}
}
๐ป 3. CLI์์ ํจ์ ํธ์ถ ๋ฐ ์คํ ํ์ธ
์์ฑํ ํจ์๋ ํฐ๋ฏธ๋์์ ์ฆ์ ์คํํ ์ ์์ต๋๋ค:
# 1. ๊ธฐ๋ณธ ์ธ์๋ก hello ํจ์ ํธ์ถ
dagger call hello
์์ ์ฝ์ ์ถ๋ ฅ:
Hello, Dagger World!
# 2. ์ปค์คํ
์ธ์ ์ ๋ฌ ํธ์ถ
dagger call hello --message="Dagger๋ ๋ก์ปฌ๊ณผ CI๋ฅผ ํ๋๋ก ์ฐ๊ฒฐํฉ๋๋ค."
์์ ์ฝ์ ์ถ๋ ฅ:
Dagger๋ ๋ก์ปฌ๊ณผ CI๋ฅผ ํ๋๋ก ์ฐ๊ฒฐํฉ๋๋ค.
4. [2๋จ๊ณ] ํต์ฌ ๊ธฐ๋ฅ 1: TypeScript SDK ๊ธฐ๋ฐ ์ค์ ์น ์ ํ๋ฆฌ์ผ์ด์ ํ์ดํ๋ผ์ธ
ํธ์คํธ ๋จธ์ ์ ์์ค์ฝ๋๋ฅผ ์ฝ์ด **๋ฆฐํธ(Lint) ๊ฒ์ฌ โ ๋จ์ ํ ์คํธ(Test) โ ํ๋ก๋์ ๋น๋(Build) โ ๊ฒฐ๊ณผ๋ฌผ ๋ด๋ณด๋ด๊ธฐ(Export)**๋ฅผ ์ํํ๋ ์์ ํ ์ค๋ฌด ํ์ดํ๋ผ์ธ์ ๋๋ค.
// src/index.ts
import { dag, Container, Directory, object, func } from "@dagger.io/dagger";
@object()
export class WebAppPipeline {
/**
* Node.js ๋ฒ ์ด์ค ํ๊ฒฝ๊ณผ ์บ์ ๋ณผ๋ฅจ์ด ์ฌ์ ์ธํ
๋ ์ปจํ
์ด๋ ๋ฐํ (์ฌ์ฌ์ฉ ํฌํผ)
*/
private baseEnv(source: Directory): Container {
// ๐ก npm ์บ์ ๋๋ ํ ๋ฆฌ๋ฅผ Cache Volume์ผ๋ก ๋ง์ดํธํ์ฌ ์์กด์ฑ ์ฌ๋ค์ด๋ก๋ ๋ฐฉ์ง!
const nodeCache = dag.cacheVolume("node-modules-cache");
return dag
.container()
.from("node:20-alpine")
.withMountedCache("/root/.npm", nodeCache)
.withDirectory("/app", source, {
// ๋ถํ์ํ ๋ฌด๊ฑฐ์ด ๋๋ ํ ๋ฆฌ๋ ์ปจํ
์ด๋ ์ ์ก์์ ์ ์ธ!
exclude: ["node_modules", ".git", "dist"],
})
.withWorkdir("/app")
.withExec(["npm", "ci"]);
}
/**
* 1. ์ฝ๋ ์คํ์ผ ๋ฐ ๋ฆฐํธ(ESLint) ๊ฒ์ฌ
*/
@func()
async lint(source: Directory): Promise<string> {
return await this.baseEnv(source)
.withExec(["npm", "run", "lint"])
.stdout();
}
/**
* 2. ๋จ์ ํ
์คํธ(Jest/Vitest) ์คํ
*/
@func()
async test(source: Directory): Promise<string> {
return await this.baseEnv(source)
.withExec(["npm", "test", "--", "--run"])
.stdout();
}
/**
* 3. ํ๋ก๋์
์ ์ ๋น๋ ์ํ ํ dist ๋๋ ํ ๋ฆฌ ๋ฐํ
*/
@func()
async build(source: Directory): Promise<Directory> {
return this.baseEnv(source)
.withExec(["npm", "run", "build"])
.directory("/app/dist");
}
}
ํฐ๋ฏธ๋์์ ํ์ฌ ๋๋ ํ ๋ฆฌ(.)์ ์์ค์ฝ๋๋ฅผ ๋๊ธฐ๋ฉฐ ๊ฐ๊ฐ์ ๋จ๊ณ๋ฅผ ์คํํฉ๋๋ค:
# ๋จ์ ํ
์คํธ ์คํ
dagger call test --source=.
# ํ๋ก๋์
๋น๋ ํ ํธ์คํธ์ ./dist ํด๋๋ก ๊ฒฐ๊ณผ๋ฌผ ์ถ์ถ
dagger call build --source=. -o ./dist
5. [2๋จ๊ณ] ํต์ฌ ๊ธฐ๋ฅ 2: Go SDK ๊ธฐ๋ฐ ๋ฉํฐ ์คํ ์ด์ง ๋น๋ & Docker ์ด๋ฏธ์ง ๋ ์ง์คํธ๋ฆฌ ํธ์
Go SDK๋ฅผ ์ฌ์ฉํ์ฌ Go ์ ํ๋ฆฌ์ผ์ด์ ์ ์ปดํ์ผํ๊ณ , ์ด๊ฒฝ๋ Scratch/Alpine ์ด๋ฏธ์ง๋ก ํจํค์งํ ํ, Secret์ ์์ ํ๊ฒ ๋ง์ดํธํ์ฌ Docker Hub ๋๋ ์ฌ๋ด ECR๋ก ํธ์ํ๋ ์์ ์ ๋๋ค.
// main.go
package main
import (
"context"
"fmt"
"main/internal/dagger"
)
type GoAppPipeline struct{}
// 1. ๋จ์ ํ
์คํธ ์คํ ํจ์
func (m *GoAppPipeline) Test(ctx context.Context, source *dagger.Directory) (string, error) {
// Go ๋ชจ๋ ์บ์ ๋ณผ๋ฅจ ์ ์
goModCache := dag.CacheVolume("go-mod-cache")
return dag.Container().
From("golang:1.23-alpine").
WithMountedCache("/go/pkg/mod", goModCache).
WithDirectory("/src", source, dagger.ContainerWithDirectoryOpts{
Exclude: []string{".git", "bin"},
}).
WithWorkdir("/src").
WithExec([]string{"go", "test", "-v", "./..."}).
Stdout(ctx)
}
// 2. ๋ฐ์ด๋๋ฆฌ ์ปดํ์ผ ๋ฐ ์ปจํ
์ด๋ ์ด๋ฏธ์ง ๋น๋ & ๋ ์ง์คํธ๋ฆฌ ํธ์
func (m *GoAppPipeline) Publish(
ctx context.Context,
source *dagger.Directory,
imageTag string,
registryUser string,
registryPassword *dagger.Secret, // โจ ๋ฉ๋ชจ๋ฆฌ ์์์ ์์ ํ๊ฒ ๊ฒฉ๋ฆฌ๋๋ Secret
) (string, error) {
// Step 1: ๋น๋ ์ปจํ
์ด๋์์ CGO ์์ด ์ ์ ๋ฐ์ด๋๋ฆฌ ๋น๋
builder := dag.Container().
From("golang:1.23-alpine").
WithDirectory("/src", source).
WithWorkdir("/src").
WithEnvVariable("CGO_ENABLED", "0").
WithEnvVariable("GOOS", "linux").
WithExec([]string{"go", "build", "-o", "/bin/app", "."})
binary := builder.File("/bin/app")
// Step 2: ๋ฐํ์ ์ด๊ฒฝ๋ Alpine ์ด๋ฏธ์ง์ ๋ฐ์ด๋๋ฆฌ ๋ณต์ฌ
runtimeImg := dag.Container().
From("alpine:3.20").
WithFile("/usr/local/bin/app", binary).
WithEntrypoint([]string{"/usr/local/bin/app"})
// Step 3: Secret์ ์ฌ์ฉํ ๋ ์ง์คํธ๋ฆฌ ๋ก๊ทธ์ธ ํ ํธ์
targetRepo := fmt.Sprintf("%s/my-app:%s", registryUser, imageTag)
imageDigest, err := runtimeImg.
WithRegistryAuth("docker.io", registryUser, registryPassword).
Publish(ctx, targetRepo)
if err != nil {
return "", err
}
return fmt.Sprintf("์ด๋ฏธ์ง ๋ฐฐํฌ ์ฑ๊ณต: %s (Digest: %s)", targetRepo, imageDigest), nil
}
ํฐ๋ฏธ๋์์ ํ๊ฒฝ๋ณ์์ ์ ์ฅ๋ Docker ํ ํฐ์ Dagger Secret์ผ๋ก ์์ ํ๊ฒ ์ ๋ฌํ์ฌ ์คํ:
# ์์ ํ๊ฒ ์ํฌ๋ฆฟ ์ ๋ฌํ๋ฉฐ ํผ๋ธ๋ฆฌ์
export DOCKER_PASS="my-secret-token"
dagger call publish \
--source=. \
--image-tag="v1.0.0" \
--registry-user="myuser" \
--registry-password=env:DOCKER_PASS
6. [3๋จ๊ณ] ์ค๋ฌด ์์ฉ ํจํด 1: ์ค์๊ฐ ๋ํํ ๋๋ฒ๊น
(--interactive)
Dagger์ ๊ฐ์ฅ ๊ฐ๋ ฅํ ํฌ๋ฌ ๊ธฐ๋ฅ์ ํ์ดํ๋ผ์ธ ์คํจ ์ ํด๋น ์คํจ ์ง์ ์ ์ปจํ ์ด๋ ์๋ก ์ฆ์ ๋ค์ด๊ฐ ์ ์๋ ๋ํํ ๋๋ฒ๊น (Interactive Debugging) ๋ชจ๋์ ๋๋ค.
# ๐ก -i ๋๋ --interactive ํ๋๊ทธ๋ฅผ ๋ถ์ฌ ์คํ
dagger call test --source=. --interactive
- ํ์ดํ๋ผ์ธ ๋์ค
npm test๋ ์ปดํ์ผ์ด ์คํจํ๋ฉด, Dagger Engine์ด ํ๋ก์ธ์ค๋ฅผ ์ค๋จ์ํค๊ณ ์ค๋ฅ๊ฐ ๋ฐ์ํ ์ปจํ ์ด๋ ๋ด๋ถ ํฐ๋ฏธ๋(sh) ์ธ์ ์ ์ฌ์ฉ์ ํ๋ฉด์ ์ฆ์ ๋์์ค๋๋ค. - ์ฌ์ฉ์๋ ์ปจํ
์ด๋ ์์์
ls,cat /tmp/error.log,env๋ฑ์ ์คํํ๋ฉฐ ์ ํ์ผ์ด ์์๋์ง, ๊ถํ์ด ์ ๋ถ์กฑํ๋์ง๋ฅผ ๊ทธ ์๋ฆฌ์์ ๋ฐ๋ก ํ์ธํ๊ณ ์์ ํ ์ ์์ต๋๋ค!
7. [3๋จ๊ณ] ์ค๋ฌด ์์ฉ ํจํด 2: GitHub Actions 100% ๋ฌด๊ฒฐ์ ์ํด๋ฆญ ์ฐ๋
์๋ฐฑ ์ค์ ๋ณต์กํ GitHub Actions YAML์ ์์ฑํ ํ์๊ฐ ์์ต๋๋ค. GitHub Actions๋ ๋จ์ํ Dagger CLI๋ฅผ ํธ์ถํ๋ **๋จ 20์ค์ ์ด๊ฒฝ๋ ๋ํผ(Wrapper)**๋ก ์ถ์๋ฉ๋๋ค.
# .github/workflows/ci.yml
name: Dagger CI/CD Pipeline
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
jobs:
pipeline:
runs-on: ubuntu-latest
steps:
# 1. ์์ค์ฝ๋ ์ฒดํฌ์์
- name: Checkout Repository
uses: actions/checkout@v4
# 2. ๊ณต์ Dagger Action์ ํตํด Dagger CLI ๋ฐ Engine ์๋ ๊ธฐ๋
- name: Run Dagger Pipeline
uses: dagger/dagger-for-github@v7
with:
version: "latest"
verb: "call"
args: "test --source=."
env:
# (์ ํ ์ฌํญ) Dagger Cloud ํ ํฐ ์ค์ ์ ์น ๋์๋ณด๋์์ ์ค์๊ฐ ์๊ฐํ ์ง์
DAGGER_CLOUD_TOKEN: ${{ secrets.DAGGER_CLOUD_TOKEN }}
[!TIP] ์ด์ ๊ฐ๋ฐํ์ CI ๋ฌธ์ ๋ฅผ ๊ณ ์น๊ธฐ ์ํด ๋ ์ด์
git push๋ฅผ ํ๊ณ GitHub ์น ๋ธ๋ผ์ฐ์ ์์ ์คํผ๋๊ฐ ๋๊ธฐ๋ฅผ ๊ธฐ๋ค๋ฆด ํ์๊ฐ ์์ต๋๋ค! ๋ก์ปฌ ํฐ๋ฏธ๋์์dagger call test --source=.๊ฐ ํต๊ณผํ๋ฉด, GitHub Actions์์๋ ์ํ์ ์ผ๋ก 100% ๋์ผํ๊ฒ ํต๊ณผํฉ๋๋ค.
8. ์ค๋ฌด ์ฃผ์์ฌํญ & ํ๋ก๋์ ์ฒดํฌ๋ฆฌ์คํธ (Troubleshooting & Checklist)
โ ๏ธ ์ด๋ณด์๊ฐ ํํ ๊ฒช๋ ์ค์ Top 5
- ๋ฌด๊ฑฐ์ด ํธ์คํธ ๋๋ ํ ๋ฆฌ(
.git,node_modules) ๋ฌด๋จ ๋ง์ดํธ:dag.host().directory(".")ํธ์ถ ์exclude์ต์ ์์ด ๋ง์ดํธํ๋ฉด ๊ธฐ๊ฐ๋ฐ์ดํธ ๋จ์์ ๋ถํ์ํ ํ์ผ์ด Dagger Engine์ผ๋ก ์ ์ก๋์ด ๋น๋ ์์์ด 30์ด ์ด์ ์ง์ฐ๋ฉ๋๋ค. ํญ์exclude: ["node_modules", ".git", "target", "dist"]๋ฅผ ์ง์ ํ์ธ์.
- ์ํฌ๋ฆฟ์ ํ๋ฌธ ํ๊ฒฝ๋ณ์(
withEnvVariable)๋ก ์ ๋ฌํ๋ ๋ณด์ ์ฌ๊ณ :- API ํค๋ ๋ ์ง์คํธ๋ฆฌ ์ํธ๋ฅผ
withEnvVariable("PASSWORD", pass)๋ก ์ ๋ฌํ๋ฉด ์ปจํ ์ด๋ ๋ ์ด์ด ํ์คํ ๋ฆฌ ๋ฐ Dagger ๋ก๊ทธ์ ์๊ตฌ ๋ ธ์ถ๋ฉ๋๋ค. ๋ฐ๋์withSecretVariable๋ฐdagger.Secretํ์ ์ ์ฌ์ฉํ์ธ์.
- API ํค๋ ๋ ์ง์คํธ๋ฆฌ ์ํธ๋ฅผ
- ์บ์ ๋ณผ๋ฅจ(Cache Volume) ์ด๋ฆ ์ถฉ๋ ๋ฐ ๋ฌดํ ๋์ :
dag.cacheVolume("cache")์ฒ๋ผ ๋๋ฌด ์ผ๋ฐ์ ์ธ ์ด๋ฆ์ ์ฌ์ฉํ๋ฉด ๋ค๋ฅธ ํ๋ก์ ํธ๋ ๋ธ๋์น์ ์์กด์ฑ๊ณผ ๊ผฌ์ผ ์ ์์ต๋๋ค.node-cache-${repoName}์ฒ๋ผ ๊ณ ์ ํ ์ ๋์ฌ๋ฅผ ๊ถ์ฅํฉ๋๋ค.
- WSL2 ๋๋ Docker ๋ฐ๋ชฌ ๋ฆฌ์์ค ๊ณ ๊ฐ:
- Dagger Engine์ ๋น๋ ๊ฐ์์ ์ํด ๋์คํฌ ์บ์๋ฅผ ์ ๊ทน ํ์ฉํฉ๋๋ค. ๋น๋ ์๋๊ฐ ๊ฐ์๊ธฐ ๋๋ ค์ง๊ฑฐ๋
no space left on device์ค๋ฅ๊ฐ ๋ฐ์ํ๋ฉดdocker system prune -f๋๋dagger engine stop์ ์คํํ์ฌ ์บ์๋ฅผ ์ ๋ฆฌํ์ธ์.
- Dagger Engine์ ๋น๋ ๊ฐ์์ ์ํด ๋์คํฌ ์บ์๋ฅผ ์ ๊ทน ํ์ฉํฉ๋๋ค. ๋น๋ ์๋๊ฐ ๊ฐ์๊ธฐ ๋๋ ค์ง๊ฑฐ๋
- Dagger SDK ๋ฒ์ ๊ณผ Dagger CLI ๋ฒ์ ์ ๋ถ์ผ์น:
package.json์@dagger.io/dagger๋ฒ์ ๊ณผ ๋ก์ปฌ์ ์ค์น๋dagger version๊ฐ์ ๋ง์ด๋ ๋ฒ์ ์ฐจ์ด๊ฐ ํด ๊ฒฝ์ฐ GraphQL API ์คํค๋ง ๋ถ์ผ์น ์๋ฌ๊ฐ ๋ฐ์ํ ์ ์์ต๋๋ค. ์ฃผ๊ธฐ์ ์ผ๋ก ๋ฒ์ ์ ์ผ์น์ํค์ธ์.
๐ ํ๋ก๋์ ์ด์ ์ฒดํฌ๋ฆฌ์คํธ (Production Checklist)
- Dagger Engine ๋ฆฌ์์ค ํ๋: CI ๋ฌ๋ ํ๊ฒฝ์์ Docker ๋ฐ๋ชฌ์ ์ถฉ๋ถํ ๋ฉ๋ชจ๋ฆฌ(์ต์ 4GB ์ด์) ํ ๋น ์ฌ๋ถ ํ์ธ
- ์๊ฒฉ ์บ์(Remote Cache / S3 / Registry) ๋ฐฑ์๋ ํ์ฑํ: ์ฌ๋ฌ CI ๋ฌ๋ ๊ฐ ์บ์๋ฅผ ๊ณต์ ํ๊ธฐ ์ํด
--export-cache๋ฐ--import-cache์ต์ ๊ตฌ์ฑ - ๋น๋ฐ์ ๋ณด ๋ง์คํน: ๋ชจ๋ ์๊ฒฉ์ฆ๋ช
์ด
dagger.Secretํ์ ์ผ๋ก ๋ณดํธ๋์ด ์ฝ์ ์ถ๋ ฅ ์***๋ก ์์ ํ๊ฒ ๊ฐ๋ ค์ง๋์ง ๊ฒ์ฆ - ๋ฉํฐ ํ๋ซํผ(Multi-platform) ์ง์ ๊ฒ์ฆ: ARM64(M1/M2/M3 Mac)์ AMD64(CI x86_64 ์๋ฒ) ๊ฐ ๋ฐ์ด๋๋ฆฌ ํฌ๋ก์ค ์ปดํ์ผ ์ต์
(
GOARCH,platform) ๋ช ์ - ์ธํฐ๋ํฐ๋ธ ์ ๋๋ฒ๊น
์ ์ฐจ ์์ง: ์ฅ์ ๋ฐ์ ์ ๋ก์ปฌ์์
-iํ๋๊ทธ๋ก 3๋ถ ๋ด ๊ทผ๋ณธ ์์ธ ๋ถ์ ๊ฐ๋ฅ ์ฌ๋ถ ํ ์คํธ
์๊ฒฌ ๋ฐ ์ง๋ฌธ
0์์ง ๋ฑ๋ก๋ ์๊ฒฌ์ด ์์ต๋๋ค. ์ฒซ ๋ฒ์งธ ๋๊ธ์ ๋จ๊ฒจ๋ณด์ธ์!
๋๊ธ ์์
๋๊ธ ์ญ์