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
## [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
### Added
* option to specify the path to the Dockerfile
......@@ -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.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.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.3]: https://git.sc.uni-leipzig.de/ubl/bdd_dev/webmasterei/deployer/compare/release%2F1.4.2...release%2F1.4.3
[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
* `--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.
* `--reset`: this ignores eventually existing config-folders of docker, helm and kubectl and removes them.
* `--debug`: outputs executed commands
## docker build
......@@ -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.
* `--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
* `--pull`: tells docker to always pull newer images before building
* `--debug`: outputs executed commands
## docker publish
......@@ -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.
* `--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
* `--debug`: outputs executed commands
## docker deploy
......@@ -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.
* `--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.
* `--debug`: outputs executed commands
## docker undeploy
......@@ -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
* `--name`: sets the name of the deployment.
* `--reset`: this ignores eventually existing config-folders of docker, helm and kubectl and removes them.
* `--debug`: outputs executed commands
## docker add-repo
......@@ -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.
* `--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.
* `--debug`: outputs executed commands
# Assumptions
......
......@@ -9,7 +9,7 @@ context="context"
account="account"
ca_file="${HOME}/k8s-ca.crt"
image_file=""
docker_file="Dockerfile"
docker_file=""
dockerconfig=""
tags=""
helmargs=""
......@@ -25,7 +25,8 @@ repo_url=""
build_context="."
timeout="60"
reset=""
dockerargs=""
debug=""
! getopt --test > /dev/null
if [[ ${PIPESTATUS[0]} -ne 4 ]]; then
echo "I’m sorry, `getopt --test` failed in this environment."
......@@ -33,7 +34,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:,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
# -temporarily store output to be able to check for errors
......@@ -120,9 +121,17 @@ while true; do
shift 2
;;
--docker-file)
docker_file="$2"
docker_file="-f $2"
shift 2
;;
--pull)
dockerargs="${dockerargs} --pull"
shift
;;
--debug)
debug="true"
shift
;;
--)
shift
break
......@@ -135,12 +144,19 @@ while true; do
esac
done
debug() {
if [ "$debug" != "true" ];then return; fi
echo -e "\n[$(date +'%Y-%m-%d')] ${FUNCNAME[1]}: $@"
}
prepare_kubectl() {
local out
local args=""
if [ "${reset}" == "true" ];then
echo -ne "Removing \".kube\" folder (because \"--reset\" was provided) ..."
debug "rm -rf ${HOME}/.kube/*"
out=`rm -rf ${HOME}/.kube/*`
if [ "$?" != "0" ];then
echo "failed"
......@@ -183,6 +199,7 @@ prepare_kubectl() {
fi
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}`
if [ "$?" != "0" ];then
echo "failed"
......@@ -192,6 +209,7 @@ prepare_kubectl() {
echo "done"
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)"`
if [ "$?" != "0" ];then
echo "failed"
......@@ -201,6 +219,7 @@ prepare_kubectl() {
echo "done"
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}"`
if [ "$?" != "0" ];then
echo "failed"
......@@ -210,6 +229,7 @@ prepare_kubectl() {
echo "done"
echo -ne "\tActivating context..."
debug "kubectl config use-context \"${context}\""
out=`kubectl config use-context "${context}"`
if [ "$?" != "0" ];then
echo "failed"
......@@ -220,6 +240,7 @@ prepare_kubectl() {
echo -ne "\tTesting context..."
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`
if [ "$?" != "0" ];then
echo "failed"
......@@ -235,6 +256,7 @@ prepare_kubectl() {
prepare_helm() {
if [ "${reset}" == "true" ];then
echo -ne "Removing \".helm\" folder (because \"--reset\" was provided) ..."
debug "rm -rf ${HOME}/.helm/*"
out=`rm -rf ${HOME}/.helm/*`
if [ "$?" != "0" ];then
echo "failed"
......@@ -249,6 +271,7 @@ prepare_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`
if [ "$?" != "0" ];then
echo "failed!"
......@@ -276,7 +299,7 @@ helm_add_repo() {
fi
local cmd="helm repo add --tiller-connection-timeout=120 --tiller-namespace=\"${namespace}\" ${name} ${repo_url}"
debug "$cmd"
local out=`$cmd 2>&1`
if [ "$?" != "0" ];then
echo "failed"
......@@ -306,6 +329,7 @@ helm_deploy() {
local cmd
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`
if [ "$?" != "0" ];then
echo "failed"
......@@ -317,7 +341,7 @@ helm_deploy() {
helmargs=$(echo -e "$helmargs" | sed -E 's/(^[[:space:]]*)|([[:space:]]*$)//g')
cmd="helm upgrade --install --wait --timeout=${timeout} --tiller-namespace=${namespace} --namespace=${namespace}"
cmd="$cmd --namespace=${namespace} --recreate-pods ${name} ${charts} ${helmargs}"
debug "$cmd"
out=`$cmd 2>&1`
if [ "$?" != "0" ];then
echo "failed"
......@@ -339,6 +363,7 @@ helm_undeploy() {
local out
debug "helm delete --tiller-namespace=\"${namespace}\" ${name}"
out=`helm delete --tiller-namespace="${namespace}" ${name} 2>&1`
if [ "$?" != "0" ];then
......@@ -358,6 +383,7 @@ prepare_image_publisher() {
if [ "${reset}" == "true" ];then
echo -ne "Removing \".docker\" folder (because \"--reset\" was provided) ..."
debug "rm -rf ${HOME}/.docker/*"
out=`rm -rf ${HOME}/.docker/*`
if [ "$?" != "0" ];then
echo "failed"
......@@ -371,6 +397,7 @@ prepare_image_publisher() {
fi
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
if [ "$?" != "0" ];then
echo "failed"
......@@ -389,6 +416,7 @@ save_image() {
return 0
fi
debug "docker save --output=${image_file} ${image_name}"
out=`docker save --output=${image_file} ${image_name} 2>&1`
if [ "$?" != "0" ];then
echo "failed"
......@@ -403,14 +431,15 @@ build_image() {
echo -ne "building image..."
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
echo "adding $arg to build command"
echo -e "\nadding $arg to build command"
cmd="$cmd --build-arg $arg --build-arg ${arg,,}"
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`
if [ "$?" != "0" ];then
echo "failed"
......@@ -435,6 +464,7 @@ import_image() {
return 0
fi
debug "docker load --input=${image_file}"
out=`docker load --input=${image_file} 2>&1`
if [ "$?" != "0" ];then
echo "failed"
......@@ -465,12 +495,14 @@ publish_image() {
echo ""
for tag in $tags; do
echo -ne "\t${name}:${tag}..."
debug "docker tag ${image_name} ${name}:${tag}"
out=`docker tag ${image_name} ${name}:${tag} 2>&1`
if [ "$?" != "0" ];then
echo "failed"
echo "$out"
return 1
fi
debug "docker push ${name}:${tag}"
out=`docker push ${name}:${tag} 2>&1`
if [ "$?" != "0" ];then
echo "failed"
......
version: '2'
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:
build: .
volumes:
......@@ -50,6 +39,17 @@ services:
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
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: .
volumes:
......@@ -61,6 +61,17 @@ services:
DOCKER_HOST: tcp://docker:2375
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: .
volumes:
......