From 807af46687cd340db816c6e36c87f481f212eaac Mon Sep 17 00:00:00 2001 From: Diogo Silva <49190578+diogosilva30@users.noreply.github.com> Date: Sat, 14 Oct 2023 18:44:04 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat:=20add=20optional=20subpath=20?= =?UTF-8?q?folder=20variable?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 1 + entrypoint.sh | 12 ++++++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index b6f9e62..e18db01 100644 --- a/README.md +++ b/README.md @@ -115,6 +115,7 @@ Using Airflow Git Sync is simple: | Variable | Description | Default Value | | --- | --- | --- | | `REPO_URL` | The URL of the Git repository to sync | `N/A` (required) | + | `SUBFOLDER_PATH` | The repository sub-folder to sync. Leaving empty copies the entire repo | `N/A` (optional) | | `GIT_BRANCH` | The Git branch to sync | `main` | | `DIRECTORY_NAME` | The name of the directory to clone the repository into | `project` | | `DESTINATION_PATH` | The path to sync the repository to | `/app/sync` | diff --git a/entrypoint.sh b/entrypoint.sh index 3ed26fc..fd2e19b 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,5 +1,6 @@ #!/bin/sh PROJECT_DIRECTORY="/app/${DIRECTORY_NAME:-project}" +SUBFOLDER=${SUBFOLDER_PATH:-""} # Fetch the sub-folder path from an environment variable mkdir -p ~/.ssh @@ -11,7 +12,7 @@ if [ ! -d "$PROJECT_DIRECTORY/.git" ]; then cd $PROJECT_DIRECTORY git remote add origin $REPO_URL git pull origin ${GIT_BRANCH:-main} - rsync -vazC $PROJECT_DIRECTORY/ ${DESTINATION_PATH:-/app/sync} + rsync -vazC $PROJECT_DIRECTORY/$SUBFOLDER ${DESTINATION_PATH:-/app/sync} fi if [[ "$PWD" != "$PROJECT_DIRECTORY" ]] @@ -24,6 +25,9 @@ while true; do git -C $PROJECT_DIRECTORY pull origin ${GIT_BRANCH:-main} git clean -fd sleep ${INTERVAL:-10} - rsync -vazC $PROJECT_DIRECTORY/ ${DESTINATION_PATH:-/app/sync} -done - + if [ -z "$SUBFOLDER" ]; then + rsync -vazC $PROJECT_DIRECTORY/ ${DESTINATION_PATH:-/app/sync} + else + rsync -vazC $PROJECT_DIRECTORY/$SUBFOLDER ${DESTINATION_PATH:-/app/sync} + fi +done \ No newline at end of file