585be2656df636a49b03f08d629e65d73662e431
[petitboot] / docker / builder-include
1 #!/usr/bin/env bash
2
3 arch() {
4         local m="$(uname -m)"
5
6         case "${m}" in
7                 aarch64) echo "arm64" ;;
8                 x86_64)  echo "amd64" ;;
9                 *)       echo "${m}" ;;
10         esac
11 }
12
13 arch_tag() {
14         local a="$(arch)"
15
16         case "${a}" in
17                 amd64) echo "" ;;
18                 *)     echo "-${a}" ;;
19         esac
20 }
21
22 docker_from() {
23         local a="$(arch)"
24
25         case "${a}" in
26                 amd64) echo "ubuntu:17.10" ;;
27                 arm64) echo "arm64v8/ubuntu:17.10" ;;
28                 ppc64le) echo "ppc64le/ubuntu:17.10" ;;
29                 *)
30                         echo "${name}: ERROR: Unknown arch ${a}" >&2
31                         exit 1
32                 ;;
33         esac
34 }
35
36 run_cmd () {
37         local cmd="${*}"
38
39         if [[ -n ${verbose} || -n "${dry_run}" ]]; then
40                 echo "==> ${cmd}"
41         fi
42
43         if [[ -n "${dry_run}" ]]; then
44                 true
45         else
46                 eval "${cmd}"
47         fi
48 }
49
50 show_tag () {
51         echo "${DOCKER_TAG}"
52 }
53
54 : ${VERSION:="3"}
55 : ${ARCH_TAG:="$(arch_tag)"}
56 : ${DOCKER_NAME:="pb-builder"}
57 : ${DOCKER_TAG:="${DOCKER_NAME}:${VERSION}${ARCH_TAG}"}