-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathdocker-build.sh
executable file
·44 lines (34 loc) · 1.28 KB
/
docker-build.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
#!/bin/bash
args=$@
if [ -z "$args" ]; then
echo "Command arguments are missing."
echo "Usage: ./docker-build.sh <command>"
echo "Example: ./docker-build.sh npm run build-firefox"
exit
fi
mkdir logs || echo "Ignore"
rm -rf node_modules
rm -rf dist
#docker rmi -f tab-master-5000-build-env:latest -f
docker build -t tab-master-5000-build-env . || echo ""
# Kill the container on exit in case of an interruption
cleanUp() {
printf "\n\nInterrupted, killing container\n\n"
exec docker kill $id
rm $logPath
trap - EXIT
}
trap cleanUp SIGINT
# Unix timestamps
ts=$(date "+%s")
# Get the current shorthand commit hash
commit=$(git log --pretty=format:'%h' -n 1)
# Runs the container detached, bind mounts to the current directory,
# and run the npm scripts in a shell. assigns the container hash to $id.
# Then installs node modules and runs the command arguments of this script.
id=$(docker run -it -d -e COMMIT_HASH=$commit -v $(pwd):/tm5k tab-master-5000-build-env /bin/sh -c "npm install && $args")
logPath=./logs/build-$commit-$ts.log
echo "Container: $id"
docker logs -f $id 2>&1 | tee -a $logPath
# Remove color code artifacts and resulting empty lines from the log file
echo $(cat $logPath | sed -r 's/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[mGK]//g' | sed -r '/^\s*$/d') > $logPath