forked from jessfraz/jenkins-dsl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate-repo-dockerfiles.sh
executable file
·163 lines (135 loc) · 3.48 KB
/
generate-repo-dockerfiles.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
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#!/bin/bash
# This script generates the DSLs for building Dockerfiles in each of my repos.
set -e
set -o pipefail
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
generate_dsl(){
local orig=$1
local user=${orig%/*}
local name=${orig#*/}
local suite=latest
case "${user}/${name}" in
"kylemanna/docker-openvpn")
name=openvpn-server
;;
"rroemhild/docker-ejabberd")
name=ejabberd
;;
*) ;;
esac
local image=${name}:${suite}
rname=${name//-/_}
file="${DIR}/projects/repo-dockerfiles/${rname//./_}.groovy"
echo "${file} | ${image}"
cat <<-EOF > $file
freeStyleJob('${rname//./_}') {
displayName('${name}')
description('Build Dockerfiles in ${orig}.')
checkoutRetryCount(3)
properties {
githubProjectUrl('https://github.com/${orig}')
sidebarLinks {
link('https://hub.docker.com/r/jess/${name}', 'Docker Hub: jess/${name}', 'notepad.png')
}
}
logRotator {
numToKeep(2)
daysToKeep(2)
}
scm {
git {
remote {
url('https://github.com/${orig}.git')
}
branches('*/master')
extensions {
wipeOutWorkspace()
cleanAfterCheckout()
}
}
}
triggers {
cron('H H * * *')
githubPush()
}
wrappers { colorizeOutput() }
environmentVariables(DOCKER_CONTENT_TRUST: '1')
steps {
shell('docker build --rm --force-rm -t r.j3ss.co/${image} .')
shell('docker tag r.j3ss.co/${image} jess/${image}')
shell('docker push --disable-content-trust=false r.j3ss.co/${image}')
shell('docker push --disable-content-trust=false jess/${image}')
EOF
# also push the weather-server & reg-server images
if [[ "${user}/${name}" == "jessfraz/weather" ]] || [[ "${user}/${name}" == "jessfraz/reg" ]]; then
image=${name}-server:${suite}
cat <<-EOF >> $file
shell('docker build --rm --force-rm --no-cache -t r.j3ss.co/${image} server')
shell('docker tag r.j3ss.co/${image} jess/${image}')
shell('docker push --disable-content-trust=false r.j3ss.co/${image}')
shell('docker push --disable-content-trust=false jess/${image}')
EOF
fi
cat <<-EOF >> $file
}
publishers {
postBuildScripts {
steps {
shell('docker rm \$(docker ps --filter status=exited -q 2>/dev/null) 2> /dev/null || true')
shell('docker rmi \$(docker images --filter dangling=true -q 2>/dev/null) 2> /dev/null || true')
}
onlyIfBuildSucceeds(false)
}
retryBuild {
retryLimit(2)
fixedDelay(15)
}
extendedEmail {
recipientList('\$DEFAULT_RECIPIENTS')
contentType('text/plain')
triggers {
stillFailing {
attachBuildLog(true)
}
}
}
wsCleanup()
}
}
EOF
}
repos=(
jessfraz/apk-file
jessfraz/audit
jessfraz/bane
jessfraz/battery
jessfraz/certok
jessfraz/cliaoke
jessfraz/dockfmt
jessfraz/dstats
jessfraz/ghb0t
jessfraz/magneto
jessfraz/netns
jessfraz/netscan
jessfraz/onion
jessfraz/pastebinit
jessfraz/pepper
jessfraz/pony
jessfraz/reg
jessfraz/riddler
jessfraz/s3server
jessfraz/snippetlib
jessfraz/udict
jessfraz/upmail
jessfraz/weather
kylemanna/docker-openvpn
rroemhild/docker-ejabberd
)
main(){
mkdir -p $DIR/projects/repo-dockerfiles
echo "FILE | IMAGE"
for r in "${repos[@]}"; do
generate_dsl "${r}"
done
}
main