github.com/ssube/gitlab-ci-multi-runner@v1.2.1-0.20160607142738-b8d1285632e6/Makefile (about) 1 NAME ?= gitlab-ci-multi-runner 2 PACKAGE_NAME ?= $(NAME) 3 PACKAGE_CONFLICT ?= $(PACKAGE_NAME)-beta 4 REVISION := $(shell git rev-parse --short HEAD || echo unknown) 5 LAST_TAG := $(shell git describe --tags --abbrev=0) 6 COMMITS := $(shell echo `git log --oneline $(LAST_TAG)..HEAD | wc -l`) 7 VERSION := $(shell (cat VERSION || echo dev) | sed -e 's/^v//g') 8 BUILT := $(shell date +%Y-%m-%dT%H:%M:%S%:z) 9 ifneq ($(RELEASE),true) 10 VERSION := $(shell echo $(VERSION)~beta.$(COMMITS).g$(REVISION)) 11 endif 12 BRANCH := $(shell git show-ref | grep "$(REVISION)" | grep -v HEAD | awk '{print $$2}' | sed -r 's/refs\/(remotes\/origin|heads)\///' | sort | head -n 1) 13 ITTERATION := $(shell date +%s) 14 PACKAGE_CLOUD ?= ayufan/gitlab-ci-multi-runner 15 PACKAGE_CLOUD_URL ?= https://packagecloud.io/ 16 BUILD_PLATFORMS ?= -os '!netbsd' -os '!openbsd' 17 S3_UPLOAD_PATH ?= master 18 DEB_PLATFORMS ?= debian/wheezy debian/jessie debian/stretch debian/buster \ 19 ubuntu/precise ubuntu/trusty ubuntu/utopic ubuntu/vivid ubuntu/wily ubuntu/xenial \ 20 raspbian/wheezy raspbian/jessie raspbian/stretch raspbian/buster \ 21 linuxmint/petra linuxmint/qiana linuxmint/rebecca linuxmint/rafaela linuxmint/rosa 22 DEB_ARCHS ?= amd64 i386 arm armhf 23 RPM_PLATFORMS ?= el/6 el/7 \ 24 ol/6 ol/7 \ 25 fedora/20 fedora/21 fedora/22 fedora/23 26 RPM_ARCHS ?= x86_64 i686 arm armhf 27 GO_LDFLAGS ?= -X main.NAME=$(PACKAGE_NAME) -X main.VERSION=$(VERSION) -X main.REVISION=$(REVISION) -X main.BUILT=$(BUILT) -X main.BRANCH=$(BRANCH) 28 GO_FILES ?= $(shell find . -name '*.go') 29 export GO15VENDOREXPERIMENT := 1 30 export CGO_ENABLED := 0 31 32 all: deps verify build 33 34 help: 35 # Commands: 36 # make all => deps verify build 37 # make version - show information about current version 38 # 39 # Development commands: 40 # make install - install the version suitable for your OS as gitlab-ci-multi-runner 41 # make docker - build docker dependencies 42 # 43 # Testing commands: 44 # make verify - run fmt, complexity, test and lint 45 # make fmt - check source formatting 46 # make test - run project tests 47 # make lint - check project code style 48 # make vet - examine code and report suspicious constructs 49 # make complexity - check code complexity 50 # 51 # Deployment commands: 52 # make deps - install all dependencies 53 # make build - build project for all supported OSes 54 # make package - package project using FPM 55 # make packagecloud - send all packages to packagecloud 56 # make packagecloud-yank - remove specific version from packagecloud 57 58 version: FORCE 59 @echo Current version: $(VERSION) 60 @echo Current iteration: $(ITTERATION) 61 @echo Current revision: $(REVISION) 62 @echo Current branch: $(BRANCH) 63 @echo Build platforms: $(BUILD_PLATFORMS) 64 @echo DEB platforms: $(DEB_PLATFORMS) 65 @echo RPM platforms: $(RPM_PLATFORMS) 66 bash -c 'echo TEST: ${GO15VENDOREXPERIMENT}' 67 68 verify: fmt vet lint complexity test 69 70 deps: 71 # Installing dependencies... 72 go get -u github.com/golang/lint/golint 73 go get github.com/mitchellh/gox 74 go get golang.org/x/tools/cmd/cover 75 go get github.com/fzipp/gocyclo 76 go get -u github.com/jteeuwen/go-bindata/... 77 go install cmd/vet 78 79 out/docker/prebuilt.tar.gz: $(GO_FILES) 80 # Create directory 81 mkdir -p out/docker 82 83 ifneq (, $(shell docker info)) 84 # Building gitlab-runner-helper 85 gox -osarch=linux/amd64 \ 86 -ldflags "$(GO_LDFLAGS)" \ 87 -output="dockerfiles/build/gitlab-runner-helper" \ 88 ./apps/gitlab-runner-helper 89 90 # Build docker images 91 docker build -t gitlab-runner-build:$(REVISION) dockerfiles/build 92 docker build -t gitlab-runner-cache:$(REVISION) dockerfiles/cache 93 docker build -t gitlab-runner-service:$(REVISION) dockerfiles/service 94 docker save -o out/docker/prebuilt.tar \ 95 gitlab-runner-build:$(REVISION) \ 96 gitlab-runner-service:$(REVISION) \ 97 gitlab-runner-cache:$(REVISION) 98 gzip -f -9 out/docker/prebuilt.tar 99 else 100 $(warning =============================================) 101 $(warning WARNING: downloading prebuilt docker images that will be embedded in gitlab-runner) 102 $(warning WARNING: to use images compiled from your code install Docker Engine) 103 $(warning WARNING: and remove out/docker/prebuilt.tar.gz) 104 $(warning =============================================) 105 curl -o out/docker/prebuilt.tar.gz \ 106 https://gitlab-ci-multi-runner-downloads.s3.amazonaws.com/master/docker/prebuilt.tar.gz 107 endif 108 109 executors/docker/bindata.go: out/docker/prebuilt.tar.gz 110 # Generating embedded data 111 go-bindata \ 112 -pkg docker \ 113 -nocompress \ 114 -nomemcopy \ 115 -nometadata \ 116 -prefix out/docker/ \ 117 -o executors/docker/bindata.go \ 118 out/docker/prebuilt.tar.gz 119 120 docker: executors/docker/bindata.go 121 122 build: executors/docker/bindata.go 123 # Building $(NAME) in version $(VERSION) for $(BUILD_PLATFORMS) 124 gox $(BUILD_PLATFORMS) \ 125 -ldflags "$(GO_LDFLAGS)" \ 126 -output="out/binaries/$(NAME)-{{.OS}}-{{.Arch}}" 127 128 build_current: executors/docker/bindata.go 129 # Building $(NAME) in version $(VERSION) for current platform 130 go build \ 131 -ldflags "$(GO_LDFLAGS)" \ 132 -o "out/binaries/$(NAME)" 133 134 fmt: 135 # Checking project code formatting... 136 @go fmt ./... | awk '{ print "Please run go fmt"; exit 1 }' 137 138 vet: 139 # Checking for suspicious constructs... 140 @go vet ./... 141 142 lint: 143 # Checking project code style... 144 @golint ./... | ( ! grep -v -e "be unexported" -e "don't use an underscore in package name" -e "ALL_CAPS" ) 145 146 complexity: 147 # Checking code complexity 148 @gocyclo -over 9 $(shell find . -name '*.go' | grep -v \ 149 -e "/Godeps" \ 150 -e "/helpers/shell_escape.go" \ 151 -e "/executors/parallels/" \ 152 -e "/executors/virtualbox/") 153 154 test: executors/docker/bindata.go 155 # Running tests... 156 @go test ./... -cover 157 158 install: executors/docker/bindata.go 159 go install --ldflags="$(GO_LDFLAGS)" 160 161 dockerfiles: 162 make -C dockerfiles all 163 164 mocks: FORCE 165 go get github.com/vektra/mockery/.../ 166 rm -rf mocks/ 167 mockery -dir=$(GOPATH)/src/github.com/ayufan/golang-kardianos-service -name=Interface 168 mockery -dir=./common -name=Network 169 mockery -dir=./helpers/docker -name=Client 170 171 test-docker: 172 make test-docker-image IMAGE=centos:6 TYPE=rpm 173 make test-docker-image IMAGE=centos:7 TYPE=rpm 174 make test-docker-image IMAGE=debian:wheezy TYPE=deb 175 make test-docker-image IMAGE=debian:jessie TYPE=deb 176 make test-docker-image IMAGE=ubuntu-upstart:precise TYPE=deb 177 make test-docker-image IMAGE=ubuntu-upstart:trusty TYPE=deb 178 make test-docker-image IMAGE=ubuntu-upstart:utopic TYPE=deb 179 180 test-docker-image: 181 tests/test_installation.sh $(IMAGE) out/$(TYPE)/$(PACKAGE_NAME)_amd64.$(TYPE) 182 tests/test_installation.sh $(IMAGE) out/$(TYPE)/$(PACKAGE_NAME)_amd64.$(TYPE) Y 183 184 build-and-deploy: 185 make build BUILD_PLATFORMS="-os=linux -arch=amd64" 186 make package-deb-fpm ARCH=amd64 PACKAGE_ARCH=amd64 187 scp out/deb/$(PACKAGE_NAME)_amd64.deb $(SERVER): 188 ssh $(SERVER) dpkg -i $(PACKAGE_NAME)_amd64.deb 189 190 build-and-deploy-binary: 191 make build BUILD_PLATFORMS="-os=linux -arch=amd64" 192 scp out/binaries/$(PACKAGE_NAME)-linux-amd64 $(SERVER):/usr/bin/gitlab-runner 193 194 package: package-deps package-deb package-rpm 195 196 package-deb: 197 # Building Debian compatible packages... 198 make package-deb-fpm ARCH=amd64 PACKAGE_ARCH=amd64 199 make package-deb-fpm ARCH=386 PACKAGE_ARCH=i386 200 make package-deb-fpm ARCH=arm PACKAGE_ARCH=arm 201 make package-deb-fpm ARCH=arm PACKAGE_ARCH=armhf 202 203 package-rpm: 204 # Building RedHat compatible packages... 205 make package-rpm-fpm ARCH=amd64 PACKAGE_ARCH=amd64 206 make package-rpm-fpm ARCH=386 PACKAGE_ARCH=i686 207 make package-rpm-fpm ARCH=arm PACKAGE_ARCH=arm 208 make package-rpm-fpm ARCH=arm PACKAGE_ARCH=armhf 209 210 package-deps: 211 # Installing packaging dependencies... 212 gem install fpm 213 214 package-deb-fpm: 215 @mkdir -p out/deb/ 216 fpm -s dir -t deb -n $(PACKAGE_NAME) -v $(VERSION) \ 217 -p out/deb/$(PACKAGE_NAME)_$(PACKAGE_ARCH).deb \ 218 --deb-priority optional --category admin \ 219 --force \ 220 --deb-compression bzip2 \ 221 --after-install packaging/scripts/postinst.deb \ 222 --before-remove packaging/scripts/prerm.deb \ 223 --url https://gitlab.com/gitlab-org/gitlab-ci-multi-runner \ 224 --description "GitLab Runner" \ 225 -m "Kamil Trzciński <ayufan@ayufan.eu>" \ 226 --license "MIT" \ 227 --vendor "ayufan.eu" \ 228 --conflicts $(PACKAGE_CONFLICT) \ 229 --provides gitlab-runner \ 230 --replaces gitlab-runner \ 231 --depends ca-certificates \ 232 --depends git \ 233 --depends curl \ 234 --depends tar \ 235 --deb-suggests docker-engine \ 236 -a $(PACKAGE_ARCH) \ 237 packaging/root/=/ \ 238 out/binaries/$(NAME)-linux-$(ARCH)=/usr/bin/gitlab-ci-multi-runner 239 240 package-rpm-fpm: 241 @mkdir -p out/rpm/ 242 fpm -s dir -t rpm -n $(PACKAGE_NAME) -v $(VERSION) \ 243 -p out/rpm/$(PACKAGE_NAME)_$(PACKAGE_ARCH).rpm \ 244 --rpm-compression bzip2 --rpm-os linux \ 245 --force \ 246 --after-install packaging/scripts/postinst.rpm \ 247 --before-remove packaging/scripts/prerm.rpm \ 248 --url https://gitlab.com/gitlab-org/gitlab-ci-multi-runner \ 249 --description "GitLab Runner" \ 250 -m "Kamil Trzciński <ayufan@ayufan.eu>" \ 251 --license "MIT" \ 252 --vendor "ayufan.eu" \ 253 --conflicts $(PACKAGE_CONFLICT) \ 254 --provides gitlab-runner \ 255 --replaces gitlab-runner \ 256 --depends git \ 257 --depends curl \ 258 --depends tar \ 259 -a $(PACKAGE_ARCH) \ 260 packaging/root/=/ \ 261 out/binaries/$(NAME)-linux-$(ARCH)=/usr/bin/gitlab-ci-multi-runner 262 263 packagecloud: packagecloud-deps packagecloud-deb packagecloud-rpm 264 265 packagecloud-deps: 266 # Installing packagecloud dependencies... 267 gem install package_cloud 268 269 packagecloud-deb: 270 # Sending Debian compatible packages... 271 -for DIST in $(DEB_PLATFORMS); do \ 272 package_cloud push --url $(PACKAGE_CLOUD_URL) $(PACKAGE_CLOUD)/$$DIST out/deb/*.deb; \ 273 done 274 275 packagecloud-rpm: 276 # Sending RedHat compatible packages... 277 -for DIST in $(RPM_PLATFORMS); do \ 278 package_cloud push --url $(PACKAGE_CLOUD_URL) $(PACKAGE_CLOUD)/$$DIST out/rpm/*.rpm; \ 279 done 280 281 packagecloud-yank: 282 ifneq ($(YANK),) 283 # Removing $(YANK) from packagecloud... 284 -for DIST in $(DEB_PLATFORMS); do \ 285 for ARCH in $(DEB_ARCHS); do \ 286 package_cloud yank --url $(PACKAGE_CLOUD_URL) $(PACKAGE_CLOUD)/$$DIST $(PACKAGE_NAME)_$(YANK)_$$ARCH.deb & \ 287 done; \ 288 done; \ 289 for DIST in $(RPM_PLATFORMS); do \ 290 for ARCH in $(RPM_ARCHS); do \ 291 package_cloud yank --url $(PACKAGE_CLOUD_URL) $(PACKAGE_CLOUD)/$$DIST $(PACKAGE_NAME)-$(YANK)-1.$$ARCH.rpm & \ 292 done; \ 293 done; \ 294 wait 295 else 296 # No version specified in YANK 297 @exit 1 298 endif 299 300 s3-upload: 301 export ARTIFACTS_DEST=artifacts; curl -sL https://raw.githubusercontent.com/travis-ci/artifacts/master/install | bash 302 ./artifacts upload \ 303 --permissions public-read \ 304 --working-dir out \ 305 --target-paths "$(S3_UPLOAD_PATH)/" \ 306 $(shell cd out/; find . -type f) 307 308 FORCE: