begin refactor
This commit is contained in:
29
deploy-container/Dockerfile
Normal file
29
deploy-container/Dockerfile
Normal file
@@ -0,0 +1,29 @@
|
||||
# Start from the code-server Debian base image
|
||||
FROM codercom/code-server:latest
|
||||
|
||||
USER coder
|
||||
|
||||
# Apply VS Code settings
|
||||
COPY settings.json .local/share/code-server/User/settings.json
|
||||
|
||||
# Use bash shell
|
||||
ENV SHELL=/bin/bash
|
||||
|
||||
# Install unzip + rclone (support for remote filesystem)
|
||||
RUN sudo apt-get update && sudo apt-get install unzip -y
|
||||
RUN curl https://rclone.org/install.sh | sudo bash
|
||||
|
||||
# You can add custom software and dependencies for your environment here. Some examples:
|
||||
# RUN code-server --install-extension esbenp.prettier-vscode
|
||||
# RUN sudo apt-get install -y build-essential
|
||||
# RUN COPY myTool /home/coder/myTool
|
||||
|
||||
# Fix permissions for code-server
|
||||
RUN sudo chown -R coder:coder /home/coder/.local
|
||||
|
||||
# Port
|
||||
ENV PORT=8080
|
||||
|
||||
# Use our custom entrypoint script first
|
||||
COPY deploy-container-entrypoint.sh /usr/bin/deploy-container-entrypoint.sh
|
||||
ENTRYPOINT ["/usr/bin/deploy-container-entrypoint.sh"]
|
||||
60
deploy-container/README.md
Normal file
60
deploy-container/README.md
Normal file
@@ -0,0 +1,60 @@
|
||||
# code-server-deploy-container
|
||||
|
||||
An image built for deploying code-server to [railway.app](https://railway.app), [Heroku](https://heroku.com), or other app engines.
|
||||
|
||||
To launch your code-server environment, click the button below and log in with GitHub.
|
||||
|
||||
[](https://railway.app/new?template=https%3A%2F%2Fgithub.com%2Fbpmct%2Fcode-server-railway&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)
|
||||
|
||||
For Railway, it will ask you to make a new repo to store this image, so you can add additional software to your repo's `Dockerfile` in the future.
|
||||
|
||||
For Heroku, we recommend [using this repo as a template](https://github.com/bpmct/code-server-railway/generate) and using the one-click deploy on your own repo to further modify your app.
|
||||
|
||||

|
||||
|
||||
## 💾 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.
|
||||
|
||||
You can generate the rclone config on any machine, but it works great on the code-server environment itself, or Google Cloud Shell :)
|
||||
|
||||
```sh
|
||||
# 1. install rclone
|
||||
# see https://rclone.org/install/ for other install options
|
||||
$ curl https://rclone.org/install.sh | sudo bash
|
||||
|
||||
# 2. create a new rclone remote with your favorite storage provider ☁️
|
||||
$ rclone config
|
||||
|
||||
# 3. Encode your rclone config and copy to your clipboard
|
||||
$ cat $(rclone config file | sed -n 2p) | base64 --wrap=0 # Linux
|
||||
$ cat $(rclone config file | sed -n 2p) | base64 --b 0 # MacOS
|
||||
```
|
||||
|
||||
Now, you can add the following the environment variables in the code-server cloud app:
|
||||
|
||||
| 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_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 | |
|
||||
|
||||
```sh
|
||||
|
||||
# How to use:
|
||||
|
||||
$ 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
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 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
|
||||
40
deploy-container/deploy-container-entrypoint.sh
Executable file
40
deploy-container/deploy-container-entrypoint.sh
Executable file
@@ -0,0 +1,40 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Allow user to aupply a start dir, default to /home/coder/project
|
||||
START_DIR=/home/coder/project
|
||||
|
||||
# add rclone config and start rclone, if supplied
|
||||
if [[ -z "${RCLONE_DATA}" ]]; then
|
||||
echo "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
|
||||
|
||||
else
|
||||
echo "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
|
||||
|
||||
# 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
|
||||
chmod +x push_remote.sh pull_remote.sh
|
||||
|
||||
if rclone ls $RCLONE_REMOTE_PATH; then
|
||||
# grab the files from the remote instead
|
||||
echo "Pulling existing files from remote..."
|
||||
/home/coder/pull_remote.sh&
|
||||
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&
|
||||
fi
|
||||
|
||||
fi
|
||||
|
||||
# Now we can run code-server with the default entrypoint
|
||||
/usr/bin/entrypoint.sh --bind-addr 0.0.0.0:8080 $START_DIR
|
||||
7
deploy-container/settings.json
Normal file
7
deploy-container/settings.json
Normal file
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"workbench.colorTheme": "Default Dark+",
|
||||
"git.postCommitCommand": "sync",
|
||||
"git.enableSmartCommit": true,
|
||||
"git.confirmSync": false,
|
||||
"git.autofetch": true
|
||||
}
|
||||
Reference in New Issue
Block a user