Stamp git commit into docker builds.
Conditionally include git commit into about page. The if condition is true when the following docker build arg is included --build-arg=COMMIT=$(git rev-parse --short HEAD) or when built via github (release.yml)
This commit is contained in:
		
							parent
							
								
									aadf099f50
								
							
						
					
					
						commit
						ad0b43cd45
					
				|  | @ -4,6 +4,7 @@ LABEL maintainer="Khanh Ngo <k@ndk.name" | ||||||
| 
 | 
 | ||||||
| ARG TARGETOS=linux | ARG TARGETOS=linux | ||||||
| ARG TARGETARCH=amd64 | ARG TARGETARCH=amd64 | ||||||
|  | ARG COMMIT= | ||||||
| 
 | 
 | ||||||
| ARG BUILD_DEPENDENCIES="npm \ | ARG BUILD_DEPENDENCIES="npm \ | ||||||
|     yarn" |     yarn" | ||||||
|  | @ -54,7 +55,7 @@ RUN cp -r /build/custom/ assets/ | ||||||
| 
 | 
 | ||||||
| # Build | # Build | ||||||
| RUN rice embed-go && \ | RUN rice embed-go && \ | ||||||
|     CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -a -o wg-ui . |     CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -ldflags="-X main.gitCommit=${COMMIT}" -a -o wg-ui . | ||||||
| 
 | 
 | ||||||
| # Release stage | # Release stage | ||||||
| FROM alpine:3.16 | FROM alpine:3.16 | ||||||
|  |  | ||||||
|  | @ -202,7 +202,13 @@ feature work. | ||||||
| Go to the project root directory and run the following command: | Go to the project root directory and run the following command: | ||||||
| 
 | 
 | ||||||
| ```sh | ```sh | ||||||
| docker build -t wireguard-ui . | docker build --build-arg=COMMIT=$(git rev-parse --short HEAD) -t wireguard-ui . | ||||||
|  | ``` | ||||||
|  | 
 | ||||||
|  | or | ||||||
|  | 
 | ||||||
|  | ```sh | ||||||
|  | docker compose build --build-arg=COMMIT=$(git rev-parse --short HEAD) | ||||||
| ``` | ``` | ||||||
| 
 | 
 | ||||||
| ### Build binary file | ### Build binary file | ||||||
|  |  | ||||||
							
								
								
									
										1
									
								
								main.go
								
								
								
								
							
							
						
						
									
										1
									
								
								main.go
								
								
								
								
							|  | @ -116,6 +116,7 @@ func main() { | ||||||
| 	// set app extra data
 | 	// set app extra data
 | ||||||
| 	extraData := make(map[string]string) | 	extraData := make(map[string]string) | ||||||
| 	extraData["appVersion"] = appVersion | 	extraData["appVersion"] = appVersion | ||||||
|  | 	extraData["gitCommit"] = gitCommit | ||||||
| 	extraData["basePath"] = util.BasePath | 	extraData["basePath"] = util.BasePath | ||||||
| 
 | 
 | ||||||
| 	// create rice box for embedded template
 | 	// create rice box for embedded template
 | ||||||
|  |  | ||||||
|  | @ -30,6 +30,12 @@ About | ||||||
|                             <label for="version" class="control-label">Current version</label> |                             <label for="version" class="control-label">Current version</label> | ||||||
|                             <input type="text" class="form-control" id="version" value="{{ .appVersion }}" readonly> |                             <input type="text" class="form-control" id="version" value="{{ .appVersion }}" readonly> | ||||||
|                         </div> |                         </div> | ||||||
|  | {{ if .gitCommit }} | ||||||
|  |                         <div class="form-group"> | ||||||
|  |                             <label for="version" class="control-label">git commit hash</label> | ||||||
|  |                             <input type="text" class="form-control" id="version" value="{{ .gitCommit }}" readonly> | ||||||
|  |                         </div> | ||||||
|  | {{ end }} | ||||||
|                         <div class="form-group"> |                         <div class="form-group"> | ||||||
|                             <label for="currentReleaseDate" class="control-label">Current version release date</label> |                             <label for="currentReleaseDate" class="control-label">Current version release date</label> | ||||||
|                             <input type="text" class="form-control" id="currentReleaseDate" readonly> |                             <input type="text" class="form-control" id="currentReleaseDate" readonly> | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue