Serge Bazanski | 5aa494f | 2021-05-18 18:57:10 +0200 | [diff] [blame] | 1 | #!/usr/bin/env bash |
| 2 | |
| 3 | # This script can be run by Monogon Labs employees to push the Builder image |
| 4 | # built from //build/ci/Dockerfile into a public registry image. That image is |
| 5 | # then consumed by external, non-public infrastructure code as a basis to run |
| 6 | # Jenkins CI agents. |
| 7 | # |
| 8 | # For more information, see //build/ci/README.md. |
| 9 | |
| 10 | set -euo pipefail |
| 11 | |
| 12 | main() { |
| 13 | if [[ "$HOME" == /user ]] && [[ -d /user ]] && [[ -d /home/ci ]]; then |
| 14 | echo "WARNING: likely running within Builder image instead of the host environment." >&2 |
| 15 | echo "If this script was invoked using 'bazel run', please instead do:" >&2 |
| 16 | echo " \$ scripts/bin/bazel build //build/ci:push_ci_image" >&2 |
| 17 | echo " \$ bazel-bin/build/ci/push_ci_image" >&2 |
| 18 | echo "This will build the script within the container but run it on the host." >&2 |
| 19 | fi |
| 20 | |
| 21 | local podman="$(command -v podman || true)" |
| 22 | if [[ -z "$podman" ]]; then |
| 23 | echo "'podman' must be available in the system PATH to build the image." >&2 |
| 24 | exit 1 |
| 25 | fi |
| 26 | |
| 27 | local dockerfile="build/ci/Dockerfile" |
| 28 | if [[ ! -f "${dockerfile}" ]]; then |
| 29 | echo "Could not find ${dockerfile} - this script needs to be run from the root of the Monogon repository." >&2 |
| 30 | ecit 1 |
| 31 | fi |
| 32 | |
| 33 | local image="gcr.io/monogon-infra/monogon-builder:$(date +%s)" |
| 34 | |
| 35 | echo "Building image ${image} from ${dockerfile}..." |
| 36 | "${podman}" build -t "${image}" - < "${dockerfile}" |
| 37 | echo "Pushing image ${image}..." |
| 38 | "${podman}" push "${image}" |
| 39 | echo "Done, new image is ${image}" |
| 40 | } |
| 41 | |
| 42 | main "$@" |
| 43 | |