|
3 | 3 | # Allow user to aupply a start dir, default to /home/coder/project
|
4 | 4 | START_DIR=${1:-/home/coder/project}
|
5 | 5 |
|
6 |
| -# Clone the git repo, if it exists |
7 |
| -[ -z "${GIT_REPO}" ] && echo "No GIT_REPO specified"; git clone $GIT_REPO $START_DIR |
8 |
| - |
9 | 6 | # add rclone config and start rclone, if supplied
|
10 | 7 | if [[ -z "${RCLONE_DATA}" ]]; then
|
11 | 8 | echo "RCLONE_DATA is not specified. Files will not persist"
|
| 9 | + |
| 10 | + # Clone the git repo, if it exists |
| 11 | + [ -z "${GIT_REPO}" ] && echo "No GIT_REPO specified"; git clone $GIT_REPO $START_DIR |
| 12 | + |
12 | 13 | else
|
13 | 14 | echo "Copying rclone config..."
|
14 | 15 | mkdir -p /home/coder/.config/rclone/
|
15 | 16 | touch /home/coder/.config/rclone/rclone.conf
|
16 | 17 | echo $RCLONE_DATA | base64 -d > /home/coder/.config/rclone/rclone.conf
|
17 | 18 |
|
18 |
| - echo "Syncing files..." |
| 19 | + # Full path to the remote filesystem |
| 20 | + RCLONE_REMOTE_PATH=${RCLONE_REMOTE_NAME:-code-server-remote}:${RCLONE_DESTINATION:-code-server-files} |
| 21 | + RCLONE_SOURCE_PATH=${RCLONE_SOURCE:-$START_DIR} |
| 22 | + echo "rclone sync $RCLONE_SOURCE_PATH $RCLONE_REMOTE_PATH -vv" > /home/coder/push_remote.sh |
| 23 | + echo "rclone sync $RCLONE_REMOTE_PATH $RCLONE_SOURCE_PATH -vv" > /home/coder/pull_remote.sh |
| 24 | + |
| 25 | + if rclone ls $RCLONE_REMOTE_PATH | grep -q 'directory not found'; then |
| 26 | + # we need to clone the git repo and sync |
| 27 | + echo "Pushing initial files to remote..." |
| 28 | + [ -z "${GIT_REPO}" ] && echo "No GIT_REPO specified" && mkdir -p $START_DIR && echo "intial file" > $START_DIR/file.txt; git clone $GIT_REPO $START_DIR |
| 29 | + /home/coder/push_remote.sh& |
| 30 | + else |
| 31 | + echo "Pulling files from remote..." |
| 32 | + # grab the files from the remote instead |
| 33 | + /home/coder/pull_remote.sh& |
| 34 | + fi |
19 | 35 |
|
20 |
| - touch /home/coder/sync_remote.sh && chmod +x /home/coder/sync_remote.sh |
21 |
| - echo "rclone sync ${RCLONE_SOURCE:-"/home/coder/"} ${RCLONE_REMOTE_NAME:-code-server-remote}:${RCLONE_DESTINATION:-code-server-files} -vv" > /home/coder/sync_remote.sh |
22 |
| - /home/coder/sync_remote.sh& |
23 | 36 | fi
|
24 | 37 |
|
25 | 38 | # Now we can run code-server with the default entrypoint
|
|
0 commit comments