mirror of https://github.com/grafana/grafana.git
				
				
				
			Build: Add optional build-args for COMMIT_SHA and BUILD_BRANCH (#66672)
* Remove .git from .dockerignore
* Revert "Remove .git from .dockerignore"
This reverts commit 5a4658f270.
* Add optional COMMIT_SHA and BUILD_BRANCH environment variables
			
			
This commit is contained in:
		
							parent
							
								
									28b8d564fe
								
							
						
					
					
						commit
						614427c602
					
				|  | @ -31,6 +31,8 @@ RUN yarn build | ||||||
| 
 | 
 | ||||||
| FROM ${GO_IMAGE} as go-builder | FROM ${GO_IMAGE} as go-builder | ||||||
| 
 | 
 | ||||||
|  | ARG COMMIT_SHA="" | ||||||
|  | ARG BUILD_BRANCH="" | ||||||
| ARG GO_BUILD_TAGS="oss" | ARG GO_BUILD_TAGS="oss" | ||||||
| ARG WIRE_TAGS="oss" | ARG WIRE_TAGS="oss" | ||||||
| ARG BINGO="true" | ARG BINGO="true" | ||||||
|  | @ -62,7 +64,9 @@ COPY pkg pkg | ||||||
| COPY scripts scripts | COPY scripts scripts | ||||||
| COPY conf conf | COPY conf conf | ||||||
| COPY .github .github | COPY .github .github | ||||||
| COPY .git .git | 
 | ||||||
|  | ENV COMMIT_SHA=${COMMIT_SHA} | ||||||
|  | ENV BUILD_BRANCH=${BUILD_BRANCH} | ||||||
| 
 | 
 | ||||||
| RUN make build-go GO_BUILD_TAGS=${GO_BUILD_TAGS} WIRE_TAGS=${WIRE_TAGS} | RUN make build-go GO_BUILD_TAGS=${GO_BUILD_TAGS} WIRE_TAGS=${WIRE_TAGS} | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
							
								
								
									
										4
									
								
								Makefile
								
								
								
								
							
							
						
						
									
										4
									
								
								Makefile
								
								
								
								
							|  | @ -191,6 +191,8 @@ build-docker-full: ## Build Docker image for development. | ||||||
| 	--build-arg BINGO=false \
 | 	--build-arg BINGO=false \
 | ||||||
| 	--build-arg GO_BUILD_TAGS=$(GO_BUILD_TAGS) \
 | 	--build-arg GO_BUILD_TAGS=$(GO_BUILD_TAGS) \
 | ||||||
| 	--build-arg WIRE_TAGS=$(WIRE_TAGS) \
 | 	--build-arg WIRE_TAGS=$(WIRE_TAGS) \
 | ||||||
|  | 	--build-arg COMMIT_SHA=$$(git rev-parse --short HEAD) \
 | ||||||
|  | 	--build-arg BUILD_BRANCH=$$(git rev-parse --abbrev-ref HEAD) \
 | ||||||
| 	--tag grafana/grafana$(TAG_SUFFIX):dev \
 | 	--tag grafana/grafana$(TAG_SUFFIX):dev \
 | ||||||
| 	$(DOCKER_BUILD_ARGS) | 	$(DOCKER_BUILD_ARGS) | ||||||
| 
 | 
 | ||||||
|  | @ -202,6 +204,8 @@ build-docker-full-ubuntu: ## Build Docker image based on Ubuntu for development. | ||||||
| 	--build-arg BINGO=false \
 | 	--build-arg BINGO=false \
 | ||||||
| 	--build-arg GO_BUILD_TAGS=$(GO_BUILD_TAGS) \
 | 	--build-arg GO_BUILD_TAGS=$(GO_BUILD_TAGS) \
 | ||||||
| 	--build-arg WIRE_TAGS=$(WIRE_TAGS) \
 | 	--build-arg WIRE_TAGS=$(WIRE_TAGS) \
 | ||||||
|  | 	--build-arg COMMIT_SHA=$$(git rev-parse --short HEAD) \
 | ||||||
|  | 	--build-arg BUILD_BRANCH=$$(git rev-parse --abbrev-ref HEAD) \
 | ||||||
| 	--build-arg BASE_IMAGE=ubuntu:20.04 \
 | 	--build-arg BASE_IMAGE=ubuntu:20.04 \
 | ||||||
| 	--build-arg GO_IMAGE=golang:1.20.3 \
 | 	--build-arg GO_IMAGE=golang:1.20.3 \
 | ||||||
| 	--tag grafana/grafana$(TAG_SUFFIX):dev-ubuntu \
 | 	--tag grafana/grafana$(TAG_SUFFIX):dev-ubuntu \
 | ||||||
|  |  | ||||||
|  | @ -217,12 +217,22 @@ func ldflags(opts BuildOpts) (string, error) { | ||||||
| 		return "", err | 		return "", err | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
|  | 	commitSha := getGitSha() | ||||||
|  | 	if v := os.Getenv("COMMIT_SHA"); v != "" { | ||||||
|  | 		commitSha = v | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	buildBranch := getGitBranch() | ||||||
|  | 	if v := os.Getenv("BUILD_BRANCH"); v != "" { | ||||||
|  | 		buildBranch = v | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
| 	var b bytes.Buffer | 	var b bytes.Buffer | ||||||
| 	b.WriteString("-w") | 	b.WriteString("-w") | ||||||
| 	b.WriteString(fmt.Sprintf(" -X main.version=%s", opts.version)) | 	b.WriteString(fmt.Sprintf(" -X main.version=%s", opts.version)) | ||||||
| 	b.WriteString(fmt.Sprintf(" -X main.commit=%s", getGitSha())) | 	b.WriteString(fmt.Sprintf(" -X main.commit=%s", commitSha)) | ||||||
| 	b.WriteString(fmt.Sprintf(" -X main.buildstamp=%d", buildStamp)) | 	b.WriteString(fmt.Sprintf(" -X main.buildstamp=%d", buildStamp)) | ||||||
| 	b.WriteString(fmt.Sprintf(" -X main.buildBranch=%s", getGitBranch())) | 	b.WriteString(fmt.Sprintf(" -X main.buildBranch=%s", buildBranch)) | ||||||
| 	if v := os.Getenv("LDFLAGS"); v != "" { | 	if v := os.Getenv("LDFLAGS"); v != "" { | ||||||
| 		b.WriteString(fmt.Sprintf(" -extldflags \"%s\"", v)) | 		b.WriteString(fmt.Sprintf(" -extldflags \"%s\"", v)) | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue