Last active
February 6, 2019 18:26
-
-
Save diegograssato/bd67c0b72a4848e9cdca599ba535b6f6 to your computer and use it in GitHub Desktop.
Env with minikube
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import javaposse.jobdsl.plugin.* | |
def REPOSITORY = "https://github.com/diegograssato/simple-java-maven-app.git" | |
def REGION = 'us-east-1' | |
def ECR_ID = 'XXXXX' | |
def LABEL = "worker-${UUID.randomUUID().toString()}" | |
def REGISTRY = "${ECR_ID}.dkr.ecr.${REGION}.amazonaws.com" | |
def REGISTRY_CREDENTIAL = 'demo-ecr-credentials' | |
def IMAGE_NAME = 'WILL BE MODIFIED IN THE FIRST STEP' | |
def HELM_CHART = 'WILL BE MODIFIED IN THE FIRST STEP' | |
def TAG = 'WILL BE MODIFIED IN THE FIRST STEP' | |
def SHORT_COMMIT = 'WILL BE MODIFIED IN THE FIRST STEP' | |
def IMAGE_PULL_SECRET = "${REGION}-ecr-registry" | |
podTemplate(label: LABEL, containers: [ | |
containerTemplate(name: 'docker', image: 'docker', command: 'cat', ttyEnabled: true), | |
containerTemplate(name: 'maven', image: 'maven:3.3.9-jdk-8-alpine', ttyEnabled: true, command: 'cat'), | |
containerTemplate(name: 'helm', image: 'lachlanevenson/k8s-helm:v2.11.0', command: 'cat', ttyEnabled: true), | |
containerTemplate(name: 'kubectl', image: 'lachlanevenson/k8s-kubectl:v1.8.8', command: 'cat', ttyEnabled: true), | |
], | |
volumes: [ | |
hostPathVolume(mountPath: '/var/run/docker.sock', hostPath: '/var/run/docker.sock'), | |
] | |
) { | |
node(LABEL) { | |
stage('Cloning project') { | |
git url: REPOSITORY , branch: 'master' | |
//Populate the values provide by pom.xml | |
TAG = readMavenPom().getVersion() | |
IMAGE_NAME = readMavenPom().getName() | |
//Populate the values provide by package.json | |
// packageJSON = readJSON file: 'package.json' | |
// TAG = packageJSON.version | |
// IMAGE_NAME = packageJSON.name | |
HELM_CHART = "${IMAGE_NAME}-deploy" | |
sh 'git rev-parse HEAD > GIT_COMMIT' | |
SHORT_COMMIT = readFile('GIT_COMMIT').take(6) | |
echo "*** Build [ ${HELM_CHART} ] version [ ${TAG} ] commit [ ${SHORT_COMMIT} ]" | |
} | |
container('docker') { | |
stage('Deploying to AWS ECR') { | |
echo "*** Deploying to AWS ECR [ ${REGISTRY}/${IMAGE_NAME}:${TAG} ]" | |
docker.withRegistry("https://${REGISTRY}", "ecr:${REGION}:${REGISTRY_CREDENTIAL}") { | |
def customImage = docker.build(IMAGE_NAME) | |
customImage.push(TAG) | |
//customImage.push('latest') | |
} | |
} | |
stage('Remove Unused docker image') { | |
sh "docker rmi ${REGISTRY}/${IMAGE_NAME}:${TAG} | true" | |
sh "docker rmi ${IMAGE_NAME} | true" | |
} | |
} | |
stage('Deploy on K8s') { | |
container('helm') { | |
dir(".build"){ | |
echo "Deploy [ ${IMAGE_NAME}:${TAG} ] on K8s using chart [ ${HELM_CHART} ]" | |
sh """ | |
helm upgrade --install ${HELM_CHART} \ | |
--set image.tag=${TAG} \ | |
--set image.repository=${REGISTRY}/${IMAGE_NAME} \ | |
--set image.imagePullSecrets=${IMAGE_PULL_SECRET} \ | |
--set image.pullPolicy=Always \ | |
${HELM_CHART} | |
""" | |
} | |
} | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
echo -e "\nInstall minikube" | |
minikube start \ | |
--network-plugin=cni \ | |
--vm-driver=kvm2 --memory 4096 --cpus 4 \ | |
--bootstrapper=kubeadm | |
sleep 30 | |
if (! which helm > /dev/null); then | |
## Install helm | |
echo -e "\nInstall helm" | |
curl https://raw.githubusercontent.com/helm/helm/master/scripts/get > get_helm.sh | |
chmod 700 get_helm.sh | |
sudo ./get_helm.sh | |
helm init | |
sleep 10 | |
rm get_helm.sh | |
fi | |
# Configurando tiller client | |
echo -e "\nConfigure tiller" | |
kubectl -n kube-system create sa tiller \ | |
&& kubectl create clusterrolebinding tiller \ | |
--clusterrole cluster-admin \ | |
--serviceaccount=kube-system:tiller | |
helm init --skip-refresh --upgrade --service-account tiller | |
echo -e "\nConfigure ingress" | |
kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/master/deploy/mandatory.yaml | |
kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/master/deploy/provider/cloud-generic.yaml | |
minikube addons enable ingress | |
echo -e "\nConfigure dashboard" | |
minikube addons enable dashboard | |
kubectl get pods -n ingress-nginx | |
kubectl create namespace stage | |
kubectl create namespace prod |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment