From 48c662be2e17c433545adebdb2a029e02396e49e Mon Sep 17 00:00:00 2001 From: Jephte Clain Date: Mon, 8 Oct 2018 11:50:56 +0400 Subject: [PATCH] =?UTF-8?q?g=C3=A9rer=20les=20tags=20autrement.=20ajouter?= =?UTF-8?q?=20push?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dk | 44 +++++++++++++++++++++++++++++++++++++++----- 1 file changed, 39 insertions(+), 5 deletions(-) diff --git a/dk b/dk index 1226144..8fc9cff 100755 --- a/dk +++ b/dk @@ -10,6 +10,7 @@ USAGE COMMANDES build + push run up logs @@ -84,6 +85,15 @@ function compose_set_env_args() { fi } +function initialize_build_env() { + CTXDIR=. + NAME= + TAGS=(latest) + VERSION= +} +function default_update_build_env() { :; } +function update_build_env() { default_update_build_env; } + function default_compose_build() { docker-compose \ "${replace_env_args[@]}" "${env_args[@]}" \ @@ -92,7 +102,11 @@ function default_compose_build() { } function default_docker_build() { [ -n "$VERSION" ] || docker_add_build_arg VERSION "$(get_version)" - replace_build_args+=(-t "$NAME:$VERSION" -t "$NAME:latest") + [ -n "$VERSION" ] && TAGS+=("$VERSION") + local tag + for tag in "${TAGS[@]}"; do + replace_build_args+=(-t "$NAME:$tag") + done docker build \ "${replace_env_args[@]}" "${env_args[@]}" \ "${replace_build_args[@]}" "${build_args[@]}" \ @@ -103,20 +117,30 @@ function docker_build() { default_docker_build "$@"; } function auto_build() { local -a replace_env_args env_args local -a replace_build_args build_args - CTXDIR=. - NAME= - VERSION= + initialize_build_env if [ -f docker-compose.yml ]; then compose_set_env_args + update_build_env compose_build else docker_parse_env_args docker_check_name docker_add_build_arg build_date "$(date +%y%m%d)" + update_build_env docker_build fi } +function auto_push() { + local -a tags tag + initialize_build_env + update_build_env + for tag in "${TAGS[@]}"; do + tags+=("$NAME:$tag") + done + docker push "${tags[@]}" +} + function default_compose_up() { docker-compose \ "${replace_env_args[@]}" "${env_args[@]}" \ @@ -240,7 +264,7 @@ set_defaults dk chdir= profile="$PROFILE" -args=(+ +args=( --help '$exit_with display_help' -d:,--chdir: chdir= -p:,--profile: profile= @@ -269,6 +293,16 @@ while [ $# -gt 0 ]; do enote "Profil $profile" auto_build "${args[@]}" || die ;; + push) + [ -f .build.scripts.sh ] && source ./.build.scripts.sh + [ -f build.scripts.sh ] && source ./build.scripts.sh + args=() + while [ $# -gt 0 -a "$1" != -- ]; do + args+=("$1"); shift + done + enote "Profil $profile" + auto_push "${args[@]}" || die + ;; s|run|start) args=() while [ $# -gt 0 -a "$1" != -- ]; do