-
Notifications
You must be signed in to change notification settings - Fork 0
/
.sourceme
executable file
·63 lines (55 loc) · 2.53 KB
/
.sourceme
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
#!/usr/bin/env bash
#.sourceme
: "${PG_CONTAINERNAME:=titan-pg}"
: "${JAR=postgresql-42.2.8.jar}"
[[ "`uname`" != "Darwin" ]] && echo "This script was only built/testing on MacOS. Exiting" && exit 1
echo "Preparing environment variables for demo"
if [[ ! -f `which jq` ]]; then
echo "your system doesn't have jq. fetching docker container"
docker pull stedolan/jq
alias jq="docker run -i stedolan/jq"
else
echo "Found `which jq`"
fi
echo "Checking for jdbc/${JAR}"
if [[ -f jdbc/${JAR} ]]; then
echo "Found jdbc/${JAR}"
else
echo "Could not find jdbc/${JAR}."
echo "Either ensure ${JAR} is in the jdbc folder, or set the JAR variable to the correct name."
exit 1
fi
echo "Checking for changelog/changelog.yaml from previous demo"
if [[ -f changelog/changelog.yaml ]]; then
echo "Found changelog/changelog.yaml. Removing in 3s if not canceled"
sleep 3
rm changelog/changelog.yaml
else
echo "changelog/changelog.yaml not found. Proceeding."
fi
if [[ "$1" == "PERSIST" ]]; then
LOCALDATA="-v $(pwd)/data:/data"
echo "ssh container will mount and write titan commits to $(pwd)/data "
else
unset LOCALDATA
echo "ssh container will be started without local data persistence"
fi
[[ $(docker images mongo | wc -l) -eq 1 ]] && docker pull mongo:latest
[[ $(docker images liquibase/liquibase | wc -l) -eq 1 ]] && docker pull liquibase/liquibase
[[ $(docker images insecure-ssh | wc -l) -eq 1 ]] && echo "Building ssh container" && docker build -t insecure-ssh:latest -f insecureSSH.Dockerfile .
IPADDRESS=$(docker network inspect bridge | jq -r '.[].Containers[]|select(.Name=="'$PG_CONTAINERNAME'")|.IPv4Address| split("/")|.[0]')
alias liquibase="docker run -v $(pwd)/jdbc:/liquibase/jdbc -v $(pwd)/changelog:/liquibase/changelog liquibase/liquibase --driver=org.postgresql.Driver --classpath=/liquibase/jdbc/${JAR} --url="jdbc:postgresql://$IPADDRESS:5432/postgres" --changeLogFile=/liquibase/changelog/changelog.yaml --username=postgres --password=postgres"
alias startSSHD="docker run -d -p 2222:22 ${LOCALDATA} --name titan-sshd insecure-ssh:latest"
alias mongo='docker exec -it titan-mongo mongo'
alias psql="docker exec ${PG_CONTAINERNAME} psql"
if [[ $(docker ps -a --filter name="titan-sshd" | wc -l) -eq 1 ]]; then
echo "Starting titan-sshd container"
startSSHD
else
echo "Restarting titan-sshd container"
docker rm -f titan-sshd
startSSHD
fi
sleep 3
SSHSERVER=$(docker network inspect bridge | jq -r '.[].Containers[]|select(.Name=="titan-sshd")|.IPv4Address| split("/")|.[0]')
echo "Ready for demo"