diff --git a/Changelog.md b/Changelog.md index 59b6a3128981a6fc59d6d291e2c82b0a9090e7eb..1e1e5ebcb7991cdd6c6610f71b448aa42c978146 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,5 +1,12 @@ # Changelog +## [1.2.0] - 2018-09-05 +### Added +* `add-repo` command to add remote repositories + +### Changed +* increased timeout from 60 to 120 + ## [1.1.1] - 2018-08-14 ### Added * `--values` option to specify value overrides from YAML file @@ -13,3 +20,4 @@ [1.1.0]: https://git.sc.uni-leipzig.de/ubl/bdd_dev/webmasterei/deployer/compare/release%2F1.0.0...release%2F1.1.0 [1.1.1]: https://git.sc.uni-leipzig.de/ubl/bdd_dev/webmasterei/deployer/compare/release%2F1.1.0...release%2F1.1.1 +[1.2.0]: https://git.sc.uni-leipzig.de/ubl/bdd_dev/webmasterei/deployer/compare/release%2F1.1.1...release%2F1.2.0 diff --git a/Readme.md b/Readme.md index b6545b12585321afb6f443db11808a8b22d73dbd..3ef432e122be35f6a203820cccb20963fed8a40f 100644 --- a/Readme.md +++ b/Readme.md @@ -43,9 +43,9 @@ $ deployer deploy \ --cluster-url https://k8s-cluster.example.com:6443 \ --certificate-authority "$base64_encoded_cacert" \ --token "$base64_encoded_bearer_token" \ + --service-account tiller-service-account \ --name example-staging \ - --charts ./helmcharts \ - --service-account tiller-service-account + --charts ./helmcharts ``` *deploys helm-charts found at `./helmcharts` to namespace *example_namespace** @@ -63,11 +63,29 @@ $ deployer undeploy \ --cluster-url https://k8s-cluster.example.com:6443 \ --certificate-authority "$base64_encoded_cacert" \ --token "$base64_encoded_bearer_token" \ - --name example-staging \ - --service-account tiller-service-account + --service-account tiller-service-account \ + --name example-staging ``` *undeploys deployment named *example-staging* from namespace *example_namespace** +## deployer add-repo + +This command adds a public repository of helm-charts to choose from. The credentials are provided by the cluster-admin as well as the namespace and the service-account. + +``` +$ deployer deploy \ + --namespace example_namespace \ + --cluster-url https://k8s-cluster.example.com:6443 \ + --certificate-authority "$base64_encoded_cacert" \ + --token "$base64_encoded_bearer_token" \ + --service-account tiller-service-account \ + --name incubator \ + --repo-url https://kubernetes-charts-incubator.storage.googleapis.com/ +``` +*adds the *incubator* repository with the url https://kubernetes-charts-incubator.storage.googleapis.com/* + +From now on charts located in this repository can be deployed by using the `--charts` option and providing the chart prefixed by `incubator/`. + # Advanced Configuration ## docker build @@ -90,7 +108,7 @@ $ deployer undeploy \ * `--namespace`: sets the k8s-namespace where the deployment is located. This string is provided by the k8s-admin. * `--service-account`: this is the name of the service-account, that is used to perform the deployment. This string is provided by the k8s-admin * `--name`: sets the name of the deployment. -* `--charts`: sets the path where the helm-charts reside. +* `--charts`: sets the path where the helm-charts reside or the public chart e.g. `stable/maridb`. * `--values`: overrides the values from `Values.yaml` in the helm-charts with values in the specified YAML file. May be provided multiple times. * `--set`: overrides the values from `Values.yaml` in the helm-charts. Provide multiple `--set`-options if you want to provide multiple overrides. * `--set-string`: overrides the values from `Values.yaml` in the helm-charts as string. Provide multiple `--set-string`-options if you want to provide multiple overrides. @@ -104,6 +122,16 @@ $ deployer undeploy \ * `--service-account`: this is the name of the service-account, that is used to perform the deployment. This string is provided by the k8s-admin * `--name`: sets the name of the deployment. +## docker add-repo + +* `--cluster-url`: sets the url to the kube-apiserver. This URL is provided by the k8s-admin. +* `--certificate-authority`: sets the certificate-authority certificate as base64-encoded string. This string is provided by the k8s-admin +* `--token`: sets the bearer token of the service-account as bas64-encoded string. This string is provided by the k8s-admin. +* `--namespace`: sets the k8s-namespace where the deployment is located. This string is provided by the k8s-admin. +* `--service-account`: this is the name of the service-account, that is used to perform the deployment. This string is provided by the k8s-admin +* `--name`: sets the name of the repo to add. +* `--repo-url`: sets the repository-url of the repo to add. + # Assumptions This tool makes a few assumptions in order to simplify usage respecting the workflow and cluster-configuration principals if University Library Leipzig diff --git a/assets/deployer b/assets/deployer index cd3239cb266de414666534b69210f2f6634e83ff..ef5fcc0142dbac1a197541c266099592f1d504bf 100755 --- a/assets/deployer +++ b/assets/deployer @@ -11,7 +11,7 @@ ca_file="${HOME}/k8s-ca.crt" image_file="" dockerconfig="" tags="" -valueargs="" +helmargs="" buildargs="" charts="" name="" @@ -20,6 +20,7 @@ token="" namespace="" cluster_url="" service_account="" +repo_url="" ! getopt --test > /dev/null if [[ ${PIPESTATUS[0]} -ne 4 ]]; then @@ -28,7 +29,7 @@ if [[ ${PIPESTATUS[0]} -ne 4 ]]; then fi OPTIONS= -LONGOPTS=docker-config:,tag:,build-arg:,values:,set:,set-string:,charts:,name:,token:,certificate-authority:,namespace:,cluster-url:,service-account:,output:,input: +LONGOPTS=docker-config:,tag:,build-arg:,values:,set:,set-string:,charts:,name:,token:,certificate-authority:,namespace:,cluster-url:,service-account:,output:,input:,repo-url: # -use ! and PIPESTATUS to get exit code with errexit set # -temporarily store output to be able to check for errors @@ -59,7 +60,7 @@ while true; do shift 2 ;; -f|--values|-s|--set|--set-string) - valueargs="${valueargs} $1 $2" + helmargs="${helmargs} $1 $2" shift 2 ;; -c|--charts) @@ -98,6 +99,10 @@ while true; do image_file="$2" shift 2 ;; + --repo-url) + repo_url="$2" + shift 2 + ;; --) shift break @@ -201,7 +206,7 @@ prepare_kubectl() { prepare_helm() { echo -ne "Preparing helm..." - out=`helm init --wait --tiller-namespace="${namespace}" --service-account ${service_account} --force-upgrade` + out=`helm init --wait --tiller-namespace="${namespace}" --service-account="${service_account}" --upgrade --force-upgrade` if [ "$?" != "0" ];then echo "failed!" echo "$out" @@ -212,6 +217,33 @@ prepare_helm() { return 0 } +helm_add_repo() { + echo -ne "Adding repository \"${name}\" ..." + + if [ "${name}" == "" ];then + echo "failed" + echo "no repository name specified" + return 1 + fi + + if [ "${repo_url}" == "" ];then + echo "failed" + echo "no repository-url specified" + return 1 + fi + + local cmd="helm repo add --tiller-connection-timeout=120 --tiller-namespace=\"${namespace}\" ${name} ${repo_url}" + + local out=`$cmd 2>&1` + if [ "$?" != "0" ];then + echo "failed" + echo "$out" + return 1 + fi + + echo "done" +} + helm_deploy() { echo -ne "Deploying ${name}..." @@ -239,9 +271,9 @@ helm_deploy() { fi fi - valueargs=$(echo -e "$valueargs" | sed -E 's/(^[[:space:]]*)|([[:space:]]*$)//g') + helmargs=$(echo -e "$helmargs" | sed -E 's/(^[[:space:]]*)|([[:space:]]*$)//g') cmd="helm upgrade --install --wait --timeout=60 --tiller-namespace=${namespace}" - cmd="$cmd --namespace=${namespace} ${name} ${charts} ${valueargs}" + cmd="$cmd --namespace=${namespace} ${name} ${charts} ${helmargs}" out=`$cmd 2>&1` if [ "$?" != "0" ];then @@ -264,7 +296,7 @@ helm_undeploy() { local out - out=`helm delete --tiller-namespace=${namespace} ${name} 2>&1` + out=`helm delete --tiller-namespace="${namespace}" ${name} 2>&1` if [ "$?" != "0" ];then echo "failed" @@ -410,6 +442,9 @@ case $1 in publish) prepare_image_publisher && import_image && publish_image ;; + add-repo) + prepare_kubectl && prepare_helm && helm_add_repo + ;; deploy) prepare_kubectl && prepare_helm && helm_deploy ;; diff --git a/docker-compose.yml b/docker-compose.yml index c38fbc1ae9781c2b94f301637e7300278196c593..4220e90fc3103de751f5979b78fe4242068b93c8 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -31,7 +31,7 @@ services: - docker environment: DOCKER_HOST: tcp://docker:2375 - command: deployer deploy --namespace test --cluster-url https://172.18.85.125:6443 --certificate-authority ${ca_cert} --token ${token} --name testdeploy --charts ./examplechart --service-account test --set image.tag=stable + command: deployer deploy --namespace test --cluster-url https://172.18.85.125:6443 --certificate-authority ${ca_cert} --token ${token} --service-account test --name testdeploy --charts ./examplechart --set image.tag=stable undeploy: build: . @@ -42,7 +42,18 @@ services: - docker environment: DOCKER_HOST: tcp://docker:2375 - command: deployer undeploy --namespace test --cluster-url https://172.18.85.125:6443 --certificate-authority ${ca_cert} --token ${token} --name testdeploy --service-account test + command: deployer undeploy --namespace test --cluster-url https://172.18.85.125:6443 --certificate-authority ${ca_cert} --token ${token} --service-account test --name testdeploy + + add-repo: + build: . + volumes: + - ./:/app + - ./assets/deployer:/usr/local/bin/deployer + depends_on: + - docker + environment: + DOCKER_HOST: tcp://docker:2375 + command: deployer add-repo --namespace test --cluster-url https://172.18.85.125:6443 --certificate-authority ${ca_cert} --token ${token} --service-account test --name test --repo-url https://kubernetes-charts.storage.googleapis.com docker: image: docker:dind