Skip to content

Commit

Permalink
✨ feat: add optional subpath folder variable
Browse files Browse the repository at this point in the history
  • Loading branch information
diogosilva30 authored Oct 14, 2023
1 parent 4ec528e commit 807af46
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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` |
Expand Down
12 changes: 8 additions & 4 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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" ]]
Expand All @@ -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

0 comments on commit 807af46

Please sign in to comment.