-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·125 lines (105 loc) · 2.88 KB
/
build.sh
File metadata and controls
executable file
·125 lines (105 loc) · 2.88 KB
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
#!/bin/sh
NETWORK_NAME="whale"
SLSOFFLINE_IMAGE_NAME="slsoffline"
DYNAMODB_CONTAINER_NAME="dynamodblocal-1"
SLSOFFLINE_CONTAINER_NAME="slsoffline-1"
REBUILD=0
REMOVE=0
function printUsage {
echo "Usage: ./build.sh COMMAND
Run docker scripts
Commands:
rebuild Remove and build all stuff from scratch
run Run all containers
remove Remove all stuff"
}
case $1 in
rebuild)
REBUILD=1
;;
remove)
REMOVE=1
;;
run)
;;
-h | --help )
printUsage
exit
;;
*)
echo "command $1 is not recognized as a valid command"
printUsage
exit 1
esac
function stopAndRemoveContainer {
a=$(docker container ls -aq -f name=$1)
if [ "$a" != "" ]; then
echo "stopping container $a..."
docker container stop $a
echo "removing container $a..."
docker container rm -v $a
fi
}
function removeImage {
if [ "$(docker images -q $1 2>/dev/null)" != "" ]; then
echo "removing image $1..."
docker image rm $1 .
fi
}
function buildImage {
if [ "$(docker images -q $1 2>/dev/null)" == "" ]; then
echo "building image $1..."
docker image build -t $1 .
fi
}
function removeNetwork {
if [ "$(docker network ls -qf name=$1 2>/dev/null)" != "" ]; then
echo "removing network $1..."
docker network rm $1
fi
}
function createNetwork {
if [ "$(docker network ls -qf name=$1 2>/dev/null)" == "" ]; then
echo "creating network $1..."
docker network create $1
fi
}
if [ $REMOVE -eq 1 ]; then
echo "removing local npm packages..."
npm uninstall `ls -1 node_modules | tr '/\n' ' '`
else
echo "running npm install..."
npm install
fi
stopAndRemoveContainer $DYNAMODB_CONTAINER_NAME
stopAndRemoveContainer $SLSOFFLINE_CONTAINER_NAME
if [ $REBUILD -eq 1 ] || [ $REMOVE -eq 1 ]; then
removeImage $SLSOFFLINE_IMAGE_NAME
fi
if [ $REMOVE -ne 1 ]; then
buildImage $SLSOFFLINE_IMAGE_NAME
fi
if [ $REBUILD -eq 1 ] || [ $REMOVE -eq 1 ]; then
removeNetwork $NETWORK_NAME
fi
if [ $REMOVE -ne 1 ]; then
createNetwork $NETWORK_NAME
fi
if [ $REMOVE -ne 1 ]; then
echo "running contaner $DYNAMODB_CONTAINER_NAME..."
docker container run --network $NETWORK_NAME \
--name $DYNAMODB_CONTAINER_NAME \
-d \
-p 8000:8000 \
cnadiminti/dynamodb-local -sharedDb –inMemory
echo "running contaner $SLSOFFLINE_CONTAINER_NAME..."
docker container run --network $NETWORK_NAME \
--name $SLSOFFLINE_CONTAINER_NAME \
-d \
-p 3001:3001 \
--mount type=bind,source=$(pwd),target=/app \
$SLSOFFLINE_IMAGE_NAME
echo "running dynamodb migration script..."
docker exec -ti $SLSOFFLINE_CONTAINER_NAME \
bash -c '/app/node_modules/.bin/sls dynamodb migrate --stage dkr'
fi