-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
executable file
·65 lines (54 loc) · 1.67 KB
/
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/env bash
# Build Executer for SSLScan Docker Image CI/CD.
# Run via cron, build, test, push, fail fast.
# Env Vars for SSH
source /root/.ssh/agent/root || . /root/.ssh/agent/root
# Log file
log="/home/docker/sslscan/sslscan_docker_image/log_build.log"
# Build current timestamp
timestamp () {
date +"%Y%m%d_%H%M"
}
# Static start time.
ts=$(timestamp)
# Exception Catcher
except () {
logger $1
return 1
}
# log and print to stdout
# logger is called by except so to avoid infinte loops do not call except from logger.
logger () {
echo $1 || printf "\nError! logger function failed to stdout.\n"
echo $(timestamp) - $1 >> $log || printf "\nError! logger function failed to file.\n"
}
# Test the build of SSLScan works.
test () {
docker run --rm $1 https://google.com.au | tee -a $log || return 1
}
# Run the build and push to Git and Docker.
run () {
docker build /home/docker/sslscan/sslscan_docker_image/ -t blairy/sslscan:$ts --no-cache --rm --pull | tee -a $log || except "Docker build failed!"
if test blairy/sslscan:$ts
then
git="/usr/bin/git -C /home/docker/sslscan/sslscan_docker_image/"
$git pull && \
$git add --all && \
$git commit -a -m "Automatic build "$ts && \
$git push | tee -a $log || except "Git Failed!"
docker push blairy/sslscan:$ts | tee -a $log || except "Docker push failed!"
else
except "SSLScan Test Failed!"
fi
}
# Manage execution
if run; then
logger "Build and Push successfull!"
exit 0
else
except "Run Failed!"
exit 1
fi
# Prune
cd /home/docker/sslscan/sslscan_docker_image/ && /usr/bin/git gc --prune
printf "ERROR! escaped context!" && exit 1