-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun.sh
More file actions
executable file
·71 lines (60 loc) · 1.86 KB
/
Copy pathrun.sh
File metadata and controls
executable file
·71 lines (60 loc) · 1.86 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
#!/bin/bash
# Function to build Docker image with version from package.json
build_image() {
version=$(jq -r '.version' package.json)
docker build -t shreyasnayak21/nodejs-faas:$version .
}
# Function to push Docker image to registry
push_image() {
version=$(jq -r '.version' package.json)
docker push shreyasnayak21/nodejs-faas:$version
}
# Function to stop and remove old container, then run new build
run_container() {
version=$(jq -r '.version' package.json)
container_id=$(docker ps -q --filter "ancestor=shreyasnayak21/nodejs-faas:$version")
if [ -n "$container_id" ]; then
docker stop $container_id
docker rm $container_id
fi
docker run --name nodejs-faas -p 9256:9256 shreyasnayak21/nodejs-faas:$version
}
# Function to stop and remove old container, then run new build in background
start_container() {
version=$(jq -r '.version' package.json)
container_id=$(docker ps -q --filter "ancestor=shreyasnayak21/nodejs-faas:$version")
if [ -n "$container_id" ]; then
docker stop $container_id
docker rm $container_id
fi
docker run -d --name nodejs-faas -p 9256:9256 shreyasnayak21/nodejs-faas:$version
}
# Function to kill running container
kill_container() {
version=$(jq -r '.version' package.json)
container_id=$(docker ps -q --filter "ancestor=shreyasnayak21/nodejs-faas:$version")
if [ -n "$container_id" ]; then
docker kill $container_id
fi
}
# Main script
case "$1" in
--build)
build_image
;;
--push)
push_image
;;
--run)
run_container
;;
--start)
start_container
;;
--kill)
kill_container
;;
*)
echo "Usage: $0 {--build|--push|--run|--start|--kill}"
exit 1
esac