Skip to content

add dotfiles support #41

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jun 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 27 additions & 24 deletions deploy-container/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ An container image built for deploying code-server.

## Guides

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

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

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

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

``` Dockerfile
```Dockerfile
# Install a VS Code extension:
# 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
RUN code-server --install-extension esbenp.prettier-vscode

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

# Copy files:
# Copy files:
COPY deploy-container/myTool /home/coder/myTool
```

---

## Environment variables

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

---

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.
Expand All @@ -48,7 +51,7 @@ This image has built-in support for [rclone](https://rclone.org/) so that your f

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

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

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

``` sh
```sh

# --- How to use ---

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

# In VS Code:
# use items in bottom bar or ctrl + P, run task: push_remote or pull_remote or
# use items in bottom bar or ctrl + P, run task: push_remote or pull_remote or
```

### Popular rclone flags

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

``` none
```none
--exclude "node_modules/**" --exclude ".git/**"
```

---

## Todo

* [ ] Make `push_remote` and `pull_remote` commands in path
* [ ] Impliment file watcher or auto file sync in VS Code
* [ ] Attach a "push" on a git stash??
* [ ] Add support for SSH / VS Code remote access
* [ ] Make rclone logs visible in environment for debugging
- [ ] Make `push_remote` and `pull_remote` commands in path
- [ ] Impliment file watcher or auto file sync in VS Code
- [ ] Attach a "push" on a git stash??
- [ ] Add support for SSH / VS Code remote access
- [ ] Make rclone logs visible in environment for debugging
19 changes: 19 additions & 0 deletions deploy-container/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,25 @@ else

fi

# Add dotfiles, if set
if [ -n "$DOTFILES_REPO" ]; then
# grab the files from the remote instead of running project_init()
echo "[$PREFIX] Cloning dotfiles..."
mkdir -p $HOME/dotfiles
git clone $DOTFILES_REPO $HOME/dotfiles

DOTFILES_SYMLINK="${RCLONE_AUTO_PULL:-true}"

# symlink repo to $HOME
if [ $DOTFILES_SYMLINK = "true" ]; then
shopt -s dotglob
ln -sf source_file $HOME/dotfiles/* $HOME
fi

# run install script, if it exists
[ -f "$HOME/dotfiles/install.sh" ] && $HOME/dotfiles/install.sh
fi

echo "[$PREFIX] Starting code-server..."
# Now we can run code-server with the default entrypoint
/usr/bin/entrypoint.sh --bind-addr 0.0.0.0:8080 $START_DIR