aboutsummaryrefslogtreecommitdiff
path: root/bake.sh
diff options
context:
space:
mode:
authorGalen Guyer <galen@galenguyer.com>2022-02-14 18:11:28 -0500
committerGalen Guyer <galen@galenguyer.com>2022-02-14 18:11:28 -0500
commitb97b649cb3fe2217e46800e5bfc649ff20076625 (patch)
tree613d5e5edcaa5b84ff45bda35430be698e91911d /bake.sh
alpine: builds for mainline and stable
Diffstat (limited to 'bake.sh')
-rwxr-xr-xbake.sh45
1 files changed, 45 insertions, 0 deletions
diff --git a/bake.sh b/bake.sh
new file mode 100755
index 0000000..78eb435
--- /dev/null
+++ b/bake.sh
@@ -0,0 +1,45 @@
+#!/usr/bin/env bash
+# build, tag, and push docker images
+
+# exit if a command fails
+set -o errexit
+# exit if required variables aren't set
+set -o nounset
+
+# check for docker
+if command -v docker 2>&1 >/dev/null; then
+ echo "using docker..." >&2
+else
+ echo "could not find docker, exiting" >&2
+ exit 1
+fi
+
+# if no registry is provided, tag image as "local" registry
+registry="${REGISTRY:-local}"
+echo "using registry $registry..." >&2
+
+# retrieve latest alpine version
+alpine="${ALPINE:-$(curl -sSL https://www.alpinelinux.org/downloads/ | grep -P 'Current Alpine Version' | grep -o -P '\d+\.\d+\.\d+')}"
+echo "using alpine version $alpine..." >&2
+
+# retreive latest nginx stable version
+nginx_stable="${NGINX_STABLE:-$(curl -sSL https://nginx.org/en/download.html | grep -P '(\/download\/nginx-\d+\.\d+\.\d+\.tar\.gz)' -o | uniq | head -n2 | tail -n1 | grep -o -P '\d+\.\d+\.\d+')}"
+echo "using nginx stable version $nginx_stable..." >&2
+
+# retrieve latest nginx mainline version
+nginx_mainline="${NGINX_MAINLINE:-$(curl -sSL https://nginx.org/en/download.html | grep -P '(\/download\/nginx-\d+\.\d+\.\d+\.tar\.gz)' -o | uniq | head -n1 | grep -o -P '\d+\.\d+\.\d+')}"
+echo "using nginx mainline version $nginx_mainline..." >&2
+
+# pass core count into container for build process
+core_count="${CORE_COUNT:-$(nproc)}"
+echo "using $core_count cores..." >&2
+
+# create docker images
+export ALPINE_VER="$alpine"
+export CORE_COUNT="$core_count"
+export REGISTRY="$registry"
+export NGINX_MAINLINE="$nginx_mainline"
+export NGINX_STABLE="$nginx_stable"
+docker buildx bake \
+ $(if [ "${REGISTRY}" != "local" ]; then echo "--push"; fi) \
+ "$@"