aboutsummaryrefslogtreecommitdiff
path: root/www/build-images.sh
blob: 903ecad0187f3815b82d1e2dd0103395b8aacb31 (plain)
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
#!/usr/bin/env bash
set -euo pipefail

WORKDIR="/tmp/${EVENTLINE_JOB_NAME}"

cleanup() {
	rm -rf "${WORKDIR}"
}

trap cleanup EXIT

ret=0; buildah images adyxax/alpine &>/dev/null || ret=$?
if [[ "${ret}" != 0 ]]; then
	buildah rmi --all || true
	ALPINE_LATEST=$(curl --silent https://dl-cdn.alpinelinux.org/alpine/latest-stable/releases/x86_64/ |
		perl -lane '$latest = $1 if $_ =~ /^<a href="(alpine-minirootfs-\d+\.\d+\.\d+-x86_64\.tar\.gz)">/; END {print $latest}'
	)
	if [ ! -e "./${ALPINE_LATEST}" ]; then
		echo "Fetching ${ALPINE_LATEST}..."
		curl --silent "https://dl-cdn.alpinelinux.org/alpine/latest-stable/releases/x86_64/${ALPINE_LATEST}" \
			--output "./${ALPINE_LATEST}"
	fi

	ctr=$(buildah from scratch)
	buildah add "${ctr}" "${ALPINE_LATEST}" /
	buildah run "${ctr}" /bin/sh -c 'apk upgrade --no-cache'
	buildah run "${ctr}" /bin/sh -c 'apk add --no-cache pcre sqlite-libs'
	buildah commit "${ctr}" adyxax/alpine
	buildah rm "${ctr}"
fi

ret=0; buildah images adyxax/hugo &>/dev/null || ret=$?
if [[ "${ret}" != 0 ]]; then
	hugo=$(buildah from adyxax/alpine)
	buildah run "${hugo}" /bin/sh -c 'apk add --no-cache go git hugo make'
	buildah commit "${hugo}" adyxax/hugo
else
	hugo=$(buildah from adyxax/hugo)
fi

buildah run -v "${WORKDIR}":/www "${hugo}" -- sh -c 'cd /www; make build'
buildah rm "${hugo}"

ret=0; buildah images adyxax/nginx &>/dev/null || ret=$?
if [[ "${ret}" != 0 ]]; then
	nginx=$(buildah from adyxax/alpine)
	buildah run "${nginx}" /bin/sh -c 'apk add --no-cache nginx'
	buildah commit "${nginx}" adyxax/nginx
else
	nginx=$(buildah from adyxax/nginx)
fi

(cd "${WORKDIR}/deploy" && buildah copy "${nginx}" nginx.conf headers_secure.conf headers_static.conf /etc/nginx/)
buildah config \
	--author 'Julien Dessaux' \
	--cmd nginx \
	--port 80 \
	"${nginx}"
(cd "${WORKDIR}" && buildah copy "${nginx}" public /var/www/www.adyxax.org)
buildah commit "${nginx}" adyxax/www
buildah rm "${nginx}"

ctr=$(buildah from scratch)
(cd "${WORKDIR}" && buildah copy "${ctr}" search/search /)
buildah config \
	--author 'Julien Dessaux' \
	--cmd /search \
	--port 8080 \
	"${ctr}"
buildah commit "${ctr}" adyxax/www-search
buildah rm "${ctr}"

trap - EXIT