From d24806b7d4d33cb324b4ab41a14d0a58f18ff230 Mon Sep 17 00:00:00 2001 From: Anatoly Cherkasov Date: Sat, 10 Sep 2016 01:24:38 +0300 Subject: [PATCH] BJ-49: add build_utils (#56) --- .gitmodules | 4 ++++ Jenkinsfile | 40 +++++++++++++++++++++------------------- Makefile | 40 ++++++++++++++++++++++++---------------- build_utils | 1 + utils.mk | 46 ---------------------------------------------- 5 files changed, 50 insertions(+), 81 deletions(-) create mode 100644 .gitmodules create mode 160000 build_utils delete mode 100644 utils.mk diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..ca5a761 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,4 @@ +[submodule "build_utils"] + path = build_utils + url = git@github.com:rbkmoney/build_utils.git + branch = master diff --git a/Jenkinsfile b/Jenkinsfile index e622b42..e573114 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,28 +1,30 @@ #!groovy -// Args: -// GitHub repo name -// Jenkins agent label -// Tracing artifacts to be stored alongside build logs -pipeline("damsel", 'docker-host', "_build/") { +build('damsel', 'docker-host') { + checkoutRepo() + loadBuildUtils() - runStage('compile') { - sh "make w_container_compile" - } + def pipeDefault + runStage('load pipeline') { + env.JENKINS_LIB = "build_utils/jenkins_lib" + pipeDefault = load("${env.JENKINS_LIB}/pipeDefault.groovy") + } - // Build failed without this file: _build/test/logs/index.html (Hi, jenkins_pipeline_lib) - runStage('folder_create') { - sh "make w_container_create" - } + pipeDefault() { - if (env.BRANCH_NAME == 'master') { - runStage('deploy_nexus') { - sh "make w_container_deploy_nexus" + runStage('compile') { + sh "make wc_compile" } - } else { - runStage('java_compile') { - sh "make w_container_java_compile" + + runStage('Execute build container') { + withCredentials([[$class: 'FileBinding', credentialsId: 'java-maven-settings.xml', variable: 'SETTINGS_XML']]) { + if (env.BRANCH_NAME == 'master') { + sh 'make wc_deploy_nexus SETTINGS_XML=$SETTINGS_XML' + } else { + sh 'make wc_java_compile SETTINGS_XML=$SETTINGS_XML' + } + } } - } + } } diff --git a/Makefile b/Makefile index 233794f..4b618fa 100644 --- a/Makefile +++ b/Makefile @@ -4,23 +4,28 @@ THRIFT_OPTIONS_erlang = scoped_typenames THRIFT_OPTIONS_java = fullcamel THRIFT_OPTIONS_html = standalone -REGISTRY := dr.rbkmoney.com -ORG_NAME := rbkmoney -BASE_IMAGE := "$(REGISTRY)/$(ORG_NAME)/build:530114ab63a7ff0379a2220169a0be61d3f7c64c" +UTILS_PATH := build_utils +TEMPLATES_PATH := . -RELNAME := damsel + +# Name of the service +SERVICE_NAME := damsel +# Service image default tag +SERVICE_IMAGE_TAG ?= $(shell git rev-parse HEAD) +# The tag for service image to be pushed with +SERVICE_IMAGE_PUSH_TAG ?= $(SERVICE_IMAGE_TAG) + + +BUILD_IMAGE_TAG := 753126790c9ecd763840d9fe58507335af02b875 FILES = $(wildcard proto/*.thrift) DESTDIR = _gen -CALL_ANYWHERE := clean all create java_compile compile doc deploy_nexus -CALL_W_CONTAINER := $(CALL_ANYWHERE) - -BASE_IMAGE ?= rbkmoney/build +CALL_W_CONTAINER := clean all create java_compile compile doc deploy_nexus all: compile -include utils.mk +-include $(UTILS_PATH)/make_lib/utils_container.mk define generate $(THRIFT_EXEC) -r -strict --gen $(1):$(THRIFT_OPTIONS_$(1)) -out $(2) $(3) @@ -32,13 +37,10 @@ endef CUTLINE = $(shell printf '=%.0s' $$(seq 1 80)) -.PHONY: $(CALL_W_CONTAINER) create $(UTIL_TARGETS) +.PHONY: $(CALL_W_CONTAINER) create LANGUAGE_TARGETS = $(foreach lang, $(THRIFT_LANGUAGES), verify-$(lang)) -# Build failed without this file: _build/test/logs/index.html (Hi, jenkins_pipeline_lib) -create: - mkdir -p _build/test/logs && touch _build/test/logs/index.html compile: $(LANGUAGE_TARGETS) @echo "Ok" @@ -86,13 +88,19 @@ $(TARGETS):: $(DESTDIR)/$(LANGUAGE)/%: % endif endif +ifdef SETTINGS_XML +DOCKER_RUN_OPTS = -v $(SETTINGS_XML):$(SETTINGS_XML) +DOCKER_RUN_OPTS += -e SETTINGS_XML=$(SETTINGS_XML) +endif COMMIT_HASH = $(shell git --no-pager log -1 --pretty=format:"%h") NUMBER_COMMITS = $(shell git rev-list --count HEAD) java_compile: - mvn compile + $(if $(SETTINGS_XML),,echo "SETTINGS_XML not defined" ; exit 1) + mvn compile -s $(SETTINGS_XML) deploy_nexus: - mvn versions:set versions:commit -DnewVersion="1.$(NUMBER_COMMITS)-$(COMMIT_HASH)" \ - && mvn deploy -Dpath_to_thrift="$(THRIFT_EXEC)" + $(if $(SETTINGS_XML),, echo "SETTINGS_XML not defined"; exit 1) + mvn versions:set versions:commit -DnewVersion="1.$(NUMBER_COMMITS)-$(COMMIT_HASH)" -s $(SETTINGS_XML) \ + && mvn deploy -s $(SETTINGS_XML) -Dpath_to_thrift="$(THRIFT_EXEC)" diff --git a/build_utils b/build_utils new file mode 160000 index 0000000..2b1c328 --- /dev/null +++ b/build_utils @@ -0,0 +1 @@ +Subproject commit 2b1c328ce9a42d9072850f03685005a4153efc28 diff --git a/utils.mk b/utils.mk deleted file mode 100644 index 8c296b1..0000000 --- a/utils.mk +++ /dev/null @@ -1,46 +0,0 @@ -SHELL := /bin/bash - -which = $(if $(shell which $(1) 2>/dev/null),\ - $(shell which $(1) 2>/dev/null),\ - $(error "Error: could not locate $(1)!")) - -DOCKER = $(call which,docker) -DOCKER_COMPOSE = $(call which,docker-compose) - -UTIL_TARGETS := to_dev_container w_container_% w_compose_% run_w_container_% check_w_container_% - -ifndef RELNAME -$(error RELNAME is not set) -endif - -ifndef CALL_W_CONTAINER -$(error CALL_W_CONTAINER is not set) -endif - -to_dev_container: - $(DOCKER) run -it --rm -v $$PWD:$$PWD --workdir $$PWD $(BASE_IMAGE) /bin/bash - -w_container_%: - $(MAKE) -s run_w_container_$* - -w_compose_%: - $(MAKE) -s run_w_compose_$* - -run_w_container_%: check_w_container_% - { \ - $(DOCKER) run --rm -v $$PWD:$$PWD --workdir $$PWD $(BASE_IMAGE) make $* ; \ - res=$$? ; exit $$res ; \ - } - -run_w_compose_%: check_w_container_% - { \ - $(DOCKER_COMPOSE) up -d ; \ - $(DOCKER_COMPOSE) exec -T $(RELNAME) make $* ; \ - res=$$? ; \ - $(DOCKER_COMPOSE) down ; \ - exit $$res ; \ - } - -check_w_container_%: - $(if $(filter $*,$(CALL_W_CONTAINER)),,\ - $(error "Error: target '$*' cannot be called w_container_")) \ No newline at end of file