From a300c1497251032d5b40cb86e10cab264cb25492 Mon Sep 17 00:00:00 2001 From: Julien Dessaux Date: Tue, 6 Sep 2022 00:40:46 +0200 Subject: Reworked the building of the website in a container with buildah --- deploy/build-image.sh | 59 +++++++++++++++++++++++++++++---------------------- 1 file changed, 34 insertions(+), 25 deletions(-) (limited to 'deploy/build-image.sh') diff --git a/deploy/build-image.sh b/deploy/build-image.sh index 4d576dd..a9cf511 100755 --- a/deploy/build-image.sh +++ b/deploy/build-image.sh @@ -1,55 +1,64 @@ #!/usr/bin/env bash -set -eu +set -euo pipefail -(cd .. && make clean build) - -ret=0; output=$(buildah images adyxax/alpine &>/dev/null) || ret=$? -if [ $ret != 0 ]; then +ret=0; buildah images adyxax/alpine &>/dev/null || ret=$? +if [[ "${ret}" != 0 ]]; then + buildah rmi --all ALPINE_LATEST=$(curl --silent https://dl-cdn.alpinelinux.org/alpine/latest-stable/releases/x86_64/ | perl -lane '$latest = $1 if $_ =~ /^/; 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} + 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 add --no-cache pcre sqlite-libs' - buildah commit $ctr adyxax/alpine + 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 - ctr=$(buildah from adyxax/alpine) - #buildah run $ctr /bin/sh -c 'apk upgrade --no-cache' + hugo=$(buildah from adyxax/hugo) fi +buildah run -v "${PWD}":/www "${hugo}" -- sh -c 'cd /www; make build' +buildah rm "${hugo}" + ret=0; buildah images adyxax/nginx &>/dev/null || ret=$? -if [ $ret != 0 ]; then +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 + buildah run "${nginx}" /bin/sh -c 'apk add --no-cache nginx' + buildah commit "${nginx}" adyxax/nginx else nginx=$(buildah from adyxax/nginx) - #buildah run $nginx /bin/sh -c 'apk upgrade --no-cache' fi -buildah copy $nginx nginx.conf headers_secure.conf headers_static.conf /etc/nginx/ +(cd deploy && buildah copy "${nginx}" nginx.conf headers_secure.conf headers_static.conf /etc/nginx/) buildah config \ --author 'Julien Dessaux' \ --cmd nginx \ --port 80 \ - $nginx -buildah copy $nginx ../public /var/www/www.adyxax.org + "${nginx}" +buildah copy "${nginx}" public /var/www/www.adyxax.org -buildah commit $nginx adyxax/www -buildah rm $nginx +buildah commit "${nginx}" adyxax/www +buildah rm "${nginx}" ctr=$(buildah from scratch) -buildah copy $ctr ../search/search / +buildah copy "${ctr}" search/search / buildah config \ --author 'Julien Dessaux' \ --cmd /search \ --port 8080 \ - $ctr -buildah commit $ctr adyxax/www-search -buildah rm $ctr + "${ctr}" +buildah commit "${ctr}" adyxax/www-search +buildah rm "${ctr}" -- cgit v1.2.3