1
0
mirror of synced 2026-01-07 09:05:45 -05:00
Files
airbyte/tools/bin/build_image.sh
2021-10-19 11:20:21 -07:00

49 lines
1.3 KiB
Bash
Executable File

#!/usr/bin/env bash
set -e
ROOT_DIR="$1"
PROJECT_DIR="$2"
DOCKERFILE="$3"
TAGGED_IMAGE="$4"
ID_FILE="$5"
FOLLOW_SYMLINKS="$6"
cd "$ROOT_DIR"
. tools/lib/lib.sh
assert_root
cd "$PROJECT_DIR"
function validate_dockerignore() {
excludes_all=$(grep -w '^\*$' .dockerignore)
excludes_except=$(grep -w '^!.*' .dockerignore)
if [ -n "$excludes_all" ] || [ -n "$excludes_except" ]; then
error "Cannot include exclusion exceptions when following symlinks. Please use an exclude pattern that doesn't use exclude-all (e.g: *) or exclude-except (e.g: !/some/pattern)"
fi
}
args=(
-f "$DOCKERFILE"
-t "$TAGGED_IMAGE"
--iidfile "$ID_FILE"
)
if [ "$FOLLOW_SYMLINKS" == "true" ]; then
exclusions=()
if [ -f ".dockerignore" ]; then
validate_dockerignore
exclusions+=(--exclude-from .dockerignore)
fi
# Docker does not follow symlinks in the build context. So we create a tar of the directory, following symlinks, and provide the archive to Docker
# to use as the build context
tar cL "${exclusions[@]}" . | docker build - "${args[@]}"
else
JDK_VERSION="${JDK_VERSION:-14.0.2}"
if [[ -z "${DOCKER_BUILD_PLATFORM}" ]]; then
docker build --build-arg JDK_VERSION="$JDK_VERSION" . "${args[@]}"
else
docker build --build-arg JDK_VERSION="$JDK_VERSION" --platform="$DOCKER_BUILD_PLATFORM" . "${args[@]}"
fi
fi