-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy pathinit_pip_gcsfuse.sh
96 lines (79 loc) · 2.55 KB
/
init_pip_gcsfuse.sh
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
#!/bin/bash
# Copyright 2020 Google Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# This file installs python packages, install gcsfuse then mount GCS buckets as a file system
set -exo pipefail
# Python Packages to Install
PACKAGES="pendulum scipy markdown"
function err() {
echo "[$(date +'%Y-%m-%dT%H:%M:%S%z')]: $*" >&2
exit 1
}
function run_with_retry() {
local -r cmd=("$@")
for ((i = 0; i < 10; i++)); do
if "${cmd[@]}"; then
return 0
fi
sleep 5
done
err "Failed to run command: ${cmd[*]}"
}
function install_pip() {
if command -v pip >/dev/null; then
echo "pip is already installed."
return 0
fi
if command -v easy_install >/dev/null; then
echo "Installing pip with easy_install..."
run_with_retry easy_install pip
return 0
fi
echo "Installing python-pip..."
run_with_retry apt update
run_with_retry apt install python-pip -y
}
function gcsfuse_install(){
echo "Installing gcsfuse..."
GCSFUSE_REPO=gcsfuse-$(lsb_release -c -s)
export GCSFUSE_REPO
echo "deb https://packages.cloud.google.com/apt $GCSFUSE_REPO main" | sudo tee /etc/apt/sources.list.d/gcsfuse.list
curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
sudo apt-get update
sudo apt-get install gcsfuse -y
sudo groupadd fuse
sudo usermod -a -G fuse "$USER"
}
function gcsfuse_mount(){
# Mount a bucket by “gcsfuse <your-bucket-name> <your-path/to/mount>”
# EDIT: bucket to mount, path
mkdir path-1
gcsfuse kristin-0105 path-1
echo "GCS bucket succesfully mounted at the specificed path"
# Mount a bucket by “gcsfuse <your-bucket-name> <your-path/to/mount>”
mkdir path-2
gcsfuse notebooks-staging-bucket-kk path-2
echo "GCS bucket succesfully mounted at the specificed path"
}
function gcsfuse_check(){
# Check the mounted storage bucket as persistent disk by “df -h”
df -h
}
function main() {
run_with_retry pip install --upgrade "${PACKAGES}"
run_with_retry gcsfuse_install
run_with_retry gcsfuse_mount
run_with_retry gcsfuse_check
}
main