Skip to content

Commit a8ceb53

Browse files
committed
push and pull kinda
1 parent 37edf9c commit a8ceb53

File tree

2 files changed

+36
-13
lines changed

2 files changed

+36
-13
lines changed

README.md

+16-6
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,26 @@ $ cat $(rclone config file | sed -n 2p) | base64 --b 0 # MacOS
3131

3232
Now, you can add the following the environment variables in the code-server cloud app:
3333

34-
| Environment Variable | Description | Default Value | Required |
35-
| -------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------- | -------- |
36-
| RCLONE_DATA | the encoded rclone config you copied in step 3 | n/a ||
37-
| RCLONE_REMOTE_NAME | the name of the remote you added in step 2.<br />check with `$ rclone listremotes` | code-server-remote | |
38-
| RCLONE_SOURCE | source directory to sync files in the code-server container | the entire home directory: `/home/coder/` | |
39-
| RCLONE_DESTINATION | the path in the remote that rclone syncs to. change this if you have multiple code-server environments, or if you want to better organize your files. | code-server-files | |
34+
| Environment Variable | Description | Default Value | Required |
35+
| -------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------- | -------- |
36+
| RCLONE_DATA | the encoded rclone config you copied in step 3 | n/a ||
37+
| RCLONE_REMOTE_NAME | the name of the remote you added in step 2.<br />check with `$ rclone listremotes` | code-server-remote | |
38+
| RCLONE_SOURCE | source directory to sync files in the code-server container | the project directory: `/home/coder/project` | |
39+
| RCLONE_DESTINATION | the path in the remote that rclone syncs to. change this if you have multiple code-server environments, or if you want to better organize your files. | code-server-files | |
40+
41+
```sh
42+
43+
# How to use:
44+
45+
$ sh /home/coder/push-remote.sh # save your uncomitted files to the remote
46+
47+
$ sh /home/coder/pull-remote.sh # get latest files from the remote
48+
```
4049

4150
---
4251

4352
## Todo:
4453

54+
- [ ] Impliment file watcher or auto file sync in VS Code
4555
- [ ] Add support for SSH / VS Code remote access
4656
- [ ] Make rclone logs visible in environment for debugging

railway-entrypoint.sh

+20-7
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,36 @@
33
# Allow user to aupply a start dir, default to /home/coder/project
44
START_DIR=${1:-/home/coder/project}
55

6-
# Clone the git repo, if it exists
7-
[ -z "${GIT_REPO}" ] && echo "No GIT_REPO specified"; git clone $GIT_REPO $START_DIR
8-
96
# add rclone config and start rclone, if supplied
107
if [[ -z "${RCLONE_DATA}" ]]; then
118
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+
1213
else
1314
echo "Copying rclone config..."
1415
mkdir -p /home/coder/.config/rclone/
1516
touch /home/coder/.config/rclone/rclone.conf
1617
echo $RCLONE_DATA | base64 -d > /home/coder/.config/rclone/rclone.conf
1718

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
1935

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&
2336
fi
2437

2538
# Now we can run code-server with the default entrypoint

0 commit comments

Comments
 (0)