From fe1fc6013596a012e8b5c40c3f6e695c9eca5403 Mon Sep 17 00:00:00 2001 From: Julien Dessaux Date: Tue, 2 Nov 2021 19:27:20 +0100 Subject: Added container building script --- deploy/build-image.sh | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++ deploy/repositories | 2 ++ 2 files changed, 59 insertions(+) create mode 100755 deploy/build-image.sh create mode 100644 deploy/repositories diff --git a/deploy/build-image.sh b/deploy/build-image.sh new file mode 100755 index 0000000..aa14a2f --- /dev/null +++ b/deploy/build-image.sh @@ -0,0 +1,57 @@ +#!/usr/bin/env bash +set -eu + +ret=0; output=$(buildah images adyxax/alpine &>/dev/null) || ret=$? +if [ $ret != 0 ]; then + 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} + 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 +else + ctr=$(buildah from adyxax/alpine) + #buildah run $ctr /bin/sh -c 'apk upgrade --no-cache' +fi + +ret=0; buildah images adyxax/nim &>/dev/null || ret=$? +if [ $ret != 0 ]; then + nim=$(buildah from adyxax/alpine) + # Alpine edge is necessary to get a nim package for now + buildah add $nim repositories /etc/apk/ + buildah run $nim /bin/sh -c 'apk upgrade --no-cache' + buildah run $nim /bin/sh -c 'apk add --no-cache nim nimble git pcre sqlite gcc musl-dev' + buildah config --workingdir /code $nim + buildah commit $nim adyxax/nim +else + nim=$(buildah from adyxax/nim) + #buildah run $nim /bin/sh -c 'apk upgrade --no-cache' +fi + +buildah copy $nim .././ /code +buildah config --workingdir /code $nim +buildah run $nim nimble build +buildah copy --from $nim $ctr /code/short ./ + +### Committing the nim work environment ### +buildah config --workingdir / $nim +buildah run $nim rm -rf /code +buildah commit $nim adyxax/nim +buildah rm $nim + +### Finishing ### +buildah config \ + --author 'Julien Dessaux' \ + --cmd /short \ + --port 5000 \ + $ctr + +buildah commit $ctr adyxax/short +buildah rm $ctr diff --git a/deploy/repositories b/deploy/repositories new file mode 100644 index 0000000..0112bc9 --- /dev/null +++ b/deploy/repositories @@ -0,0 +1,2 @@ +http://dl-cdn.alpinelinux.org/alpine/edge/main +http://dl-cdn.alpinelinux.org/alpine/edge/community -- cgit v1.2.3