4

使用 SmartIDE 开发golang项目 - 远方V3

 1 year ago
source link: https://www.cnblogs.com/smallidea/p/16961708.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

使用 SmartIDE 开发golang项目

很荣幸在去年加入到 SmartIDE 产品组,从事开发工作,期间产品经历了无数个迭代,一段非常难忘的经历......

项目之初一位大牛提出了一个哲学问题 —— 先有鸡还是有蛋(SmartIDE 如何开发 SmartIDE),借着这话题,本文将以 Golang 项目 SmartIDE CLI 为例进行演示。

官网概述:https://smartide.cn/zh/docs/overview/

OpenAI 的解释是:SmartIDE 是一款软件开发环境的工具,它使用容器技术来解决软件运行环境的一致性、标准化、快速获取、可扩展性和可维护性问题。它将 IDE 的边界重新定义为包括代码编辑器、运行时、SDK、中间件、应用服务器、配置和底层操作系统等内容。

289667-20221208151212482-1088471304.png

一些适用的场景:

  1. 开发环境腐化
  • 作为一个工程狮(工程师),底子里就是喜欢各种尝试新事物(新工具、新框架...),有时候玩翻车了,然后告诉领导 / 老板今天我要闭关修炼(重装系统)
  • 程序员就是多核的电脑,项目之间来回切换,新旧不同的项目,甚至不同的技术栈,开发调试环境不能隔离,折腾不说,很容易带着问题就上了生产
  • 自己的电脑开了一堆的软件,好像这个不能关,那个也得留着,此时再来调试或者压测,电脑直接嗝屁了
  • 程序员到处救火,一个开发环境搞半天,增加了对客户或者用户的响应时间,市场压力山大
  • 项目组进了小鲜肉,一个环境要帮忙装半天
  • 演示一下,不做更深入的开发

问题:
SmartIDE 的本质还是 WebIDE,所以缺点也是很明显。

  • 体验上没有桌面IDE流畅,貌似又回来了原来C/S架构的看不中B/S架构,但是大势所趋现在的B/S架构的市场占有率是碾压式的。
  • 服务器资源的限制,给每个用户、每个项目单独划分一定的资源
  • 受限于网络传输的速度,这个不太好解决,就算是内网也一样可能出问题

总结:
SmartIDE 对于市场来说还是比较新,还需要时间才能够推广开来,易用性 和 流畅度总会找到一个平衡。

简单来说,按照用户的需求,比如技术栈、IDE类型,本地或者Server 通过 CLI工具调度 docker、k8s ,按照编排好的镜像创建独立的开发环境给到用户使用。

画图工具:https://app.diagrams.net/

289667-20221213231407047-569628793.png

从开发的角度,有三个重要的组成部分,CLI、Server、Image

  • CLI, 通过 Cobra 框架实现对shell命令的支持,比如 command、args、flag 这些元素,在业务上主要是支持在 本地、远程主机、k8s 三类资源上创建独立开发环境
  • Server,是一个运行在服务器上的调度平台,基于 Gin Vue Amin 这个框架的插件式开发,即不动核心代码在单独的文件夹中开发业务即可
  • Image,为各种语言编排了独立的镜像,并根据共性编排了base镜像
289667-20221213235321055-226673068.png

本地安装 SmartIDE CLI

参考:https://smartide.dev/zh/docs/install/cli/
建议安装每日构建版,以mac为例

# Intel芯片
curl -OL  "https://smartidedl.blob.core.chinacloudapi.cn/builds/$(curl -L -s https://smartidedl.blob.core.chinacloudapi.cn/builds/stable.txt)/smartide-osx" \
&& mv -f smartide-osx /usr/local/bin/smartide \
&& ln -s -f /usr/local/bin/smartide /usr/local/bin/se \
&& chmod +x /usr/local/bin/smartide

远程主机上安装 sysbox

参考 https://smartide.dev/zh/docs/install/docker/linux/

## 国内安装包下载
wget https://smartidedl.blob.core.chinacloudapi.cn/hybrid/sysbox/sysbox-ce_0.5.2-0.linux_amd64.deb

## 国际安装包下载
wget https://downloads.nestybox.com/sysbox/releases/v0.5.2/sysbox-ce_0.5.2-0.linux_amd64.deb

## 删除现有的所有容器
docker rm $(docker ps -a -q) -f

## 安装
sudo apt-get install ./sysbox-ce_0.5.2-0.linux_amd64.deb

## 查看运行状态,注意 active (running) 文本
sudo systemctl status sysbox -n20

通过CLI创建

## 添加 host
smartide host add {vm-host-ip} --password {vm-password} --username {vm-username}
## 在 vm 上新建工作区
smartide start --host {host-id} --repourl https://github.com/SmartIDE/SmartIDE.git 
289667-20221214101731839-1398413732.png

启动完成后,会自动在默认浏览器中打开webide,在terminal中会自动运行一些shell command,让它们执行完即可

289667-20221214101843090-1134544642.png

通过 Server 创建

公网测试地址: https://dev.smartide.cn/

289667-20221214111038959-1721108170.png

创建成功后,可以点击icon打开WebIDE

289667-20221214111226795-489895013.png

手动安装go插件

289667-20221214102231098-2056302891.png

工具安装

289667-20221214102345865-1685311003.png

全选,等待安装结束

289667-20221214102437519-1898074096.png
289667-20221214102453292-1859246528.png

进入到CLI目录下,比如 http://localhost:6900/?folder=vscode-remote://localhost:6900/home/project/cli

289667-20221214102036255-593460474.png

创建 lauch.json 文件

289667-20221214102744448-1797895350.png

以version命令为例

        {
            "name": "Version",
            "type": "go",
            "request": "launch",
            "console": "integratedTerminal",
            "mode": "debug",
            "apiVersion": 2,
            "program": "${workspaceFolder}",
            "showLog": true,
            "trace": "verbose",
            "args": [
                "version"
            ]
        },
289667-20221214103450446-734180665.png

Start 命令调试

## 创建目录
mkdir -p /home/smartide/test

## 添加配置到launch.json
        {
            "name": "Start",
            "type": "go",
            "request": "launch",
            "apiVersion": 2,
            "program": "${workspaceFolder}",
            "cwd": "/home/smartide/test",
            "console": "integratedTerminal",            
            "mode": "debug",
            "args": [
                "start",
                "--repourl", "https://github.com/idcf-boat-house/boathouse-calculator.git",
                "-d"
            ]
        },

进入断点

289667-20221214110926941-658974153.png

Recommend

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK