有点标题党的嫌疑哈!之前给大家分享了一套 开发环境 主要使用的是 cloud9 但是 cloud9只能做个编辑器 还达不到IDE的效果,今天来更新一下新的IDE 。

目前市面上毕竟成熟的 WebIDE 都是大公司开发的,要么就需要收费,要么就是国外的,要么是特别重(Eclips Che 7)需要运行在K8s上,对于企业来说基本上没有什么难度,但是个人开发者来说就需要一款轻便的IDE了。

前几天我朋友给我发消息说笔记本电脑固态硬盘坏了,刚刚开的项目写了大半结果找不回来了(试过各种办法了),真是个糟糕的一天。突然想起微软的 vscode 可以通过浏览器运行,经过一番搜索后找到了一个新玩意,code-server (官网) 是一个基于vscode的在线开发编辑,非常强大,主要是和本地电脑上安装的 vscode 一样,包括插件和主题也是相互支持。通过半天的组装和测试,基本上完成了环境搭建。

已经内置了:git zsh omyzsh(目前需要打开Terminal需要手动输入:zsh )

集成了常用开发组件:容器管理:portainer、数据库:mysql、队列缓存数据:redis、数据库管理:phpMyAdmin、对象存储:Minio(兼容亚马逊S3的对象存储)、代码仓库:gitea 基本上涵盖了常用开发环境。

docker-compose 如下:

version: "2.1"
networks:
  webide:
    driver: bridge
services:

### Portainer ################################################
  portainer:
    container_name: portainer
    image: portainer/portainer
    volumes:
      - ./docker_data/portainer:/data
      - /var/run/docker.sock:/var/run/docker.sock
    ports:
      - 9010:9000
    networks:
      - webide
### web_ide_php ################################################
  web_ide_php:
    # image: dragonlhp/coder-server-php
    build: .
    container_name: web_ide_php
    environment:
      - PUID=1000
      - PGID=1000
      - TZ=Asia/Shanghai
      - PASSWORD=password
      - SUDO_PASSWORD=password
    volumes:
      ##  编辑器配置文件
      - ./docker_conf/code/.config:/config/.config
      - ./docker_conf/code/.local:/config/.local
      - ./docker_conf/code/data:/config/data
      - ./docker_conf/code/extensions:/config/extensions
     ##  php-fpm 配置文件
      - ./docker_conf/code/php7.4/fpm/pool.d/www.conf:/etc/php/7.4/fpm/pool.d/www.conf
     ##  nginx配置文件
      - ./docker_conf/code/nginx/nginx.conf:/etc/nginx/nginx.conf
      - ./docker_conf/code/nginx/conf.d:/etc/nginx/conf.d
      - ./docker_data/code/log/nginx:/var/log/nginx/
      - ./start_service.sh:/start_service.sh
     ##  默认工作空间 
      - D:\docker:/config/workspace
      - C:\Users\lenovo\.ssh:/config/.ssh
    command: ['sh','/start_service.sh']
    ports:
      - 8443:8443
      - 80:80
    networks:
      - webide

### db ################################################
  db:
    container_name: "db"
    image: mysql:8
    restart: always
    environment:
      - MYSQL_ROOT_PASSWORD=root
      - MYSQL_USER=gitea
      - MYSQL_PASSWORD=gitea
      - MYSQL_DATABASE=gitea
    command:
      --default-authentication-plugin=mysql_native_password
      --character-set-server=utf8mb4
      --collation-server=utf8mb4_general_ci
      --explicit_defaults_for_timestamp=true
      --lower_case_table_names=1
      --max_allowed_packet=128M;
    volumes:
      - ./docker_data/mysql:/var/lib/mysql
    ports:
      - "3306:3306"
    networks:
      - webide
### redis ################################################
  redis:
    #定义主机名
    container_name: redis
    #使用的镜像
    image: redis
    #容器的映射端口
    ports:
      - 6379:6379
    # command: redis-server /etc/conf/redis.conf
    #定义挂载点
    volumes:
      - ./docker_data/redis/data:/data
      - ./docker_conf/redis/conf:/etc/conf
    #环境变量
    privileged: true
    environment:
      - TZ=Asia/Shanghai
      - LANG=en_US.UTF-8
    networks:
      - webide

# ### phpmyadmin ################################################
#   phpmyadmin:
#     image: "phpmyadmin/phpmyadmin"
#     container_name: "phpmyadmin"
#     ports:
#       - "9080:80"
#     environment:
#       - PMA_ARBITRARY=1 
#       - MYSQL_ROOT_PASSWORD=root
#     depends_on:
#       - db
#     networks:
#       - webide

# ### minio ################################################
#   minio:
#     image: minio/minio:latest
#     container_name: minio
#     ports:
#       - "9098:9000"
#     restart: always
#     command: server /data
#     environment:
#       MINIO_ACCESS_KEY: admin
#       MINIO_SECRET_KEY: admin123 #大于等于8位
#     logging:
#       options:
#         max-size: "50M" # 最大文件上传限制
#         max-file: "10"
#       driver: json-file
#     volumes:
#       - ./docker_data/minio:/data # 映射文件路径
#     networks:
#       - webide
# ### gitea ################################################
#   gitea:
#     image: gitea/gitea:latest
#     container_name: gitea
#     environment:
#       - USER_UID=1000
#       - USER_GID=1000
#       - DB_TYPE=mysql
#       - DB_HOST=db:3306
#       - DB_NAME=gitea
#       - DB_USER=gitea
#       - DB_PASSWD=gitea
#     restart: always
#     volumes:
#       - ./docker_data/gitea:/data
#     ports:
#       - "3000:3000"
#       - "222:22"
#     depends_on:
#       - db
#     networks:
#       - webide

以下主要是用于其他开发语言的环境搭建,内部已经添加上国内源  可以直接构建容器使用,或者添加其他语言的开发环境。

通用版 dockerfile:

FROM linuxserver/code-server
USER root
COPY install.sh /tmp/install.sh
RUN cp /etc/apt/sources.list /etc/apt/sources.list.bak \
    && cat /dev/null  > /etc/apt/sources.list \
    && echo 'deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse' > /etc/apt/sources.list \
    && echo 'deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse' >> /etc/apt/sources.list \
    && echo 'deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse' >> /etc/apt/sources.list \
    && echo 'deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse' >> /etc/apt/sources.list \
    && echo 'deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse' >> /etc/apt/sources.list \
    && echo 'deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse' >> /etc/apt/sources.list \
    && echo 'deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse' >> /etc/apt/sources.list \
    && echo 'deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse' >> /etc/apt/sources.list \
    && echo 'deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse' >> /etc/apt/sources.list \
    && echo 'deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse' >> /etc/apt/sources.list \
    && cat /etc/apt/sources.list \
    && apt update && sudo apt install -y wget zsh vim software-properties-common \
    && sh /tmp/install.sh \
    && chsh -s /bin/zsh \
    && sudo apt install -y   \
    && sudo add-apt-repository ppa:apt-fast/stable \
    && sudo apt-get update \
    && DEBIAN_FRONTEND=noninteractive apt install -y apt-fast \
    && apt-get clean && rm -rf /tmp/* /var/lib/apt/lists/* /var/tmp/*  /var/cache/apt/*
WORKDIR /config/workspace/

以下是基于上面的容器继续构建的PHP7.4开发环境,包含一些常用扩展 并且增加的 swoole  redis ,需要其他扩展可以试试 。

pecl install  xxxxxx  (xxx 是扩展名称),注意增加扩展配置 。

dockerfile:

FROM linuxserver/code-server
USER root
COPY install.sh /tmp/install.sh
RUN cp /etc/apt/sources.list /etc/apt/sources.list.bak \
    && cat /dev/null  > /etc/apt/sources.list \
    && echo 'deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse' > /etc/apt/sources.list \
    && echo 'deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse' >> /etc/apt/sources.list \
    && echo 'deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse' >> /etc/apt/sources.list \
    && echo 'deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse' >> /etc/apt/sources.list \
    && echo 'deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse' >> /etc/apt/sources.list \
    && echo 'deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse' >> /etc/apt/sources.list \
    && echo 'deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse' >> /etc/apt/sources.list \
    && echo 'deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse' >> /etc/apt/sources.list \
    && echo 'deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse' >> /etc/apt/sources.list \
    && echo 'deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse' >> /etc/apt/sources.list \
    && cat /etc/apt/sources.list \
    && apt update && sudo apt install -y wget zsh vim nginx software-properties-common \
    && sh /tmp/install.sh \
    && sudo apt install -y   \
    && sudo add-apt-repository ppa:apt-fast/stable \
    && sudo apt-get update \
    && DEBIAN_FRONTEND=noninteractive apt install -y apt-fast \
    && add-apt-repository ppa:ondrej/php \
    && find /etc/apt/sources.list.d/ -type f -name "ondrej-ubuntu-php-bionic.list" -exec  sed  -i.bak -r  's#deb(-src)?\s*http(s)?://ppa.launchpad.net#deb\1 https\2://launchpad.proxy.ustclug.org#ig' {} \; \
    && sudo apt-get update && apt install -y php7.4 php7.4-dev php-pear php7.4-fpm php7.4-mysql \
    && apt-get clean && rm -rf /tmp/* /var/lib/apt/lists/* /var/tmp/* /var/cache/apt/* /var/log/*
RUN sudo apt-get update \
    && apt install -y php7.4-sqlite3 php7.4-zip* php7.4-curl php7.4-json php7.4-mbstring php7.4-xml php7.4-intl php7.4-gd \
    && apt install -y composer \
    && sed -i '184i return false;' /usr/share/php/PEAR/REST.php \
    && pecl install swoole \
    && echo "extension=swoole.so" > /etc/php/7.4/mods-available/swoole.ini \
    && echo "extension=swoole.so" > /etc/php/7.4/cli/conf.d/swoole.ini \
    && pecl install redis \
    && echo "extension=redis.so" > /etc/php/7.4/mods-available/redis.ini \
    && echo "extension=redis.so" > /etc/php/7.4/cli/conf.d/redis.ini \
    && sed '36c listen = 0.0.0.0:9000' /etc/php/7.4/fpm/pool.d/www.conf \
    && composer config -g repo.packagist composer  https://mirrors.aliyun.com/composer/  \
    && chsh -s /bin/zsh \
    && apt-get clean && rm -rf /tmp/* /var/lib/apt/lists/* /var/tmp/* /var/cache/apt/* /var/log/*

 

Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐