helm + jenkins

This commit is contained in:
Edward Viaene
2018-08-03 13:36:02 +00:00
parent 5ef3428269
commit a16ccb0d9a
5 changed files with 126 additions and 1 deletions

View File

@@ -0,0 +1,34 @@
pipeline {
agent {
kubernetes {
label 'helm-pod'
containerTemplate {
name 'helm'
image 'wardviaene/helm-s3'
ttyEnabled true
command 'cat'
}
}
}
stages {
stage('Run helm') {
steps {
container('helm') {
git url: 'git://github.com/wardviaene/kubernetes-course.git', branch: 'master'
sh '''
HELM_BUCKET=helm-rytcufor
PACKAGE=demo-chart
export AWS_REGION=eu-west-1
cp -r /home/helm/.helm ~
helm repo add my-charts s3://${HELM_BUCKET}/charts
cd helm/${PACKAGE}
helm dependency update
helm package .
helm s3 push --force ${PACKAGE}-*.tgz my-charts
'''
}
}
}
}
}

View File

@@ -0,0 +1,46 @@
pipeline {
agent {
kubernetes {
label 'helm-pod'
defaultContainer 'jnlp'
yaml """
apiVersion: v1
kind: Pod
metadata:
labels:
some-label: helm-pod
spec:
serviceAccount: jenkins
containers:
- name: helm-pod
image: wardviaene/helm-s3
command:
- cat
tty: true
"""
}
}
stages {
stage('Run helm') {
steps {
container('helm-pod') {
git url: 'git://github.com/wardviaene/kubernetes-course.git', branch: 'master'
sh '''
HELM_BUCKET=helm-rytcufor
PACKAGE=demo-chart
export AWS_REGION=eu-west-1
cp -r /home/helm/.helm ~
helm repo add my-charts s3://${HELM_BUCKET}/charts
DEPLOYED=$(helm list |grep -E "^${PACKAGE}" |grep DEPLOYED |wc -l)
if [ $DEPLOYED == 0 ] ; then
helm install --name ${PACKAGE} my-charts/${PACKAGE}
else
helm upgrade ${PACKAGE} my-charts/${PACKAGE}
fi
'''
}
}
}
}
}

4
helm/jenkins/README.md Normal file
View File

@@ -0,0 +1,4 @@
# install jenkins
```
helm install --name jenkins --set rbac.install=true,Master.RunAsUser=1000,Master.FsGroup=1000 stable/jenkins
```

32
helm/put-bucket-policy.sh Executable file
View File

@@ -0,0 +1,32 @@
#!/bin/bash
DEFAULT_REGION="eu-west-1"
AWS_REGION="${AWS_REGION:-${DEFAULT_REGION}}"
BUCKET="helm-rytcufor"
NODE_ROLE_ARN="arn:aws:iam::*"
export AWS_REGION
aws s3api put-bucket-policy --bucket ${BUCKET} --policy '{
"Statement": [
{
"Effect": "Allow",
"Principal": {
"AWS": "'${NODE_ROLE_ARN}'"
},
"Action": [
"s3:GetObject",
"s3:PutObject"
],
"Resource": "arn:aws:s3:::'${BUCKET}'/*"
},
{
"Effect": "Allow",
"Principal": {
"AWS": "'${NODE_ROLE_ARN}'"
},
"Action": "s3:ListBucket",
"Resource": "arn:aws:s3:::'${BUCKET}'"
}
]
}'

View File

@@ -2,18 +2,27 @@
set -e
# create random string
RANDOM_STRING=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 8 | tr '[:upper:]' '[:lower:]' | head -n 1)
# it's important to set the AWS_REGION if not set. Change the default
DEFAULT_REGION="eu-west-1"
AWS_REGION="${AWS_REGION:-${DEFAULT_REGION}}"
export AWS_REGION
# create s3 bucket
if [ "$AWS_REGION" == "us-east-1" ] ; then
aws s3api create-bucket --bucket helm-${RANDOM_STRING}
else
aws s3api create-bucket --bucket helm-${RANDOM_STRING} --region $AWS_REGION --create-bucket-configuration LocationConstraint=${AWS_REGION}
fi
# install helm s3 plugin
helm plugin install https://github.com/hypnoglow/helm-s3.git
# initialize s3 bucket
helm s3 init s3://helm-${RANDOM_STRING}/charts
helm repo add my-charts s3://helm-lcxqoc24/charts
# add repository to helm
helm repo add my-charts s3://helm-${RANDOM_STRING}/charts