Split definition into files and add #App to create argocd project

Signed-off-by: Tom Chauveau <tom.chauveau@epitech.eu>
This commit is contained in:
Tom Chauveau 2021-09-09 13:00:23 +02:00 committed by Sam Alba
parent f038e11fc5
commit b136cdcaaf
3 changed files with 94 additions and 58 deletions

47
stdlib/argocd/app.cue Normal file
View File

@ -0,0 +1,47 @@
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}
_ctr: os.Container & {
from: #CLI & {
"config": config
}
command: #"""
argocd app create "$APP_NAME" \
--repo "$APP_REPO" \
--path "$APP_PATH" \
--dest-server "$APP_SERVER" \
--dest-namespace "$APP_NAMESPACE"
"""#
env: {
APP_NAME: name
APP_REPO: repo
APP_PATH: path
APP_SERVER: server
APP_NAMESPACE: namespace
}
}
}

View File

@ -1,15 +1,14 @@
// ArgoCD applications
package app
package argocd
import (
"alpha.dagger.io/argocd"
"alpha.dagger.io/dagger"
"alpha.dagger.io/dagger/op"
)
// Get an application
#Application: {
config: argocd.#Config
// Get application's status
#Status: {
// ArgoCD configuration
config: #Config
// ArgoCD application
name: dagger.#Input & {string}
@ -37,7 +36,7 @@ import (
outputs: #up: [
op.#Load & {
from: argocd.#CLI & {
from: #CLI & {
"config": config
}
},
@ -45,10 +44,15 @@ import (
op.#Exec & {
args: ["sh", "-c",
#"""
ls ~/.argocd
cat ~/.argocd/config
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
env: {
APPLICATION: name
ARGOCD_OPTS: "--port-forward-namespace argocd"
}
},
op.#Export & {
@ -57,53 +61,3 @@ import (
},
]
}
// Sync an application to its target state
#Synchronization: {
config: argocd.#Config
// ArgoCD application
application: dagger.#Input & {string}
#up: [
op.#Load & {
from: argocd.#CLI & {
"config": config
}
},
op.#Exec & {
args: [
"sh", "-c", #"""
argocd app sync "$APPLICATION"
"""#,
]
env: APPLICATION: application
},
]
}
// Wait for an application to reach a synced and healthy state
#SynchronizedApplication: {
config: argocd.#Config
// ArgoCD application
application: dagger.#Input & {string}
#up: [
op.#Load & {
from: argocd.#CLI & {
"config": config
}
},
op.#Exec & {
args: [
"sh", "-c", #"""
argocd app wait "$APPLICATION"
"""#,
]
env: APPLICATION: application
},
]
}

35
stdlib/argocd/sync.cue Normal file
View File

@ -0,0 +1,35 @@
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
"""#
env: APPLICATION: application
if wait {
env: WAIT_FLAG: "wait"
}
}
}