build consistent statically linked binary for docker image
* use golang 1.10.1 images everywhere * introduce a `static-linux` target to build a statically linked 64-bit binary only * use that binary for the official image and the circle build and tests * use a multi-stage dockerfile for a consistent build environment
This commit is contained in:
		
							parent
							
								
									efe5a2e56b
								
							
						
					
					
						commit
						5f9d3f818c
					
				|  | @ -4,11 +4,11 @@ jobs: | ||||||
| 
 | 
 | ||||||
|   build: |   build: | ||||||
|     docker: |     docker: | ||||||
|       - image: circleci/golang:1.10 |       - image: circleci/golang:1.10.1 | ||||||
|     working_directory: /go/src/github.com/roboll/helmfile |     working_directory: /go/src/github.com/roboll/helmfile | ||||||
|     steps: |     steps: | ||||||
|       - checkout |       - checkout | ||||||
|       - run: make build |       - run: make static-linux | ||||||
|       - persist_to_workspace: |       - persist_to_workspace: | ||||||
|           root: /go/src/github.com/roboll/helmfile |           root: /go/src/github.com/roboll/helmfile | ||||||
|           paths: |           paths: | ||||||
|  | @ -16,7 +16,7 @@ jobs: | ||||||
| 
 | 
 | ||||||
|   test: |   test: | ||||||
|     docker: |     docker: | ||||||
|       - image: circleci/golang:1.10 |       - image: circleci/golang:1.10.1 | ||||||
|     working_directory: /go/src/github.com/roboll/helmfile |     working_directory: /go/src/github.com/roboll/helmfile | ||||||
|     steps: |     steps: | ||||||
|       - checkout |       - checkout | ||||||
|  | @ -76,7 +76,7 @@ jobs: | ||||||
| 
 | 
 | ||||||
|   release: |   release: | ||||||
|     docker: |     docker: | ||||||
|       - image: circleci/golang:1.10 |       - image: circleci/golang:1.10.1 | ||||||
|     working_directory: /go/src/github.com/roboll/helmfile |     working_directory: /go/src/github.com/roboll/helmfile | ||||||
|     steps: |     steps: | ||||||
|     - checkout |     - checkout | ||||||
|  | @ -84,7 +84,6 @@ jobs: | ||||||
|     - run: |     - run: | ||||||
|         command: | |         command: | | ||||||
|           docker login -u="$DOCKER_USER" -p="$DOCKER_PASS" quay.io |           docker login -u="$DOCKER_USER" -p="$DOCKER_PASS" quay.io | ||||||
|           make tools |  | ||||||
|           BUILD_URL="$CIRCLE_BUILD_URL" make push release |           BUILD_URL="$CIRCLE_BUILD_URL" make push release | ||||||
| 
 | 
 | ||||||
| workflows: | workflows: | ||||||
|  |  | ||||||
							
								
								
									
										15
									
								
								Dockerfile
								
								
								
								
							
							
						
						
									
										15
									
								
								Dockerfile
								
								
								
								
							|  | @ -1,3 +1,16 @@ | ||||||
|  | FROM golang:1.10.1-alpine3.7 as builder | ||||||
|  | 
 | ||||||
|  | RUN apk add --no-cache make git | ||||||
|  | WORKDIR /go/src/github.com/roboll/helmfile/ | ||||||
|  | 
 | ||||||
|  | COPY Makefile /go/src/github.com/roboll/helmfile/Makefile | ||||||
|  | RUN make tools | ||||||
|  | 
 | ||||||
|  | COPY . /go/src/github.com/roboll/helmfile/ | ||||||
|  | RUN make static-linux | ||||||
|  | 
 | ||||||
|  | # ----------------------------------------------------------------------------- | ||||||
|  | 
 | ||||||
| FROM alpine:3.7 | FROM alpine:3.7 | ||||||
| 
 | 
 | ||||||
| RUN apk add --no-cache ca-certificates | RUN apk add --no-cache ca-certificates | ||||||
|  | @ -11,6 +24,6 @@ RUN wget ${HELM_LOCATION}/${HELM_FILENAME} && \ | ||||||
|     tar zxf ${HELM_FILENAME} && mv /linux-amd64/helm /usr/local/bin/ && \ |     tar zxf ${HELM_FILENAME} && mv /linux-amd64/helm /usr/local/bin/ && \ | ||||||
|     rm ${HELM_FILENAME} && rm -r /linux-amd64 |     rm ${HELM_FILENAME} && rm -r /linux-amd64 | ||||||
| 
 | 
 | ||||||
| COPY dist/helmfile_linux_amd64 /usr/local/bin/helmfile | COPY --from=builder /go/src/github.com/roboll/helmfile/dist/helmfile_linux_amd64 /usr/local/bin/helmfile | ||||||
| 
 | 
 | ||||||
| CMD ["/usr/local/bin/helmfile"] | CMD ["/usr/local/bin/helmfile"] | ||||||
|  |  | ||||||
							
								
								
									
										6
									
								
								Makefile
								
								
								
								
							
							
						
						
									
										6
									
								
								Makefile
								
								
								
								
							|  | @ -29,6 +29,10 @@ cross: | ||||||
| 	gox -os '!freebsd !netbsd' -arch '!arm' -output "dist/{{.Dir}}_{{.OS}}_{{.Arch}}" -ldflags '-X main.Version=${TAG}' ${TARGETS} | 	gox -os '!freebsd !netbsd' -arch '!arm' -output "dist/{{.Dir}}_{{.OS}}_{{.Arch}}" -ldflags '-X main.Version=${TAG}' ${TARGETS} | ||||||
| .PHONY: cross | .PHONY: cross | ||||||
| 
 | 
 | ||||||
|  | static-linux: | ||||||
|  | 	env CGO_ENABLED=0 gox -osarch="linux/amd64" -output "dist/{{.Dir}}_{{.OS}}_{{.Arch}}" -ldflags '-X main.Version=${TAG}' ${TARGETS} | ||||||
|  | .PHONY: linux | ||||||
|  | 
 | ||||||
| clean: | clean: | ||||||
| 	rm dist/helmfile_* | 	rm dist/helmfile_* | ||||||
| .PHONY: clean | .PHONY: clean | ||||||
|  | @ -41,7 +45,7 @@ release: pristine cross | ||||||
| 	@ghr -b ${BODY} -t ${GITHUB_TOKEN} -u ${ORG} -recreate ${TAG} dist | 	@ghr -b ${BODY} -t ${GITHUB_TOKEN} -u ${ORG} -recreate ${TAG} dist | ||||||
| .PHONY: release | .PHONY: release | ||||||
| 
 | 
 | ||||||
| image: cross | image: | ||||||
| 	docker build -t quay.io/${ORG}/helmfile:${TAG} . | 	docker build -t quay.io/${ORG}/helmfile:${TAG} . | ||||||
| 
 | 
 | ||||||
| run: image | run: image | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue