Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow following symlinks when building docker images #1332

Merged
merged 1 commit into from
Dec 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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