From 69a6d97d3e24e9dabd44553f2ba1bd49183db806 Mon Sep 17 00:00:00 2001 From: Xin Wang Date: Sun, 21 Jul 2019 07:26:25 +0800 Subject: [PATCH] add build stage --- .travis.yml | 10 ++++++++-- Makefile | 15 +++++---------- deploy/disk/docker/Dockerfile | 8 +++++--- 3 files changed, 18 insertions(+), 15 deletions(-) diff --git a/.travis.yml b/.travis.yml index b99cfbda..e429bb29 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,8 +1,14 @@ language: go -go: +go: - "1.12" +services: + - docker +before_install: + - docker pull golang:1.12.7-alpine + - docker pull k8s.gcr.io/debian-base:v1.0.0 + install: - go get -u github.com/golang/dep/cmd/dep - dep ensure -vendor-only script: - - make + - make disk-container diff --git a/Makefile b/Makefile index 33955f5d..7985e32b 100644 --- a/Makefile +++ b/Makefile @@ -17,18 +17,15 @@ .PHONY: all disk DISK_IMAGE_NAME=dockerhub.qingcloud.com/csiplugin/csi-qingcloud -DISK_IMAGE_VERSION=canary -DISK_PLUGIN_NAME=qingcloud-disk-csi-driver +DISK_IMAGE_TAG=canary ROOT_PATH=$(pwd) PACKAGE_LIST=./cmd/... ./pkg/... disk: - if [ ! -d ./vendor ]; then dep ensure; fi - CGO_ENABLED=0 GOOS=linux go build -a -ldflags '-extldflags "-static"' -o _output/${DISK_PLUGIN_NAME} ./cmd/disk + docker build -t ${DISK_IMAGE_NAME}-builder:${DISK_IMAGE_TAG} -f deploy/disk/docker/Dockerfile . --target builder -disk-container: disk - cp _output/${DISK_PLUGIN_NAME} deploy/disk/docker - docker build -t $(DISK_IMAGE_NAME):$(DISK_IMAGE_VERSION) deploy/disk/docker +disk-container: + docker build -t ${DISK_IMAGE_NAME}:${DISK_IMAGE_TAG} -f deploy/disk/docker/Dockerfile . install-dev: cp /root/.qingcloud/config.yaml deploy/disk/kubernetes/base/config.yaml @@ -60,6 +57,4 @@ sanity-test: ${ROOT_PATH}/csi-sanity --csi.endpoint /var/lib/kubelet/plugins/disk.csi.qingcloud.com/csi.sock --csi.testvolumesize 107374182400 clean: - go clean -r -x - rm -rf ./_output - rm -rf deploy/disk/docker/${DISK_PLUGIN_NAME} + go clean -r -x \ No newline at end of file diff --git a/deploy/disk/docker/Dockerfile b/deploy/disk/docker/Dockerfile index 39aa23e1..b3e0d725 100644 --- a/deploy/disk/docker/Dockerfile +++ b/deploy/disk/docker/Dockerfile @@ -14,14 +14,16 @@ # | limitations under the License. # +------------------------------------------------------------------------- +FROM golang:1.12.7-alpine as builder +WORKDIR /go/src/github.com/yunify/qingcloud-csi +COPY . . +RUN CGO_ENABLED=0 GOOS=linux go build -a -ldflags '-extldflags "-static"' -o _output/qingcloud-disk-csi-driver ./cmd/disk FROM k8s.gcr.io/debian-base:v1.0.0 LABEL maintainers="Yunify" LABEL description="QingCloud CSI plugin" - RUN clean-install util-linux e2fsprogs xfsprogs mount ca-certificates udev -COPY qingcloud-disk-csi-driver /qingcloud-disk-csi-driver +COPY --from=builder /go/src/github.com/yunify/qingcloud-csi/_output/qingcloud-disk-csi-driver /qingcloud-disk-csi-driver RUN chmod +x /qingcloud-disk-csi-driver && \ mkdir -p /var/log/qingcloud-disk-csi-driver - ENTRYPOINT ["/qingcloud-disk-csi-driver"]