-
Notifications
You must be signed in to change notification settings - Fork 643
Containers: Add VS Code tasks and improve overall documentation & flexibility #12
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
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
6b17676
make START_DIR configurable
bpmct 4a66224
fix permissions order
bpmct ed0b599
fix start dir bug
bpmct c87abcb
fix logic
bpmct cab263d
make START_DIR
bpmct e2acb34
cool loggins
bpmct 4c4fa1a
reuse clone function
bpmct cd4060f
i'm a bash noob
bpmct 935800a
even more of a bash noob
bpmct 8e51dce
add hashed info
bpmct 0158e89
add ability to add tasks
bpmct bfa9c95
add vs code instructions for task
bpmct e995984
rclone fix
bpmct 45c63b9
document vscode tasks
bpmct ba36254
fix labels
bpmct b96f1de
mention additional variables
bpmct 1c703a4
add better docs for dev tools
bpmct 28f2ccc
support rclone flags
bpmct File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,14 +13,17 @@ Docker Hub: `bencdr/code-server-deploy-container` | |
|
||
## Environment variables: | ||
|
||
| Variable Name | Description | Default Value | | ||
| ------------- | ---------------------------------------------------------- | ------------- | | ||
| `PASSWORD` | Password for code-server | | ||
| `USE_LINK` | Use code-server --link instead of a password (coming soon) | false | | ||
| `GIT_REPO` | A git repository to clone | | | ||
|
||
| 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 | | ||
--- | ||
|
||
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. | ||
|
||
## 💾 Persist your filesystem with `rclone` | ||
|
||
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. | ||
|
@@ -44,18 +47,24 @@ 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_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  | 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. type `rclone help flags for a list." | | | | ||
```sh | ||
|
||
# How to use: | ||
# --- How to use --- | ||
|
||
# Terminal: | ||
$ 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: | ||
# ctrl + P, run task: push_remote or pull_remote | ||
Comment on lines
+65
to
+67
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. documented the new tasks |
||
``` | ||
|
||
--- | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,81 @@ | ||
#!/bin/bash | ||
|
||
START_DIR=/home/coder/project | ||
START_DIR="${START_DIR:-/home/coder/project}" | ||
|
||
PREFIX="deploy-code-server" | ||
|
||
mkdir -p $START_DIR | ||
|
||
# function to clone the git repo or add a user's first file if no repo was specified. | ||
project_init () { | ||
[ -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 | ||
} | ||
|
||
# add rclone config and start rclone, if supplied | ||
if [[ -z "${RCLONE_DATA}" ]]; then | ||
echo "RCLONE_DATA is not specified. Files will not persist" | ||
echo "[$PREFIX] RCLONE_DATA is not specified. Files will not persist" | ||
|
||
# Clone the git repo, if it exists | ||
[ -z "${GIT_REPO}" ] && echo "No GIT_REPO specified"; git clone $GIT_REPO $START_DIR | ||
# start the project | ||
project_init | ||
|
||
else | ||
echo "Copying rclone config..." | ||
echo "[$PREFIX] Copying rclone config..." | ||
mkdir -p /home/coder/.config/rclone/ | ||
touch /home/coder/.config/rclone/rclone.conf | ||
echo $RCLONE_DATA | base64 -d > /home/coder/.config/rclone/rclone.conf | ||
|
||
# defasult to true | ||
RCLONE_VSCODE_TASKS="${RCLONE_VSCODE_TASKS:-true}" | ||
RCLONE_AUTO_PUSH="${RCLONE_AUTO_PUSH:-true}" | ||
RCLONE_AUTO_PULL="${RCLONE_AUTO_PULL:-true}" | ||
|
||
if [ $RCLONE_VSCODE_TASKS = "true" ]; then | ||
# copy our tasks config to VS Code | ||
echo "[$PREFIX] Applying VS Code tasks for rclone" | ||
cp /tmp/rclone-tasks.json /home/coder/.local/share/code-server/User/tasks.json | ||
# install the extension to add to menu bar | ||
code-server --install-extension actboy168.tasks& | ||
else | ||
# user specified they don't want to apply the tasks | ||
echo "[$PREFIX] Skipping VS Code tasks for rclone" | ||
fi | ||
|
||
|
||
|
||
# Full path to the remote filesystem | ||
RCLONE_REMOTE_PATH=${RCLONE_REMOTE_NAME:-code-server-remote}:${RCLONE_DESTINATION:-code-server-files} | ||
RCLONE_SOURCE_PATH=${RCLONE_SOURCE:-$START_DIR} | ||
echo "rclone sync $RCLONE_SOURCE_PATH $RCLONE_REMOTE_PATH -vv" > /home/coder/push_remote.sh | ||
echo "rclone sync $RCLONE_REMOTE_PATH $RCLONE_SOURCE_PATH -vv" > /home/coder/pull_remote.sh | ||
echo "rclone sync $RCLONE_SOURCE_PATH $RCLONE_REMOTE_PATH $RCLONE_FLAGS -vv" > /home/coder/push_remote.sh | ||
echo "rclone sync $RCLONE_REMOTE_PATH $RCLONE_SOURCE_PATH $RCLONE_FLAGS -vv" > /home/coder/pull_remote.sh | ||
chmod +x push_remote.sh pull_remote.sh | ||
|
||
if rclone ls $RCLONE_REMOTE_PATH; then | ||
# grab the files from the remote instead of re-cloning the git repo | ||
echo "Pulling existing files from remote..." | ||
/home/coder/pull_remote.sh& | ||
|
||
if [ $RCLONE_AUTO_PULL = "true" ]; then | ||
# grab the files from the remote instead of running project_init() | ||
echo "[$PREFIX] Pulling existing files from remote..." | ||
/home/coder/pull_remote.sh& | ||
else | ||
# user specified they don't want to apply the tasks | ||
echo "[$PREFIX] Auto-pull is disabled" | ||
fi | ||
|
||
else | ||
# we need to clone the git repo and sync | ||
echo "Pushing initial files to remote..." | ||
[ -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 | ||
/home/coder/push_remote.sh& | ||
|
||
if [ $RCLONE_AUTO_PUSH = "true" ]; then | ||
# we need to clone the git repo and sync | ||
echo "[$PREFIX] Pushing initial files to remote..." | ||
project_init | ||
/home/coder/push_remote.sh& | ||
else | ||
# user specified they don't want to apply the tasks | ||
echo "[$PREFIX] Auto-push is disabled" | ||
fi | ||
|
||
fi | ||
|
||
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/bin/bash | ||
|
||
echo "This is a demo tool that could be brought into the code-server workspace" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
{ | ||
"version": "2.0.0", | ||
"tasks": [ | ||
{ | ||
"label": "push_remote", | ||
"type": "shell", | ||
"command": "sh /home/coder/push_remote.sh", | ||
"presentation": { | ||
"reveal": "always" | ||
}, | ||
"problemMatcher": [], | ||
"options": { | ||
"statusbar": { | ||
"label": "$(repo-push) rclone: push" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i slightly modified the labels |
||
} | ||
} | ||
}, | ||
{ | ||
"label": "pull_remote", | ||
"type": "shell", | ||
"command": "sh /home/coder/pull_remote.sh", | ||
"presentation": { | ||
"reveal": "always" | ||
}, | ||
"problemMatcher": [], | ||
"options": { | ||
"statusbar": { | ||
"label": "$(repo-pull) rclone: pull" | ||
} | ||
} | ||
} | ||
] | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added hashed password :)