$ docker run -it --rm -p 8000:8000 sagarpanda/vscode
$ docker run -it --rm -p 8000:8000 -e SERVER_BASE_PATH="/code/abc" sagarpanda/vscode
Last active
October 12, 2024 11:30
-
-
Save sagarpanda/d2dc7ead2776cd425b1587ea579bd21f to your computer and use it in GitHub Desktop.
openvscode server
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
| # Access VSCode Server at port 3000 - http://[CONTAINER_NAME].code.localhost | |
| # Access Internal APP at port 9000 - http://[PORT].[CONTAINER_NAME].code.localhost | |
| # | |
| # Dockerfile | |
| # FROM nginx:latest | |
| # COPY default.conf /etc/nginx/conf.d/default.conf | |
| # EXPOSE 80 | |
| # | |
| # docker network create homenet | |
| # docker build . -t sagarpanda/nginx | |
| # docker run -it --rm --name gateway -p 80:80 --network homenet sagarpanda/nginx | |
| server { | |
| listen 80; | |
| listen [::]:80; | |
| server_name "~^(?<upstream_app>[0-9a-z]+)\.code\..*$"; | |
| client_max_body_size 0; | |
| location / { | |
| resolver 127.0.0.11 ipv6=off valid=10s; | |
| proxy_http_version 1.1; | |
| proxy_set_header Upgrade $http_upgrade; | |
| proxy_set_header Connection "upgrade"; | |
| set $upstream_port 3000; | |
| set $upstream_proto http; | |
| proxy_pass $upstream_proto://$upstream_app:$upstream_port; | |
| } | |
| } | |
| server { | |
| listen 80; | |
| listen [::]:80; | |
| server_name "~^(?<upstream_port>[0-9]{1,10})\.(?<upstream_app>[0-9a-z]+)\.code\..*$"; | |
| client_max_body_size 0; | |
| location / { | |
| resolver 127.0.0.11 ipv6=off valid=10s; | |
| proxy_http_version 1.1; | |
| proxy_set_header Upgrade $http_upgrade; | |
| proxy_set_header Connection "upgrade"; | |
| set $upstream_proto http; | |
| proxy_pass $upstream_proto://$upstream_app:$upstream_port; | |
| } | |
| } | |
| # Ref - https://github.com/linuxserver/reverse-proxy-confs/blob/master/openvscode-server.subdomain.conf.sample | |
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
| #!/bin/bash | |
| node /home/openvscode-server/rproxy/server.js & | |
| /home/.openvscode-server/bin/openvscode-server --host 0.0.0.0 --port 8001 --server-base-path $SERVER_BASE_PATH --without-connection-token |
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
| FROM gitpod/openvscode-server:latest | |
| SHELL ["/bin/bash", "-c"] | |
| ENV OPENVSCODE_SERVER_ROOT="/home/.openvscode-server" | |
| ENV OPENVSCODE="${OPENVSCODE_SERVER_ROOT}/bin/openvscode-server" | |
| ENV SERVER_BASE_PATH="/code/xyz" | |
| USER root | |
| RUN apt update -y | |
| RUN apt install curl -y | |
| RUN apt install vim -y | |
| USER openvscode-server | |
| RUN git config --global http.sslverify false | |
| # NVM Install | |
| RUN git clone https://github.com/nvm-sh/nvm.git .nvm | |
| RUN cd ~/.nvm && git checkout v0.40.1 && . ./nvm.sh | |
| COPY --chown=openvscode-server:openvscode-server ./.bashrc /home/workspace | |
| # NodeJs Install | |
| ENV NODE_VERSION=20.18.0 | |
| ENV NVM_DIR=/home/workspace/.nvm | |
| RUN . "$NVM_DIR/nvm.sh" && nvm install ${NODE_VERSION} | |
| RUN . "$NVM_DIR/nvm.sh" && nvm alias default node | |
| ENV PATH="${NVM_DIR}/versions/node/v${NODE_VERSION}/bin/:${PATH}" | |
| # Yarn Install | |
| RUN npm install -g yarn | |
| COPY --chown=openvscode-server:openvscode-server ./entrypoint.sh /home/openvscode-server | |
| RUN ["chmod", "+x", "/home/openvscode-server/entrypoint.sh"] | |
| RUN mkdir -p /home/openvscode-server/rproxy | |
| COPY --chown=openvscode-server:openvscode-server ./package.json /home/openvscode-server/rproxy | |
| RUN cd /home/openvscode-server/rproxy && npm install | |
| COPY --chown=openvscode-server:openvscode-server ./server.js /home/openvscode-server/rproxy | |
| # WORKDIR /home/workspace/repos/my-project | |
| EXPOSE 3000 | |
| ENTRYPOINT [ "/home/openvscode-server/entrypoint.sh" ] |
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
| { | |
| "name": "openvscode-server-demo", | |
| "version": "1.0.0", | |
| "description": "", | |
| "main": "index.js", | |
| "scripts": { | |
| "dev": "nodemon server.js", | |
| "start": "node server.js" | |
| }, | |
| "keywords": [], | |
| "author": "", | |
| "license": "ISC", | |
| "dependencies": { | |
| "cors": "^2.8.5", | |
| "express": "^4.21.0", | |
| "http-proxy-middleware": "^3.0.2" | |
| }, | |
| "devDependencies": { | |
| "nodemon": "^3.1.7" | |
| } | |
| } |
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
| const http = require('http'); | |
| const express = require('express'); | |
| const cors = require('cors'); // Not Required | |
| const { createProxyMiddleware } = require('http-proxy-middleware'); | |
| const app = express(); | |
| const server = http.createServer(app); | |
| app.use(cors()); | |
| const VSCODE_PORT = 8001; | |
| const R_PROXY_PORT = 8000; | |
| const route = (req) => { | |
| let target = `http://localhost:${VSCODE_PORT}`; | |
| if (req.url.includes('/code/proxy')) { | |
| const port = req.url.split('/')[3]; | |
| if (port) { | |
| target = `http://localhost:${port}`; | |
| } | |
| } | |
| return target; | |
| }; | |
| const rProxy = createProxyMiddleware({ | |
| target: `http://localhost:${VSCODE_PORT}`, | |
| changeOrigin: true, | |
| ws: true, | |
| pathFilter: '/code', | |
| router: route, | |
| pathRewrite: { '^/code/proxy/\\d+': '' }, | |
| }); | |
| app.use(rProxy); | |
| app.get('/', (req, res) => { | |
| res.send('Server is running'); | |
| }); | |
| server.listen(R_PROXY_PORT, () => | |
| console.log(`server running on port ${R_PROXY_PORT}`) | |
| ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment