2 # 2021-04-07 Olaf Bohlen <olbohlen@eenfach.de>
3 # 2021-11-30 Till Wegmueller <toasterson@gmail.com>
4 # instead of putting all this into the Jenkinsfile I decided to put the actual code in this script
9 HTTPCONF
="/etc/apache2/2.4/conf.d/pkgdepotd.conf"
11 # just run prepare once to initially set up the environment
12 # this must be run as root
14 echo "jenkinshelper: preparing..."
15 pkg
install web
/server
/apache-24
16 mkdir
-p /etc
/apache
2/2.4/conf.d
&& chown root
:sys
/etc
/apache
2/2.4/conf.d
17 grep "#ProxyPassMatch /default/(.*)\$ http://127.0.0.1:10000/\$1 nocanon max=200" "${HTTPCONF}" >/dev
/null
2>&1
19 echo "jenkinshelper: Initializing a new apache config at ${HTTPCONF}"
20 echo "#ProxyPassMatch /default/(.*)\$ http://127.0.0.1:10000/\$1 nocanon max=200" >"${HTTPCONF}"
22 echo "jenkinshelper: Preserving an existing ${HTTPCONF}"
25 cat >/etc
/apache
2/2.4/conf.d
/00-proxy.conf
<<EOF
26 LoadModule proxy_module libexec/mod_proxy.so
27 LoadModule proxy_connect_module libexec/mod_proxy_connect.so
28 LoadModule proxy_ftp_module libexec/mod_proxy_ftp.so
29 LoadModule proxy_http_module libexec/mod_proxy_http.so
30 LoadModule proxy_ajp_module libexec/mod_proxy_ajp.so
35 RequestHeader unset Origin
36 AllowEncodedSlashes NoDecode
39 chown root
:builders
"${HTTPCONF}"
40 chmod 664 "${HTTPCONF}"
41 svcadm
enable svc
:/network
/http
:apache24
46 if [ ! -f /etc
/apache
2/2.4/conf.d
/00-proxy.conf
]; then
47 echo "jenkinshelper: aborting, please run \"jenkinshelper -p\" initially as root on this jenkins instance once"
50 echo "jenkinshelper: running gmake setup"
54 # scan the git log for changed components
55 # we try to be smart and assume that all updates will always touch
56 # the components Makefile also (to update COMPONENT_REVISION, etc)
57 stage_build_changed
() {
59 for f
in $
(git
diff --name-only HEAD..origin
/oi
/hipster |
grep Makefile
; exit 0); do
60 echo "jenkinshelper: building for ${f%/*}..."
62 cd "${f%/*}" && gmake clean
&& gmake PARALLEL_JOBS
=$
(psrinfo
-t -c) publish
65 echo "jenkinshelper: done with ${f%/*} return code ${rc}"
66 if [ rc
-ne 0 ] ; then
73 # prepare the pkg.depotd server instance, if an instance already
74 # exists for this branch, we will use that - otherwise create a
76 stage_prepare_pkgdepotd
() {
77 # we need the platform for the path to the repo
80 # check if we already have this branch set up as a pkg.depotd:
81 if ! svcs
"pkg/server:${BRANCH_NAME}" >/dev
/null
2>&1; then
83 # get highest port from ${HTTPCONF} to figure out the next free one
84 nextport
=$
(($
(nawk
-F '[/:]' '{ print $7 }' <"${HTTPCONF}" |
sort -n |
tail -1) + 1))
86 # set-up a new pkg/server instance
87 svccfg
-s pkg
/server
<<EOF
91 setprop pkg/port=${nextport}
92 setprop pkg/readonly=true
93 setprop pkg/pkg_root=/
94 setprop pkg/inst_root=${WORKSPACE}/${platform}/repo
95 setprop pkg/proxy_base=${JENKINS_URL%:[0-9]*/}/${BRANCH_NAME}/
99 # enable the new pkg/server instance
100 svcadm
enable pkg
/server
:${BRANCH_NAME}
102 # add the new proxy rule to our apache config
103 echo "ProxyPassMatch /${BRANCH_NAME}/(.*)\$ http://127.0.0.1:${nextport}/\$1 nocanon max=200" >>"${HTTPCONF}"
107 # we need to refresh the repo:
108 pkgrepo refresh
-s ${WORKSPACE}/${platform}/repo
110 # also restarting pkg.depotd does not hurt
111 svcadm restart pkg
/server
:${BRANCH_NAME}
113 # graceful restart apache to reload config
114 svcadm refresh svc
:/network
/http
:apache24
117 # cleanup the pkg.depotd server instance
119 # we need the platform for the path to the repo
122 if ! "svcs pkg/server:${BRANCH_NAME}" >/dev
/null
2>&1; then
123 # disable the instance
124 svcadm disable pkg
/server
:${BRANCH_NAME}
126 # svcadm is a async operation thus sleep here
129 # remove instance from SMF
130 svccfg delete pkg
/server
:${BRANCH_NAME}
133 sed "/^ProxyPassMatch /${BRANCH_NAME}/d"
135 # graceful restart apache to reload config
136 svcadm refresh svc
:/network
/http
:apache24
143 jenkinshelper.ksh [ -h | -p | -s <stage> ]
145 -p run only ONCE to initialize your environment
146 -s followed by the stage to run, currently:
147 setup, build_changed, prepare_pkgdepotd
153 # call this script with the stage as an argument to -s
155 while getopts s
:hp argv
; do
157 s
) stage
="stage_${OPTARG}" ;;
158 p
) stage
="prepare" ;;
162 shift $
(expr ${OPTIND} - 1)
164 # run requested stage