Skip to content

Commit

Permalink
Allow following symlinks when building docker images (#1332)
Browse files Browse the repository at this point in the history
  • Loading branch information
sherifnada committed Dec 15, 2020
1 parent c48129f commit 894c4d5
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 5 deletions.
6 changes: 5 additions & 1 deletion buildSrc/src/main/groovy/airbyte-docker.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ abstract class AirbyteDockerTask extends DefaultTask {
@Input
String dockerfileName

@Input
boolean followSymlinks = false

@OutputFile
abstract File idFileOutput

Expand All @@ -38,7 +41,7 @@ abstract class AirbyteDockerTask extends DefaultTask {
def tag = DockerHelpers.getDevTaggedImage(projectDir, dockerfileName)

project.exec {
commandLine scriptPath, rootDir.absolutePath, projectDir.absolutePath, dockerfileName, tag, idFileOutput.absolutePath
commandLine scriptPath, rootDir.absolutePath, projectDir.absolutePath, dockerfileName, tag, idFileOutput.absolutePath, followSymlinks
}
}
}
Expand Down Expand Up @@ -138,6 +141,7 @@ class AirbyteDockerPlugin implements Plugin<Project> {
def filteredProjectFiles = project.fileTree(project.projectDir).filter {
file -> !file.toString().contains(".venv")
}

project.task(taskName, type: AirbyteDockerTask) {
def dockerPath = Paths.get(project.projectDir.absolutePath, dockerFile)
def hash = MessageDigest.getInstance("MD5").digest(dockerPath.getBytes()).encodeHex().toString()
Expand Down
31 changes: 27 additions & 4 deletions tools/bin/build_image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,37 @@ 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"

docker build \
-f "$DOCKERFILE" . \
-t "$TAGGED_IMAGE" \
--iidfile "$ID_FILE"
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
docker build . "${args[@]}"
fi

0 comments on commit 894c4d5

Please sign in to comment.