容器化配置生成神器

How Buildpacks Work
https://docs.cloudfoundry.org/buildpacks/understand-buildpacks.html

https://github.com/alibaba/derrick

简介

Derrick 是一个可以帮助开发者快速完成应用容器化的工具。Derrick 主要关注的是希望容器化的开发者如何在本地进行开发的问题。开发者可以通过使用 Derrick 加速本地应用容器化迁移的过程

Derrick 自动生成以下配置

  • Dockerfile
  • .dockerignore
  • docker-compose.yml
  • Jenkinsfile
  • kubernetes-deployment.yaml

安装 derrick

yum install python2-pip python-devel
mkdir ~/.pip -p

vim ~/.pip/pip.conf

[global]
index-url = https://mirrors.aliyun.com/pypi/simple/

[install]
trusted-host=mirrors.aliyun.com
pip install --upgrade pip
pip install python-derrick

下载 derrick-nodejs-demo node 项目

git clone https://github.com/ringtail/derrick-nodejs-demo

选择需要部署的平台,支持 Kubernetes 和 Swarm

derrick config

? Which Orchestration Engine would you like to choose?  Kubernetes

查看

cat /root/.derrick/derrick_conf 
{"engine": "Kubernetes"}

运行 Derrick

cd derrick-nodejs-demo

derrick init

? Please input image name with tag (such as "registry.com/user/repo:tag"):   harbor.od.com/public/derrick-nodejs-demo:v1
Derrick detect your platform is NodeJs and compile successfully.

查看生成的配置

git status

# 位于分支 master
# 未跟踪的文件:
#   (使用 "git add ..." 以包含要提交的内容)
#
#	.dockerignore
#	Dockerfile
#	Jenkinsfile
#	derrick_conf
#	docker-compose.yml
#	kubernetes-deployment.yaml
提交为空,但是存在尚未跟踪的文件(使用 "git add" 建立跟踪)

本地验证容器化结果

derrick up

Kubernetes is the default Orchestration Engine.
Sending build context to Docker daemon  1.797MB
Step 1/14 : FROM node:8-alpine AS base
 ---> 2b8fcdc6230a
Step 2/14 : WORKDIR /app
 ---> Using cache
 ---> 2f5194e0f321
Step 3/14 : COPY package.json .
 ---> Using cache
 ---> dd7a6bb4e2f2
Step 4/14 : RUN npm set progress=false && npm config set depth 0
 ---> Using cache
 ---> 64f0f9bd880c
Step 5/14 : RUN npm install --only=production --registry=https://registry.npm.taobao.org
 ---> Using cache
 ---> 493907003ec3
Step 6/14 : RUN cp -R node_modules prod_node_modules
 ---> Using cache
 ---> fbdd30f8251d
Step 7/14 : RUN npm install --registry=https://registry.npm.taobao.org
 ---> Using cache
 ---> 11412722a789
Step 8/14 : FROM base As test
 ---> 11412722a789
Step 9/14 : COPY . /app
 ---> 78d3d562a7be
Step 10/14 : RUN npm test
 ---> Running in 9106c2adc96e

> [email protected] test /app
> node_modules/mocha/bin/mocha



  Array
    #indexOf()
      ✓ should return -1 when the value is not present


  1 passing (5ms)

Removing intermediate container 9106c2adc96e
 ---> 40ac0fe678cf
Step 11/14 : FROM base AS release
 ---> 11412722a789
Step 12/14 : COPY --from=base /app/prod_node_modules /app/node_modules
 ---> f1a3aef03736
Step 13/14 : COPY . /app
 ---> 083d3a927c98
Step 14/14 : CMD ["npm","start"]
 ---> Running in aaee7341a2e1
Removing intermediate container aaee7341a2e1
 ---> 7953078a90a0
Successfully built 7953078a90a0
Successfully tagged harbor.od.com/public/derrick-nodejs-demo:v1
The push refers to repository [harbor.od.com/public/derrick-nodejs-demo]
f9b4ddec6b27: Pushed 
64143b79bddd: Pushed 
6db30f1a9496: Pushed 
253c314e33fe: Pushed 
c5a780245e52: Pushed 
872254c3f3d5: Pushed 
6d6ae580e2c9: Pushed 
f0baca6ea476: Pushed 
6b73202914ee: Pushed 
9851b6482f16: Pushed 
540b4f5b2c41: Pushed 
6b27de954cca: Pushed 
v1: digest: sha256:509794c9029afd128b93a11a8d7e32e5561061aeffb2ae25f7e0e1c0d780cc75 size: 2830
service/derrick-nodejs-demo created
deployment.extensions/derrick-nodejs-demo created
Your application has been up to running! You can run `kubectl get svc` to get exposed ports.

你可能感兴趣的:(kubernetes)