cue modules: move stdlib to pkg/alpha.dagger.io

In preparation for Europa, we will vendor multiple CUE modules:

- `pkg/alpha.dagger.io`: legacy non-europa packages
- `pkg/dagger.io`: core Europa packages
- `pkg/universe.dagger.io`: Europa universe

Signed-off-by: Andrea Luzzardi <aluzzardi@gmail.com>
This commit is contained in:
Andrea Luzzardi
2022-01-11 12:40:02 -08:00
parent e5316f3a1e
commit 282759c0e5
277 changed files with 33 additions and 31 deletions

View File

@@ -0,0 +1,99 @@
// Kustomize config management
package kustomize
import (
"alpha.dagger.io/dagger/op"
"alpha.dagger.io/dagger"
"alpha.dagger.io/alpine"
)
#Kustomization: {
// Kustomize binary version
version: *"v3.8.7" | string @dagger(input)
#code: #"""
[ -e /usr/local/bin/kubectl ] || {
curl -s "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh" | bash && mv kustomize /usr/local/bin
}
"""#
#up: [
op.#Load & {
from: alpine.#Image & {
package: bash: true
package: jq: true
package: curl: true
}
},
op.#WriteFile & {
dest: "/entrypoint.sh"
content: #code
},
op.#Exec & {
args: [
"/bin/bash",
"--noprofile",
"--norc",
"-eo",
"pipefail",
"/entrypoint.sh",
]
},
]
}
// Apply a Kubernetes Kustomize folder
#Kustomize: {
// Kubernetes source
source: dagger.#Artifact @dagger(input)
// Optional Kustomization file
kustomization: string @dagger(input)
// Kustomize binary version
version: *"v3.8.7" | string @dagger(input)
#code: #"""
cp /kustomization.yaml /source | true
mkdir -p /output
kustomize build /source >> /output/result.yaml
"""#
#up: [
op.#Load & {
from: #Kustomization & {"version": version}
},
op.#WriteFile & {
dest: "/entrypoint.sh"
content: #code
},
if kustomization != _|_ {
op.#WriteFile & {
dest: "/kustomization.yaml"
content: kustomization
mode: 0o600
}
},
op.#Exec & {
always: true
args: [
"/bin/bash",
"--noprofile",
"--norc",
"-eo",
"pipefail",
"/entrypoint.sh",
]
mount: "/source": from: source
},
op.#Subdir & {
dir: "/output"
},
]
}

View File

@@ -0,0 +1,31 @@
package kustomize
import (
"encoding/yaml"
"alpha.dagger.io/dagger"
)
TestKustomize: {
testdata: dagger.#Artifact
// Run Kustomize
kustom: #Kustomize & {
source: testdata
kustomization: yaml.Marshal({
resources: ["deployment.yaml", "pod.yaml"]
images: [{
name: "nginx"
newTag: "v1"
}]
replicas: [{
name: "nginx-deployment"
count: 2
}]
})
}
// Verify kustomization generation
verify: #VerifyKustomize & {
source: kustom
}
}

View File

@@ -0,0 +1,22 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
labels:
app: nginx-deployment
spec:
replicas: 1
template:
metadata:
name: nginx-deployment
labels:
app: nginx-deployment
spec:
containers:
- name: nginx-deployment
image: nginx
imagePullPolicy: IfNotPresent
restartPolicy: Always
selector:
matchLabels:
app: nginx-deployment

View File

@@ -0,0 +1,12 @@
apiVersion: v1
kind: Pod
metadata:
name: test-pod
labels:
app: test-pod
spec:
containers:
- name: test-pod
image: nginx
imagePullPolicy: IfNotPresent
restartPolicy: Always

View File

@@ -0,0 +1,72 @@
package kustomize
import (
"alpha.dagger.io/dagger/op"
"alpha.dagger.io/dagger"
"alpha.dagger.io/alpine"
)
#VerifyKustomize: {
source: dagger.#Artifact
#up: [
op.#Load & {
from: alpine.#Image & {
package: bash: true
}
},
// Check files
op.#Exec & {
always: true
args: [
"sh", "-c", "test $(ls /source | wc -l) = 1",
]
mount: "/source": from: source
},
// Check image tag kustomization
op.#Exec & {
always: true
args: [
"sh", "-c", #"""
grep -q "\- image: nginx:v1" /source/result.yaml
"""#,
]
mount: "/source": from: source
},
// Check replicas kustomization
op.#Exec & {
always: true
args: [
"sh", "-c", #"""
grep -q "replicas: 2" /source/result.yaml
"""#,
]
mount: "/source": from: source
},
// Check pod merge by kustomization
op.#Exec & {
always: true
args: [
"sh", "-c", #"""
grep -q "kind: Pod" /source/result.yaml
"""#,
]
mount: "/source": from: source
},
// Check pod name
op.#Exec & {
always: true
args: [
"sh", "-c", #"""
grep -q "name: test-pod" /source/result.yaml
"""#,
]
mount: "/source": from: source
},
]
}