-
Notifications
You must be signed in to change notification settings - Fork 33
/
create_dockerfile.sh
executable file
·128 lines (110 loc) · 3.72 KB
/
create_dockerfile.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
#!/bin/bash
dist=${1:-bookworm}
version=${2:-5.7.4}
DATE=$(date +"%Y-%m-%d")
KAM_ARCHIVE_REPO="https://deb-archive.kamailio.org/repos/kamailio-${version}"
get_kam_repo() {
if ! wget -q -O /tmp/Packages "${KAM_ARCHIVE_REPO}/dists/${dist}/main/binary-amd64/Packages" ; then
echo "https://deb.kamailio.org/kamailio${kam_version}"
else
echo "${KAM_ARCHIVE_REPO}"
fi
}
get_kam_version() {
if [[ ${version} =~ 4\.4\.[0-9] ]] ; then
kam_version="44"
elif [[ ${version} =~ 5\.([0-9])\.[0-9] ]] ; then
kam_version="5${BASH_REMATCH[1]}"
else
echo "unknown kamailio version '${version}'" >&2
fi
}
kam_packages() {
if ! wget -q -O /tmp/Packages "${KAM_ARCHIVE_REPO}/dists/${dist}/main/binary-amd64/Packages" ; then
KAM_REPO="https://deb.kamailio.org/kamailio${kam_version}"
wget -q -O /tmp/Packages "${KAM_REPO}/dists/${dist}/main/binary-amd64/Packages"
fi
repo_version=$(awk '/Version:/ { print $2 }' /tmp/Packages| head -1)
if [[ ${repo_version} =~ ^${version} ]] ; then
awk -vver="${repo_version}" '/Package:/ { print $2"="ver}' /tmp/Packages | xargs
else
echo "packages in repository \"deb ${KAM_REPO} ${dist} main\" doesn't match version: [${version}]" >&2
echo "version in repository: [${repo_version}]" >&2
fi
}
create_dockerfile() {
cat >"${DOCKERFILE}" <<EOF
FROM ${docker_tag}
LABEL org.opencontainers.image.authors="Victor Seva <[email protected]>"
# Important! Update this no-op ENV variable when this Dockerfile
# is updated with the current date. It will force refresh of all
# of the base images and things like 'apt-get update' won't be using
# old cached versions when the Dockerfile is built.
ENV REFRESHED_AT=${DATE}
EOF
if ${archived} ; then
cat >>"${DOCKERFILE}" <<EOF
# fix repositories
${RULE}
EOF
fi
cat >>"${DOCKERFILE}" <<EOF
RUN rm -rf /var/lib/apt/lists/* && apt-get update && \
DEBIAN_FRONTEND=noninteractive apt-get install -qq --assume-yes gnupg wget apt-transport-https
# kamailio repo
RUN echo "deb ${KAM_REPO} ${dist} main" > \
/etc/apt/sources.list.d/kamailio.list
EOF
if ${apt_key} ; then
echo "RUN wget -O- https://deb.kamailio.org/kamailiodebkey.gpg | apt-key add -" >> ${DOCKERFILE}
else
cat >>"${DOCKERFILE}" <<EOF
RUN wget -O /tmp/kamailiodebkey.gpg https://deb.kamailio.org/kamailiodebkey.gpg && \
gpg --output /etc/apt/trusted.gpg.d/deb-kamailio-org.gpg --dearmor /tmp/kamailiodebkey.gpg
EOF
fi
cat >>"${DOCKERFILE}" <<EOF
RUN apt-get update && \
DEBIAN_FRONTEND=noninteractive apt-get install -qq --assume-yes ${PKGS} \
&& apt-get clean && rm -rf /var/lib/apt/lists/*
# set SHM_MEMORY and PKG_MEMORY from ENV
ENV SHM_MEMORY=${SHM_MEMORY:-64}
ENV PKG_MEMORY=${PKG_MEMORY:-8}
VOLUME /etc/kamailio
ENTRYPOINT kamailio -DD -E -m \${SHM_MEMORY} -M \${PKG_MEMORY}
EOF
}
case ${dist} in
noble|jammy|focal|bionic|xenial|trusty|precise) base=ubuntu ;;
squeeze|wheezy|jessie|stretch|buster|bullseye|bookworm) base=debian ;;
*)
echo "ERROR: no ${dist} base supported"
exit 1
;;
esac
case ${dist} in
squeeze|wheezy|jessie|stretch) docker_tag=${base}/eol:${dist};;
*) docker_tag=${base}:${dist}
esac
case ${dist} in
bookworm) apt_key=false ;;
*) apt_key=true
esac
archived=false
case ${dist} in
precise)
archived=true ; MIRROR=old-release.ubuntu.com
RULE="RUN sed -i -e 's/archive.ubuntu.com/old-releases.ubuntu.com/g' /etc/apt/sources.list"
;;
squeeze|wheezy|jessie|stretch)
archived=true ; MIRROR=archive.debian.org
RULE="RUN sed -i -e 's/deb.debian.org/archive.debian.org/g' -e '/security.debian.org/d' -e '/${dist}-updates/d' /etc/apt/sources.list"
;;
esac
get_kam_version
KAM_REPO=$(get_kam_repo)
PKGS=$(kam_packages)
[ -n "${PKGS}" ] || exit 1
mkdir -p "${dist}"
DOCKERFILE="${dist}/Dockerfile"
create_dockerfile