Pārlūkot izejas kodu

cicd: 增加手动构建镜像流程

Yi 1 gadu atpakaļ
vecāks
revīzija
5641426df2
3 mainītis faili ar 68 papildinājumiem un 0 dzēšanām
  1. 6 0
      .drone.yml
  2. 21 0
      Makefile
  3. 41 0
      scripts/http-images.sh

+ 6 - 0
.drone.yml

@@ -3,6 +3,12 @@ type: docker
 name: kpt-tmr
 
 steps:
+  - name: clone
+    image: alpine/git
+    commands:
+     - git clone -b develop http://192.168.1.8:3000/baishaojie/tmrgo.git
+     - ls -l
+     - pwd
   - name: build
     image: plugins/docker:20.14.2
     volumes:

+ 21 - 0
Makefile

@@ -0,0 +1,21 @@
+GO_FILES=`go list ./... | grep -v -E "mock|store|test|fake|cmd|bin|backend|google|logger|proto"`
+
+proto-build:
+	protoc -I=. --go_out=:./proto/go/ --go_opt=paths=source_relative \
+    --go-grpc_out=:./proto/go/ --go-grpc_opt=paths=source_relative ./backend/common/*.proto
+
+	protoc -I=. --go_out=:./proto/go/ --go_opt=paths=source_relative \
+    --go-grpc_out=:./proto/go/ --go-grpc_opt=paths=source_relative ./backend/operation/*.proto
+
+ci-test:
+	go test $(GO_FILES) -coverprofile .cover.txt
+	go tool cover -func .cover.txt
+	rm .cover.txt
+
+lint:
+	golangci-lint run ./...
+
+build:
+	rm -rf bin
+	mkdir -p bin
+	GOARCH=amd64 GOOS=linux CGO_ENABLED=0 go build -o bin/kptTmr -ldflags "-X kpt.kptyun.cn:3000/kpt-event/kpt-tmr/pod.appVersion=${version}" main.go

+ 41 - 0
scripts/http-images.sh

@@ -0,0 +1,41 @@
+#!/bin/bash
+set -e
+
+tag=$1
+if [ -n "$tag" ]
+then
+  echo "当前镜像tag: $tag"
+else
+  echo "请输入当前镜像tag"
+  exit
+fi
+
+### go testing
+# echo "============ go test start ================"
+# make ci-test
+# echo "============  go test end  ================"
+
+### go build
+echo "============ go build start ================"
+make build version=${tag}
+echo "============  go build end  ================"
+
+echo "============push images start================"
+
+export aliYunDockerDNS=registry.cn-hangzhou.aliyuncs.com
+export aliYunDockerUsername=kptzhu@163.com
+export aliYunDockerPassword=zhuz1898
+export images=kpt-event/kpt-tmr
+
+docker build -t ${images}:${tag} -f ./Dockerfile .
+docker login ${aliYunDockerDNS} --username ${aliYunDockerUsername} --password ${aliYunDockerPassword}
+
+docker tag ${images}:${tag}  ${aliYunDockerDNS}/${images}:${tag}
+docker tag ${images}:${tag}  ${aliYunDockerDNS}/${images}:latest
+
+docker push ${aliYunDockerDNS}/${images}:${tag}
+docker push ${aliYunDockerDNS}/${images}:latest
+
+docker rmi ${images}:${tag} ${aliYunDockerDNS}/${images}:${tag} ${aliYunDockerDNS}/${images}:latest
+
+echo "============push images end ================"