summaryrefslogtreecommitdiffstats
path: root/packaging/manual_nightly_deployment.sh
blob: a0999bb188ae149eef787607a355c5a08b73ac46 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#!/usr/bin/env bash
#
# This tool allows netdata team to manually deploy nightlies
# It emulates the nightly operations required for a new version to be published for our users
#
# Copyright: SPDX-License-Identifier: GPL-3.0-or-later
#
# Author  : Pavlos Emm. Katsoulakis <paul@netdata.cloud>
#
set -e

# 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 || echo "")
if [ -n "${CWD}" ] || [ ! "${TOP_LEVEL}" == "netdata" ]; then
    echo "Run as .travis/$(basename "$0") from top level directory of netdata git repository"
    echo "Changelog generation process aborted"
    exit 1
fi

if [ $# -lt 1 ] || [ $# -gt 2 ]; then
	echo "Run as ./$(basename "$0") [docker|gcs]|all]  from the top level directory of netdata GIT repository"
	exit 1
fi

GSUTIL_BINARY=$(command -v gsutil 2> /dev/null)
if [ -z "${GSUTIL_BINARY}" ]; then
	echo "No gsutil utility available, you need gsutil deployed to manually deploy to GCS"
	exit 1
fi;

# Function declarations
publish_docker() {

	# Ensure REPOSITORY present
	if [ -z "${REPOSITORY}" ]; then
		echo "Please provide the repository to deploy the containers:"
		read -r REPOSITORY
		export REPOSITORY
	else
		echo "Docker publishing to ${REPOSITORY}"
	fi

	# Ensure DOCKER_USERNAME present
	if [ -z "${DOCKER_USERNAME}" ]; then
		echo "For repository ${REPOSITORY}, Please provide the docker USERNAME to use:"
		read -r DOCKER_USERNAME
		export DOCKER_USERNAME
	else
		echo "Using docker username ${DOCKER_USERNAME}"
	fi

	# Ensure DOCKER_PASS present
	if [ -z "${DOCKER_PASS}" ]; then
		echo "Username ${DOCKER_USERNAME} received, now give me the password:"
		read -r -s DOCKER_PASS
		export DOCKER_PASS
	else
		echo "Docker password has already been set to env, using that"
	fi

	echo "Building Docker images.."
	packaging/docker/build.sh

	echo "Publishing Docker images.."
	packaging/docker/publish.sh
}

publish_nightly_binaries() {
	echo "Publishing nightly binaries to GCS"

	echo "Please select the bucket to sync, from the ones available to you:"
	bucket_list=$(${GSUTIL_BINARY} list | tr '\n' ' ')
	declare -A buckets
	idx=0
	for abucket in ${bucket_list}; do
		echo "${idx}. ${abucket}"
		buckets["${idx}"]=${abucket}
		((idx=idx+1))
	done
	read -p"Selection>" -r -n 1 selected_bucket

	echo "Ok!"
	echo "Syncing artifacts directory contents with GCS bucket: ${buckets[${selected_bucket}]}"
	if [ -d artifacts ]; then
		${GSUTIL_BINARY} -m rsync -r artifacts "${buckets["${selected_bucket}"]}"
		echo "GCS Sync complete!"
	else
		echo "Directory artifacts does not exist, nothing to do on GCS"
	fi
}

prepare_and_publish_gcs() {
	# Prepare the artifacts directory
	echo "Preparing artifacts directory contents"
	.travis/create_artifacts.sh

	# Publish it to GCS
	publish_nightly_binaries

	# Clean up
	echo "Cleaning up repository"
	make clean || echo "Nothing to clean"
	make distclean || echo "Nothing to distclean"
	rm -rf artifacts
}

# Mandatory variable declarations
export TRAVIS_REPO_SLUG="netdata/netdata"

echo "Manual nightly deployment procedure started"
case "$1" in
	"docker")
		publish_docker
		;;
	"gcs")
		prepare_and_publish_gcs
		;;
	"all")
		publish_docker
		prepare_and_publish_gcs
		;;
	*)
		echo "ERROR: Invalid request parameter $1. Valid values are: docker, gcs, all"
		;;
esac
echo "Manual nightly deployment completed!"