Sunset Mikoto commited on
Commit
8ddd487
·
1 Parent(s): ac50462

deploy-code-server

Browse files
Dockerfile ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Start from the code-server Debian base image
2
+ FROM codercom/code-server:latest
3
+
4
+ USER coder
5
+
6
+ # Apply VS Code settings
7
+ # COPY deploy-container/settings.json .local/share/code-server/User/settings.json
8
+
9
+ # Use bash shell
10
+ ENV SHELL=/bin/bash
11
+
12
+ # Install unzip + rclone (support for remote filesystem)
13
+ RUN sudo apt-get update && sudo apt-get install unzip -y
14
+ RUN curl https://rclone.org/install.sh | sudo bash
15
+
16
+ # Copy rclone tasks to /tmp, to potentially be used
17
+ COPY deploy-container/rclone-tasks.json /tmp/rclone-tasks.json
18
+
19
+ # Fix permissions for code-server
20
+ RUN sudo chown -R coder:coder /home/coder/.local
21
+
22
+ # You can add custom software and dependencies for your environment below
23
+ # -----------
24
+
25
+ # Install a VS Code extension:
26
+ # 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
27
+ # RUN code-server --install-extension esbenp.prettier-vscode
28
+
29
+ # Install apt packages:
30
+ # RUN sudo apt-get install -y ubuntu-make
31
+
32
+ # Copy files:
33
+ # COPY deploy-container/myTool /home/coder/myTool
34
+
35
+ # -----------
36
+
37
+ # Port
38
+ ENV PORT=7860
39
+ ENV PASSWORD=huggingface
40
+
41
+ # Use our custom entrypoint script first
42
+ COPY deploy-container/entrypoint.sh /usr/bin/deploy-container-entrypoint.sh
43
+ ENTRYPOINT ["/usr/bin/deploy-container-entrypoint.sh"]
deploy-container/README.md ADDED
@@ -0,0 +1,119 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # code-server-deploy-container
2
+
3
+ An container image built for deploying code-server.
4
+
5
+ ## Guides
6
+
7
+ - [Deploy on Railway](../guides/railway.md)
8
+ - [Deploy on Heroku](../guides/heroku.md)
9
+
10
+ Docker Hub: `bencdr/code-server-deploy-container`
11
+
12
+ To run the container locally, you can use:
13
+
14
+ ```console
15
+ docker run -p 127.0.0.1:8080:8080 \
16
+ -v "$PWD/project:/home/coder/project" \
17
+ -u "$(id -u):$(id -g)" \
18
+ -e "DOCKER_USER=$USER" \
19
+ -e "PASSWORD=12345" \
20
+ -it bencdr/code-server-deploy-container:latest
21
+ ```
22
+
23
+ ## Modifying your code-server environment
24
+
25
+ To update your code-server version, modify the version number on line 2 in your Dockerfile. See the [list of tags](https://hub.docker.com/r/codercom/code-server/tags?page=1&ordering=last_updated) for the latest version.
26
+
27
+ We've included some examples on how to add additional dependencies in the root-level [Dockerfile](../Dockerfile):
28
+
29
+ ```Dockerfile
30
+ # Install a VS Code extension:
31
+ # 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
32
+ RUN code-server --install-extension esbenp.prettier-vscode
33
+
34
+ # Install apt packages:
35
+ RUN sudo apt-get install -y ubuntu-make
36
+
37
+ # Copy files:
38
+ COPY deploy-container/myTool /home/coder/myTool
39
+ ```
40
+
41
+ ---
42
+
43
+ ## Environment variables
44
+
45
+ | Variable Name | Description | Default Value |
46
+ | ------------------ | -------------------------------------------------------------------------------------------------- | ------------------- |
47
+ | `PASSWORD` | Password for code-server | |
48
+ | `HASHED_PASSWORD` | Overrrides PASSWORD. [SHA-256 hash](https://xorbin.com/tools/sha256-hash-calculator) of password |
49
+ | `USE_LINK` | Use code-server --link instead of a password (coming soon) | false |
50
+ | `GIT_REPO` | A git repository to clone | |
51
+ | `DOTFILES_REPO` | A [dotfiles](https://dotfiles.github.io/) repo to save preferences. Runs install.sh, if it exists. | |
52
+ | `DOTFILES_SYMLINK` | Symlinks dotfiles repo to $HOME, if exits. | true |
53
+ | `START_DIR` | The directory code-server opens (and clones repos in) | /home/coder/project |
54
+
55
+ ---
56
+
57
+ 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.
58
+
59
+ ## 💾 Persist your filesystem with `rclone`
60
+
61
+ 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.
62
+
63
+ You can generate the rclone config on any machine, but it works great on the code-server environment itself, or Google Cloud Shell :)
64
+
65
+ ```sh
66
+ # 1. install rclone
67
+ # see https://rclone.org/install/ for other install options
68
+ $ curl https://rclone.org/install.sh | sudo bash
69
+
70
+ # 2. create a new rclone remote with your favorite storage provider ☁️
71
+ $ rclone config
72
+
73
+ # 3. Encode your rclone config and copy to your clipboard
74
+ $ cat $(rclone config file | sed -n 2p) | base64 --wrap=0 # Linux
75
+ $ cat $(rclone config file | sed -n 2p) | base64 --b 0 # MacOS
76
+ ```
77
+
78
+ Now, you can add the following the environment variables in the code-server cloud app:
79
+
80
+ | Environment Variable | Description | Default Value | Required |
81
+ | -------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------- | -------- |
82
+ | RCLONE_DATA | the encoded rclone config you copied in step 3 | n/a | ✅ |
83
+ | RCLONE_REMOTE_NAME | the name of the remote you added in step 2.<br />check with `$ rclone listremotes` | code-server-remote | |
84
+ | RCLONE_SOURCE | source directory to sync files in the code-server container | the project directory: `/home/coder/project` | |
85
+ | 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 | |
86
+ | RCLONE_VSCODE_TASKS | import push and pull shortcuts into VS Code ![rclone screenshot from VS Code](../img/rclone-vscode-tasks.png) | true |
87
+ | RCLONE_AUTO_PUSH | automatically push files on startup if the rclone remote is empty (environment -> rclone remote) | true | |
88
+ | RCLONE_AUTO_PULL | automatically pull files on startup if the rclone remote is not empty (rclone -> environment remote) | true | |
89
+ | RCLONE_FLAGS | additional flags to attach to the push and pull script.<br />type `$ rclone help flags` for a list. | | |
90
+
91
+ ```sh
92
+
93
+ # --- How to use ---
94
+
95
+ # Terminal:
96
+ $ sh /home/coder/push_remote.sh # save your uncomitted files to the remote
97
+ $ sh /home/coder/pull_remote.sh # get latest files from the remote
98
+
99
+ # In VS Code:
100
+ # use items in bottom bar or ctrl + P, run task: push_remote or pull_remote or
101
+ ```
102
+
103
+ ### Popular rclone flags
104
+
105
+ To avoid syncing unnecessary directories, add this to `RCLONE_FLAGS` :
106
+
107
+ ```none
108
+ --exclude "node_modules/**" --exclude ".git/**"
109
+ ```
110
+
111
+ ---
112
+
113
+ ## Todo
114
+
115
+ - [ ] Make `push_remote` and `pull_remote` commands in path
116
+ - [ ] Impliment file watcher or auto file sync in VS Code
117
+ - [ ] Attach a "push" on a git stash??
118
+ - [ ] Add support for SSH / VS Code remote access
119
+ - [ ] Make rclone logs visible in environment for debugging
deploy-container/entrypoint.sh ADDED
@@ -0,0 +1,100 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+
3
+ START_DIR="${START_DIR:-/home/coder/project}"
4
+
5
+ PREFIX="deploy-code-server"
6
+
7
+ mkdir -p $START_DIR
8
+
9
+ # function to clone the git repo or add a user's first file if no repo was specified.
10
+ project_init () {
11
+ [ -z "${GIT_REPO}" ] && echo "[$PREFIX] No GIT_REPO specified" && echo "Example file. Have questions? Join us at https://community.coder.com" > $START_DIR/coder.txt || git clone $GIT_REPO $START_DIR
12
+ }
13
+
14
+ # add rclone config and start rclone, if supplied
15
+ if [[ -z "${RCLONE_DATA}" ]]; then
16
+ echo "[$PREFIX] RCLONE_DATA is not specified. Files will not persist"
17
+
18
+ # start the project
19
+ project_init
20
+
21
+ else
22
+ echo "[$PREFIX] Copying rclone config..."
23
+ mkdir -p /home/coder/.config/rclone/
24
+ touch /home/coder/.config/rclone/rclone.conf
25
+ echo $RCLONE_DATA | base64 -d > /home/coder/.config/rclone/rclone.conf
26
+
27
+ # default to true
28
+ RCLONE_VSCODE_TASKS="${RCLONE_VSCODE_TASKS:-true}"
29
+ RCLONE_AUTO_PUSH="${RCLONE_AUTO_PUSH:-true}"
30
+ RCLONE_AUTO_PULL="${RCLONE_AUTO_PULL:-true}"
31
+
32
+ if [ $RCLONE_VSCODE_TASKS = "true" ]; then
33
+ # copy our tasks config to VS Code
34
+ echo "[$PREFIX] Applying VS Code tasks for rclone"
35
+ cp /tmp/rclone-tasks.json /home/coder/.local/share/code-server/User/tasks.json
36
+ # install the extension to add to menu bar
37
+ code-server --install-extension actboy168.tasks&
38
+ else
39
+ # user specified they don't want to apply the tasks
40
+ echo "[$PREFIX] Skipping VS Code tasks for rclone"
41
+ fi
42
+
43
+
44
+
45
+ # Full path to the remote filesystem
46
+ RCLONE_REMOTE_PATH=${RCLONE_REMOTE_NAME:-code-server-remote}:${RCLONE_DESTINATION:-code-server-files}
47
+ RCLONE_SOURCE_PATH=${RCLONE_SOURCE:-$START_DIR}
48
+ echo "rclone sync $RCLONE_SOURCE_PATH $RCLONE_REMOTE_PATH $RCLONE_FLAGS -vv" > /home/coder/push_remote.sh
49
+ echo "rclone sync $RCLONE_REMOTE_PATH $RCLONE_SOURCE_PATH $RCLONE_FLAGS -vv" > /home/coder/pull_remote.sh
50
+ chmod +x push_remote.sh pull_remote.sh
51
+
52
+ if rclone ls $RCLONE_REMOTE_PATH; then
53
+
54
+ if [ $RCLONE_AUTO_PULL = "true" ]; then
55
+ # grab the files from the remote instead of running project_init()
56
+ echo "[$PREFIX] Pulling existing files from remote..."
57
+ /home/coder/pull_remote.sh&
58
+ else
59
+ # user specified they don't want to apply the tasks
60
+ echo "[$PREFIX] Auto-pull is disabled"
61
+ fi
62
+
63
+ else
64
+
65
+ if [ $RCLONE_AUTO_PUSH = "true" ]; then
66
+ # we need to clone the git repo and sync
67
+ echo "[$PREFIX] Pushing initial files to remote..."
68
+ project_init
69
+ /home/coder/push_remote.sh&
70
+ else
71
+ # user specified they don't want to apply the tasks
72
+ echo "[$PREFIX] Auto-push is disabled"
73
+ fi
74
+
75
+ fi
76
+
77
+ fi
78
+
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
+
98
+ echo "[$PREFIX] Starting code-server..."
99
+ # Now we can run code-server with the default entrypoint
100
+ /usr/bin/entrypoint.sh --bind-addr 0.0.0.0:8080 $START_DIR
deploy-container/myTool/test.sh ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ #!/bin/bash
2
+
3
+ echo "This is a demo tool that could be brought into the code-server workspace"
deploy-container/rclone-tasks.json ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "version": "2.0.0",
3
+ "tasks": [
4
+ {
5
+ "label": "push_remote",
6
+ "type": "shell",
7
+ "command": "sh /home/coder/push_remote.sh",
8
+ "presentation": {
9
+ "reveal": "always"
10
+ },
11
+ "problemMatcher": [],
12
+ "options": {
13
+ "statusbar": {
14
+ "label": "$(repo-push) rclone: push"
15
+ }
16
+ }
17
+ },
18
+ {
19
+ "label": "pull_remote",
20
+ "type": "shell",
21
+ "command": "sh /home/coder/pull_remote.sh",
22
+ "presentation": {
23
+ "reveal": "always"
24
+ },
25
+ "problemMatcher": [],
26
+ "options": {
27
+ "statusbar": {
28
+ "label": "$(repo-pull) rclone: pull"
29
+ }
30
+ }
31
+ }
32
+ ]
33
+ }
deploy-container/settings.json ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ {
2
+ "workbench.colorTheme": "Default Dark+",
3
+ "git.postCommitCommand": "sync",
4
+ "git.enableSmartCommit": true,
5
+ "git.confirmSync": false,
6
+ "git.autofetch": true
7
+ }