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:
48
pkg/alpha.dagger.io/argocd/app.cue
Normal file
48
pkg/alpha.dagger.io/argocd/app.cue
Normal file
@@ -0,0 +1,48 @@
|
||||
package argocd
|
||||
|
||||
import (
|
||||
"alpha.dagger.io/dagger"
|
||||
"alpha.dagger.io/os"
|
||||
)
|
||||
|
||||
// Create an ArgoCD application
|
||||
#App: {
|
||||
// ArgoCD configuration
|
||||
config: #Config
|
||||
|
||||
// App name
|
||||
name: dagger.#Input & {string}
|
||||
|
||||
// Repository url (git or helm)
|
||||
repo: dagger.#Input & {string}
|
||||
|
||||
// Folder to deploy
|
||||
path: dagger.#Input & {"." | string}
|
||||
|
||||
// Destination server
|
||||
server: dagger.#Input & {*"https://kubernetes.default.svc" | string}
|
||||
|
||||
// Destination namespace
|
||||
namespace: dagger.#Input & {*"default" | string}
|
||||
|
||||
os.#Container & {
|
||||
image: #CLI & {
|
||||
"config": config
|
||||
}
|
||||
command: #"""
|
||||
argocd app create "$APP_NAME" \
|
||||
--repo "$APP_REPO" \
|
||||
--path "$APP_PATH" \
|
||||
--dest-server "$APP_SERVER" \
|
||||
--dest-namespace "$APP_NAMESPACE"
|
||||
"""#
|
||||
always: true
|
||||
env: {
|
||||
APP_NAME: name
|
||||
APP_REPO: repo
|
||||
APP_PATH: path
|
||||
APP_SERVER: server
|
||||
APP_NAMESPACE: namespace
|
||||
}
|
||||
}
|
||||
}
|
99
pkg/alpha.dagger.io/argocd/argocd.cue
Normal file
99
pkg/alpha.dagger.io/argocd/argocd.cue
Normal file
@@ -0,0 +1,99 @@
|
||||
// ArgoCD client operations
|
||||
package argocd
|
||||
|
||||
import (
|
||||
"alpha.dagger.io/alpine"
|
||||
"alpha.dagger.io/dagger"
|
||||
"alpha.dagger.io/dagger/op"
|
||||
)
|
||||
|
||||
// ArgoCD configuration
|
||||
#Config: {
|
||||
// ArgoCD CLI binary version
|
||||
version: *"v2.0.5" | dagger.#Input & {string}
|
||||
|
||||
// ArgoCD server
|
||||
server: dagger.#Input & {string}
|
||||
|
||||
// ArgoCD project
|
||||
project: *"default" | dagger.#Input & {string}
|
||||
|
||||
// Basic authentification to login
|
||||
basicAuth: {
|
||||
// Username
|
||||
username: dagger.#Input & {string}
|
||||
|
||||
// Password
|
||||
password: dagger.#Input & {dagger.#Secret}
|
||||
} | *null
|
||||
|
||||
// ArgoCD authentication token
|
||||
token: dagger.#Input & {*null | dagger.#Secret}
|
||||
}
|
||||
|
||||
// Re-usable CLI component
|
||||
#CLI: {
|
||||
config: #Config
|
||||
|
||||
#up: [
|
||||
op.#Load & {
|
||||
from: alpine.#Image & {
|
||||
package: bash: true
|
||||
package: jq: true
|
||||
package: curl: true
|
||||
}
|
||||
},
|
||||
|
||||
// Install the ArgoCD CLI
|
||||
op.#Exec & {
|
||||
args: ["sh", "-c",
|
||||
#"""
|
||||
curl -sSL -o /usr/local/bin/argocd https://github.com/argoproj/argo-cd/releases/download/$VERSION/argocd-linux-amd64 &&
|
||||
chmod +x /usr/local/bin/argocd
|
||||
"""#,
|
||||
]
|
||||
env: VERSION: config.version
|
||||
},
|
||||
|
||||
if config.basicAuth != null && config.token == null {
|
||||
// Login to ArgoCD server
|
||||
op.#Exec & {
|
||||
args: ["sh", "-c", #"""
|
||||
argocd login "$ARGO_SERVER" --username "$ARGO_USERNAME" --password $(cat /run/secrets/password) --insecure
|
||||
"""#,
|
||||
]
|
||||
env: {
|
||||
ARGO_SERVER: config.server
|
||||
ARGO_USERNAME: config.basicAuth.username
|
||||
}
|
||||
mount: "/run/secrets/password": secret: config.basicAuth.password
|
||||
}
|
||||
},
|
||||
|
||||
if config.token != null && config.basicAuth == null {
|
||||
// Write config file
|
||||
op.#Exec & {
|
||||
args: ["sh", "-c",
|
||||
#"""
|
||||
mkdir -p ~/.argocd && cat > ~/.argocd/config << EOF
|
||||
contexts:
|
||||
- name: "$SERVER"
|
||||
server: "$SERVER"
|
||||
user: "$SERVER"
|
||||
current-context: "$SERVER"
|
||||
servers:
|
||||
- grpc-web-root-path: ""
|
||||
server: "$SERVER"
|
||||
users:
|
||||
- auth-token: $(cat /run/secrets/token)
|
||||
name: "$SERVER"
|
||||
EOF
|
||||
"""#,
|
||||
]
|
||||
mount: "/run/secrets/token": secret: config.token
|
||||
env: SERVER: config.server
|
||||
}
|
||||
},
|
||||
|
||||
]
|
||||
}
|
59
pkg/alpha.dagger.io/argocd/status.cue
Normal file
59
pkg/alpha.dagger.io/argocd/status.cue
Normal file
@@ -0,0 +1,59 @@
|
||||
package argocd
|
||||
|
||||
import (
|
||||
"alpha.dagger.io/dagger"
|
||||
"alpha.dagger.io/dagger/op"
|
||||
)
|
||||
|
||||
// Get application's status
|
||||
#Status: {
|
||||
// ArgoCD configuration
|
||||
config: #Config
|
||||
|
||||
// ArgoCD application
|
||||
name: dagger.#Input & {string}
|
||||
|
||||
// ArgoCD CLI output
|
||||
outputs: {
|
||||
// Application health
|
||||
health: dagger.#Output & {string}
|
||||
|
||||
// Application sync state
|
||||
sync: dagger.#Output & {string}
|
||||
|
||||
// Namespace
|
||||
namespace: dagger.#Output & {string}
|
||||
|
||||
// Server
|
||||
server: dagger.#Output & {string}
|
||||
|
||||
// Comma separated list of application URLs
|
||||
urls: dagger.#Output & {string}
|
||||
|
||||
// Last operation state message
|
||||
state: dagger.#Output & {string}
|
||||
}
|
||||
|
||||
outputs: #up: [
|
||||
op.#Load & {
|
||||
from: #CLI & {
|
||||
"config": config
|
||||
}
|
||||
},
|
||||
|
||||
op.#Exec & {
|
||||
args: ["sh", "-c",
|
||||
#"""
|
||||
argocd app get "$APPLICATION" --output json | jq '{health:.status.health.status,sync:.status.sync.status,namespace:.spec.destination.namespace,server:.spec.destination.server,urls:(.status.summary.externalURLs//[]|join(",")),state:.status.operationState.message}' > /output.json
|
||||
"""#,
|
||||
]
|
||||
env: APPLICATION: name
|
||||
always: true
|
||||
},
|
||||
|
||||
op.#Export & {
|
||||
source: "/output.json"
|
||||
format: "json"
|
||||
},
|
||||
]
|
||||
}
|
41
pkg/alpha.dagger.io/argocd/sync.cue
Normal file
41
pkg/alpha.dagger.io/argocd/sync.cue
Normal file
@@ -0,0 +1,41 @@
|
||||
package argocd
|
||||
|
||||
import (
|
||||
"alpha.dagger.io/dagger"
|
||||
"alpha.dagger.io/os"
|
||||
)
|
||||
|
||||
// Sync an application to its targer state
|
||||
#Sync: {
|
||||
// ArgoCD configuration
|
||||
config: #Config
|
||||
|
||||
// ArgoCD application
|
||||
application: dagger.#Input & {string}
|
||||
|
||||
// Wait the application to sync correctly
|
||||
wait: dagger.#Input & {*false | bool}
|
||||
|
||||
ctr: os.#Container & {
|
||||
image: #CLI & {
|
||||
"config": config
|
||||
}
|
||||
command: #"""
|
||||
argocd app sync "$APPLICATION"
|
||||
|
||||
if [ -n "$WAIT_FLAG" ]; then
|
||||
argocd app wait "$APPLICATION"
|
||||
fi
|
||||
"""#
|
||||
always: true
|
||||
env: APPLICATION: application
|
||||
if wait {
|
||||
env: WAIT_FLAG: "wait"
|
||||
}
|
||||
}
|
||||
|
||||
status: #Status & {
|
||||
config: ctr.image.config
|
||||
name: application
|
||||
}
|
||||
}
|
38
pkg/alpha.dagger.io/argocd/tests/argocd.cue
Normal file
38
pkg/alpha.dagger.io/argocd/tests/argocd.cue
Normal file
@@ -0,0 +1,38 @@
|
||||
package argocd
|
||||
|
||||
import (
|
||||
"alpha.dagger.io/dagger"
|
||||
"alpha.dagger.io/os"
|
||||
)
|
||||
|
||||
TestConfig: argocdConfig: #Config & {
|
||||
version: dagger.#Input & {*"v2.0.5" | string}
|
||||
server: dagger.#Input & {*"dagger-example-argocd-server.tld" | string}
|
||||
basicAuth: {
|
||||
username: dagger.#Input & {*"admin" | string}
|
||||
password: dagger.#Input & {dagger.#Secret}
|
||||
}
|
||||
}
|
||||
|
||||
TestClient: os.#Container & {
|
||||
image: #CLI & {
|
||||
config: TestConfig.argocdConfig
|
||||
}
|
||||
command: #"""
|
||||
argocd account list | grep "$ARGOCD_USERNAME"
|
||||
"""#
|
||||
env: ARGOCD_USERNAME: TestConfig.argocdConfig.basicAuth.username
|
||||
}
|
||||
|
||||
TestApp: #App & {
|
||||
config: TestConfig.argocdConfig
|
||||
name: "daggerci-test"
|
||||
repo: "https://github.com/argoproj/argocd-example-apps.git"
|
||||
path: "guestbook"
|
||||
}
|
||||
|
||||
TestArgoCDStatus: #Sync & {
|
||||
config: TestApp.config
|
||||
application: TestApp.name
|
||||
wait: true
|
||||
}
|
14
pkg/alpha.dagger.io/argocd/tests/infra/infra.cue
Normal file
14
pkg/alpha.dagger.io/argocd/tests/infra/infra.cue
Normal file
@@ -0,0 +1,14 @@
|
||||
package infra
|
||||
|
||||
import (
|
||||
"alpha.dagger.io/dagger"
|
||||
"alpha.dagger.io/kubernetes"
|
||||
)
|
||||
|
||||
TestKubeconfig: dagger.#Input & {string}
|
||||
|
||||
TestArgoInfra: kubernetes.#Resources & {
|
||||
kubeconfig: TestKubeconfig
|
||||
namespace: "argocd"
|
||||
url: "https://raw.githubusercontent.com/argoproj/argo-cd/stable/manifests/install.yaml"
|
||||
}
|
Reference in New Issue
Block a user