Skip to content

Commit 1973128

Browse files
authored
add support for dotfiles repos (#25)
* initial tests for dotfiles * fix order * first attempt at dotfiles magic * trigger rebuild * fix symlink? * fix symlink again * another weird fix * another test * fix symlink this time? * fix
1 parent 4797d0e commit 1973128

File tree

3 files changed

+45
-19
lines changed

3 files changed

+45
-19
lines changed

deploy-container/README.md

+23-17
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,7 +15,7 @@ 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
@@ -33,22 +33,23 @@ COPY deploy-container/myTool /home/coder/myTool
3333

3434
| Variable Name | Description | Default Value |
3535
| ----------------- | ------------------------------------------------------------------------------------------------ | ------------------- |
36-
| `PASSWORD` | Password for code-server | |
36+
| `PASSWORD` | Password for code-server | |
3737
| `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 |
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 |
41+
| `DOTFILES_REPO` | GitHub path to a dotfiles repository with your personal configuration across devices. | |
4142
---
4243

43-
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.
44+
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.
4445

4546
## 💾 Persist your filesystem with `rclone`
4647

4748
This image has built-in support for [rclone](https://rclone.org/) so that your files don't get lost when code-server is re-deployed.
4849

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

51-
```sh
52+
``` sh
5253
# 1. install rclone
5354
# see https://rclone.org/install/ for other install options
5455
$ curl https://rclone.org/install.sh | sudo bash
@@ -66,15 +67,20 @@ Now, you can add the following the environment variables in the code-server clou
6667
| Environment Variable | Description | Default Value | Required |
6768
| -------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------- | -------- |
6869
| 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 | |
70+
| RCLONE_REMOTE_NAME | the name of the remote you added in step 2.<br />check with `$ rclone listremotes` | code-server-remote | |
7071
| RCLONE_SOURCE | source directory to sync files in the code-server container | the project directory: `/home/coder/project` | |
7172
| 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 |
73+
| RCLONE_VSCODE_TASKS | import push and pull shortcuts into VS Code
74+
75+
![rclone screenshot from VS Code](../img/rclone-vscode-tasks.png)
76+
77+
| true |
78+
7379
| RCLONE_AUTO_PUSH | automatically push files on startup if the rclone remote is empty (environment -> rclone remote) | true | |
7480
| RCLONE_AUTO_PULL | automatically pull files on startup if the rclone remote is not empty (rclone -> environment remote) | true | |
7581
| RCLONE_FLAGS | additional flags to attach to the push and pull script.<br />type `$ rclone help flags` for a list. | | |
7682

77-
```sh
83+
``` sh
7884

7985
# --- How to use ---
8086

@@ -90,8 +96,8 @@ $ sh /home/coder/pull_remote.sh # get latest files from the remote
9096

9197
## Todo
9298

93-
- [ ] Make `push_remote` and `pull_remote` commands in path
94-
- [ ] Impliment file watcher or auto file sync in VS Code
95-
- [ ] Attach a "push" on a git stash??
96-
- [ ] Add support for SSH / VS Code remote access
97-
- [ ] Make rclone logs visible in environment for debugging
99+
* [ ] Make `push_remote` and `pull_remote` commands in path
100+
* [ ] Impliment file watcher or auto file sync in VS Code
101+
* [ ] Attach a "push" on a git stash??
102+
* [ ] Add support for SSH / VS Code remote access
103+
* [ ] Make rclone logs visible in environment for debugging

deploy-container/entrypoint.sh

+20
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,26 @@ else
7676

7777
fi
7878

79+
# Extract the user's dotfiles, if they exist
80+
if [[ -z "${DOTFILES_REPO}" ]]; then
81+
echo "[$PREFIX] DOTFILES_REPO is not specified"
82+
else
83+
echo "[$PREFIX] DOTFILES_REPO is specified"
84+
git clone $DOTFILES_REPO /home/coder/dotfiles
85+
86+
# Symlink if install.sh doesn't exist.
87+
# If it exits, run it
88+
if [ -f "/home/coder/dotfiles/install.sh" ]; then
89+
echo "[$PREFIX] install.sh exists, running it..."
90+
/bin/sh /home/coder/dotfiles/install.sh
91+
else
92+
echo "[$PREFIX] install.sh does not exist, symlinking dotfiles..."
93+
ln -sv /home/coder/dotfiles/* ~/
94+
fi
95+
96+
97+
fi
98+
7999
echo "[$PREFIX] Starting code-server..."
80100
# Now we can run code-server with the default entrypoint
81101
/usr/bin/entrypoint.sh --bind-addr 0.0.0.0:8080 $START_DIR

guides/railway.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Use Railway + code-server to get a dev environment that you can access from any
88

99
## Step 1: Click button to deploy
1010

11-
[![Deploy on Railway](https://railway.app/button.svg)](https://railway.app/new?template=https%3A%2F%2Fgithub.com%2Fcdr%2Fdeploy-code-server&envs=PASSWORD%2CGIT_REPO&PASSWORDDesc=Your+password+to+log+in+to+code-server+with&GIT_REPODesc=A+git+repo+to+clone+and+open+in+code-server+%28ex.+https%3A%2F%2Fgithub.com%2Fcdr%2Fdocs.git%29)
11+
[![Deploy on Railway](https://railway.app/button.svg)](https://railway.app/new?template=https%3A%2F%2Fgithub.com%2Fcdr%2Fdeploy-code-server%2F&envs=PASSWORD%2CGIT_REPO%2CDOTFILES_REPO&optionalEnvs=GIT_REPO%2CDOTFILES_REPO&PASSWORDDesc=Your+password+to+log+in+to+code-server+with&GIT_REPODesc=A+git+repo+to+clone+and+open+in+code-server+(ex.+https%3A%2F%2Fgithub.com%2Fcdr%2Fdocs.git)&DOTFILES_REPODesc=Environment+configuration+not+related+to+this+specific+environment.+(see+https%3A%2F%2Fdotfiles.github.io%2F))
1212

1313
## Step 2: Configure & launch your environment
1414

@@ -27,7 +27,7 @@ You also need to specity a `PASSWORD` and a `GIT_REPO` to clone in your environm
2727
1. Open the source repo in GitHub and edit the `Dockerfile`
2828
1. Add some custom tools (like NodeJS) and push to the main branch:
2929

30-
```Dockerfile
30+
``` Dockerfile
3131
# You can add custom software and dependencies for your environment here. Some examples:
3232

3333
# RUN code-server --install-extension esbenp.prettier-vscode

0 commit comments

Comments
 (0)