forked from AlexsLemonade/refinebio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommon.sh
executable file
·69 lines (60 loc) · 3.17 KB
/
common.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
#!/bin/bash
# These are lists of docker images that we use. The actual names end
# up being <DOCKERHUB_REPO>/dr_<IMAGE_NAME> but this is useful for scripting.
export ALL_CCDL_IMAGES="smasher illumina affymetrix salmon transcriptome no_op downloaders foreman api"
# Sometimes we only want to work with the worker images.
export CCDL_WORKER_IMAGES="smasher illumina affymetrix salmon transcriptome no_op downloaders"
get_ip_address () {
if [ `uname` == "Linux" ]; then
echo $(ip route get 8.8.8.8 | grep -oE 'src ([0-9]{1,3}\.){3}[0-9]{1,3}' | awk '{print $2; exit}')
elif [ `uname` == 'Darwin' ]; then # MacOS
echo $(ifconfig | grep "inet " | grep -v 127.0.0.1 | cut -d\ -f2 | tail -1)
fi
}
get_docker_db_ip_address () {
docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' drdb 2> /dev/null
}
get_docker_es_ip_address () {
docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' dres 2> /dev/null
}
# `coverage report -m` will always have an exit code of 0 which makes
# it seem like the test is passing. Therefore we store the exit code
# of running the tests as $exit_code, then report the coverage, and
# then exit with the appropriate code.
# This is done a function so arguments to the tests can be passed through.
run_tests_with_coverage () {
echo "coverage run --source=\".\" manage.py test --no-input $@; exit_code=\$?; coverage report -m; exit \$exit_code"
}
# This function checks whether a given docker image name ($1:$CIRCLE_TAG)
# exists in Docker Hub or not using Docker Hub API V2. Based on:
# https://stackoverflow.com/questions/32113330/check-if-imagetag-combination-already-exists-on-docker-hub
function docker_img_exists() {
TOKEN=$(curl -s -H "Content-Type: application/json" -X POST \
-d '{"username": "'${DOCKER_ID}'", "password": "'${DOCKER_PASSWD}'"}' \
https://hub.docker.com/v2/users/login/ | jq -r .token)
EXISTS=$(curl -s -H "Authorization: JWT ${TOKEN}" \
https://hub.docker.com/v2/repositories/$1/tags/?page_size=10000 \
| jq -r "[.results | .[] | .name == \"$2\"] | any" 2> /dev/null)
test -n "$EXISTS" -a "$EXISTS" = true
}
# A tag is linked to a commit hash, not a branch. A single commit hash
# can end up on multiple branches. So we first check to see if we're
# on master, then on dev, then error out because we should only deploy master or dev.
get_master_or_dev() {
# Takes the version that is being deployed as its only parameter
version=$1
if [[ -z $version ]]; then
echo "You must pass the version to get_master_or_dev."
else
master_check=$(git log origin/master --decorate=full | grep "$version" || true)
dev_check=$(git log origin/dev --decorate=full | grep "$version" || true)
# All dev versions should end with '-dev' and all master versions should not.
if [[ ! -z $master_check ]] && [[ $version != *-dev ]]; then
echo "master"
elif [[ ! -z $dev_check ]] && [[ $version == *-dev ]]; then
echo "dev"
else
echo "Why in the world was update_docker_img.sh called from a branch other than dev or master?!?!?"
fi
fi
}