Skip to content

Commit 42a095c

Browse files
authored
add dotfiles support (#41)
* initial dotfiles clone * add symlink * reverse dotfiles check * fix dir creation * touch up * document it
1 parent 7475972 commit 42a095c

File tree

2 files changed

+46
-24
lines changed

2 files changed

+46
-24
lines changed

deploy-container/README.md

+27-24
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ An container image built for deploying code-server.
44

55
## Guides
66

7-
* [Deploy on Railway](../guides/railway.md)
8-
* [Deploy on Heroku](../guides/heroku.md)
7+
- [Deploy on Railway](../guides/railway.md)
8+
- [Deploy on Heroku](../guides/heroku.md)
99

1010
Docker Hub: `bencdr/code-server-deploy-container`
1111

@@ -15,29 +15,32 @@ To update your code-server version, modify the version number on line 2 in your
1515

1616
We've included some examples on how to add additoonal dependencies in the root-level [Dockerfile](../Dockerfile):
1717

18-
``` Dockerfile
18+
```Dockerfile
1919
# Install a VS Code extension:
2020
# Note: we use a different marketplace than VS Code. See https://github.com/cdr/code-server/blob/main/docs/FAQ.md#differences-compared-to-vs-code
2121
RUN code-server --install-extension esbenp.prettier-vscode
2222

2323
# Install apt packages:
2424
RUN sudo apt-get install -y ubuntu-make
2525

26-
# Copy files:
26+
# Copy files:
2727
COPY deploy-container/myTool /home/coder/myTool
2828
```
2929

3030
---
3131

3232
## Environment variables
3333

34-
| Variable Name | Description | Default Value |
35-
| ----------------- | ------------------------------------------------------------------------------------------------ | ------------------- |
36-
| `PASSWORD` | Password for code-server | |
37-
| `HASHED_PASSWORD` | Overrrides PASSWORD. [SHA-256 hash](https://xorbin.com/tools/sha256-hash-calculator) of password |
38-
| `USE_LINK` | Use code-server --link instead of a password (coming soon) | false |
39-
| `GIT_REPO` | A git repository to clone | |
40-
| `START_DIR` | The directory code-server opens (and clones repos in) | /home/coder/project |
34+
| Variable Name | Description | Default Value |
35+
| ------------------ | -------------------------------------------------------------------------------------------------- | ------------------- |
36+
| `PASSWORD` | Password for code-server | |
37+
| `HASHED_PASSWORD` | Overrrides PASSWORD. [SHA-256 hash](https://xorbin.com/tools/sha256-hash-calculator) of password |
38+
| `USE_LINK` | Use code-server --link instead of a password (coming soon) | false |
39+
| `GIT_REPO` | A git repository to clone | |
40+
| `DOTFILES_REPO` | A [dotfiles](https://dotfiles.github.io/) repo to save preferences. Runs install.sh, if it exists. | |
41+
| `DOTFILES_SYMLINK` | Symlinks dotfiles repo to $HOME, if exits. | true |
42+
| `START_DIR` | The directory code-server opens (and clones repos in) | /home/coder/project |
43+
4144
---
4245

4346
Other code-server environment variables (such as `CODE_SERVER_CONFIG` ) can also be used. See the [code-server FAQ](https://github.com/cdr/code-server/blob/main/docs/FAQ.md) for details.
@@ -48,7 +51,7 @@ This image has built-in support for [rclone](https://rclone.org/) so that your f
4851

4952
You can generate the rclone config on any machine, but it works great on the code-server environment itself, or Google Cloud Shell :)
5053

51-
``` sh
54+
```sh
5255
# 1. install rclone
5356
# see https://rclone.org/install/ for other install options
5457
$ curl https://rclone.org/install.sh | sudo bash
@@ -65,16 +68,16 @@ Now, you can add the following the environment variables in the code-server clou
6568

6669
| Environment Variable | Description | Default Value | Required |
6770
| -------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------- | -------- |
68-
| RCLONE_DATA | the encoded rclone config you copied in step 3 | n/a | |
69-
| RCLONE_REMOTE_NAME | the name of the remote you added in step 2.<br />check with `$ rclone listremotes` | code-server-remote | |
71+
| RCLONE_DATA | the encoded rclone config you copied in step 3 | n/a ||
72+
| RCLONE_REMOTE_NAME | the name of the remote you added in step 2.<br />check with `$ rclone listremotes` | code-server-remote | |
7073
| RCLONE_SOURCE | source directory to sync files in the code-server container | the project directory: `/home/coder/project` | |
7174
| 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 | |
72-
| RCLONE_VSCODE_TASKS | import push and pull shortcuts into VS Code ![rclone screenshot from VS Code](../img/rclone-vscode-tasks.png) | true |
75+
| RCLONE_VSCODE_TASKS | import push and pull shortcuts into VS Code ![rclone screenshot from VS Code](../img/rclone-vscode-tasks.png) | true |
7376
| RCLONE_AUTO_PUSH | automatically push files on startup if the rclone remote is empty (environment -> rclone remote) | true | |
7477
| RCLONE_AUTO_PULL | automatically pull files on startup if the rclone remote is not empty (rclone -> environment remote) | true | |
75-
| RCLONE_FLAGS | additional flags to attach to the push and pull script.<br />type `$ rclone help flags` for a list. | | |
78+
| RCLONE_FLAGS | additional flags to attach to the push and pull script.<br />type `$ rclone help flags` for a list. | | |
7679

77-
``` sh
80+
```sh
7881

7982
# --- How to use ---
8083

@@ -83,23 +86,23 @@ $ sh /home/coder/push_remote.sh # save your uncomitted files to the remote
8386
$ sh /home/coder/pull_remote.sh # get latest files from the remote
8487

8588
# In VS Code:
86-
# use items in bottom bar or ctrl + P, run task: push_remote or pull_remote or
89+
# use items in bottom bar or ctrl + P, run task: push_remote or pull_remote or
8790
```
8891

8992
### Popular rclone flags
9093

9194
To avoid syncing unnecessary directories, add this to `RCLONE_FLAGS` :
9295

93-
``` none
96+
```none
9497
--exclude "node_modules/**" --exclude ".git/**"
9598
```
9699

97100
---
98101

99102
## Todo
100103

101-
* [ ] Make `push_remote` and `pull_remote` commands in path
102-
* [ ] Impliment file watcher or auto file sync in VS Code
103-
* [ ] Attach a "push" on a git stash??
104-
* [ ] Add support for SSH / VS Code remote access
105-
* [ ] Make rclone logs visible in environment for debugging
104+
- [ ] Make `push_remote` and `pull_remote` commands in path
105+
- [ ] Impliment file watcher or auto file sync in VS Code
106+
- [ ] Attach a "push" on a git stash??
107+
- [ ] Add support for SSH / VS Code remote access
108+
- [ ] Make rclone logs visible in environment for debugging

deploy-container/entrypoint.sh

+19
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,25 @@ else
7676

7777
fi
7878

79+
# Add dotfiles, if set
80+
if [ -n "$DOTFILES_REPO" ]; then
81+
# grab the files from the remote instead of running project_init()
82+
echo "[$PREFIX] Cloning dotfiles..."
83+
mkdir -p $HOME/dotfiles
84+
git clone $DOTFILES_REPO $HOME/dotfiles
85+
86+
DOTFILES_SYMLINK="${RCLONE_AUTO_PULL:-true}"
87+
88+
# symlink repo to $HOME
89+
if [ $DOTFILES_SYMLINK = "true" ]; then
90+
shopt -s dotglob
91+
ln -sf source_file $HOME/dotfiles/* $HOME
92+
fi
93+
94+
# run install script, if it exists
95+
[ -f "$HOME/dotfiles/install.sh" ] && $HOME/dotfiles/install.sh
96+
fi
97+
7998
echo "[$PREFIX] Starting code-server..."
8099
# Now we can run code-server with the default entrypoint
81100
/usr/bin/entrypoint.sh --bind-addr 0.0.0.0:8080 $START_DIR

0 commit comments

Comments
 (0)