forked from abn/rpmbuilder
-
Notifications
You must be signed in to change notification settings - Fork 1
/
crypt-keeper
executable file
·93 lines (77 loc) · 2.08 KB
/
crypt-keeper
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
#!/usr/bin/env bash
DOCKER_REGISRY_USER=alectolytic
function generate() {
SOURCES=${SOURCES-/sources}
OUTPUT=${OUTPUT-/output}
WORKSPACE=${WORKSPACE-/workspace}
RPM_BUILD_DIR=${RPM_BUILD_DIR-/rpmbuild}
DISTRO=${1-fedora}
RELEASE=${2-latest}
ROOT=$(pwd)/${DISTRO}/${RELEASE}/
ASSETS=${ROOT}/assets
DOCKERFILE=${ROOT}/Dockerfile
rm -rf ${ROOT} && mkdir -p ${ROOT}
# prepare files
cp -R ./assets ${ROOT}/.
# cp LICENCE README.md
YUM="yum"
PACKAGES="rpm-build rpmdevtools yum-utils rpmlint"
case "${DISTRO}" in
centos|cloudrouter*centos)
EXTRA_PACKAGES="epel-release";
;;
fedora)
YUM="dnf";
EXTRA_PACKAGES="'dnf-command(builddep)'";
;;
esac
# header
cat > ${DOCKERFILE} << EOF
FROM ${DISTRO}:${RELEASE}
MAINTAINER "Arun Neelicattu" <[email protected]>
ENV WORKSPACE=${WORKSPACE} \\
SOURCES=${SOURCES} \\
OUTPUT=${OUTPUT} \\
RPM_BUILD_DIR=${RPM_BUILD_DIR}
RUN ${YUM} -y install ${PACKAGES} ${EXTRA_PACKAGES} \\
&& ${YUM} -y clean all \\
&& ln -sf \${RPM_BUILD_DIR} /root/rpmbuild \\
&& mkdir -p \${SOURCES} \\
\${WORKSPACE} \\
\${OUTPUT} \\
\${RPM_BUILD_DIR}/{BUILD,RPMS,SOURCES,SPECS,SRPMS}
VOLUME ["\${SOURCES}", "\${OUTPUT}", "\${WORKSPACE}", "\${RPM_BUILD_DIR}"]
ADD ./assets/build /usr/bin/build
CMD ["build"]
EOF
}
function map-all() {
while IFS=' ' read -r -a input; do
$1 ${input[0]} ${input[1]}
done < ./defaults
}
function docker-image-name() {
DISTRO=${1}
VERSION=${2}
echo -n "${DOCKER_REGISRY_USER}/rpmbuilder:${DISTRO/\//-}-${VERSION}"
}
function build() {
DISTRO=${1}
VERSION=${2}
cd ${DISTRO}/${VERSION} \
&& docker build -t $(docker-image-name ${DISTRO} ${VERSION}) .
cd -
}
function push() {
DISTRO=${1}
VERSION=${2}
docker push $(docker-image-name ${DISTRO} ${VERSION})
}
case "$1" in
generate|build|push)
if [ "$2" == "all" ]; then
map-all $1
else
$1 $2 $3
fi ;;
esac