-
Notifications
You must be signed in to change notification settings - Fork 4
/
build-images.sh
100 lines (87 loc) · 3.33 KB
/
build-images.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
#!/bin/bash
# Terminate on error
set -e
# Prepare variables for later use
images=()
# The image will be pushed to GitHub container registry
repobase="ghcr.io/nethesis"
# Configure the image name
reponame="nethvoice-proxy-postgres"
# Build and commit the image
buildah bud \
-t "${repobase}/${reponame}" \
-t "${repobase}/${reponame}:${IMAGETAG:-latest}" \
modules/postgres
# Append the image URL to the images array
images+=("${repobase}/${reponame}")
# Configure the image name
reponame="nethvoice-proxy-kamailio"
# Build and commit the image
buildah bud \
-t "${repobase}/${reponame}" \
-t "${repobase}/${reponame}:${IMAGETAG:-latest}" \
modules/kamailio
# Append the image URL to the images array
images+=("${repobase}/${reponame}")
# Configure the image name
reponame="nethvoice-proxy-redis"
# Build and commit the image
buildah bud \
-t "${repobase}/${reponame}" \
-t "${repobase}/${reponame}:${IMAGETAG:-latest}" \
modules/redis
# Append the image URL to the images array
images+=("${repobase}/${reponame}")
# Configure the image name
reponame="nethvoice-proxy-rtpengine"
buildah bud \
-t "${repobase}/${reponame}" \
-t "${repobase}/${reponame}:${IMAGETAG:-latest}" \
modules/rtpengine
# Append the image URL to the images array
images+=("${repobase}/${reponame}")
# Configure the image name
reponame="nethvoice-proxy"
# Create a new empty container image
container=$(buildah from scratch)
# Reuse existing nodebuilder-kickstart container, to speed up builds
if ! buildah containers --format "{{.ContainerName}}" | grep -q nodebuilder-nethvoice-proxy; then
echo "Pulling NodeJS runtime..."
buildah from --name nodebuilder-nethvoice-proxy -v "${PWD}:/usr/src:Z" docker.io/library/node:lts
fi
echo "Build static UI files with node..."
buildah run \
--workingdir=/usr/src/ui \
--env="NODE_OPTIONS=--openssl-legacy-provider" \
nodebuilder-nethvoice-proxy \
sh -c "yarn install && yarn build"
# Add imageroot directory to the container image
buildah add "${container}" imageroot /imageroot
buildah add "${container}" ui/dist /ui
# Setup the entrypoint, ask to reserve one TCP port with the label and set a rootless container
buildah config --entrypoint=/ \
--label="org.nethserver.max-per-node=1" \
--label="org.nethserver.rootfull=0" \
--label="org.nethserver.authorizations=node:fwadm traefik@any:certadm" \
--label="org.nethserver.tcp-ports-demand=2" \
--label="org.nethserver.images=${repobase}/nethvoice-proxy-postgres:${IMAGETAG:-latest} \
${repobase}/nethvoice-proxy-kamailio:${IMAGETAG:-latest} \
${repobase}/nethvoice-proxy-redis:${IMAGETAG:-latest} \
${repobase}/nethvoice-proxy-rtpengine:${IMAGETAG:-latest}" \
"${container}"
# Commit the image
buildah commit "${container}" "${repobase}/${reponame}"
buildah commit "${container}" "${repobase}/${reponame}:${IMAGETAG:-latest}"
# Append the image URL to the images array
images+=("${repobase}/${reponame}")
# Setup CI when pushing to Github.
# Warning! docker::// protocol expects lowercase letters (,,)
if [[ -n "${CI}" ]]; then
# Set output value for Github Actions
printf "::set-output name=images::%s\n" "${images[*]}"
else
# Just print info for manual push
printf "Publish the images with:\n\n"
for image in "${images[@],,}"; do printf " buildah push %s docker://%s:%s\n" "${image}" "${image}" "${IMAGETAG:-latest}" ; done
printf "\n"
fi