-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathgenerate-repo-dockerfiles.sh
executable file
·204 lines (173 loc) · 5.32 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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
#!/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#*/}
case "${user}/${name}" in
"kylemanna/docker-openvpn")
name=openvpn-server
;;
*) ;;
esac
local image=${name}
case "$image" in
"contained.af")
image="contained";;
"present.j3ss.co")
image="present";;
esac
# Make sure the webhook for jenkins exists.
if [[ "${user}" == "jessfraz" ]] || [[ "${user}" == "genuinetools" ]]; then
make webhook-jenkins-create REPO="${user}/${name}" 1>/dev/null
fi
rname=${name//-/_}
rname=${rname//1/one}
file="${DIR}/projects/repo-dockerfiles/${rname//./_}.groovy"
echo "${file} | ${image}"
cat <<-EOF > "$file"
freeStyleJob('${rname//./_}') {
displayName('${name}')
description('Build Dockerfiles in ${orig}.')
concurrentBuild()
checkoutRetryCount(3)
properties {
githubProjectUrl('https://github.com/${orig}')
sidebarLinks {
link('https://hub.docker.com/r/jess/${image}', 'Docker Hub: jess/${image}', 'notepad.png')
link('https://hub.docker.com/r/jessfraz/${image}', 'Docker Hub: jessfraz/${image}', 'notepad.png')
link('https://r.j3ss.co/repo/${image}/tags', 'Registry: r.j3ss.co/${image}', 'notepad.png')
EOF
if [[ "$image" == "contained" ]]; then
cat <<-EOF >> "$file"
link('https://hub.docker.com/r/jess/docker', 'Docker Hub: jess/docker', 'notepad.png')
link('https://hub.docker.com/r/jessfraz/docker', 'Docker Hub: jessfraz/docker', 'notepad.png')
link('https://r.j3ss.co/repo/docker/tags', 'Registry: r.j3ss.co/docker', 'notepad.png')
EOF
fi
cat <<-EOF >> "$file"
}
}
logRotator {
numToKeep(100)
daysToKeep(15)
}
scm {
git {
remote {
url('https://github.com/${orig}.git')
}
branches('*/master', '*/tags/*')
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}:latest .')
shell('docker tag r.j3ss.co/${image}:latest jess/${image}:latest')
shell('docker tag r.j3ss.co/${image}:latest jessfraz/${image}:latest')
shell('docker push --disable-content-trust=false r.j3ss.co/${image}:latest')
shell('docker push --disable-content-trust=false jess/${image}:latest')
shell('docker push --disable-content-trust=false jessfraz/${image}:latest')
EOF
if [[ "$image" != "bpfd" ]]; then
cat <<-EOF >> "$file"
shell('for tag in \$(git tag); do git checkout \$tag; docker build --rm --force-rm -t r.j3ss.co/${image}:\$tag . || true; docker push --disable-content-trust=false r.j3ss.co/${image}:\$tag || true; docker tag r.j3ss.co/${image}:\$tag jess/${image}:\$tag || true; docker push --disable-content-trust=false jess/${image}:\$tag || true; done')
EOF
fi
if [[ "$image" == "contained" ]]; then
cat <<-EOF >> "$file"
shell('git checkout master')
shell('docker build --rm --force-rm -f Dockerfile.dind -t r.j3ss.co/docker:userns .')
shell('docker tag r.j3ss.co/docker:userns jess/docker:userns')
shell('docker tag r.j3ss.co/docker:userns jessfraz/docker:userns')
shell('docker push --disable-content-trust=false r.j3ss.co/docker:userns')
shell('docker push --disable-content-trust=false jess/docker:userns')
shell('docker push --disable-content-trust=false jessfraz/docker:userns')
EOF
fi
cat <<-EOF >> "$file"
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')
}
publishers {
retryBuild {
retryLimit(2)
fixedDelay(15)
}
extendedEmail {
recipientList('\$DEFAULT_RECIPIENTS')
contentType('text/plain')
triggers {
stillFailing {
attachBuildLog(true)
}
}
}
wsCleanup()
}
}
EOF
}
repos=(
genuinetools/1up
genuinetools/amicontained
genuinetools/apk-file
genuinetools/audit
genuinetools/bane
genuinetools/bpfd
genuinetools/bpfps
genuinetools/certok
genuinetools/contained.af
genuinetools/ghb0t
genuinetools/img
genuinetools/magneto
genuinetools/netns
genuinetools/pepper
genuinetools/reg
genuinetools/releases
genuinetools/riddler
genuinetools/sshb0t
genuinetools/udict
genuinetools/upmail
genuinetools/weather
jessfraz/battery
jessfraz/cliaoke
jessfraz/dstats
jessfraz/dockfmt
jessfraz/gitable
jessfraz/gmailfilters
jessfraz/morningpaper2remarkable
jessfraz/netscan
jessfraz/party-clippy
jessfraz/pastebinit
jessfraz/pony
jessfraz/present.j3ss.co
jessfraz/s3server
jessfraz/secping
jessfraz/ship
jessfraz/snippetlib
jessfraz/tdash
jessfraz/tripitcalb0t
kylemanna/docker-openvpn
)
main(){
rm -rf "$DIR/projects/repo-dockerfiles"
mkdir -p "$DIR/projects/repo-dockerfiles"
echo "FILE | IMAGE"
for r in "${repos[@]}"; do
generate_dsl "${r}"
done
}
main