#!groovy def repository = "registry.c.test-chamber-13.lan" def repositoryCreds = "harbor-repository-creds" def workspace def bitbetterCert = "bitbetter-certificate" def bitwardenVersion def label = "kubernetes-${UUID.randomUUID().toString()}" def templateName = "pipeline-worker" pipeline { agent { kubernetes { yaml functions.podYaml( repo: repository, templateName: templateName, alpine: true, kaniko: true, [ [ name: "dotnet", path: "${repository}/microsoft/dotnet/sdk:6.0", command: "/bin/bash" ] ] ) } } stages { stage ("Prepare") { steps { script { workspace = pwd() dir("bitbetter") { checkout ([ $class: "GitSCM", branches: [ [ name: "refs/heads/master", ], ], userRemoteConfigs: [ [ url: "ssh://git@gitea.c.test-chamber-13.lan:31822/nhyatt/BitBetter.git", credentialsId: "Gitea-Read-Only-Token", ], ], extensions: [ [ $class: "CloneOption", shallow: true, ], [ $class: "CheckoutOption", timeout: 2, ], ], ]) } } container ("alpine") { script { withCredentials([file( credentialsId: bitbetterCert, variable: "FILE", )]) { environment { WORKSPACE = workspace } sh 'cp "${FILE}" "${WORKSPACE}/bitbetter/.keys/cert.cert"' } sh """ if [ ! -f "/usr/bin/curl" ] || [ ! -x "/usr/bin/curl" ]; then apk add --no-cache curl fi mkdir "${WORKSPACE}/bitbetter/src/bitBetter/.keys" cp "${WORKSPACE}/bitbetter/.keys/cert.cert" "${WORKSPACE}/bitbetter/src/bitBetter/.keys/cert.cert" """ bitwardenVersion = sh ( script: """ curl --silent \\ --location \\ "https://go.btwrdn.co/bw-sh-versions" | \\ grep '^ *"'coreVersion'":' | \\ awk -F\\: '{ print \$2 }' | \\ sed -e 's/,\$//' -e 's/^"//' -e 's/"\$//' """, returnStdout: true ).trim() } } } } stage ("Compile") { steps { container ("dotnet") { script { sh """ cd "${workspace}/bitbetter/src/bitBetter" ./build.sh """ } } } } stage ("Build API") { steps { container ("kaniko") { script { withCredentials([usernameColonPassword( credentialsId: repositoryCreds, variable: "dCreds" )]) { sh "set +x; printf '{\"auths\":{\"%s\":{\"auth\": \"%s\"}}}' \"${repository}\" \"${dcreds.bytes.encodeBase64().toString()}\" > /kaniko/.docker/config.json" } sh """ /kaniko/executor \\ --force \\ --context "${workspace}/bitbetter/src/bitBetter/" \\ -f "${workspace}/bitbetter/src/bitBetter/Dockerfile" \\ --destination "${repository}/library/bitbetter-api:${bitwardenVersion}" \\ --destination "${repository}/library/bitbetter-api:latest" \\ --build-arg "BITWARDEN_TAG=bitwarden/api:${bitwardenVersion}" """ } } } } stage ("Build Identity") { steps { container ("kaniko") { script { withCredentials([usernameColonPassword( credentialsId: repositoryCreds, variable: "dCreds" )]) { sh "set +x; printf '{\"auths\":{\"%s\":{\"auth\": \"%s\"}}}' \"${repository}\" \"${dcreds.bytes.encodeBase64().toString()}\" > /kaniko/.docker/config.json" } sh """ /kaniko/executor \\ --force \\ --context "${workspace}/bitbetter/src/bitBetter/" \\ -f "${workspace}/bitbetter/src/bitBetter/Dockerfile" \\ --destination "${repository}/library/bitbetter-identity:${bitwardenVersion}" \\ --destination "${repository}/library/bitbetter-identity:latest" \\ --build-arg "BITWARDEN_TAG=bitwarden/identity:${bitwardenVersion}" """ } } } } } }