Skip to content

Commit

Permalink
k8client version
Browse files Browse the repository at this point in the history
  • Loading branch information
wangzhezhe committed Jul 2, 2015
1 parent 2dece30 commit f271088
Show file tree
Hide file tree
Showing 12 changed files with 474 additions and 239 deletions.
Binary file modified ApiServer/ApiServer
Binary file not shown.
61 changes: 30 additions & 31 deletions ApiServer/Fti/fti.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package Fti
import (
"archive/tar"
"compress/gzip"
"fmt"
"io"
// "io/ioutil"
"github.com/fsouza/go-dockerclient"
Expand All @@ -23,9 +22,9 @@ const (
func Filecompress(tw *tar.Writer, dir string, fi os.FileInfo) error {

//打开文件 open当中是 目录名称/文件名称 构成的组合
fmt.Println(dir + fi.Name())
log.Println(dir + fi.Name())
fr, err := os.Open(dir + fi.Name())
fmt.Println(fr.Name())
log.Println(fr.Name())
if err != nil {
return err
}
Expand All @@ -43,7 +42,7 @@ func Filecompress(tw *tar.Writer, dir string, fi os.FileInfo) error {
return err
}
//打印文件名称
fmt.Println("add the file: " + fi.Name())
log.Println("add the file: " + fi.Name())
return nil

}
Expand All @@ -52,8 +51,8 @@ func Dircompress(tw *tar.Writer, dir string) error {

//打开文件夹
dirhandle, err := os.Open(dir)
//fmt.Println(dir.Name())
//fmt.Println(reflect.TypeOf(dir))
//log.Println(dir.Name())
//log.Println(reflect.TypeOf(dir))
if err != nil {
return err
}
Expand All @@ -62,7 +61,7 @@ func Dircompress(tw *tar.Writer, dir string) error {
//fis, err := ioutil.ReadDir(dir)
fis, err := dirhandle.Readdir(0)
//fis的类型为 []os.FileInfo
//fmt.Println(reflect.TypeOf(fis))
//log.Println(reflect.TypeOf(fis))
if err != nil {
return err
}
Expand All @@ -84,8 +83,8 @@ func Dircompress(tw *tar.Writer, dir string) error {
// }

newname := dir + fi.Name()
fmt.Println("using dir")
fmt.Println(newname)
log.Println("using dir")
log.Println(newname)
//这个样直接continue就将所有文件写入到了一起 没有层级结构了
//Filecompress(tw, dir, fi)
err = Dircompress(tw, newname+"/")
Expand All @@ -110,12 +109,12 @@ func Dirtotar(sourcedir string, tardir string, newimage string) error {
//file write 在tardir目录下创建
_, err := os.Stat(sourcedir)
if err != nil {
fmt.Println("please create the deploy dir")
log.Println("please create the deploy dir")
return err
}
fw, err := os.Create(tardir + "/" + newimage + ".tar.gz")
//type of fw is *os.File
// fmt.Println(reflect.TypeOf(fw))
// log.Println(reflect.TypeOf(fw))
if err != nil {
return err

Expand All @@ -129,7 +128,7 @@ func Dirtotar(sourcedir string, tardir string, newimage string) error {
//tar write
tw := tar.NewWriter(gw)
defer tw.Close()
// fmt.Println(reflect.TypeOf(tw))
// log.Println(reflect.TypeOf(tw))
//add the deployments contens
//Dircompress(tw, "deployments/")
err = Dircompress(tw, sourcedir+"/")
Expand All @@ -147,11 +146,11 @@ func Dirtotar(sourcedir string, tardir string, newimage string) error {
// panic(err)

//}
//fmt.Println(reflect.TypeOf(os.FileInfo(fileinfo)))
//log.Println(reflect.TypeOf(os.FileInfo(fileinfo)))
//dockerfile要单独放在根目录下 和其他archivefile并列
//Filecompress(tw, "", fileinfo)

fmt.Println("tar.gz packaging OK")
log.Println("tar.gz packaging OK")
return nil

}
Expand All @@ -160,14 +159,14 @@ func Dirtotar(sourcedir string, tardir string, newimage string) error {
func SourceTar(filename string) *os.File {
//"tardir/deployments.tar.gz"
fw, _ := os.Open(filename)
//fmt.Println(reflect.TypeOf(fw))
//log.Println(reflect.TypeOf(fw))
return fw

}

func Systemexec(s string) {
cmd := exec.Command("/bin/sh", "-c", s)
fmt.Println(s)
log.Println(s)
out, err := cmd.StdoutPipe()
go func() {
o := bufio.NewReader(out)
Expand All @@ -176,7 +175,7 @@ func Systemexec(s string) {
if err == io.EOF {
break
} else {
fmt.Println(string(line))
log.Println(string(line))
}
}
}()
Expand All @@ -188,7 +187,7 @@ func Systemexec(s string) {

func Createdockerfile(username string, baseimage string, newimage string, warName string) error {
targetDocker := applications + "/" + username + "/" + newimage + "_deploy" + "/" + "Dockerfile"
fmt.Println("tardocker:", targetDocker)
log.Println("tardocker:", targetDocker)
_, err := os.Stat(targetDocker)
if err == nil {
os.Remove(targetDocker)
Expand Down Expand Up @@ -238,7 +237,7 @@ func Wartoimage(dockerdeamon string, imageprefix string, username string, baseim
//todo: add a rest api which could receive the tar file and put the war file into the _deploy dir
//a war->tar->war add scripts(such as dockerfile) -> tar -> image
//Createdir(deploydir)
fmt.Println(tardir)
log.Println(tardir)
Createdir(tardir)
defer os.RemoveAll(tardir)
//delete the temp dir at last
Expand All @@ -259,12 +258,12 @@ func Wartoimage(dockerdeamon string, imageprefix string, username string, baseim
//using go-docker client
endpoint := dockerdeamon
client, _ := docker.NewClient(endpoint)
//fmt.Println(client)
//log.Println(client)
filename := tardir + "/" + newimage + ".tar.gz"
//filename := "tardir/Dockerfile"
tarStream := SourceTar(filename)
defer tarStream.Close()
fmt.Println(tarStream)
log.Println(tarStream)

//dockerhub的认证信息
auth := docker.AuthConfiguration{
Expand Down Expand Up @@ -319,15 +318,15 @@ func Createdir(imagename string) (string, error) {
exist := Exist(imagename)

if exist {
fmt.Println("the folder exist , remove it")
log.Println("the folder exist , remove it")
Cleandir(imagename)
}
dirname := imagename
err := os.MkdirAll(dirname, 0777)
if err != nil {
return "", err
}
fmt.Println("create succesful: " + dirname)
log.Println("create succesful: " + dirname)
return dirname, nil

}
Expand All @@ -337,8 +336,8 @@ func Cleandir(dirname string) {

//打开文件夹
dirhandle, err := os.Open(dirname)
//fmt.Println(dirname)
//fmt.Println(reflect.TypeOf(dir))
//log.Println(dirname)
//log.Println(reflect.TypeOf(dir))
if err != nil {
panic(nil)
}
Expand All @@ -347,7 +346,7 @@ func Cleandir(dirname string) {
//fis, err := ioutil.ReadDir(dir)
fis, err := dirhandle.Readdir(0)
//fis的类型为 []os.FileInfo
//fmt.Println(reflect.TypeOf(fis))
//log.Println(reflect.TypeOf(fis))
if err != nil {
panic(err)
}
Expand All @@ -357,27 +356,27 @@ func Cleandir(dirname string) {
for _, fi := range fis {
if fi.IsDir() {
newname := dirname + "/" + fi.Name()
//fmt.Println("using dir")
//fmt.Println(newname)
//log.Println("using dir")
//log.Println(newname)
//这个样直接continue就将所有文件写入到了一起 没有层级结构了
//Filecompress(tw, dir, fi)
Cleandir(newname)

} else {
//如果是普通文件 直接写入 dir 后面已经有了 /
filename := dirname + "/" + fi.Name()
fmt.Println(filename)
log.Println(filename)
err := os.Remove(filename)
if err != nil {
panic(err)
}
fmt.Println("delete " + filename)
log.Println("delete " + filename)
}

}
//递归结束 删除当前文件夹
err = os.Remove(dirname)
fmt.Println("delete " + dirname)
log.Println("delete " + dirname)
if err != nil {
panic(err)
}
Expand Down
15 changes: 15 additions & 0 deletions ApiServer/applications/cxy/logtest-1.1.1.war_deploy/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# VERSION 0.0.1
# using a tomcat7 image
FROM jre7-tomcat7
# sign name
MAINTAINER zju

#copy the war file into the webapps
ADD /applications/cxy/logtest-1.1.1.war_deploy/logtest.war /usr/local/tomcat/webapps/


# port 22
EXPOSE 22

# Tomcat 8080
EXPOSE 8080
Binary file not shown.
15 changes: 11 additions & 4 deletions ApiServer/conf/app.conf
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,17 @@ EnableDocs = true

[dev]
k8sip = 121.40.171.96
etcdmachines = "https://localhost:2379"
serverCrt = /home/zjw/etcdkey/etcd-v2.0.10-linux-amd64/server.crt
serverKey = /home/zjw/etcdkey/etcd-v2.0.10-linux-amd64/server.key
rootCrt = /home/zjw/etcdkey/etcd-v2.0.10-linux-amd64/ca.crt
//etcdmachines = "https://localhost:2379"
//serverCrt = /home/zjw/etcdkey/etcd-v2.0.10-linux-amd64/server.crt
//serverKey = /home/zjw/etcdkey/etcd-v2.0.10-linux-amd64/server.key
//rootCrt = /home/zjw/etcdkey/etcd-v2.0.10-linux-amd64/ca.crt
//etcdmachines = "https://localhost:2379"
etcdmachines = "https://etcdmaster:2379"
serverCrt = /home/wangzhe/etcdcerts/server.crt
serverKey = /home/wangzhe/etcdcerts/server.key
rootCrt = /home/wangzhe/etcdcerts/ca.crt
DOCKER_BUILD_DEAMON="unix:///var/run/docker.sock"
APIVERSION="v1beta3"
[prod]


Expand Down
Loading

0 comments on commit f271088

Please sign in to comment.