Browse Source

netdata/packaging/ci: Add some extra info on various stages, also introduce a check_login.sh step in prior to docker publishing, for early fail if credentials are messed up. Waiting the full build is overhead (#5928)

Paul Emm. Katsoulakis 5 years ago
parent
commit
0e54203dc8
2 changed files with 53 additions and 1 deletions
  1. 12 1
      .travis.yml
  2. 41 0
      packaging/docker/check_login.sh

+ 12 - 1
.travis.yml

@@ -139,7 +139,12 @@ jobs:
 
     name: Generate changelog and TAG the release (only on special commit msg)
     before_script: post_message "TRAVIS_MESSAGE" "Packaging step for release initiated"
-    script: .travis/generate_changelog_and_tag_release.sh
+    script:
+    - echo "GIT Branch:" && git branch
+    - echo "Last commit:" && git log -1
+    - echo "GIT Describe:" && git describe
+    - echo "packaging/version:" && cat packaging/version
+    - .travis/generate_changelog_and_tag_release.sh
     after_failure: post_message "TRAVIS_MESSAGE" "<!here> Packaging for release failed"
     git:
       depth: false
@@ -159,6 +164,7 @@ jobs:
     - echo "Last commit:" && git log -1
     - echo "GIT Describe:" && git describe
     - echo "packaging/version:" && cat packaging/version
+    - packaging/docker/check_login.sh
     - packaging/docker/build.sh
     - packaging/docker/publish.sh
     after_failure: post_message "TRAVIS_MESSAGE" "<!here> Docker image publishing failed"
@@ -216,7 +222,12 @@ jobs:
     name: Build & Publish docker images
     before_script: post_message "TRAVIS_MESSAGE" "Publishing docker images for nightlies"
     script:
+    - echo "GIT Branch:" && git branch
+    - echo "Last commit:" && git log -1
+    - echo "GIT Describe:" && git describe
+    - echo "packaging/version:" && cat packaging/version
     - docker info
+    - packaging/docker/check_login.sh
     - packaging/docker/build.sh
     - packaging/docker/publish.sh
     after_failure: post_message "TRAVIS_MESSAGE" "<!here> Nightly docker image publish failed"

+ 41 - 0
packaging/docker/check_login.sh

@@ -0,0 +1,41 @@
+#!/usr/bin/env bash
+#
+# This is a credential checker script, to help get early input on docker credentials status
+# If these are wrong, then build/publish has no point running
+#
+# Copyright: SPDX-License-Identifier: GPL-3.0-or-later
+#
+# Author  : Pavlos Emm. Katsoulakis (paul@netdata.cloud)
+
+set -e
+
+if [ "${BASH_VERSINFO[0]}" -lt "4" ]; then
+	echo "This mechanism currently can only run on BASH version 4 and above"
+	exit 1
+fi
+
+DOCKER_CMD="docker "
+
+# There is no reason to continue if we cannot log in to docker hub
+if [ -z ${DOCKER_USERNAME+x} ] || [ -z ${DOCKER_PWD+x} ]; then
+    echo "No docker hub username or password found, aborting without publishing"
+    exit 1
+fi
+
+# If we are not in netdata git repo, at the top level directory, fail
+TOP_LEVEL=$(basename "$(git rev-parse --show-toplevel)")
+CWD=$(git rev-parse --show-cdup)
+if [ -n "$CWD" ] || [ ! "${TOP_LEVEL}" == "netdata" ]; then
+    echo "Run as ./packaging/docker/$(basename "$0") from top level directory of netdata git repository"
+    echo "Docker build process aborted"
+    exit 1
+fi
+
+# Login to docker hub to allow futher operations
+echo "Attempting to login to docker"
+echo "$DOCKER_PWD" | $DOCKER_CMD login -u "$DOCKER_USERNAME" --password-stdin
+
+echo "Docker login successful!"
+$DOCKER_CMD logout
+
+echo "Docker login validation completed"