概述
本文介绍如何在本地搭建openshift3.9开发环境,开发环境里面容器的进程均是以容器的方式运行,编译源代码可以生成二进制、rpm包和镜像。我们以Mac为本地环境。
正文
安装git
brew install git
安装docker
具体安装方法请参照Google,安装好后需要到右上角docker图标里的Preferences,把docker里面的内存参数调整为4G或以上(默认是2G),因为如果内存太小的话在编译的时候会出现out of memory错误
安装golang
go的版本要求是1.9, 不能是1.10
下载goland IDE
IDE用于编辑源代码的,这里用Intellij系列的Goland
创建开发环境目录
mkdir -p /go/src/github.com/openshift
因为go语言项目必须要放在src目录下,所以以上目录是必须的
下载openshift origin, origin-web-console-server, origin-web-console, origin-web-catalog, origin-web-common源代码
openshift origin的主要代码库是origin,origin-web-console是UI的代码库,origin-web-console-server是UI后端的代码库,origin-web-catalog和origin-web-common是UI代码库的依赖库。
cd /go/src/github.com/openshift
git clone https://github.com/openshift/origin.git
git clone https://github.com/openshift/origin-web-console-server.git
git clone https://github.com/openshift/origin-web-console.git
git clone https://github.com/openshift/origin-web-catalog.git
git clone https://github.com/openshift/origin-web-common.git
进入以上每个项目,把分支切换为release-3.9 或者enterprise-3.9
git checkout release-3.9
git checkout enterprise-3.9
用Goland打开项目/go/src/github.com/openshift,并设置GOROOT和GOPATH
生成openshift/origin-base , openshift/origin-source和openshift/origin-release三个镜像
cd origin
hack/env hack/build-base-images.sh
生成二进制文件,rpm包和各种镜像
cd origin
hack/env make release
生成origin web console的二进制文件,rpm包和镜像
cd origin-web-console-server
make
OS_BUILD_ENV_PRESERVE=_output/local/bin hack/env make build-images
查看镜像的tag
docker images
修改生成的web-console的镜像的tag,和其他的镜像的tag保持一致
之前生成的origin-web-console的镜像的tag和其他的镜像的tag不同,需要修改成一样的,不然后面启动容器集群的时候会报错,下面的tag需要换成真实的
docker tag openshift/origin-web-console:b02b6d7 openshift/origin-web-console:71543b2
删除镜像是 tagged的镜像
docker rmi $(docker images | grep "^<none>" | awk "{print $3}")
本地下载二进制文件oc或者在本地编译生成oc
把oc的路径加入到PATH以便于调用
cd origin
$ export PATH="$( source hack/lib/init.sh; echo "${OS_OUTPUT_BINPATH}/$( os::build::host_platform )/" ):${PATH}"
启动openshift集群
oc cluster up --version="71543b2"
成功后会出现以下输出:
Deleted existing OpenShift container
Using Docker shared volumes for OpenShift volumes
Using 127.0.0.1 as the server IP
Starting OpenShift using openshift/origin:71543b2 ...
OpenShift server started.
The server is accessible via web console at:
https://127.0.0.1:8443
You are logged in as:
User: developer
Password: <any value>
To login as administrator:
oc login -u system:admin