Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
No results found
Show changes
Commits on Source (1)
# Changelog # Changelog
## [1.4.4] - 2019-03-18
### Added
* debug-option which outputs executed commands and their arguments
* `--pull` to always try to pull newer images before building
### Fixed
* Dockerfile is now context-sensitive when not specified explicitly (default docker-behaviour)
## [1.4.3] - 2019-03-14 ## [1.4.3] - 2019-03-14
### Added ### Added
* option to specify the path to the Dockerfile * option to specify the path to the Dockerfile
...@@ -86,4 +94,5 @@ ...@@ -86,4 +94,5 @@
[1.4.0]: https://git.sc.uni-leipzig.de/ubl/bdd_dev/webmasterei/deployer/compare/release%2F1.3.2...release%2F1.4.0 [1.4.0]: https://git.sc.uni-leipzig.de/ubl/bdd_dev/webmasterei/deployer/compare/release%2F1.3.2...release%2F1.4.0
[1.4.1]: https://git.sc.uni-leipzig.de/ubl/bdd_dev/webmasterei/deployer/compare/release%2F1.4.0...release%2F1.4.1 [1.4.1]: https://git.sc.uni-leipzig.de/ubl/bdd_dev/webmasterei/deployer/compare/release%2F1.4.0...release%2F1.4.1
[1.4.2]: https://git.sc.uni-leipzig.de/ubl/bdd_dev/webmasterei/deployer/compare/release%2F1.4.1...release%2F1.4.2 [1.4.2]: https://git.sc.uni-leipzig.de/ubl/bdd_dev/webmasterei/deployer/compare/release%2F1.4.1...release%2F1.4.2
[1.4.3]: https://git.sc.uni-leipzig.de/ubl/bdd_dev/webmasterei/deployer/compare/release%2F1.4.2...release%2F1.4.3 [1.4.3]: https://git.sc.uni-leipzig.de/ubl/bdd_dev/webmasterei/deployer/compare/release%2F1.4.2...release%2F1.4.3
\ No newline at end of file [1.4.4]: https://git.sc.uni-leipzig.de/ubl/bdd_dev/webmasterei/deployer/compare/release%2F1.4.3...release%2F1.4.4
\ No newline at end of file
...@@ -97,6 +97,7 @@ From now on charts located in this repository can be deployed by using the `--ch ...@@ -97,6 +97,7 @@ From now on charts located in this repository can be deployed by using the `--ch
* `--namespace`: sets the k8s-namespace where the deployment is located. 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. * `--service-account`: this is the name of the service-account, that is used to perform the deployment.
* `--reset`: this ignores eventually existing config-folders of docker, helm and kubectl and removes them. * `--reset`: this ignores eventually existing config-folders of docker, helm and kubectl and removes them.
* `--debug`: outputs executed commands
## docker build ## docker build
...@@ -107,6 +108,8 @@ From now on charts located in this repository can be deployed by using the `--ch ...@@ -107,6 +108,8 @@ From now on charts located in this repository can be deployed by using the `--ch
* `--reset`: this ignores eventually existing config-folders of docker, helm and kubectl and removes them. * `--reset`: this ignores eventually existing config-folders of docker, helm and kubectl and removes them.
* `--image-name`: sets the image name in the local docker-registry. Can be useful for following builds to build upon existing builds * `--image-name`: sets the image name in the local docker-registry. Can be useful for following builds to build upon existing builds
* `--docker-file`: sets the path to the Dockerfile * `--docker-file`: sets the path to the Dockerfile
* `--pull`: tells docker to always pull newer images before building
* `--debug`: outputs executed commands
## docker publish ## docker publish
...@@ -116,6 +119,7 @@ From now on charts located in this repository can be deployed by using the `--ch ...@@ -116,6 +119,7 @@ From now on charts located in this repository can be deployed by using the `--ch
* `--tags`: sets the tags of the image. Provide multiple `--tag`-options if you wish to tag an image with multiple tags. * `--tags`: sets the tags of the image. Provide multiple `--tag`-options if you wish to tag an image with multiple tags.
* `--reset`: this ignores eventually existing config-folders of docker, helm and kubectl and removes them. * `--reset`: this ignores eventually existing config-folders of docker, helm and kubectl and removes them.
* `--image-name`: specifys the image name in the local docker-registry to publish * `--image-name`: specifys the image name in the local docker-registry to publish
* `--debug`: outputs executed commands
## docker deploy ## docker deploy
...@@ -131,6 +135,7 @@ From now on charts located in this repository can be deployed by using the `--ch ...@@ -131,6 +135,7 @@ From now on charts located in this repository can be deployed by using the `--ch
* `--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. * `--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.
* `--timeout`: sets the timeout for helm. defaults to `60` seconds. * `--timeout`: sets the timeout for helm. defaults to `60` seconds.
* `--reset`: this ignores eventually existing config-folders of docker, helm and kubectl and removes them. * `--reset`: this ignores eventually existing config-folders of docker, helm and kubectl and removes them.
* `--debug`: outputs executed commands
## docker undeploy ## docker undeploy
...@@ -141,6 +146,7 @@ From now on charts located in this repository can be deployed by using the `--ch ...@@ -141,6 +146,7 @@ From now on charts located in this repository can be deployed by using the `--ch
* `--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 * `--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. * `--name`: sets the name of the deployment.
* `--reset`: this ignores eventually existing config-folders of docker, helm and kubectl and removes them. * `--reset`: this ignores eventually existing config-folders of docker, helm and kubectl and removes them.
* `--debug`: outputs executed commands
## docker add-repo ## docker add-repo
...@@ -152,6 +158,7 @@ From now on charts located in this repository can be deployed by using the `--ch ...@@ -152,6 +158,7 @@ From now on charts located in this repository can be deployed by using the `--ch
* `--name`: sets the name of the repo to add. * `--name`: sets the name of the repo to add.
* `--repo-url`: sets the repository-url of the repo to add. * `--repo-url`: sets the repository-url of the repo to add.
* `--reset`: this ignores eventually existing config-folders of docker, helm and kubectl and removes them. * `--reset`: this ignores eventually existing config-folders of docker, helm and kubectl and removes them.
* `--debug`: outputs executed commands
# Assumptions # Assumptions
......
...@@ -9,7 +9,7 @@ context="context" ...@@ -9,7 +9,7 @@ context="context"
account="account" account="account"
ca_file="${HOME}/k8s-ca.crt" ca_file="${HOME}/k8s-ca.crt"
image_file="" image_file=""
docker_file="Dockerfile" docker_file=""
dockerconfig="" dockerconfig=""
tags="" tags=""
helmargs="" helmargs=""
...@@ -25,7 +25,8 @@ repo_url="" ...@@ -25,7 +25,8 @@ repo_url=""
build_context="." build_context="."
timeout="60" timeout="60"
reset="" reset=""
dockerargs=""
debug=""
! getopt --test > /dev/null ! getopt --test > /dev/null
if [[ ${PIPESTATUS[0]} -ne 4 ]]; then if [[ ${PIPESTATUS[0]} -ne 4 ]]; then
echo "I’m sorry, `getopt --test` failed in this environment." echo "I’m sorry, `getopt --test` failed in this environment."
...@@ -33,7 +34,7 @@ if [[ ${PIPESTATUS[0]} -ne 4 ]]; then ...@@ -33,7 +34,7 @@ if [[ ${PIPESTATUS[0]} -ne 4 ]]; then
fi fi
OPTIONS= OPTIONS=
LONGOPTS=docker-config:,tag:,build-arg:,values:,set:,set-string:,charts:,name:,token:,certificate-authority:,namespace:,cluster-url:,service-account:,output:,input:,repo-url:,build-context:,timeout:,reset,image-name:,docker-file: LONGOPTS=docker-config:,tag:,build-arg:,values:,set:,set-string:,charts:,name:,token:,certificate-authority:,namespace:,cluster-url:,service-account:,output:,input:,repo-url:,build-context:,timeout:,reset,image-name:,docker-file:,pull,debug
# -use ! and PIPESTATUS to get exit code with errexit set # -use ! and PIPESTATUS to get exit code with errexit set
# -temporarily store output to be able to check for errors # -temporarily store output to be able to check for errors
...@@ -120,9 +121,17 @@ while true; do ...@@ -120,9 +121,17 @@ while true; do
shift 2 shift 2
;; ;;
--docker-file) --docker-file)
docker_file="$2" docker_file="-f $2"
shift 2 shift 2
;; ;;
--pull)
dockerargs="${dockerargs} --pull"
shift
;;
--debug)
debug="true"
shift
;;
--) --)
shift shift
break break
...@@ -135,12 +144,19 @@ while true; do ...@@ -135,12 +144,19 @@ while true; do
esac esac
done done
debug() {
if [ "$debug" != "true" ];then return; fi
echo -e "\n[$(date +'%Y-%m-%d')] ${FUNCNAME[1]}: $@"
}
prepare_kubectl() { prepare_kubectl() {
local out local out
local args="" local args=""
if [ "${reset}" == "true" ];then if [ "${reset}" == "true" ];then
echo -ne "Removing \".kube\" folder (because \"--reset\" was provided) ..." echo -ne "Removing \".kube\" folder (because \"--reset\" was provided) ..."
debug "rm -rf ${HOME}/.kube/*"
out=`rm -rf ${HOME}/.kube/*` out=`rm -rf ${HOME}/.kube/*`
if [ "$?" != "0" ];then if [ "$?" != "0" ];then
echo "failed" echo "failed"
...@@ -183,6 +199,7 @@ prepare_kubectl() { ...@@ -183,6 +199,7 @@ prepare_kubectl() {
fi fi
echo -ne "\tSetting cluster..." echo -ne "\tSetting cluster..."
debug "kubectl config set-cluster \"${cluster_name}\" --server=${cluster_url}${args}"
out=`kubectl config set-cluster "${cluster_name}" --server=${cluster_url}${args}` out=`kubectl config set-cluster "${cluster_name}" --server=${cluster_url}${args}`
if [ "$?" != "0" ];then if [ "$?" != "0" ];then
echo "failed" echo "failed"
...@@ -192,6 +209,7 @@ prepare_kubectl() { ...@@ -192,6 +209,7 @@ prepare_kubectl() {
echo "done" echo "done"
echo -ne "\tSetting credentials..." echo -ne "\tSetting credentials..."
debug "kubectl config set-credentials \"${account}\" --token=\"$(echo ${token} | base64 -d)"
out=`kubectl config set-credentials "${account}" --token="$(echo ${token} | base64 -d)"` out=`kubectl config set-credentials "${account}" --token="$(echo ${token} | base64 -d)"`
if [ "$?" != "0" ];then if [ "$?" != "0" ];then
echo "failed" echo "failed"
...@@ -201,6 +219,7 @@ prepare_kubectl() { ...@@ -201,6 +219,7 @@ prepare_kubectl() {
echo "done" echo "done"
echo -ne "\tSetting context..." echo -ne "\tSetting context..."
debug "kubectl config set-context \"${context}\" --user=\"${account}\" --cluster=\"${cluster_name}\""
out=`kubectl config set-context "${context}" --user="${account}" --cluster="${cluster_name}"` out=`kubectl config set-context "${context}" --user="${account}" --cluster="${cluster_name}"`
if [ "$?" != "0" ];then if [ "$?" != "0" ];then
echo "failed" echo "failed"
...@@ -210,6 +229,7 @@ prepare_kubectl() { ...@@ -210,6 +229,7 @@ prepare_kubectl() {
echo "done" echo "done"
echo -ne "\tActivating context..." echo -ne "\tActivating context..."
debug "kubectl config use-context \"${context}\""
out=`kubectl config use-context "${context}"` out=`kubectl config use-context "${context}"`
if [ "$?" != "0" ];then if [ "$?" != "0" ];then
echo "failed" echo "failed"
...@@ -220,6 +240,7 @@ prepare_kubectl() { ...@@ -220,6 +240,7 @@ prepare_kubectl() {
echo -ne "\tTesting context..." echo -ne "\tTesting context..."
for resource in deployment service configmap;do for resource in deployment service configmap;do
debug "kubectl --namespace=\"${namespace}\" auth can-i create $resource"
out=`kubectl --namespace="${namespace}" auth can-i create $resource` out=`kubectl --namespace="${namespace}" auth can-i create $resource`
if [ "$?" != "0" ];then if [ "$?" != "0" ];then
echo "failed" echo "failed"
...@@ -235,6 +256,7 @@ prepare_kubectl() { ...@@ -235,6 +256,7 @@ prepare_kubectl() {
prepare_helm() { prepare_helm() {
if [ "${reset}" == "true" ];then if [ "${reset}" == "true" ];then
echo -ne "Removing \".helm\" folder (because \"--reset\" was provided) ..." echo -ne "Removing \".helm\" folder (because \"--reset\" was provided) ..."
debug "rm -rf ${HOME}/.helm/*"
out=`rm -rf ${HOME}/.helm/*` out=`rm -rf ${HOME}/.helm/*`
if [ "$?" != "0" ];then if [ "$?" != "0" ];then
echo "failed" echo "failed"
...@@ -249,6 +271,7 @@ prepare_helm() { ...@@ -249,6 +271,7 @@ prepare_helm() {
echo -ne "Preparing helm..." echo -ne "Preparing helm..."
debug "helm init --wait --tiller-namespace=\"${namespace}\" --service-account=\"${service_account}\" --upgrade --force-upgrade"
out=`helm init --wait --tiller-namespace="${namespace}" --service-account="${service_account}" --upgrade --force-upgrade` out=`helm init --wait --tiller-namespace="${namespace}" --service-account="${service_account}" --upgrade --force-upgrade`
if [ "$?" != "0" ];then if [ "$?" != "0" ];then
echo "failed!" echo "failed!"
...@@ -276,7 +299,7 @@ helm_add_repo() { ...@@ -276,7 +299,7 @@ helm_add_repo() {
fi fi
local cmd="helm repo add --tiller-connection-timeout=120 --tiller-namespace=\"${namespace}\" ${name} ${repo_url}" local cmd="helm repo add --tiller-connection-timeout=120 --tiller-namespace=\"${namespace}\" ${name} ${repo_url}"
debug "$cmd"
local out=`$cmd 2>&1` local out=`$cmd 2>&1`
if [ "$?" != "0" ];then if [ "$?" != "0" ];then
echo "failed" echo "failed"
...@@ -306,6 +329,7 @@ helm_deploy() { ...@@ -306,6 +329,7 @@ helm_deploy() {
local cmd local cmd
if [ "$(helm ls --tiller-namespace=${namespace} --namespace=${namespace} --pending --deleted --failed --short | grep ${name})" != "" ];then if [ "$(helm ls --tiller-namespace=${namespace} --namespace=${namespace} --pending --deleted --failed --short | grep ${name})" != "" ];then
debug "helm delete --tiller-namespace=${namespace} --purge ${name}"
out=`helm delete --tiller-namespace=${namespace} --purge ${name} 2>&1` out=`helm delete --tiller-namespace=${namespace} --purge ${name} 2>&1`
if [ "$?" != "0" ];then if [ "$?" != "0" ];then
echo "failed" echo "failed"
...@@ -317,7 +341,7 @@ helm_deploy() { ...@@ -317,7 +341,7 @@ helm_deploy() {
helmargs=$(echo -e "$helmargs" | sed -E 's/(^[[:space:]]*)|([[:space:]]*$)//g') helmargs=$(echo -e "$helmargs" | sed -E 's/(^[[:space:]]*)|([[:space:]]*$)//g')
cmd="helm upgrade --install --wait --timeout=${timeout} --tiller-namespace=${namespace} --namespace=${namespace}" cmd="helm upgrade --install --wait --timeout=${timeout} --tiller-namespace=${namespace} --namespace=${namespace}"
cmd="$cmd --namespace=${namespace} --recreate-pods ${name} ${charts} ${helmargs}" cmd="$cmd --namespace=${namespace} --recreate-pods ${name} ${charts} ${helmargs}"
debug "$cmd"
out=`$cmd 2>&1` out=`$cmd 2>&1`
if [ "$?" != "0" ];then if [ "$?" != "0" ];then
echo "failed" echo "failed"
...@@ -339,6 +363,7 @@ helm_undeploy() { ...@@ -339,6 +363,7 @@ helm_undeploy() {
local out local out
debug "helm delete --tiller-namespace=\"${namespace}\" ${name}"
out=`helm delete --tiller-namespace="${namespace}" ${name} 2>&1` out=`helm delete --tiller-namespace="${namespace}" ${name} 2>&1`
if [ "$?" != "0" ];then if [ "$?" != "0" ];then
...@@ -358,6 +383,7 @@ prepare_image_publisher() { ...@@ -358,6 +383,7 @@ prepare_image_publisher() {
if [ "${reset}" == "true" ];then if [ "${reset}" == "true" ];then
echo -ne "Removing \".docker\" folder (because \"--reset\" was provided) ..." echo -ne "Removing \".docker\" folder (because \"--reset\" was provided) ..."
debug "rm -rf ${HOME}/.docker/*"
out=`rm -rf ${HOME}/.docker/*` out=`rm -rf ${HOME}/.docker/*`
if [ "$?" != "0" ];then if [ "$?" != "0" ];then
echo "failed" echo "failed"
...@@ -371,6 +397,7 @@ prepare_image_publisher() { ...@@ -371,6 +397,7 @@ prepare_image_publisher() {
fi fi
echo -ne "Setting docker auth config ..." echo -ne "Setting docker auth config ..."
debug "mkdir -p ${HOME}/.docker && echo \"${dockerconfig}\" >${HOME}/.docker/config.json"
mkdir -p ${HOME}/.docker && echo "${dockerconfig}" >${HOME}/.docker/config.json mkdir -p ${HOME}/.docker && echo "${dockerconfig}" >${HOME}/.docker/config.json
if [ "$?" != "0" ];then if [ "$?" != "0" ];then
echo "failed" echo "failed"
...@@ -389,6 +416,7 @@ save_image() { ...@@ -389,6 +416,7 @@ save_image() {
return 0 return 0
fi fi
debug "docker save --output=${image_file} ${image_name}"
out=`docker save --output=${image_file} ${image_name} 2>&1` out=`docker save --output=${image_file} ${image_name} 2>&1`
if [ "$?" != "0" ];then if [ "$?" != "0" ];then
echo "failed" echo "failed"
...@@ -403,14 +431,15 @@ build_image() { ...@@ -403,14 +431,15 @@ build_image() {
echo -ne "building image..." echo -ne "building image..."
local out local out
local cmd="docker build --pull --cache-from=${image_name}" local cmd="docker build ${dockerargs} --cache-from=${image_name}"
for arg in $buildargs;do for arg in $buildargs;do
echo "adding $arg to build command" echo -e "\nadding $arg to build command"
cmd="$cmd --build-arg $arg --build-arg ${arg,,}" cmd="$cmd --build-arg $arg --build-arg ${arg,,}"
done done
cmd="$cmd -t ${image_name} -f ${docker_file} ${build_context}" cmd="$cmd -t ${image_name} ${docker_file} ${build_context}"
debug "$cmd"
out=`$cmd 2>&1` out=`$cmd 2>&1`
if [ "$?" != "0" ];then if [ "$?" != "0" ];then
echo "failed" echo "failed"
...@@ -435,6 +464,7 @@ import_image() { ...@@ -435,6 +464,7 @@ import_image() {
return 0 return 0
fi fi
debug "docker load --input=${image_file}"
out=`docker load --input=${image_file} 2>&1` out=`docker load --input=${image_file} 2>&1`
if [ "$?" != "0" ];then if [ "$?" != "0" ];then
echo "failed" echo "failed"
...@@ -465,12 +495,14 @@ publish_image() { ...@@ -465,12 +495,14 @@ publish_image() {
echo "" echo ""
for tag in $tags; do for tag in $tags; do
echo -ne "\t${name}:${tag}..." echo -ne "\t${name}:${tag}..."
debug "docker tag ${image_name} ${name}:${tag}"
out=`docker tag ${image_name} ${name}:${tag} 2>&1` out=`docker tag ${image_name} ${name}:${tag} 2>&1`
if [ "$?" != "0" ];then if [ "$?" != "0" ];then
echo "failed" echo "failed"
echo "$out" echo "$out"
return 1 return 1
fi fi
debug "docker push ${name}:${tag}"
out=`docker push ${name}:${tag} 2>&1` out=`docker push ${name}:${tag} 2>&1`
if [ "$?" != "0" ];then if [ "$?" != "0" ];then
echo "failed" echo "failed"
......
version: '2' version: '2'
services: services:
build:
build: .
volumes:
- ./:/app
- ./assets/deployer:/usr/local/bin/deployer
depends_on:
- docker
environment:
DOCKER_HOST: tcp://docker:2375
command: deployer build --output .tmp/image.tar.gz
init: init:
build: . build: .
volumes: volumes:
...@@ -50,6 +39,17 @@ services: ...@@ -50,6 +39,17 @@ services:
DOCKER_HOST: tcp://docker:2375 DOCKER_HOST: tcp://docker:2375
command: deployer init --namespace test --cluster-url https://172.18.85.125:6443 --certificate-authority ${ca_cert} --token ${token} --service-account test --docker-config "${docker_config}" --reset command: deployer init --namespace test --cluster-url https://172.18.85.125:6443 --certificate-authority ${ca_cert} --token ${token} --service-account test --docker-config "${docker_config}" --reset
build:
build: .
volumes:
- ./:/app
- ./assets/deployer:/usr/local/bin/deployer
depends_on:
- docker
environment:
DOCKER_HOST: tcp://docker:2375
command: deployer build --output .tmp/image.tar.gz
build-no-save: build-no-save:
build: . build: .
volumes: volumes:
...@@ -61,6 +61,17 @@ services: ...@@ -61,6 +61,17 @@ services:
DOCKER_HOST: tcp://docker:2375 DOCKER_HOST: tcp://docker:2375
command: deployer build command: deployer build
build-with-pull:
build: .
volumes:
- ./:/app
- ./assets/deployer:/usr/local/bin/deployer
depends_on:
- docker
environment:
DOCKER_HOST: tcp://docker:2375
command: deployer build --pull
build-custom-context: build-custom-context:
build: . build: .
volumes: volumes:
......