164 lines
5.7 KiB
Plaintext
164 lines
5.7 KiB
Plaintext
use ~/bin/nu_scripts/bm.nu
|
|
use ~/bin/nu_scripts/hl.nu
|
|
use ~/bin/nu_scripts/kube.nu
|
|
use std log
|
|
|
|
# == Environment ==
|
|
def project-root [] { bm find XtractionStudioBackend }
|
|
def helm-project-name [] { "xs-backend" }
|
|
def build-host-path [] { "workingdirs/xtractionstudio" }
|
|
|
|
export def component-definitions [] {
|
|
[
|
|
{app: demo, deployment: xs-demo, target: "pushDemoImage"},
|
|
{app: logging-proxy, deployment: xs-logging-proxy, target: "pushLoggingProxyImage"},
|
|
{app: backend, deployment: xs-backend},
|
|
{app: ducklingClient, deployment: xs-duckling},
|
|
{app: flairClient, deployment: xs-flair},
|
|
{app: imageRenderer, deployment: xs-image-renderer},
|
|
{app: languageExtractor, deployment: xs-language-extractor},
|
|
{app: ocrService, deployment: xs-ocr-service},
|
|
{app: addressExtractor, deployment: xs-address-extractor},
|
|
{app: steward, deployment: xs-steward},
|
|
{app: statisticsService, deployment: xs-statistics-creator},
|
|
{app: bankExtractor, deployment: xs-bank-extractor},
|
|
{app: scriptExtractor, deployment: xs-script-extractor},
|
|
]
|
|
}
|
|
|
|
def comp-app-name [] {
|
|
apps
|
|
}
|
|
|
|
def apps [] {
|
|
component-definitions | get app
|
|
}
|
|
|
|
def find-app-target [app_name:string] {
|
|
component-definitions | where app == $app_name | first | get -i target | default $"apps:($app_name):dockerPushImage"
|
|
}
|
|
|
|
def environments [] {
|
|
[
|
|
{
|
|
name: "dev",
|
|
docker_repo: "xtractionstudio-docker.insiders-technologies.de",
|
|
helm_target: "Development",
|
|
needs_aws_login: false,
|
|
build_host: "lyssa",
|
|
},
|
|
{
|
|
name: "aws-test",
|
|
docker_repo: "047349208615.dkr.ecr.eu-central-1.amazonaws.com",
|
|
helm_target: "Awstest",
|
|
needs_aws_login: true,
|
|
build_host: "gitlab-build-host",
|
|
},
|
|
{
|
|
name: "aws-prod",
|
|
docker_repo: "047349208615.dkr.ecr.eu-central-1.amazonaws.com",
|
|
helm_target: "Awsprod",
|
|
needs_aws_login: true,
|
|
build_host: "gitlab-build-host",
|
|
},
|
|
]
|
|
}
|
|
|
|
def find-environment [] {
|
|
let name = $in
|
|
environments | where name == $name | first
|
|
}
|
|
|
|
# == Completitions ==
|
|
def comp-environment-name [] {
|
|
environments | get name
|
|
}
|
|
|
|
|
|
# == Externals ==
|
|
def call_gradle [args] {
|
|
let gradle_wrapper = ([(project-root), "gradlew"] | path join)
|
|
log debug $"use gradle_wrapper location: ($gradle_wrapper)"
|
|
run-external $gradle_wrapper $args
|
|
}
|
|
|
|
def sync [environment] {
|
|
print $"sync with ($environment.build_host)"
|
|
run-external "rsync" "-avP" "--delete" "--filter=:- .gitignore" "--exclude" .git $"(project-root)/" $"($environment.build_host):(build-host-path)"
|
|
}
|
|
|
|
def remote_aws_login [$environment] {
|
|
ssh ($environment.build_host) -t $"aws ecr get-login-password --region eu-central-1 | docker login --username AWS --password-stdin ($environment.docker_repo)"
|
|
}
|
|
|
|
def remote_gradle [environment, args:list<string>] {
|
|
print $"execute gradle with args: ($args)"
|
|
ssh $environment.build_host -t $"cd (build-host-path) ; EXCLUDE_PUSH_IMAGE=yes ./gradlew ($args | str join ' ')"
|
|
}
|
|
|
|
def build-on-host [environment, apps:list<string>] {
|
|
# let gradle_targets = ($apps | each {|app| find-app-target $app })
|
|
execute-gradle-task-on-env $environment "pushAllToDev"
|
|
}
|
|
|
|
def execute-gradle-task-on-env [environment, task:string] {
|
|
let gradle_args = (["--project-prop", $"docker.repo=($environment.docker_repo)", "--parallel"] | append $task)
|
|
if ($environment.needs_aws_login) {
|
|
remote_aws_login $environment
|
|
}
|
|
remote_gradle $environment $gradle_args
|
|
}
|
|
|
|
def helm-deploy [environment] {
|
|
print "Install helm app"
|
|
remote_gradle $environment [$"helmInstallXsBackendTo($environment.helm_target)"]
|
|
}
|
|
# build and pushing the image without changing the k8 chart
|
|
export def "push images" [environment_name:string@comp-environment-name] {
|
|
let environment = ($environment_name | find-environment)
|
|
cd (project-root)
|
|
build-on-host $environment (apps)
|
|
}
|
|
|
|
# install the complete helm app the the choosen environment, building all container
|
|
export def "full" [environment_name:string@comp-environment-name] {
|
|
let environment = ($environment_name | find-environment)
|
|
cd (project-root)
|
|
sync $environment
|
|
build-on-host $environment (apps)
|
|
helm-deploy $environment
|
|
}
|
|
|
|
# execute a single gradle task on remote machine
|
|
export def "task" [environment_name:string@comp-environment-name, task:string] {
|
|
let environment = ($environment_name | find-environment)
|
|
cd (project-root)
|
|
sync $environment
|
|
execute-gradle-task-on-env $environment $task
|
|
}
|
|
|
|
# only install the current helm chart (without building and pushing the images)
|
|
export def "helm app" [environment_name:string@comp-environment-name] {
|
|
let environment = ($environment_name | find-environment)
|
|
cd (project-root)
|
|
sync $environment
|
|
helm-deploy $environment
|
|
}
|
|
|
|
# update single deployments i.e. pushing the docker image and restart the deployment
|
|
export def "update app" [environment_name:string@comp-environment-name, app_name:string@comp-app-name] {
|
|
let environment = ($environment_name | find-environment)
|
|
cd (project-root)
|
|
sync $environment
|
|
build-on-host $environment [$app_name]
|
|
let component = (component-definitions | where app == $app_name | first)
|
|
print $"restart k8s deployment ($component.deployment)"
|
|
kube deployment restart $component.deployment
|
|
}
|
|
|
|
export def "sync code" [environment_name:string@comp-environment-name] {
|
|
let environment = ($environment_name | find-environment)
|
|
cd (project-root)
|
|
sync $environment
|
|
}
|