VS Code Server

TOC

Code Server Docker

WIP: vscode-dltdojo3r1.vsix extension

vscode-dltdojo3-v191025.png

kubectl/helm/mdbook/vscode-yarm 191026 版 (707M)

  • add kubectl and helm to image
  • add mdbook and mdbook-toc to image
  • add redhat.vscode-yaml extension to image
  • bump codercom/code-server version 2.1638-vsc1.39.2
  • bump node version 10.17.0
  • bump yarn version 1.19.1
# https://hub.docker.com/r/codercom/code-server/tags
# codercom/code-server:2.1638-vsc1.39.2 b0873f48b93a 439MB
# 
# node/npm/yarn/kubectl/helm/mdbook/vscode-yaml (707M)
#
FROM node:10.17.0-buster AS node-buster
ARG CS_VER=2.1638-vsc1.39.2
FROM codercom/code-server:2.1638-vsc1.39.2
COPY --from=node-buster /usr/local/bin/node /usr/local/bin/node
COPY --from=node-buster /usr/local/lib/node_modules /usr/local/lib/node_modules
#
# copy yarn
#
ENV YARN_VERSION v1.19.1
COPY --from=node-buster /opt/yarn-$YARN_VERSION /opt/yarn-$YARN_VERSION
USER root
RUN ls -al /usr/local/bin && \
    ln -s /usr/local/bin/node /usr/local/bin/nodejs && \
    ln -s /usr/local/lib/node_modules/npm/bin/npm-cli.js /usr/local/bin/npm && \
    ln -s /usr/local/lib/node_modules/npm/bin/npm-cli.js /usr/local/bin/npx && \
    ls -al /opt && \
    ln -s /opt/yarn-$YARN_VERSION/bin/yarn /usr/local/bin/yarn && \
    ln -s /opt/yarn-$YARN_VERSION/bin/yarnpkg /usr/local/bin/yarnpkg && \
    node --version && yarn --version && npm version

#
# kubectl download 
# https://kubernetes.io/docs/tasks/tools/install-kubectl/#install-kubectl-binary-with-curl-on-linux
# 
ENV KUBECTL_VERSION=v1.15.3
RUN curl -sLO https://storage.googleapis.com/kubernetes-release/release/${KUBECTL_VERSION}/bin/linux/amd64/kubectl && \
    chmod +x ./kubectl && mv ./kubectl /usr/local/bin/kubectl && kubectl version --client

#
# helm download 
# 
ENV HELM_VERSION=v2.14.3
RUN curl -sL https://storage.googleapis.com/kubernetes-helm/helm-${HELM_VERSION}-linux-amd64.tar.gz | tar -xvz && \
    mv linux-amd64/helm /usr/local/bin/ && rm -rf linux-amd64 && helm version --client

#
# mdbook download
#
ENV MDBOOK_VERSION=v0.3.1
RUN curl -sL https://github.com/rust-lang-nursery/mdBook/releases/download/${MDBOOK_VERSION}/mdbook-${MDBOOK_VERSION}-x86_64-unknown-linux-gnu.tar.gz | tar -xvz && \
    mv mdbook /usr/local/bin/ && mdbook --version
#
# mdbook-toc download
#
ENV MDBOOK_TOC_VERSION=0.2.2
RUN curl -sL https://github.com/badboy/mdbook-toc/releases/download/${MDBOOK_TOC_VERSION}/mdbook-toc-${MDBOOK_TOC_VERSION}-x86_64-unknown-linux-gnu.tar.gz | tar -xvz && \
    mv mdbook-toc /usr/local/bin/ && mdbook-toc --version

#
# redhat vscode yaml extension
#
RUN curl -sL https://github.com/redhat-developer/vscode-yaml/releases/download/0.5.2-beta/0.5.2-beta7.vsix \
    -o /usr/local/share/vscode-yaml.vsix

#
# Hyperledger Fabric Binaries
# [hyperledger/fabric-tools Tags - Docker Hub](https://hub.docker.com/r/hyperledger/fabric-tools/tags)
# [hyperledger/fabric-ca Tags - Docker Hub](https://hub.docker.com/r/hyperledger/fabric-ca/tags)
# [Commands Reference — hyperledger-fabricdocs master documentation](https://hyperledger-fabric.readthedocs.io/en/release-1.4/command_ref.html)
#
# COPY --from=docker.io/hyperledger/fabric-ca:1.4.3 /usr/local/bin/fabric-ca-client /usr/local/bin/
# COPY --from=docker.io/hyperledger/fabric-tools:1.4.3 /usr/local/bin/peer /usr/local/bin/
# COPY --from=docker.io/hyperledger/fabric-tools:1.4.3 /usr/local/bin/cryptogen /usr/local/bin/
# COPY --from=docker.io/hyperledger/fabric-tools:1.4.3 /usr/local/bin/configtxgen /usr/local/bin/
# COPY --from=docker.io/hyperledger/fabric-tools:1.4.3 /usr/local/bin/configtxlator /usr/local/bin/
# RUN fabric-ca-client version && cryptogen version && configtxgen -version && configtxlator version && peer version


USER coder
#
# npm global install witout root
# https://github.com/sindresorhus/guides/blob/master/npm-global-without-sudo.md
#
RUN npm config set prefix=/home/coder/.npm-packages \
    && echo '\nexport PATH="/home/coder/.npm-packages/bin:$PATH"' >> /home/coder/.bashrc

RUN mkdir -p /home/coder/.local/share/code-server/User/
ARG PATH_SETTINGS=/home/coder/.local/share/code-server/User/settings.json
# COPY settings.json ${PATH_SETTINGS}
RUN echo '{ \n\
    "terminal.integrated.shell.linux": "/bin/bash", \n\
    "files.associations": { \n\
        "[Dd]ockerfile*": "dockerfile", \n\
        "docker-compose*": "yaml" \n\
    } \n\
}' > ${PATH_SETTINGS}

RUN set -eux  && \
    code-server --install-extension /usr/local/share/vscode-yaml.vsix

#
# curl https://dltdojo.github.io/taichu-crypto/dockerfiles/v191026/Dockerfile  | docker build -t foo -
# or download Dockerfile
# curl https://dltdojo.github.io/taichu-crypto/dockerfiles/v191026/Dockerfile -o Dockerfile
# docker build -t foo .
# docker run -it --rm -v $PWD:/home/coder/project -p 8080:8080 foo 
# http://localhost:8080/?folder=/home/coder/project/
#

Dockerfile

$ curl https://dltdojo.github.io/taichu-crypto/dockerfiles/v191026/Dockerfile -o Dockerfile
$ docker build -t foo .

# or docker build from STDIN

$ curl https://dltdojo.github.io/taichu-crypto/dockerfiles/v191026/Dockerfile  | docker build -t foo -
$ docker run -it --rm -v $PWD:/home/coder/project -p 8080:8080 foo 

info  Server listening on http://0.0.0.0:8080
info    - Password is 1c578b76fcd86e7e4a68e178
info      - To use your own password, set the PASSWORD environment variable
info      - To disable use `--auth none`
info    - Not serving HTTPS

kaniko job example

apiVersion: batch/v1
kind: Job
metadata:
  name: kanikojob
spec:
  completions: 1
  template:
    metadata:
      name: kanikojob
    spec:
      restartPolicy: Never
      initContainers:
      - name: init-context
        image: curlimages/curl:latest
        args:
            - -sL
            - https://dltdojo.github.io/taichu-crypto/dockerfiles/v191026/Dockerfile
            - -o
            - /context/Dockerfile
        volumeMounts:
        - name: context
          mountPath: /context
      containers:
      # 
      # Working with MicroK8s’ registry add-on
      # registry.container-registry.svc.cluster.local:5000
      # curl http://127.0.0.1:32000/v2/_catalog
      #
      - name: kaniko
        image: gcr.io/kaniko-project/executor:latest
        args: ["--dockerfile=/context/Dockerfile",
              "--context=/context",
              "--destination=registry.container-registry.svc.cluster.local:5000/dltdojo3/mad-white:v191026"]
        volumeMounts:
          - name: context
            mountPath: /context
      volumes:
        - name: context
          emptyDir: {}

Node/NPM/Yarn 版 (508M)

目前 codercom/code-server:v2 計 146.17 MB 為 FROM ubuntu:18.04 製作。node/yarn 直接複製用 COPY --from=node:10.16.3-buster 還是 COPY --from=node:10.16.3-jessie 看起來差不多都是取自 nodejs.org/dist/latest-v10.x/

$ docker run --rm -it node:10.16.3-buster ls -al /usr/local/bin
total 40192
drwxrwxr-x  2 root root     4096 Oct 18 01:46 .
drwxr-xr-x 20 root root     4096 Oct 18 01:46 ..
-rwxrwxr-x  1 root root      116 Oct 18 01:46 docker-entrypoint.sh
-rwxrwxr-x  1 root root 41142280 Aug 15 18:50 node
lrwxrwxrwx  1 root root       19 Oct 18 01:46 nodejs -> /usr/local/bin/node
lrwxrwxrwx  1 root root       38 Aug 15 18:51 npm -> ../lib/node_modules/npm/bin/npm-cli.js
lrwxrwxrwx  1 root root       38 Aug 15 18:51 npx -> ../lib/node_modules/npm/bin/npx-cli.js
lrwxrwxrwx  1 root root       26 Oct 18 01:46 yarn -> /opt/yarn-v1.17.3/bin/yarn
lrwxrwxrwx  1 root root       29 Oct 18 01:46 yarnpkg -> /opt/yarn-v1.17.3/bin/yarnpkg

Dockfile

# image size 508 MB (node/npm/yarn)
# https://hub.docker.com/r/codercom/code-server/tags
#
ARG CS_VER=v2
FROM codercom/code-server:${CS_VER}
RUN ls -al /usr/local/bin
COPY --from=node:10.16.3-buster /usr/local/bin/node /usr/local/bin/node
# docker run --rm -it node:10.16.3-buster ls -al /usr/local/bin
# docker run --rm -it node:10.16.3-buster ls /usr/local/lib/node_modules/npm/lib
COPY --from=node:10.16.3-buster /usr/local/lib/node_modules /usr/local/lib/node_modules
COPY --from=node:10.16.3-buster /opt/yarn-v1.17.3 /opt/yarn-v1.17.3
USER root
RUN ln -s /usr/local/bin/node /usr/local/bin/nodejs && \
    ln -s /usr/local/lib/node_modules/npm/bin/npm-cli.js /usr/local/bin/npm && \
    ln -s /usr/local/lib/node_modules/npm/bin/npm-cli.js /usr/local/bin/npx && \
    ln -s /opt/yarn-v1.17.3/bin/yarn /usr/local/bin/yarn && \
    ln -s /opt/yarn-v1.17.3/bin/yarnpkg /usr/local/bin/yarnpkg && \
    ls -al /usr/local/bin && \
    node --version && yarn --version && npm version

USER coder
#
# npm global install witout root
# https://github.com/sindresorhus/guides/blob/master/npm-global-without-sudo.md
#
RUN npm config set prefix=/home/coder/.npm-packages \
    && echo '\nexport PATH="/home/coder/.npm-packages/bin:$PATH"' >> /home/coder/.bashrc

RUN mkdir -p /home/coder/.local/share/code-server/User/
ARG PATH_SETTINGS=/home/coder/.local/share/code-server/User/settings.json
# COPY settings.json ${PATH_SETTINGS}
RUN echo '{ \n\
    "terminal.integrated.shell.linux": "/bin/bash", \n\
    "files.associations": { \n\
        "[Dd]ockerfile*": "dockerfile", \n\
        "docker-compose*": "yaml" \n\
    } \n\
}' > ${PATH_SETTINGS}

rust + webassembly 開發環境 v2

效果跟 wasdk/WebAssemblyStudio: Learn, Teach, Work and Play in the WebAssembly Studio 差不多,只是多出 bash, cargo, nodejs, npm 可用。

#
# https://hub.docker.com/r/codercom/code-server/tags
#
ARG CS_VER=v2
FROM codercom/code-server:${CS_VER}
USER root
RUN apt-get update && \
    DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
        build-essential \
        ca-certificates \
        curl \
        git \
        ssh \
        gnupg \
        libssl-dev \
        pkg-config && \
    curl -sL https://deb.nodesource.com/setup_10.x | bash && \
    apt-get install nodejs -yq && \
    apt-get clean && \
    rm -rf /var/lib/apt/lists/*

USER coder
#
# install rust
#
RUN curl https://sh.rustup.rs -sSf | sh -s -- --default-toolchain stable -y
ENV USER=coder
RUN export PATH="/home/coder/.cargo/bin:$PATH" && \
    curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh -s && \
    cargo install cargo-generate
#
# npm global install witout root
# https://github.com/sindresorhus/guides/blob/master/npm-global-without-sudo.md
#
RUN npm config set prefix=/home/coder/.npm-packages && \
    echo '\nexport PATH="/home/coder/.npm-packages/bin:$PATH"' >> /home/coder/.bashrc && \
    echo '\nexport PATH="/home/coder/.cargo/bin:$PATH"' >> /home/coder/.bashrc

RUN set -eux  && \
    code-server --install-extension ms-ceintl.vscode-language-pack-zh-hant
ARG PATH_SETTINGS=/home/coder/.local/share/code-server/User/settings.json
ARG PATH_LOCALE=/home/coder/.local/share/code-server/User/locale.json
# COPY settings.json ${PATH_SETTINGS}
RUN echo '{ \n\
    "terminal.integrated.shell.linux": "/bin/bash", \n\
    "files.associations": { \n\
        "[Dd]ockerfile*": "dockerfile", \n\
        "docker-compose*": "yaml" \n\
    } \n\
}' > ${PATH_SETTINGS}

# https://code.visualstudio.com/docs/getstarted/locales
RUN echo '{ \n\
    "locale": "zh-tw" \n\
}' > ${PATH_LOCALE}
#
# docker build -t foo .
# docker run -it --rm -v $PWD:/home/coder/project -p 8080-8089:8080-8089 foo 
# http://localhost:8080/?folder=/home/coder/project/
#
# npm init rust-webpack my-app
# cd my-app && npm run start
# You must give "--host 0.0.0.0" option to webpack-dev-server in the container 

rust 開發環境 v2

#
# https://hub.docker.com/r/codercom/code-server/tags
#
ARG CS_VER=v2
FROM codercom/code-server:${CS_VER}
USER root
RUN apt-get update && \
    DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
        build-essential \
        ca-certificates \
        curl \
        git \
        ssh \
        libssl-dev \
        pkg-config && \
    apt-get clean && \
    rm -rf /var/lib/apt/lists/*

USER coder
#
# install rust
#
RUN curl https://sh.rustup.rs -sSf | sh -s -- --default-toolchain stable -y
ENV USER=coder
RUN cat $HOME/.cargo/env && echo -e '\nexport PATH="/home/coder/.cargo/bin:$PATH"' >> /home/coder/.bashrc

RUN set -eux  && \
    code-server --install-extension ms-ceintl.vscode-language-pack-zh-hant
ARG PATH_SETTINGS=/home/coder/.local/share/code-server/User/settings.json
ARG PATH_LOCALE=/home/coder/.local/share/code-server/User/locale.json
# COPY settings.json ${PATH_SETTINGS}
RUN echo '{ \n\
    "terminal.integrated.shell.linux": "/bin/bash", \n\
    "files.associations": { \n\
        "[Dd]ockerfile*": "dockerfile", \n\
        "docker-compose*": "yaml" \n\
    } \n\
}' > ${PATH_SETTINGS}

# https://code.visualstudio.com/docs/getstarted/locales
RUN echo '{ \n\
    "locale": "zh-tw" \n\
}' > ${PATH_LOCALE}
#
# docker build -t foo .
# docker run -it --rm -v $PWD:/home/coder/project -p 8080:8080 foo 
# http://localhost:8080/?folder=/home/coder/project/
# cargo new --bin hello-world 
# cd hello-world && cargo run

code-server v2 正式版本加上 vue 開發環境

#
# https://hub.docker.com/r/codercom/code-server/tags
#
ARG CS_VER=v2
FROM codercom/code-server:${CS_VER}
USER root
RUN apt-get update -yq \
    && apt-get install curl gnupg -yq \
    && curl -sL https://deb.nodesource.com/setup_10.x | bash \
    && apt-get install nodejs -yq


USER coder
#
# npm global install witout root
# https://github.com/sindresorhus/guides/blob/master/npm-global-without-sudo.md
#
RUN npm config set prefix=/home/coder/.npm-packages \
    && echo -e '\nexport PATH="/home/coder/.npm-packages/bin:$PATH"' >> /home/coder/.bashrc
RUN npm install -g @vue/cli

RUN set -eux  && \
    code-server --install-extension ms-ceintl.vscode-language-pack-zh-hant && \
    code-server --install-extension octref.vetur
ARG PATH_SETTINGS=/home/coder/.local/share/code-server/User/settings.json
ARG PATH_LOCALE=/home/coder/.local/share/code-server/User/locale.json
# COPY settings.json ${PATH_SETTINGS}
RUN echo '{ \n\
    "terminal.integrated.shell.linux": "/bin/bash", \n\
    "files.associations": { \n\
        "[Dd]ockerfile*": "dockerfile", \n\
        "docker-compose*": "yaml" \n\
    } \n\
}' > ${PATH_SETTINGS}

# https://code.visualstudio.com/docs/getstarted/locales
RUN echo '{ \n\
    "locale": "zh-tw" \n\
}' > ${PATH_LOCALE}
#
# docker build -t foo .
# docker run -it --rm -v $PWD:/home/coder/project -p 8080-8099:8080-8099 foo 
# http://localhost:8080/?folder=/home/coder/project/
#

一開始需先知道每一個使用者設定的 dev server port 才能對應

  • docker run 需要先開 port
  • package.json 裡面 vue-cli-service serve -port 8081 需要一致
docker run -it --rm -v $PWD:/home/coder/project -p 8080:8080 -p 8081:8081 foo

後來直接開 8080-8099 不用改 package.json 裡面的 port 設定。

docker run -it --rm -v $PWD:/home/coder/project -p 8080-8099:8080-8099 foo

剩下兩個問題

  • 開發時的 dev server 服務沒權限設定,每個知道 dev server port 的人都可以看到使用者正在開發的內容。
  • 有些環境只適合 443 通過如何讓使用者可以開自己的 dev server 起來用。

code-server v2 正式版本

預載中文(繁體)語言套件

#
# https://hub.docker.com/r/codercom/code-server/tags
#
ARG CS_VER=v2
FROM codercom/code-server:${CS_VER}
USER coder
RUN set -eux  && \
    code-server --install-extension ms-ceintl.vscode-language-pack-zh-hant
ARG PATH_SETTINGS=/home/coder/.local/share/code-server/User/settings.json
ARG PATH_LOCALE=/home/coder/.local/share/code-server/User/locale.json
# COPY settings.json ${PATH_SETTINGS}
RUN echo '{ \n\
    "terminal.integrated.shell.linux": "/bin/bash", \n\
    "files.associations": { \n\
        "[Dd]ockerfile*": "dockerfile", \n\
        "docker-compose*": "yaml" \n\
    } \n\
}' > ${PATH_SETTINGS}

# https://code.visualstudio.com/docs/getstarted/locales
RUN echo '{ \n\
    "locale": "zh-tw" \n\
}' > ${PATH_LOCALE}

# docker build -t foo .
# docker run -it --rm -v $PWD:/home/coder/project -p 8080:8080 foo 
# http://localhost:8080/?folder=/home/coder/project/

DEPRECATED : codercom/code-server:2.1472-vsc1.38.1

測試 code-server/Dockerfile at 2.1472-vsc1.38.1 · cdr/code-server 版本,folder 網址參數可用來切換不同學員的目錄例如

  • http://localhost:8080/?folder=/home/coder/project/alice
  • http://localhost:8080/?folder=/home/coder/project/bob
  • http://localhost:8080/?folder=/home/coder/project/Y12345
# tc.sh --run-code-server $PWD 2.1472-vsc1.38.1
run_code_server(){
    need_cmd docker
    set -x
    PROJECT_DIR=$1
    VERSION=$2
    docker run -it -p 127.0.0.1:8080:8080 \
      -v "${PROJECT_DIR}:/home/coder/project" codercom/code-server:${VERSION}
}

預載 ms-ceintl.vscode-language-pack-zh-hant VS Code 的中文(繁體)語言套件

使用 microsoft/vscode-loc: VS Code Localization Extension

#
# https://hub.docker.com/r/codercom/code-server/tags
#
ARG CS_VER=2.1472-vsc1.38.1
FROM codercom/code-server:${CS_VER}
USER coder
RUN set -eux  && \
    code-server --install-extension ms-ceintl.vscode-language-pack-zh-hant
ARG PATH_SETTINGS=/home/coder/.local/share/code-server/User/settings.json
ARG PATH_LOCALE=/home/coder/.local/share/code-server/User/locale.json
# COPY settings.json ${PATH_SETTINGS}
RUN echo '{ \n\
    "terminal.integrated.shell.linux": "/bin/bash", \n\
    "files.associations": { \n\
        "[Dd]ockerfile*": "dockerfile", \n\
        "docker-compose*": "yaml" \n\
    } \n\
}' > ${PATH_SETTINGS}

# https://code.visualstudio.com/docs/getstarted/locales
RUN echo '{ \n\
    "locale": "zh-tw" \n\
}' > ${PATH_LOCALE}

TODO

link to localhost site or github pages

curl -k https://localhost:1984/dockerfiles/Dockerfile-cs-zh-tw.txt | docker build -t cslocal -
docker run -it --rm cslocal

opt-ins service in code-server docker image

  • plantuml java server ?
  • ipfs node ?
  • nginx proxy ?

helm test