1
+#!/usr/bin/env bash
2
+#
3
+# This tool allows netdata team to manually deploy nightlies
4
+# It emulates the nightly operations required for a new version to be published for our users
5
+#
6
+# Copyright: SPDX-License-Identifier: GPL-3.0-or-later
7
+#
8
+# Author : Pavlos Emm. Katsoulakis <paul@netdata.cloud>
9
+#
10
+set -e
11
+
12
+# If we are not in netdata git repo, at the top level directory, fail
13
+TOP_LEVEL=$(basename "$(git rev-parse --show-toplevel)")
14
+CWD=$(git rev-parse --show-cdup || echo "")
15
+if [ -n "${CWD}" ] || [ ! "${TOP_LEVEL}" == "netdata" ]; then
16
+ echo "Run as .travis/$(basename "$0") from top level directory of netdata git repository"
17
+ echo "Changelog generation process aborted"
18
+ exit 1
19
+fi
20
+
21
+if [ $# -lt 1 ] || [ $# -gt 2 ]; then
22
+ echo "Run as ./$(basename "$0") [docker|gcs]|all] from the top level directory of netdata GIT repository"
23
+ exit 1
24
+fi
25
+
26
+GSUTIL_BINARY=$(command -v gsutil 2> /dev/null)
27
+if [ -z "${GSUTIL_BINARY}" ]; then
28
+ echo "No gsutil utility available, you need gsutil deployed to manually deploy to GCS"
29
+ exit 1
30
+fi;
31
+
32
+# Function declarations
33
+publish_docker() {
34
+
35
+ # Ensure REPOSITORY present
36
+ if [ -z "${REPOSITORY}" ]; then
37
+ echo "Please provide the repository to deploy the containers:"
38
+ read -r REPOSITORY
39
+ export REPOSITORY
40
+ else
41
+ echo "Docker publishing to ${REPOSITORY}"
42
+ fi
43
+
44
+ # Ensure DOCKER_USERNAME present
45
+ if [ -z "${DOCKER_USERNAME}" ]; then
46
+ echo "For repository ${REPOSITORY}, Please provide the docker USERNAME to use:"
47
+ read -r DOCKER_USERNAME
48
+ export DOCKER_USERNAME
49
+ else
50
+ echo "Using docker username ${DOCKER_USERNAME}"
51
+ fi
52
+
53
+ # Ensure DOCKER_PASS present
54
+ if [ -z "${DOCKER_PASS}" ]; then
55
+ echo "Username ${DOCKER_USERNAME} received, now give me the password:"
56
+ read -r -s DOCKER_PASS
57
+ export DOCKER_PASS
58
+ else
59
+ echo "Docker password has already been set to env, using that"
60
+ fi
61
+
62
+ echo "Building Docker images.."
63
+ packaging/docker/build.sh
64
+
65
+ echo "Publishing Docker images.."
66
+ packaging/docker/publish.sh
67
+}
68
+
69
+publish_nightly_binaries() {
70
+ echo "Publishing nightly binaries to GCS"
71
+
72
+ echo "Please select the bucket to sync, from the ones available to you:"
73
+ bucket_list=$(${GSUTIL_BINARY} list | tr '\n' ' ')
74
+ declare -A buckets
75
+ idx=0
76
+ for abucket in ${bucket_list}; do
77
+ echo "${idx}. ${abucket}"
78
+ buckets["${idx}"]=${abucket}
79
+ ((idx=idx+1))
80
+ done
81
+ read -p"Selection>" -r -n 1 selected_bucket
82
+
83
+ echo "Ok!"
84
+ echo "Syncing artifacts directory contents with GCS bucket: ${buckets[${selected_bucket}]}"
85
+ if [ -d artifacts ]; then
86
+ ${GSUTIL_BINARY} -m rsync -r artifacts "${buckets["${selected_bucket}"]}"
87
+ echo "GCS Sync complete!"
88
+ else
89
+ echo "Directory artifacts does not exist, nothing to do on GCS"
90
+ fi
91
+}
92
+
93
+prepare_and_publish_gcs() {
94
+ # Prepare the artifacts directory
95
+ echo "Preparing artifacts directory contents"
96
+ .travis/create_artifacts.sh
97
+
98
+ # Publish it to GCS
99
+ publish_nightly_binaries
100
+
101
+ # Clean up
102
+ echo "Cleaning up repository"
103
+ make clean || echo "Nothing to clean"
104
+ make distclean || echo "Nothing to distclean"
105
+ rm -rf artifacts
106
+}
107
+
108
+# Mandatory variable declarations
109
+export TRAVIS_REPO_SLUG="netdata/netdata"
110
+
111
+echo "Manual nightly deployment procedure started"
112
+case "$1" in
113
+ "docker")
114
+ publish_docker
115
+ ;;
116
+ "gcs")
117
+ prepare_and_publish_gcs
118
+ ;;
119
+ "all")
120
+ publish_docker
121
+ prepare_and_publish_gcs
122
+ ;;
123
+ *)
124
+ echo "ERROR: Invalid request parameter $1. Valid values are: docker, gcs, all"
125
+ ;;
126
+esac
127
+echo "Manual nightly deployment completed!"