-
Notifications
You must be signed in to change notification settings - Fork 63
/
docker-start.sh
executable file
·77 lines (67 loc) · 2.05 KB
/
docker-start.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
#!/bin/bash
HELP=0
SERVICE=0
EXTERNAL_IP=
EXTERNAL_PORT=
while getopts "hdi:p:" opt; do
case $opt in
h) HELP=1
;;
d) SERVICE=1
;;
i) EXTERNAL_IP="$OPTARG"
;;
p) EXTERNAL_PORT="$OPTARG"
;;
\?) echo "Invalid option -$OPTARG" >&2; exit 1
;;
esac
done
if [ $HELP -eq 1 ]; then
echo
echo "Usage:"
echo "docker_start.sh -- Run with defaults in interactive mode"
echo "docker_start.sh [params]"
echo "-h -- Show help"
echo "-d -- Run as a service"
echo "-i IP -- Specify an external IP address to use"
echo "-p port -- Specify an external port to use"
echo
exit 0
fi
if [ ! -f .env ] || [ ! -d ~/.aws ]; then
echo "Expected AWS settings not found. Please run the aws-setup script."
exit 1
fi
source .env
AWS_ACCESS_KEY_ID="$( /usr/bin/awk -F' = ' '$1 == "aws_access_key_id" {print $2}' ~/.aws/credentials )"
AWS_SECRET_ACCESS_KEY="$( /usr/bin/awk -F' = ' '$1 == "aws_secret_access_key" {print $2}' ~/.aws/credentials )"
AWS_DEFAULT_REGION="$( /usr/bin/awk -F' = ' '$1 == "region" {print $2}' ~/.aws/config )"
CONTAINER_NAME=alexa_chromecast
if [ "$( docker container inspect -f '{{.State.Status}}' $CONTAINER_NAME )" == "running" ]; then
docker stop $CONTAINER_NAME
fi
docker rm $CONTAINER_NAME 2>/dev/null
docker build -t alexa-skill-chromecast .
if [ $SERVICE -eq 1 ]; then
docker run -d --network="host" \
--name alexa_chromecast \
--restart always \
-e "AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID"\
-e "AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY"\
-e "AWS_DEFAULT_REGION=$AWS_DEFAULT_REGION"\
-e "AWS_SNS_TOPIC_ARN=$AWS_SNS_TOPIC_ARN"\
-e "EXTERNAL_IP=$EXTERNAL_IP"\
-e "EXTERNAL_PORT=$EXTERNAL_PORT"\
alexa-skill-chromecast
else
docker run --network="host" -it\
--name alexa_chromecast \
-e "AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID"\
-e "AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY"\
-e "AWS_DEFAULT_REGION=$AWS_DEFAULT_REGION"\
-e "AWS_SNS_TOPIC_ARN=$AWS_SNS_TOPIC_ARN"\
-e "EXTERNAL_IP=$EXTERNAL_IP"\
-e "EXTERNAL_PORT=$EXTERNAL_PORT"\
alexa-skill-chromecast
fi