Makefile 13.9 KB
Newer Older
1
NAME ?= gitlab-runner
2
PACKAGE_NAME ?= $(NAME)
3
export VERSION := $(shell ./ci/version)
4
REVISION := $(shell git rev-parse --short=8 HEAD || echo unknown)
5
BRANCH := $(shell git show-ref | grep "$(REVISION)" | grep -v HEAD | awk '{print $$2}' | sed 's|refs/remotes/origin/||' | sed 's|refs/heads/||' | sort | head -n 1)
6
BUILT := $(shell date -u +%Y-%m-%dT%H:%M:%S%z)
7
export TESTFLAGS ?= -cover
8 9 10 11 12 13 14

LATEST_STABLE_TAG := $(shell git -c versionsort.prereleaseSuffix="-rc" -c versionsort.prereleaseSuffix="-RC" tag -l "v*.*.*" --sort=-v:refname | awk '!/rc/' | head -n 1)
export IS_LATEST :=
ifeq ($(shell git describe --exact-match --match $(LATEST_STABLE_TAG) >/dev/null 2>&1; echo $$?), 0)
export IS_LATEST := true
endif

15
PACKAGE_CLOUD ?= ayufan/gitlab-ci-multi-runner
16
PACKAGE_CLOUD_URL ?= https://packagecloud.io/
17
BUILD_PLATFORMS ?= -os '!netbsd' -os '!openbsd'
Kamil Trzciński's avatar
Kamil Trzciński committed
18
S3_UPLOAD_PATH ?= master
19

20
# Keep in sync with docs/install/linux-repository.md
21
DEB_PLATFORMS ?= debian/wheezy debian/jessie debian/stretch debian/buster \
22
    ubuntu/trusty ubuntu/xenial ubuntu/artful ubuntu/bionic \
23
    raspbian/wheezy raspbian/jessie raspbian/stretch raspbian/buster \
24
    linuxmint/qiana linuxmint/rebecca linuxmint/rafaela linuxmint/rosa linuxmint/sarah linuxmint/serena linuxmint/sonya
25
DEB_ARCHS ?= amd64 i386 armel armhf
26 27
RPM_PLATFORMS ?= el/6 el/7 \
    ol/6 ol/7 \
28
    fedora/26 fedora/27 fedora/28 fedora/29
Kamil Trzciński's avatar
Kamil Trzciński committed
29
RPM_ARCHS ?= x86_64 i686 arm armhf
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44

PKG = gitlab.com/gitlab-org/$(PACKAGE_NAME)
COMMON_PACKAGE_NAMESPACE=$(PKG)/common

BUILD_DIR := $(CURDIR)
TARGET_DIR := $(BUILD_DIR)/out

ORIGINAL_GOPATH = $(shell echo $$GOPATH)
LOCAL_GOPATH := $(CURDIR)/.gopath
GOPATH_SETUP := $(LOCAL_GOPATH)/.ok
GOPATH_BIN := $(LOCAL_GOPATH)/bin
PKG_BUILD_DIR := $(LOCAL_GOPATH)/src/$(PKG)

export GOPATH = $(LOCAL_GOPATH)
export PATH := $(GOPATH_BIN):$(PATH)
45 46 47

# Packages in vendor/ are included in ./...
# https://github.com/golang/go/issues/11659
48
export OUR_PACKAGES ?= $(subst _$(BUILD_DIR),$(PKG),$(shell go list ./... | grep -v '/vendor/'))
49

50 51
GO_LDFLAGS ?= -X $(COMMON_PACKAGE_NAMESPACE).NAME=$(PACKAGE_NAME) -X $(COMMON_PACKAGE_NAMESPACE).VERSION=$(VERSION) \
              -X $(COMMON_PACKAGE_NAMESPACE).REVISION=$(REVISION) -X $(COMMON_PACKAGE_NAMESPACE).BUILT=$(BUILT) \
52 53
              -X $(COMMON_PACKAGE_NAMESPACE).BRANCH=$(BRANCH) \
              -s -w
54
GO_FILES ?= $(shell find . -name '*.go' | grep -v './.gopath/')
55
export CGO_ENABLED ?= 0
56

57 58

# Development Tools
59
DEP = $(GOPATH_BIN)/dep
60 61
GOX = $(GOPATH_BIN)/gox
MOCKERY = $(GOPATH_BIN)/mockery
62
DEVELOPMENT_TOOLS = $(DEP) $(GOX) $(MOCKERY)
63

64 65
MOCKERY_FLAGS = -note="This comment works around https://github.com/vektra/mockery/issues/155"

66 67
.PHONY: clean version mocks

68
all: deps docker build
Alessio Caiazza's avatar
Alessio Caiazza committed
69

70
include Makefile.docker.mk
Kamil Trzciński's avatar
Kamil Trzciński committed
71

Kamil Trzciński's avatar
Kamil Trzciński committed
72
help:
73
	# Commands:
74
	# make all => deps build
75
	# make version - show information about current version
76 77
	#
	# Development commands:
78
	# make build_simple - build executable for your arch and OS
79
	# make install - install the version suitable for your OS as gitlab-runner
80
	# make docker - build docker dependencies
81 82
	#
	# Testing commands:
Kamil Trzciński's avatar
Kamil Trzciński committed
83
	# make test - run project tests
84
	# make codequality - run code quality analysis
85 86 87
	#
	# Deployment commands:
	# make deps - install all dependencies
Kamil Trzciński's avatar
Kamil Trzciński committed
88 89 90 91 92
	# make build - build project for all supported OSes
	# make package - package project using FPM
	# make packagecloud - send all packages to packagecloud
	# make packagecloud-yank - remove specific version from packagecloud

93
version:
94 95
	@echo Current version: $(VERSION)
	@echo Current revision: $(REVISION)
96 97
	@echo Current branch: $(BRANCH)
	@echo Build platforms: $(BUILD_PLATFORMS)
98 99
	@echo DEB platforms: $(DEB_PLATFORMS)
	@echo RPM platforms: $(RPM_PLATFORMS)
100
	@echo IS_LATEST: $(IS_LATEST)
101

102
deps: $(DEVELOPMENT_TOOLS)
Kamil Trzciński's avatar
Kamil Trzciński committed
103

104
codequality:
105
	./scripts/codequality analyze --dev
106

Alessio Caiazza's avatar
Alessio Caiazza committed
107
build: $(GOX)
108
	# Building $(NAME) in version $(VERSION) for $(BUILD_PLATFORMS)
109
	gox $(BUILD_PLATFORMS) \
110
		-ldflags "$(GO_LDFLAGS)" \
111 112
		-output="out/binaries/$(NAME)-{{.OS}}-{{.Arch}}" \
		$(PKG)
Kamil Trzciński's avatar
Kamil Trzciński committed
113

114
build_simple: $(GOPATH_SETUP)
115 116 117
	# Building $(NAME) in version $(VERSION) for current platform
	go build \
		-ldflags "$(GO_LDFLAGS)" \
118 119
		-o "out/binaries/$(NAME)" \
		$(PKG)
120

121
build_current: docker build_simple
122

Alessio Caiazza's avatar
Alessio Caiazza committed
123
check_race_conditions:
124 125
	@./scripts/check_race_conditions $(OUR_PACKAGES)

126 127
test: $(PKG_BUILD_DIR) docker
	# Running tests...
128 129 130 131 132 133
	go test $(OUR_PACKAGES) $(TESTFLAGS)

parallel_test_prepare: $(GOPATH_SETUP)
	# Preparing test commands
	@./scripts/go_test_with_coverage_report prepare

134
parallel_test_execute: $(GOPATH_SETUP) pull_images_for_tests
135 136 137 138 139 140
	# executing tests
	@./scripts/go_test_with_coverage_report execute

parallel_test_coverage_report: $(GOPATH_SETUP)
	# Preparing coverage report
	@./scripts/go_test_with_coverage_report coverage
Kamil Trzciński's avatar
Kamil Trzciński committed
141

142 143 144 145
parallel_test_junit_report: $(GOPATH_SETUP)
	# Preparing jUnit test report
	@./scripts/go_test_with_coverage_report junit

146 147 148 149
pull_images_for_tests: $(GOPATH_SETUP)
	# Pulling images required for some tests
	@go run ./scripts/pull-images-for-tests/main.go

Alessio Caiazza's avatar
Alessio Caiazza committed
150
install:
151
	go install --ldflags="$(GO_LDFLAGS)" $(PKG)
152

153 154 155
dockerfiles:
	make -C dockerfiles all

156 157
# We rely on user GOPATH 'cause mockery seems not to be able to find dependencies in vendor directory
mocks: $(MOCKERY)
158
	rm -rf ./helpers/service/mocks
159
	find . -type f ! -path '*vendor/*' -name 'mock_*' -delete
160
	GOPATH=$(ORIGINAL_GOPATH) mockery $(MOCKERY_FLAGS) -dir=./vendor/github.com/ayufan/golang-kardianos-service -output=./helpers/service/mocks -name='(Interface)'
161
	GOPATH=$(ORIGINAL_GOPATH) mockery $(MOCKERY_FLAGS) -dir=./helpers/docker -all -inpkg
162
	GOPATH=$(ORIGINAL_GOPATH) mockery $(MOCKERY_FLAGS) -dir=./helpers/certificate -all -inpkg
163
	GOPATH=$(ORIGINAL_GOPATH) mockery $(MOCKERY_FLAGS) -dir=./cache -all -inpkg
164
	GOPATH=$(ORIGINAL_GOPATH) mockery $(MOCKERY_FLAGS) -dir=./common -all -inpkg
165
	GOPATH=$(ORIGINAL_GOPATH) mockery $(MOCKERY_FLAGS) -dir=./log -all -inpkg
166
	GOPATH=$(ORIGINAL_GOPATH) mockery $(MOCKERY_FLAGS) -dir=./session -all -inpkg
167
	GOPATH=$(ORIGINAL_GOPATH) mockery $(MOCKERY_FLAGS) -dir=./shells -all -inpkg
168

169
test-docker:
170 171 172 173 174 175 176
	make test-docker-image IMAGE=centos:6 TYPE=rpm
	make test-docker-image IMAGE=centos:7 TYPE=rpm
	make test-docker-image IMAGE=debian:wheezy TYPE=deb
	make test-docker-image IMAGE=debian:jessie TYPE=deb
	make test-docker-image IMAGE=ubuntu-upstart:precise TYPE=deb
	make test-docker-image IMAGE=ubuntu-upstart:trusty TYPE=deb
	make test-docker-image IMAGE=ubuntu-upstart:utopic TYPE=deb
177 178

test-docker-image:
179 180
	tests/test_installation.sh $(IMAGE) out/$(TYPE)/$(PACKAGE_NAME)_amd64.$(TYPE)
	tests/test_installation.sh $(IMAGE) out/$(TYPE)/$(PACKAGE_NAME)_amd64.$(TYPE) Y
181

182 183 184 185 186 187
build-and-deploy:
	make build BUILD_PLATFORMS="-os=linux -arch=amd64"
	make package-deb-fpm ARCH=amd64 PACKAGE_ARCH=amd64
	scp out/deb/$(PACKAGE_NAME)_amd64.deb $(SERVER):
	ssh $(SERVER) dpkg -i $(PACKAGE_NAME)_amd64.deb

188 189 190 191
build-and-deploy-binary:
	make build BUILD_PLATFORMS="-os=linux -arch=amd64"
	scp out/binaries/$(PACKAGE_NAME)-linux-amd64 $(SERVER):/usr/bin/gitlab-runner

192 193 194 195
package: package-deps package-prepare package-deb package-rpm

package-deps:
	# Installing packaging dependencies...
Alessio Caiazza's avatar
Alessio Caiazza committed
196
	which fpm 1>/dev/null || gem install rake fpm --no-ri --no-rdoc
197 198

package-prepare:
199
	chmod 755 packaging/root/usr/share/gitlab-runner/
200
	chmod 755 packaging/root/usr/share/gitlab-runner/*
201

202
package-deb: package-deps package-prepare
Kamil Trzciński's avatar
Kamil Trzciński committed
203
	# Building Debian compatible packages...
Kamil Trzciński's avatar
Kamil Trzciński committed
204
	make package-deb-fpm ARCH=amd64 PACKAGE_ARCH=amd64
205
	make package-deb-fpm ARCH=386 PACKAGE_ARCH=i386
206
	make package-deb-fpm ARCH=arm PACKAGE_ARCH=armel
Kamil Trzciński's avatar
Kamil Trzciński committed
207
	make package-deb-fpm ARCH=arm PACKAGE_ARCH=armhf
208

209
package-rpm: package-deps package-prepare
Kamil Trzciński's avatar
Kamil Trzciński committed
210
	# Building RedHat compatible packages...
Kamil Trzciński's avatar
Kamil Trzciński committed
211
	make package-rpm-fpm ARCH=amd64 PACKAGE_ARCH=amd64
Kamil Trzciński's avatar
Kamil Trzciński committed
212
	make package-rpm-fpm ARCH=386 PACKAGE_ARCH=i686
Kamil Trzciński's avatar
Kamil Trzciński committed
213 214
	make package-rpm-fpm ARCH=arm PACKAGE_ARCH=arm
	make package-rpm-fpm ARCH=arm PACKAGE_ARCH=armhf
Kamil Trzciński's avatar
Kamil Trzciński committed
215 216

package-deb-fpm:
217
	@mkdir -p out/deb/
Kamil Trzciński's avatar
Kamil Trzciński committed
218
	fpm -s dir -t deb -n $(PACKAGE_NAME) -v $(VERSION) \
Kamil Trzciński's avatar
Kamil Trzciński committed
219
		-p out/deb/$(PACKAGE_NAME)_$(PACKAGE_ARCH).deb \
220 221 222
		--deb-priority optional --category admin \
		--force \
		--deb-compression bzip2 \
223 224
		--after-install packaging/scripts/postinst.deb \
		--before-remove packaging/scripts/prerm.deb \
225
		--url https://gitlab.com/gitlab-org/gitlab-runner \
226
		--description "GitLab Runner" \
227
		-m "GitLab Inc. <support@gitlab.com>" \
228
		--license "MIT" \
229
		--vendor "GitLab Inc." \
230 231 232 233 234
		--conflicts $(PACKAGE_NAME)-beta \
		--conflicts gitlab-ci-multi-runner \
		--conflicts gitlab-ci-multi-runner-beta \
		--provides gitlab-ci-multi-runner \
		--replaces gitlab-ci-multi-runner \
235 236
		--depends ca-certificates \
		--depends git \
237 238
		--depends curl \
		--depends tar \
239
		--deb-suggests docker-engine \
Kamil Trzciński's avatar
Kamil Trzciński committed
240
		-a $(PACKAGE_ARCH) \
Kamil Trzciński's avatar
Kamil Trzciński committed
241
		packaging/root/=/ \
Alessio Caiazza's avatar
Alessio Caiazza committed
242 243
		out/binaries/$(NAME)-linux-$(ARCH)=/usr/lib/gitlab-runner/gitlab-runner \
		out/helper-images/=/usr/lib/gitlab-runner/helper-images/
244
	@if [ -n "$(GPG_KEYID)" ]; then \
245 246 247
		dpkg-sig -g "--no-tty --digest-algo 'sha512' --passphrase '$(GPG_PASSPHRASE)'" \
			-k $(GPG_KEYID) --sign builder "out/deb/$(PACKAGE_NAME)_$(PACKAGE_ARCH).deb" ;\
	fi
248

Kamil Trzciński's avatar
Kamil Trzciński committed
249
package-rpm-fpm:
250
	@mkdir -p out/rpm/
Kamil Trzciński's avatar
Kamil Trzciński committed
251
	fpm -s dir -t rpm -n $(PACKAGE_NAME) -v $(VERSION) \
Kamil Trzciński's avatar
Kamil Trzciński committed
252
		-p out/rpm/$(PACKAGE_NAME)_$(PACKAGE_ARCH).rpm \
253 254
		--rpm-compression bzip2 --rpm-os linux \
		--force \
255 256
		--after-install packaging/scripts/postinst.rpm \
		--before-remove packaging/scripts/prerm.rpm \
257
		--url https://gitlab.com/gitlab-org/gitlab-runner \
258
		--description "GitLab Runner" \
259
		-m "GitLab Inc. <support@gitlab.com>" \
260
		--license "MIT" \
261
		--vendor "GitLab Inc." \
262 263 264 265 266
		--conflicts $(PACKAGE_NAME)-beta \
		--conflicts gitlab-ci-multi-runner \
		--conflicts gitlab-ci-multi-runner-beta \
		--provides gitlab-ci-multi-runner \
		--replaces gitlab-ci-multi-runner \
267 268 269
		--depends git \
		--depends curl \
		--depends tar \
Kamil Trzciński's avatar
Kamil Trzciński committed
270
		-a $(PACKAGE_ARCH) \
Kamil Trzciński's avatar
Kamil Trzciński committed
271
		packaging/root/=/ \
Alessio Caiazza's avatar
Alessio Caiazza committed
272 273
		out/binaries/$(NAME)-linux-$(ARCH)=/usr/lib/gitlab-runner/gitlab-runner \
		out/helper-images/=/usr/lib/gitlab-runner/helper-images/
274
	@if [ -n "$(GPG_KEYID)" ] ; then \
275 276 277 278 279 280 281
		echo "yes" | setsid rpm \
			--define "_gpg_name $(GPG_KEYID)" \
			--define "_signature gpg" \
			--define "__gpg_check_password_cmd /bin/true" \
			--define "__gpg_sign_cmd %{__gpg} gpg --batch --no-armor --digest-algo 'sha512' --passphrase '$(GPG_PASSPHRASE)' --no-secmem-warning -u '%{_gpg_name}' --sign --detach-sign --output %{__signature_filename} %{__plaintext_filename}" \
			--addsign out/rpm/$(PACKAGE_NAME)_$(PACKAGE_ARCH).rpm ;\
	fi
282

Kamil Trzciński's avatar
Kamil Trzciński committed
283 284 285 286
packagecloud: packagecloud-deps packagecloud-deb packagecloud-rpm

packagecloud-deps:
	# Installing packagecloud dependencies...
287
	gem install package_cloud --version "~> 0.3.0" --no-ri --no-rdoc
Kamil Trzciński's avatar
Kamil Trzciński committed
288

289
packagecloud-deb:
Kamil Trzciński's avatar
Kamil Trzciński committed
290
	# Sending Debian compatible packages...
291 292 293
	-for DIST in $(DEB_PLATFORMS); do \
		package_cloud push --url $(PACKAGE_CLOUD_URL) $(PACKAGE_CLOUD)/$$DIST out/deb/*.deb; \
	done
294 295

packagecloud-rpm:
Kamil Trzciński's avatar
Kamil Trzciński committed
296
	# Sending RedHat compatible packages...
297 298 299
	-for DIST in $(RPM_PLATFORMS); do \
		package_cloud push --url $(PACKAGE_CLOUD_URL) $(PACKAGE_CLOUD)/$$DIST out/rpm/*.rpm; \
	done
300 301 302

packagecloud-yank:
ifneq ($(YANK),)
Kamil Trzciński's avatar
Kamil Trzciński committed
303
	# Removing $(YANK) from packagecloud...
304 305
	-for DIST in $(DEB_PLATFORMS); do \
		for ARCH in $(DEB_ARCHS); do \
Kamil Trzciński's avatar
Kamil Trzciński committed
306 307 308
			package_cloud yank --url $(PACKAGE_CLOUD_URL) $(PACKAGE_CLOUD)/$$DIST $(PACKAGE_NAME)_$(YANK)_$$ARCH.deb & \
		done; \
	done; \
309 310
	for DIST in $(RPM_PLATFORMS); do \
		for ARCH in $(RPM_ARCHS); do \
Kamil Trzciński's avatar
Kamil Trzciński committed
311 312
			package_cloud yank --url $(PACKAGE_CLOUD_URL) $(PACKAGE_CLOUD)/$$DIST $(PACKAGE_NAME)-$(YANK)-1.$$ARCH.rpm & \
		done; \
Kamil Trzciński's avatar
Kamil Trzciński committed
313 314
	done; \
	wait
Kamil Trzciński's avatar
Kamil Trzciński committed
315 316 317
else
	# No version specified in YANK
	@exit 1
318
endif
319

Kamil Trzciński's avatar
Kamil Trzciński committed
320 321 322 323 324
s3-upload:
	export ARTIFACTS_DEST=artifacts; curl -sL https://raw.githubusercontent.com/travis-ci/artifacts/master/install | bash
	./artifacts upload \
		--permissions public-read \
		--working-dir out \
Kamil Trzciński's avatar
Kamil Trzciński committed
325
		--target-paths "$(S3_UPLOAD_PATH)/" \
326
		--max-size $(shell du -bs out/ | cut -f1) \
Kamil Trzciński's avatar
Kamil Trzciński committed
327
		$(shell cd out/; find . -type f)
328
	@echo "\n\033[1m==> Download index file: \033[36mhttps://$$ARTIFACTS_S3_BUCKET.s3.amazonaws.com/$$S3_UPLOAD_PATH/index.html\033[0m\n"
Kamil Trzciński's avatar
Kamil Trzciński committed
329

330 331
release_packagecloud:
	# Releasing to https://packages.gitlab.com/runner/
332
	@./ci/release_packagecloud "$$CI_JOB_NAME"
333

334
release_s3: prepare_windows_zip prepare_zoneinfo prepare_index
335 336
	# Releasing to S3
	@./ci/release_s3
337

Alessio Caiazza's avatar
Alessio Caiazza committed
338 339 340 341 342
out/binaries/gitlab-runner-windows-%.zip: out/binaries/gitlab-runner-windows-%.exe
	zip --junk-paths $@ $<
	cd out/ && zip -r ../$@ helper-images

prepare_windows_zip: out/binaries/gitlab-runner-windows-386.zip out/binaries/gitlab-runner-windows-amd64.zip
343

344 345 346 347
prepare_zoneinfo:
	# preparing the zoneinfo file
	@cp $$GOROOT/lib/time/zoneinfo.zip out/

348
prepare_index:
349
	# Preparing index file
350 351
	@./ci/prepare_index

352
release_docker_images:
353
	# Releasing Docker images
354
	@./ci/release_docker_images
355

356 357 358
check-tags-in-changelog:
	# Looking for tags in CHANGELOG
	@git status | grep "On branch master" 2>&1 >/dev/null || echo "Check should be done on master branch only. Skipping."
359
	@for tag in $$(git tag | grep -E "^v[0-9]+\.[0-9]+\.[0-9]+$$" | sed 's|v||' | sort -g); do \
360 361 362 363 364 365
		state="MISSING"; \
		grep "^v $$tag" CHANGELOG.md 2>&1 >/dev/null; \
		[ "$$?" -eq 1 ] || state="OK"; \
		echo "$$tag:   \t $$state"; \
	done

366 367 368
prepare_release_checklist_issue_dry_run:
	make prepare_release_checklist_issue opts="-dry-run"

369
prepare_release_checklist_issue: opts ?= ""
370 371
prepare_release_checklist_issue: $(GOPATH_SETUP)
	@go run $(PKG)/scripts/prepare-release-checklist-issue \
372 373 374
		-issue-template-file ".gitlab/issue_templates/Release Checklist.md" \
		$(opts)

375 376 377 378 379
development_setup:
	test -d tmp/gitlab-test || git clone https://gitlab.com/gitlab-org/gitlab-test.git tmp/gitlab-test
	if prlctl --version ; then $(MAKE) -C tests/ubuntu parallels ; fi
	if vboxmanage --version ; then $(MAKE) -C tests/ubuntu virtualbox ; fi

380 381 382 383 384 385
dep_check: $(DEP)
	@cd $(PKG_BUILD_DIR) && $(DEP) check

dep_status: $(DEP)
	@./scripts/dep_status_check $(PKG_BUILD_DIR)

386 387 388 389 390 391 392 393 394 395
# local GOPATH
$(GOPATH_SETUP): $(PKG_BUILD_DIR)
	mkdir -p $(GOPATH_BIN)
	touch $@

$(PKG_BUILD_DIR):
	mkdir -p $(@D)
	ln -s ../../../.. $@

# development tools
396 397 398
$(DEP): $(GOPATH_SETUP)
	go get github.com/golang/dep/cmd/dep

399 400 401 402 403 404 405 406 407
$(GOX): $(GOPATH_SETUP)
	go get github.com/mitchellh/gox

$(MOCKERY): $(GOPATH_SETUP)
	go get github.com/vektra/mockery/.../

clean:
	-$(RM) -rf $(LOCAL_GOPATH)
	-$(RM) -rf $(TARGET_DIR)