pipeline { agent any stages { stage('build') { steps { checkout scm script { sh 'git rev-parse HEAD > commit' def gitCommit = readFile('commit').trim() def kubeCa = "LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUN5RENDQWJDZ0F3SUJBZ0lCQURBTkJna3Foa2lHOXcwQkFRc0ZBREFWTVJNd0VRWURWUVFERXdwcmRXSmwKY201bGRHVnpNQjRYRFRJd01ETXlNVEU0TkRrd05Wb1hEVE13TURNeE9URTRORGt3TlZvd0ZURVRNQkVHQTFVRQpBeE1LYTNWaVpYSnVaWFJsY3pDQ0FTSXdEUVlKS29aSWh2Y05BUUVCQlFBRGdnRVBBRENDQVFvQ2dnRUJBTklWClJoaDMzVVd2Yk4vS0VzZTFSY2tkM0R0VitmR251RC9yOVhmdU1BRThzaW9vT1gwQjVzcjdOVi9TWFA2dDB0ak8KQkRTRnJpODczejd0SWtMcktvNmFWNGpOcDdNUXNDbllydk9ob0EwWnJIdmpmbUljbFlXRnhwclNWWkFRZ1JpbgpiU2VRMkY2d3MwdnlTSjluMy8zTmV2RlRHT0V5WVBjWko0cGZCNjJnWkk5OFR6ZU9NWTV0QWJRQmJsRW0wdGx6ClVJSWJYTmhCVXNnWnZxU3dwTG5LMHorUVBsdkRRd0FLRCt6dmNmdlZaQk1tNGZ1bFprYkxHdGNUbUtBcVhQMWQKbGtkMUxYN205cEVoUDhKVGUvVW9WWWh5ZTRRNG0xbWQvTHgrNXJUTEg0TXBjYkV0dTR0MklPZjZTZ0l2WkJ0dwpIbnRuVG1HMTdQdjJUUzJ4WWEwQ0F3RUFBYU1qTUNFd0RnWURWUjBQQVFIL0JBUURBZ0trTUE4R0ExVWRFd0VCCi93UUZNQU1CQWY4d0RRWUpLb1pJaHZjTkFRRUxCUUFEZ2dFQkFBYkRpOXZNT085akN0WGU5WCtHNDZGdkpnVEgKMkVQb2NOUDdIcHZGNFYzQVd4eWRSaGZSK2o1eHRldG1sem5uNktjVE41WUVoenE2VXVGMlpPS1NjVUp0Yi8ydgpnQVhCTjF3SVdSZ0p2bWdVTTRLVVVwc1FpWjRsY0o1TS9IT1ByZmJrL21pdERzd01XZDlIVTZ3ZVN4NVJ6eVFGCmEvNVhtSGlSUTZRc1Q2SnovMGNIQmNCbjMwRkZCTzVudVdRMjRnVjNBTlE2NXUvUFhkalBwRExBT3d6bmV4QmYKRUZLMk1aNC9Nd0xNUjlDcGk3TWovWHUwVkxLTWhUWVVCSWQwQ0EwMllKems1RzVSbmpZVlRxWnp3L2QvaUVXQQpta1k3d1Y2d0tUV25jRDM1MVlmWjJtWGtGa293WGVDL1lHVVpEQmUza0hlQTJRVFFkMmEzMEt6dnpvOD0KLS0tLS1FTkQgQ0VSVElGSUNBVEUtLS0tLQo=" def kubeUrl = "https://45.79.61.115:443" def appName = "fetch-dht" def imagePullSecret = "registry-terrible-netowrk-pull-secret" // typo is purposeful def kubectl = docker.image("bitnami/kubectl:1.18") def registryHost = "registry.terrible.network" def imageName = "${registryHost}/terribleplan/${appName}" // build def app = docker.build("${imageName}:${gitCommit}") def betaTag = "beta" def betaImageName = "${imageName}:${betaTag}" def betaAppName = "${appName}-beta" def betaHost = "${betaAppName}.terrible.network" // beta push docker.withRegistry("https://${registryHost}", "registry-terrible-network") { app.push(betaTag) } // beta deploy kubectl.inside("--entrypoint=''") { env.NAMESPACE = betaAppName sh "set -eu" sh "install_packages gettext" sh "set -eu" sh "mkdir -p ~/.kube" withCredentials([string(credentialsId: 'fetch-dht-beta-token', variable: 'token')]) { sh "cat deploy/kubeconfig.envsubst.yml | CA='${kubeCa}' URL='${kubeUrl}' TOKEN='${token}' envsubst '\$CA,\$URL,\$TOKEN,\$NAMESPACE' > ~/.kube/config" } sh "cat deploy/manifest.envsubst.yml | HOST='${betaHost}' IMAGE_PULL_SECRET='${imagePullSecret}' IMAGE='${betaImageName}' APP_NAME='${betaAppName}' REVISION='${gitCommit}' envsubst '\$NAMESPACE,\$HOST,\$IMAGE_PULL_SECRET,\$IMAGE,\$APP_NAME,\$REVISION' | kubectl apply -f -" sh "kubectl rollout status 'deployments/${betaAppName}'" } // beta integration app.inside { sh "set -eu" sh "cp package.json /app/package.json" sh "cp yarn.lock /app/yarn.lock" sh "cd /app && yarn" sh "cd /app && ENDPOINT='https://${betaHost}' node integration.js" } def prodTag = "latest" def prodImageName = "${imageName}:${prodTag}" def prodHost = "dht.terrible.network" // push docker.withRegistry("https://${registryHost}", "registry-terrible-network") { app.push(prodTag) } // deploy kubectl.inside("--entrypoint=''") { env.NAMESPACE = appName sh "set -eu" sh "install_packages gettext" sh "set -eu" sh "mkdir -p ~/.kube" withCredentials([string(credentialsId: 'fetch-dht-prod-token', variable: 'token')]) { sh "cat deploy/kubeconfig.envsubst.yml | CA='${kubeCa}' URL='${kubeUrl}' TOKEN='${token}' envsubst '\$CA,\$URL,\$TOKEN,\$NAMESPACE' > ~/.kube/config" } sh "cat deploy/manifest.envsubst.yml | HOST='${prodHost}' IMAGE_PULL_SECRET='${imagePullSecret}' IMAGE='${prodImageName}' APP_NAME='${appName}' REVISION='${gitCommit}' envsubst '\$NAMESPACE,\$HOST,\$IMAGE_PULL_SECRET,\$IMAGE,\$APP_NAME,\$REVISION' | kubectl apply -f -" sh "kubectl rollout status 'deployments/${appName}'" } // integration app.inside { sh "set -eu" sh "cp package.json /app/package.json" sh "cp yarn.lock /app/yarn.lock" sh "cd /app && yarn" sh "cd /app && ENDPOINT='https://${prodHost}' node integration.js" } } } } } }