Skip to content

Instantly share code, notes, and snippets.

@marcosborges
Last active April 6, 2019 00:52
Show Gist options
  • Save marcosborges/34508f4a22f6df576b515d33f009269d to your computer and use it in GitHub Desktop.
Save marcosborges/34508f4a22f6df576b515d33f009269d to your computer and use it in GitHub Desktop.
FROM google/cloud-sdk:alpine
RUN apk --update add openjdk7-jre
RUN gcloud components install app-engine-java kubectl
def _provisioningMysqlUserOnGcloud(host, instance, username, password) {
withCredentials([
file (credentialsId: 'GCLOUD_SA', variable: "GCLOUD_SA")
]){
configFileProvider(
[configFile(fileId: 'dockerfiles-gcloud-sdk.dockerfile', variable: 'GCLOUD_SDK_DOCKERFILE')]
) {
sh """ cp ${env.GCLOUD_SDK_DOCKERFILE} gCloudSDK.Dockerfile """
def gcloudSDK = docker.build("gcloud-sdk-kubectl", "-f gCloudSDK.Dockerfile .")
gcloudSDK.inside(""" -e "CLOUDSDK_CONFIG=/tmp/mygcloud" -e "KUBECONFIG=/tmp/mykubectl" """) {
def data = readJSON file: "${env.GCLOUD_SA}"
sh """ gcloud config set project ${data['project_id']} """
sh """ gcloud auth activate-service-account "${data['client_email']}" --key-file="${env.GCLOUD_SA}" --project="${data['project_id']}" """
try{
sh """ gcloud sql users create ${username} --host="${host}" --instance="${instance}" --password="${password}" """
return true
} catch(e) {
return false
}
}
}
}
}
node{
_provisioningMysqlUserOnGcloud(
"%",
"dev",
"new_user",
"new_user_password"
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment