<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Quant ONE</title>
    <description>The latest articles on Forem by Quant ONE (@quantone).</description>
    <link>https://forem.com/quantone</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Forganization%2Fprofile_image%2F3303%2Fb09fa1b2-79b1-41ba-8657-46cf248dc96a.png</url>
      <title>Forem: Quant ONE</title>
      <link>https://forem.com/quantone</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/quantone"/>
    <language>en</language>
    <item>
      <title>How to run VS Code as a Container for Remote Development</title>
      <dc:creator>Sar Malik</dc:creator>
      <pubDate>Wed, 30 Dec 2020 20:02:06 +0000</pubDate>
      <link>https://forem.com/quantone/how-to-run-vs-code-as-a-container-for-remote-development-2ng3</link>
      <guid>https://forem.com/quantone/how-to-run-vs-code-as-a-container-for-remote-development-2ng3</guid>
      <description>&lt;p&gt;Launch your own &lt;a href="https://github.com/linuxserver/docker-code-server" rel="noopener noreferrer"&gt;Code Server&lt;/a&gt; container with preloaded dev tools (SDKs, npm packages, CLIs etc) for an efficient and securely accessible Web IDE in your homelab or private cloud!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fraw.githubusercontent.com%2Fcdr%2Fcode-server%2Fmain%2Fdocs%2Fassets%2Fscreenshot.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fraw.githubusercontent.com%2Fcdr%2Fcode-server%2Fmain%2Fdocs%2Fassets%2Fscreenshot.png" alt="vs-code-server"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Why VS Code in a Container?
&lt;/h2&gt;

&lt;p&gt;Remote development has taken the world by storm, it's not just a trend but here to stay as a new way that delivers on the promise of work-life balance. &lt;/p&gt;

&lt;p&gt;Teams need to adapt rapidly and deploy out infrastructure which enables developer productivity and one of the best ways we've found is - speed to onboarding. &lt;/p&gt;

&lt;p&gt;Getting up and running is simple as scaling containers with all the tooling and personalized preferences ready to go. Writing code has never been easier, anywhere and on any device powered by your own cloud.&lt;/p&gt;

&lt;h2&gt;
  
  
  Getting Started
&lt;/h2&gt;

&lt;p&gt;We've provided the full code samples used in this guide, checkout our &lt;a href="https://github.com/DigitalTransformation/vs-code-container-with-ssl/" rel="noopener noreferrer"&gt;Github&lt;/a&gt; repository to get started.&lt;/p&gt;

&lt;p&gt;👉 Clone the repo&lt;br&gt;
📜 Create an &lt;code&gt;.env&lt;/code&gt; file&lt;br&gt;
🔒 Generate SSL certificates&lt;br&gt;
🐳 &lt;code&gt;vi dockerfile&lt;/code&gt; with your own scripts&lt;br&gt;
🚀 Launch the stack with &lt;code&gt;docker-compose up&lt;/code&gt;!&lt;/p&gt;

&lt;p&gt;Clone the repo on a host server with &lt;code&gt;docker&lt;/code&gt; or &lt;code&gt;podman&lt;/code&gt; configured. It's recommended to attach mount points for storing your codebase isolated from the container runtime for redundancy and failover management.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;git clone https://github.com/DigitalTransformation/vs-code-container-with-ssl.git
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next, we'll setup the required environment variables and data paths using the included &lt;a href="https://github.com/DigitalTransformation/vs-code-container-with-ssl/blob/main/.env.template" rel="noopener noreferrer"&gt;.env.template&lt;/a&gt; replicated as &lt;code&gt;.env&lt;/code&gt; (note: it's excluded by default in .gitignore).&lt;/p&gt;

&lt;p&gt;Persistent storage for extensions and vscode settings can also be enabled by mapping &lt;code&gt;HOST_*&lt;/code&gt; variables for convenience against container restarts and rebuilds. Otherwise you'll be quite unhappy to see all the preferences wiped out! &lt;/p&gt;

&lt;p&gt;The popular vs code extension &lt;a href="https://github.com/shanalikhan/code-settings-sync" rel="noopener noreferrer"&gt;settings-sync&lt;/a&gt; is also another great way to backup preferences onto private gists but does require reinstalling extensions on every new image build.&lt;/p&gt;

&lt;p&gt;Here's an example of what you'll need to define in &lt;code&gt;.env&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;VIRTUAL_HOST=10.0.0.1
VIRTUAL_PORT=8555

HOST_CONFIG_PATH=./config
HOST_LOG_PATH=./logs

HOST_CODE_PATH=/mnt/codebase
CODE_PATH=/code

TZ=America/New_York
PASSWORD=&amp;lt;PASSWORD&amp;gt;
SUDO_PASSWORD=&amp;lt;SUDO_PASSWORD&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Nginx is used to reroute traffic from &lt;code&gt;[::]:80&lt;/code&gt; to upstream HTTPS port &lt;code&gt;[::]:8443&lt;/code&gt; with self-signed SSL certificates. Checkout and run the &lt;a href="https://github.com/DigitalTransformation/vs-code-container-with-ssl/blob/main/scripts/generate_certs.sh" rel="noopener noreferrer"&gt;generate_certs.sh&lt;/a&gt; script to emit the required certificates with signing key using &lt;code&gt;openssl&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Place both the &lt;a href="https://github.com/DigitalTransformation/vs-code-container-with-ssl/blob/main/config/nginx.conf" rel="noopener noreferrer"&gt;nginx.conf&lt;/a&gt; and certs under the paths defined in &lt;code&gt;code-server.yaml&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;listen [::]:443 ssl default_server;
        ssl_certificate /etc/nginx/certs/ssl.crt;
        ssl_certificate_key /etc/nginx/certs/ssl.key;
        ssl_protocols TLSv1.1 TLSv1.2;
        ssl_prefer_server_ciphers on;
        ssl_ciphers ECDH+AESGCM:ECDH+AES256:ECDH+AES128:DHE+AES128:!ADH:!AECDH:!MD5;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Finally, deploy the container stack on the docker host using the command &lt;code&gt;docker-compose -f code-server.yaml up&lt;/code&gt;. It may take 15-20 minutes depending on your hardware and network bandwidth for the initial build. The dockerfile pre-configures a number of devtools and updates the base image packages.&lt;/p&gt;

&lt;p&gt;To comply with Docker CIS, resource limits are defined on each of the containers but can be customized to your hardware in the compose &lt;a href="https://github.com/DigitalTransformation/vs-code-container-with-ssl/blob/main/code-server.yaml" rel="noopener noreferrer"&gt;code-server.yaml&lt;/a&gt; file.&lt;/p&gt;

&lt;h2&gt;
  
  
  Pre-Installed Dev Tools
&lt;/h2&gt;

&lt;p&gt;Here's a quick overview of what the &lt;code&gt;dockerfile&lt;/code&gt; does to extend the &lt;a href="https://github.com/linuxserver/docker-code-server" rel="noopener noreferrer"&gt;linuxserver/code-server&lt;/a&gt; base image. This allows containers to be rapidly deployed and scaled up for usage on dev teams with tooling ready to go.&lt;/p&gt;

&lt;p&gt;The output image includes SDKs for cloud native app development workloads such as React, Node, C#, AWS and Azure Cloud CLIs.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;* AWS CLI Tools
    * aws-shell
    * amplify cli
* Azure CLI
* Netlify CLI
* NPM packages
    * yarn (upstream)
    * gatsby-cli
    * gulp
    * create-react-app
* .NET Core SDK and Runtime
    * 5.0.0
    * 3.1.0
    * 2.1.0
* Python global env
    * python3 python3-pip python3-dev
* Ubuntu apt packages
    * Networking
        * wget
        * apt-transport-https
        * libssl-dev libffi-dev
    * Tools
        * ranger
        * tree
        * unzip
        * ansible
        * vim
        * htop
        * iputils-ping
    * OS/Misc
        * systemd
        * build-essential
        * ffmpeg
        * youtube-dl
        * chromium-browser
    * Default shell --&amp;gt; zsh/oh-my-zsh
        * zsh-syntax-highlighting
        * zsh-autosuggestions
        * zsh-completions
        * history-search-multi-word
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Refer to the &lt;a href="https://github.com/DigitalTransformation/vs-code-container-with-ssl/blob/main/dockerfile" rel="noopener noreferrer"&gt;Dockerfile&lt;/a&gt; for image layers. Our build image size was well over &lt;code&gt;6.5GB&lt;/code&gt; but can be as minimal as your requirements for dev tools.&lt;/p&gt;

&lt;h3&gt;
  
  
  Remote Debugging
&lt;/h3&gt;

&lt;p&gt;By default the &lt;code&gt;dockerfile&lt;/code&gt; and &lt;code&gt;code-server.yaml&lt;/code&gt; are set to expose port ranges &lt;code&gt;5000-5010&lt;/code&gt; and &lt;code&gt;8000-8010&lt;/code&gt; commonly used for web app development. Customize this for your workload such as React, Gatsby, Angular, Django, etc. to allow for remote debugging HTTP instances that are running inside the container.&lt;/p&gt;

&lt;p&gt;To allow external access on node frameworks that depend &lt;code&gt;http-server&lt;/code&gt; (instantiated with &lt;code&gt;npm&lt;/code&gt; or &lt;code&gt;yarn&lt;/code&gt;) you may need to also update your &lt;code&gt;package.json&lt;/code&gt; and bind the runtime to the host ip instead of localhost. &lt;/p&gt;

&lt;p&gt;Here are a few common examples:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"scripts"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"ng:start"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"ng serve --host 0.0.0.0"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"npm:start"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"http-server --host 0.0.0.0"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"gatsby:start"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"gatsby develop --host 0.0.0.0"&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Alternatively, if you'd prefer not to expose ports, check out the &lt;a href="https://github.com/auchenberg/vscode-browser-preview/" rel="noopener noreferrer"&gt;vscode-browser-preview&lt;/a&gt; extension which enables &lt;code&gt;chromium&lt;/code&gt; based inspection and debugging within the container itself.&lt;/p&gt;

&lt;h2&gt;
  
  
  Security Considerations
&lt;/h2&gt;

&lt;p&gt;As the base image extends &lt;code&gt;ubuntu:18.04&lt;/code&gt;, additional steps have been taken to add security measures with &lt;code&gt;hosts&lt;/code&gt; file, &lt;code&gt;fail2ban&lt;/code&gt; and &lt;code&gt;clamav&lt;/code&gt; packages preloaded. These are precautionary against attacks but insufficient against (un)known breaches.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Log Analytics&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;It's strongly recommended to configure a remote syslog daemon for log analytics with &lt;code&gt;auditd&lt;/code&gt; enabled, here's our guide on using solutions such as &lt;a href="https://ix.quant.one/GraylogAnsible" rel="noopener noreferrer"&gt;Graylog2&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Ports&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;There's a wide range of tcp ports exposed and mapped directly to the host for remote debugging apps running inside the container. By default, only the &lt;code&gt;code-server&lt;/code&gt; is allocated on ports &lt;code&gt;8443&lt;/code&gt; and &lt;code&gt;localhost:8080&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;netstat &lt;span class="nt"&gt;-tnlp&lt;/span&gt;

Active Internet connections &lt;span class="o"&gt;(&lt;/span&gt;only servers&lt;span class="o"&gt;)&lt;/span&gt;
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 0.0.0.0:8443            0.0.0.0:&lt;span class="k"&gt;*&lt;/span&gt;               LISTEN      299/node            
tcp        0      0 127.0.0.1:8080          0.0.0.0:&lt;span class="k"&gt;*&lt;/span&gt;               LISTEN      -     
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For dev workloads outside of a homelab or private cloud behind firewalls, using an nginx reverse proxy with HTTPS and auth redirects is vital to preventing sensitive code exposure.&lt;/p&gt;

&lt;h2&gt;
  
  
  What's next?
&lt;/h2&gt;

&lt;p&gt;Deploying VS Code Server in a container is a great way to provide for flexible development infrastructure in your home lab or for your team.&lt;/p&gt;

&lt;p&gt;Paired with VPN access and all your custom settings, Web IDEs make for the future of remote coding. It's rapidly scalable, gets you to coding a lot quicker, and on any device.&lt;/p&gt;

&lt;p&gt;Be sure to checkout the &lt;a href="https://github.com/DigitalTransformation/vs-code-container-with-ssl/" rel="noopener noreferrer"&gt;Github&lt;/a&gt; repository where we've provided the full code samples that can be used to deploy your own &lt;code&gt;code-server&lt;/code&gt; in minutes.&lt;/p&gt;

&lt;p&gt;I've been using it as my primary development environment and after tweaking &lt;code&gt;vscode&lt;/code&gt; settings and extensions, there's no going back. The speedup of compiling code on a dedicated server alone is worth the change.&lt;/p&gt;

&lt;p&gt;Let me know if you like this homelab setup and what you think!&lt;/p&gt;

</description>
      <category>vscode</category>
      <category>docker</category>
      <category>productivity</category>
      <category>devops</category>
    </item>
  </channel>
</rss>
