Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/add buildscript #19

Merged
merged 6 commits into from
Aug 29, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,17 @@ services:
- docker
go:
- 1.8.x
before_install:
before_install:
- curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
- sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
- sudo apt-get update
- sudo apt-get -y install docker-ce

install:
- make release
script:
- echo "test skip"
before_deploy:
- make install

deploy:
provider: releases
api_key:
Expand Down
31 changes: 29 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,35 @@
FROM alpine:edge AS build
RUN apk update
RUN apk upgrade
RUN apk add go gcc g++ make git linux-headers
WORKDIR /app
ENV GOPATH /app
ADD . /app/src/github.com/yunify/hostnic-cni
RUN cd /app/src/github.com/yunify/hostnic-cni && rm -rf bin/ && make go-build

FROM alpine:latest
MAINTAINER martinyunify <[email protected]>

ADD daemon /
COPY --from=build /app/src/github.com/yunify/hostnic-cni/bin/daemon /bin/daemon

EXPOSE 31080 31081

ENV LOGLEVEL info

ENV VXNETS vxnet-xxxxxxx

ENV POOLSIZE 3

ENV CLEANUPCACHEONEXIT false

RUN mkdir -p /opt/cni/bin/ && mkdir -p /etc/cni/net.d/

VOLUME /etc/qingcloud/

VOLUME /etc/cni/net.d/

COPY --from=build /app/src/github.com/yunify/hostnic-cni/bin/hostnic /opt/cni/bin/hostnic

ENTRYPOINT ["/bin/daemon"]

ENTRYPOINT ["/daemon"]
CMD ["start"]
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,14 @@ bin/hostnic.tar.gz : bin/hostnic
bin/daemon : $(foreach dir,$(daemon_pkg),$(wildcard $(dir)/*.go))
go build -o bin/daemon $(GO_BUILD_FLAGS) $(GIT_REPOSITORY)/cmd/daemon/

bin/.docker-images-build-timestamp : bin/daemon
cp -u Dockerfile bin
docker build -q -t $(DOCKER_IMAGE_NAME):$(BUILD_LABEL) bin/ > bin/.docker-images-build-timestamp
bin/.docker-images-build-timestamp : $(foreach dir,$(daemon_pkg),$(wildcard $(dir)/*.go)) Dockerfile
docker build -q -t $(DOCKER_IMAGE_NAME):$(BUILD_LABEL) -t $(DOCKER_IMAGE_NAME):latest . > bin/.docker-images-build-timestamp

release : test bin/hostnic.tar.gz bin/.docker-images-build-timestamp

install : release
docker push $(DOCKER_IMAGE_NAME):$(BUILD_LABEL)
docker push $(DOCKER_IMAGE_NAME):latest

clean :
docker rmi `cat bin/.docker-images-build-timestamp`
Expand Down
2 changes: 1 addition & 1 deletion generate_version.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/bin/sh
# Define the project string to be used
PROJECT=hostnic-cni

Expand Down
119 changes: 119 additions & 0 deletions kube-hostnic.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1beta1
metadata:
name: hostnic
rules:
- apiGroups:
- ""
resources:
- pods
verbs:
- get
- apiGroups:
- ""
resources:
- nodes
verbs:
- list
- watch
- apiGroups:
- ""
resources:
- nodes/status
verbs:
- patch
---
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1beta1
metadata:
name: hostnic
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: hostnic
subjects:
- kind: ServiceAccount
name: hostnic
namespace: kube-system
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: hostnic
namespace: kube-system
---
kind: ConfigMap
apiVersion: v1
metadata:
name: kube-hostnic-cni-cfg
namespace: kube-system
labels:
tier: node
app: hostnic
data:
10-hostnic.conf: |
{
"cniVersion": "0.3.1",
"name": "hostnic",
"type": "hostnic",
"bindaddr":"localhost:31080",
"ipam":{
"routes":[{"dst":"10.96.0.0/24","gw":"0.0.0.0"}]
},
"isGateway": true
}
---
apiVersion: extensions/v1beta1
kind: DaemonSet
metadata:
name: kube-qingcloud-hostnic
namespace: kube-system
labels:
tier: node
app: kube-qingcloud-hostnic
spec:
template:
metadata:
labels:
tier: node
app: kube-qingcloud-hostnic
spec:
hostNetwork: true
nodeSelector:
beta.kubernetes.io/arch: amd64
tolerations:
- key: node-role.kubernetes.io/master
operator: Exists
effect: NoSchedule
serviceAccountName: hostnic
containers:
- name: kube-qingcloud-hostnic
image: dockerhub.qingcloud.com/qingcloud/hostnic-cni:hostnic-cni-v0.8-1-g89dae0f
command: [ "start" ]
securityContext:
privileged: true
env:
- name: LOGLEVEL
value: "info"

- name: VXNETS
value: "vxnet-2xj9lrp,vxnet-h00g66q"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个实际部署的时候怎么去变更呢?或者也从 configmap 读取?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#21 如果有多个容器共用一些配置用configmap会更方便。这里只是一个示例。用户可以按需求定制。我觉得在k8s app里可以改成用configmap的。


- name: POOLSIZE
value: "3"

volumeMounts:
- name: hostnic-cfg
mountPath: /etc/cni/

- name: qingcloud-cfg
mountPath: /etc/qingcloud/

volumes:
- name: hostnic-cfg
configMap:
name: kube-hostnic-cni-cfg

- name: qingcloud-cfg
hostPath:
path: /etc/qingcloud/