Linux race-enabled builds inside Docker. (#123)
Cross-platform go builds with linux as a target platform and race enabled require to link against the linux so and have the cross platform compiler installed, which is a pain. To avoid this we build everything in Linux-native environment in a container. Note that running such builds requires replacing the operator Docker base image from Alpine to something with a real glibc (i.e. ubuntu), since the target binary needs a dynamic linker. Use -a flag in order to rebuild all packages, since we might have built them on a wrong platform.
This commit is contained in:
		
							parent
							
								
									18700b9ef7
								
							
						
					
					
						commit
						24638de665
					
				
							
								
								
									
										18
									
								
								Makefile
								
								
								
								
							
							
						
						
									
										18
									
								
								Makefile
								
								
								
								
							|  | @ -1,12 +1,13 @@ | |||
| .PHONY: clean local linux macos docker push scm-source.json | ||||
| 
 | ||||
| BINARY ?= postgres-operator | ||||
| BUILD_FLAGS ?= -v -i | ||||
| ifeq ($(RACE),1) | ||||
| 	GOFLAGS=-race | ||||
| 	BUILD_FLAGS += -race -a | ||||
|     CGO_ENABLED=1 | ||||
| endif | ||||
| 
 | ||||
| BINARY ?= postgres-operator | ||||
| BUILD_FLAGS ?= -v | ||||
| LOCAL_BUILD_FLAGS ?= $(BUILD_FLAGS) -i | ||||
| LOCAL_BUILD_FLAGS ?= $(BUILD_FLAGS) | ||||
| LDFLAGS ?= -X=main.version=$(VERSION) | ||||
| DOCKERFILE = docker/Dockerfile | ||||
| IMAGE ?= pierone.example.com/acid/$(BINARY) | ||||
|  | @ -33,13 +34,13 @@ linux: build/linux/${BINARY} | |||
| macos: build/macos/${BINARY} | ||||
| 
 | ||||
| build/${BINARY}: ${SOURCES} | ||||
| 	go build -o $@ $(LOCAL_BUILD_FLAGS) -ldflags "$(LDFLAGS)" $^ | ||||
| 	CGO_ENABLED=${CGO_ENABLED} go build -o $@ $(LOCAL_BUILD_FLAGS) -ldflags "$(LDFLAGS)" $^ | ||||
| 
 | ||||
| build/linux/${BINARY}: ${SOURCES} | ||||
| 	GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -o $@ ${BUILD_FLAGS} -ldflags "$(LDFLAGS)" $^ | ||||
| 	GOOS=linux GOARCH=amd64 CGO_ENABLED=${CGO_ENABLED} go build -o $@ ${BUILD_FLAGS} -ldflags "$(LDFLAGS)" $^ | ||||
| 
 | ||||
| build/macos/${BINARY}: ${SOURCES} | ||||
| 	GOOS=darwin GOARCH=amd64 go build -o $@ ${BUILD_FLAGS} -ldflags "$(LDFLAGS)" $^ | ||||
| 	GOOS=darwin GOARCH=amd64 CGO_ENABLED=${CGO_ENABLED} go build -o $@ ${BUILD_FLAGS} -ldflags "$(LDFLAGS)" $^ | ||||
| 
 | ||||
| docker-context: scm-source.json linux | ||||
| 	mkdir -p docker/build/ | ||||
|  | @ -48,6 +49,9 @@ docker-context: scm-source.json linux | |||
| docker: ${DOCKERFILE} docker-context | ||||
| 	cd docker && docker build --rm -t "$(IMAGE):$(TAG)" . | ||||
| 
 | ||||
| indocker-race: | ||||
| 	docker run --rm -v "${GOPATH}":"${GOPATH}" -e GOPATH="${GOPATH}" -e RACE=1 -w ${PWD} golang:1.8.1 bash -c "make linux" | ||||
| 
 | ||||
| push: | ||||
| 	docker push "$(IMAGE):$(TAG)" | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue