Skip to content

Instantly share code, notes, and snippets.

@abdennour
Created October 11, 2021 10:06
Show Gist options
  • Save abdennour/c26871cc9b7e247df2d19669cc4901dc to your computer and use it in GitHub Desktop.
Save abdennour/c26871cc9b7e247df2d19669cc4901dc to your computer and use it in GitHub Desktop.
Dockerize VSCode codr-server
FROM centos:latest
# 初始化文件夹
RUN mkdir /www /www/server /www/wwwroot /www/env /www/bak /www/server/php74 /www/server/php56 /www/wwwroot/myapp \
&& yum update -y \
&& yum install -y nodejs zip unzip wget zsh vim make cmake gcc gcc-c++ libxml2 libxml2-devel git \
nodejs zip unzip sqlite-devel m4 autoconf nginx tree \
krb5-devel openssl openssl-devel curl curl-devel libjpeg \
libjpeg-devel libpng libpng-devel freetype freetype-devel \
pcre pcre-devel libxslt libxslt-devel bzip2 bzip2-devel \
openssh-server iputils net-tools oniguruma sudo go nss -y \
&& yum upgrade \
&& ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
# Download the ZSH configuration
RUN sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" \
&& git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions \
&& git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting \
&& sed -i "s/plugins=(git)/plugins=(git zsh-syntax-highlighting zsh-autosuggestions)/g" /root/.zshrc
# Download middleware https://github.com/cdr/code-server/
RUN wget -O /www/bak/code-server.rpm https://github.com/cdr/code-server/releases/download/v3.11.1/code-server-3.11.1-amd64.rpm \
&& wget -O /www/bak/php74.tar.gz https://www.php.net/distributions/php-7.4.16.tar.gz \
&& wget -O /www/bak/php56.tar.xz https://secure.php.net/get/php-5.6.40.tar.xz/from/this/mirror \
&& wget -O /www/bak/oniguruma.tar.gz https://github.com/kkos/oniguruma/releases/download/v6.9.7.1/onig-6.9.7.1.tar.gz \
&& wget -O /www/bak/xdebug-2.5.5.tar http://pecl.php.net/get/xdebug-2.5.5.tar \
&& wget -O /www/bak/xdebug-3.0.2.tar http://pecl.php.net/get/xdebug-3.0.2.tar
# 复制文件
COPY ./Dockerfile /www/bak
COPY ./vscode.sh /vscode.sh
COPY ./favicon.png /www/bak
COPY ./favicon.svg /www/bak
COPY ./favicon.ico /www/bak
RUN chmod 777 /vscode.sh \
# 解压文件
&& tar xzvf /www/bak/php74.tar.gz -C /www/bak \
&& tar xJvf /www/bak/php56.tar.xz -C /www/bak \
&& tar -zxvf /www/bak/oniguruma.tar.gz -C /www/bak \
&& rpm -ivh /www/bak/code-server.rpm
# 编译安装oniguruma
RUN cd /www/bak/onig-onig-6.9.7 \
&& ./configure --prefix=/usr \
&& make && make install
# 编译安装php74
RUN cd /www/bak/php-7.4.16 \
&& ./configure --prefix=/www/server/php74 --with-curl \
--with-gettext --with-iconv-dir --with-kerberos --with-libdir=lib64 \
--with-mysqli --with-openssl --with-pdo-mysql --with-pdo-sqlite --with-pear \
--with-xmlrpc --with-xsl --with-zlib --with-bz2 --with-mhash \
--enable-fpm --enable-bcmath --enable-inline-optimization \
--enable-mbregex --enable-mbstring --enable-opcache --enable-pcntl --enable-shmop --enable-soap \
--enable-sockets --enable-sysvsem --enable-sysvshm --enable-xml \
&& make && make install \
&& /www/bak/php-7.4.16/build/shtool install -c ext/phar/phar.phar /www/server/php74/bin/phar.phar \
&& ln -s -f phar.phar /www/server/php74/bin/phar \
&& /www/server/php74/bin/pecl install /www/bak/xdebug-3.0.2.tar
# PHP74 配置文件
RUN cp /www/bak/php-7.4.16/php.ini-development /www/server/php74/lib/php.ini \
&& echo "zend_extension=/www/server/php74/lib/php/extensions/no-debug-non-zts-20190902/xdebug.so" >> /www/server/php74/lib/php.ini \
&& echo "xdebug.mode = debug" >>/www/server/php74/lib/php.ini \
&& echo "debug.remote_handler = dbgp" >>/www/server/php74/lib/php.ini \
&& echo "xdebug.client_host = docker.for.mac.localhost" >>/www/server/php74/lib/php.ini \
&& echo "xdebug.start_with_request = yes" >>/www/server/php74/lib/php.ini \
&& echo "xdebug.client_port = 9003" >>/www/server/php74/lib/php.ini \
&& echo "xdebug.idekey = \"PHPSTORM\"" >>/www/server/php74/lib/php.ini \
&& ln -s /www/server/php74/bin/php /www/env/php74 \
&& ln -s /www/server/php74/sbin/php-fpm /www/env/php74-fpm \
&& ln -s /www/server/php74/bin/pecl /www/env/php74-pecl \
&& ln -s /www/server/php74/bin/pear /www/env/php74-pear \
&& cp /www/server/php74/etc/php-fpm.conf.default /www/server/php74/etc/php-fpm.conf \
&& cp /www/server/php74/etc/php-fpm.d/www.conf.default /www/server/php74/etc/php-fpm.d/www.conf \
&& sed -i "s/group = nobody/group = nginx/g" /www/server/php74/etc/php-fpm.d/www.conf \
&& sed -i "s/user = nobody/user = nginx/g" /www/server/php74/etc/php-fpm.d/www.conf
# 编译安装php56
RUN cd /www/bak/php-5.6.40 \
&& ./configure --prefix=/www/server/php56 --with-curl \
--with-gettext --with-iconv-dir --with-kerberos --with-libdir=lib64 \
--with-mysqli --with-pdo-mysql --with-pdo-sqlite --with-pear \
--with-xmlrpc --with-xsl --with-zlib --with-bz2 --with-mhash \
--enable-fpm --enable-bcmath --enable-inline-optimization \
--enable-mbregex --enable-mbstring --enable-opcache --enable-pcntl --enable-shmop --enable-soap \
--enable-sockets --enable-sysvsem --enable-sysvshm --enable-xml \
&& make && make install \
&& /www/bak/php-5.6.40/build/shtool install -c ext/phar/phar.phar /www/server/php56/bin \
&& ln -s -f phar.phar /www/server/php56/bin/phar \
&& /www/server/php56/bin/pecl install /www/bak/xdebug-2.5.5.tar
# PHP56 配置文件
RUN cp /www/bak/php-5.6.40/php.ini-development /www/server/php56/lib/php.ini \
&& echo "zend_extension=/www/server/php56/lib/php/extensions/no-debug-non-zts-20131226/xdebug.so" >> /www/server/php56/lib/php.ini \
&& echo "xdebug.remote_enable = on" >>/www/server/php56/lib/php.ini \
&& echo "xdebug.remote_host = docker.for.mac.localhost" >>/www/server/php56/lib/php.ini \
&& echo "xdebug.remote_port = 9003" >>/www/server/php56/lib/php.ini \
&& echo 'xdebug.idekey="PHPSTORM"' >>/www/server/php56/lib/php.ini \
&& echo "xdebug.remote_autostart = 1" >>/www/server/php56/lib/php.ini \
&& echo "xdebug.remote_connect_back = 1" >>/www/server/php56/lib/php.ini \
&& echo "xdebug.remote_handler = \"dbgp\"" >>/www/server/php56/lib/php.ini \
&& ln -s /www/server/php56/sbin/php-fpm /www/env/php56-fpm \
&& ln -s /www/server/php56/bin/php /www/env/php56 \
&& ln -s /www/server/php56/bin/pecl /www/env/php56-pecl \
&& ln -s /www/server/php56/bin/pear /www/env/php56-pear \
&& cp /www/server/php56/etc/php-fpm.conf.default /www/server/php56/etc/php-fpm.conf \
&& sed -i "s/group = nobody/group = nginx/g" /www/server/php56/etc/php-fpm.conf \
&& sed -i "s/user = nobody/user = nginx/g" /www/server/php56/etc/php-fpm.conf
# NGINX https://www.digitalocean.com/
RUN echo 'H4sIAMACdWACA+0aaXPbuDWf9Suwjpts0iWpy7JHGo3HYzuxZ32N5e1sp+lwIBKUsAIBFgAlK1X62/sAHqIoOel2Nv6yhiMeeAeAh4d3MXxC+aMbCB69+m6tCe3w8NDeodXv3Xav+arVbXYO2s1WJ+s/POx0UPPVM7RUaSwRevUnba/RR8KJxJqEaLxE3KiD0QY6calovEZTrRPV97zFYuGGdEI1ZiIgmIPKxB784pRTvfS0EEx5lvo4FDGmXLlNVxE5J9LNOoZAiNlUKP1mCyPBejr8S/sDjJJdpRAanuIlTpI3OxgGaUy4vges4TZYkpBKEuhROs5hwwgzRSqYdlnuVGl1JwkTOBxqmW4jBETqh2VChgGoiYi34EqxU0ChEQ1AgusVjPEMrgD1DQd4nKtAhMQNpP4Gj5/J8ttsZmT5ZsLEGDOXiQkIfWLuN0J/ECnPl5LD7Za4KUhmaB83+xMamtHmWMJVphyuJaDAhB1wGeaT4efp6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yv+fxf53m93GuiK0q+0XZZjs1GWFjSHQ2WAzD4grtRpIGZ74Nou2CzsG2fLJu0w5UFM+UY0CZ1cBbKMEViCO0yiqfWgy5RrU6s3qSOU30Lx12rONSeSL2JgmOrs9/eX6/ObBv7+9fTBykQQz818XfFOQHNSwR6f3l3cP/ofLq/MbyJVq2LtkWudwd3Hnn5xdX974fzu5+uUc7YmEcN/UOUMqh7bg6fW9VEmP0bEtiPU9HSfe3u8wcP8FeNe+NAAkAAA=' | base64 --decode | tee /www/bak/nginxconfig.io-localhost.tar.gz > /dev/null \
&& tar -xzvf /www/bak/nginxconfig.io-localhost.tar.gz -C /etc/nginx \
&& sed -i "s/443/31003/g" /etc/nginx/sites-available/localhost.conf \
&& sed -i "s:unix\:/var/run/php/php-fpm.sock:127.0.0.1\:9000:g" /etc/nginx/sites-available/localhost.conf \
&& openssl dhparam -out /etc/nginx/dhparam.pem 2048 \
&& sed -i "s/ssl_stapling on/ssl_stapling off/g" /etc/nginx/nginx.conf \
&& sed -i "s/ssl_stapling_verify on/ssl_stapling_verify off/g" /etc/nginx/nginx.conf \
&& sed -i "s/keepalive_timeout 65/keepalive_timeout 300/g" /etc/nginx/nginx.conf.default
# 环境变量
RUN echo "export vscode=\"/www/env\"" >> /etc/profile \
&& echo "export PATH=\$PATH:\$vscode" >> /etc/profile \
&& sed -i "s/#PubkeyAuthentication yes/PubkeyAuthentication yes/g" /etc/ssh/sshd_config \
&& sed -i "s/PasswordAuthentication yes/PasswordAuthentication no/g" /etc/ssh/sshd_config \
&& echo "AllowUsers root" >> /etc/ssh/sshd_config \
&& mkdir -p /root/.config/code-server \
&& echo "bind-addr: 0.0.0.0:31005" > /root/.config/code-server/config.yaml \
&& echo "auth: password" >> /root/.config/code-server/config.yaml \
&& echo "password: `openssl rand -base64 12`" >> /root/.config/code-server/config.yaml \
&& echo "cert: false" >> /root/.config/code-server/config.yaml \
&& ln -s /etc/nginx/sites-available/localhost.conf /www/server/localhost.conf \
&& ln -s /etc/profile /www/server/profile \
&& echo -e '<?php phpinfo(); ?>' > /www/wwwroot/myapp/index.php \
&& echo "source /etc/profile" >> /root/.bashrc
# 证书模块 https://github.com/milkfr/certs
RUN git clone https://github.com/milkfr/certs.git /www/bak/ssl_cert \
&& sed -i "s/zhejiang/Sichuan/g" /www/bak/ssl_cert/openssl.cnf \
&& sed -i "s/hangzhou/ChengDu/g" /www/bak/ssl_cert/openssl.cnf \
&& sed -i "s/Organization Name (eg, company)/vscode/g" /www/bak/ssl_cert/openssl.cnf \
&& sed -i "s/milkfr/vscode/g" /www/bak/ssl_cert/openssl.cnf \
&& sed -i "s/[email protected]/[email protected]/g" /www/bak/ssl_cert/openssl.cnf \
&& sed -i "s/Email Address/[email protected]/g" /www/bak/ssl_cert/openssl.cnf \
&& sed -i "s/Common Name (e.g. server FQDN or YOUR name)/vscode/g" /www/bak/ssl_cert/openssl.cnf \
&& sed -i "s/vscode.github.io/vscode/g" /www/bak/ssl_cert/openssl.cnf \
&& sed -i "s/Organizational Unit Name (eg, section)/vscode/g" /www/bak/ssl_cert/openssl.cnf \
&& sed -i "s/Locality Name (eg, city)/ChengDu/g" /www/bak/ssl_cert/openssl.cnf \
&& sed -i "s/State or Province Name (full name)/Sichuan/g" /www/bak/ssl_cert/openssl.cnf \
&& sed -i "s/Country Name (2 letter code)/CN/g" /www/bak/ssl_cert/openssl.cnf \
&& sed -i "s/1/KzAYsECwt6gdLCzN7xEcnoaHXb4dtp/g" /www/bak/ssl_cert/openssl-gen.sh \
&& sed -i "s:-out ca.pem:-out ca.pem -subj \"/C=CN/ST=Sichuan/L=ChengDu/O=vscode/OU=vscode/CN=vscode/[email protected]\":g" /www/bak/ssl_cert/openssl-gen.sh \
&& sed -i "s: ca.: \${0/openssl-gen.sh}ca.:g" /www/bak/ssl_cert/openssl-gen.sh \
&& sed -i "s:openssl.cnf:\${0/openssl-gen.sh}openssl.cnf:g" /www/bak/ssl_cert/openssl-gen.sh \
&& sh /www/bak/ssl_cert/openssl-gen.sh \
&& sed -i "s/milkfr/vscode/g" /www/bak/ssl_cert/main.go \
&& sed -i "s/vscode.github.io/127.0.0.1/g" /www/bak/ssl_cert/main.go \
&& cd /www/bak/ssl_cert \
&& go run main.go 127.0.0.1 \
&& mv /www/bak/ssl_cert/ca.crt /www/bak/ssl_cert/vscode.crt \
&& mv /www/bak/ssl_cert/ca.key /www/bak/ssl_cert/vscode.key \
&& sed -i "s/false/true/g" /root/.config/code-server/config.yaml \
&& mkdir -p /root/.local/share/code-server/ \
&& cp /www/bak/ssl_cert/vscode.crt /root/.local/share/code-server/localhost.crt \
&& cp /www/bak/ssl_cert/vscode.key /root/.local/share/code-server/localhost.key
# 配置code-server
RUN cp /www/bak/favicon.svg /usr/lib/code-server/src/browser/media/favicon-dark-support.svg \
&& cp /www/bak/favicon.ico /usr/lib/code-server/src/browser/media/favicon.ico \
&& cp /www/bak/favicon.svg /usr/lib/code-server/src/browser/media/favicon.svg \
&& cp /www/bak/favicon.png /usr/lib/code-server/src/browser/media/pwa-icon-192.png \
&& cp /www/bak/favicon.png /usr/lib/code-server/src/browser/media/pwa-icon-512.png \
&& cp /www/bak/favicon.png /usr/lib/code-server/src/browser/media/pwa-icon.png \
&& sed -i "s/code-server/Visual Studio Code/g" /usr/lib/code-server/src/browser/media/manifest.json \
&& sed -i "s/Run editors on a remote server./Copyright (C) 2021 Microsoft. All rights reserved/g" /usr/lib/code-server/src/browser/media/manifest.json
ENTRYPOINT ["/vscode.sh"]
EXPOSE 22 5050 31000 31001 31002 31003
ENV TZ='Asia/Shanghai'
ENV LANG 'zh_CN.UTF-8'
STOPSIGNAL SIGQUIT
CMD ["/vscode.sh"]
echo -e "\033[1;32m start code-server succers \033[0m"
echo -e "\033[1;31m [help] \n\033[0m"
echo -e "\033[1;36m Your" "`/usr/bin/grep password /root/.config/code-server/config.yaml | grep -v "auth: password"` \033[0m"
echo -e "\033[1;35m php56-fpm & nginx \n\n\n\033[0m"
/usr/bin/code-server >> /dev/null &
/bin/bash
@abdennour
Copy link
Author

In case if this repo become private https://github.com/XRSec/Code-Server-Update

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment