| 1 |
#!/bin/bash |
| 2 |
|
| 3 |
set -eo pipefail |
| 4 |
|
| 5 |
tag="latest" |
| 6 |
image_base_name="ghcr.io/ismrmrd" |
| 7 |
push=false |
| 8 |
|
| 9 |
# parse command line arguments |
| 10 |
while [[ $# -gt 0 ]]; do |
| 11 |
key="$1" |
| 12 |
case $key in |
| 13 |
--tag) |
| 14 |
tag="$2" |
| 15 |
shift |
| 16 |
shift |
| 17 |
;; |
| 18 |
--image-base-name) |
| 19 |
image_base_name="$2" |
| 20 |
shift |
| 21 |
shift |
| 22 |
;; |
| 23 |
--push) |
| 24 |
push=true |
| 25 |
shift |
| 26 |
;; |
| 27 |
*) |
| 28 |
echo "Unknown option $key" |
| 29 |
exit 1 |
| 30 |
;; |
| 31 |
esac |
| 32 |
done |
| 33 |
|
| 34 |
# Dockerfile is in the root director one level up from this script |
| 35 |
dockerfile="$(dirname "${BASH_SOURCE[0]}")/../Dockerfile" |
| 36 |
context="$(dirname "${BASH_SOURCE[0]}")/.." |
| 37 |
|
| 38 |
# Array for targets to build |
| 39 |
targets=( "ismrmrd-test" "ismrmrd" "ismrmrd-stream-recon" "ismrmrd-stream-recon-server" ) |
| 40 |
push_targets=( "ismrmrd" "ismrmrd-stream-recon" "ismrmrd-stream-recon-server" ) |
| 41 |
|
| 42 |
# Loop over targets |
| 43 |
for target in "${targets[@]}"; do |
| 44 |
echo "Building ${target}..." |
| 45 |
docker build -t "${image_base_name}/${target}:${tag}" -f "$dockerfile" "$context" --target "$target" |
| 46 |
#If target is in push_targets, and push is true, push it |
| 47 |
if [[ " ${push_targets[@]} " =~ " ${target} " ]] && [ "$push" = true ]; then |
| 48 |
echo "Pushing ${target}..." |
| 49 |
docker push "${image_base_name}/${target}:${tag}" |
| 50 |
docker build -t "${image_base_name}/${target}:latest" -f "$dockerfile" "$context" --target "$target" |
| 51 |
docker push "${image_base_name}/${target}:latest" |
| 52 |
fi |
| 53 |
done |