Skip to content

Commit 5e4d0e8

Browse files
authored
Build: Statically compile binaries (#875)
1 parent c7e4916 commit 5e4d0e8

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

.github/workflows/build.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ jobs:
3737
GOOS: ${{ matrix.GOOS }}
3838
GOARCH: ${{ matrix.GOARCH }}
3939
SUFFIX: ${{ matrix.SUFFIX || '' }}
40+
CGO_ENABLED: 0
4041
steps:
4142
- uses: actions/checkout@v6
4243
with:
@@ -46,7 +47,7 @@ jobs:
4647
go-version-file: go.mod
4748
cache: false
4849
- name: go build
49-
run: go build -o grafana-image-renderer-"$GOOS"-"$GOARCH""$SUFFIX" -buildvcs -ldflags '-s -w' .
50+
run: go build -o grafana-image-renderer-"$GOOS"-"$GOARCH""$SUFFIX" -buildvcs -ldflags '-s -w -extldflags "-static"' .
5051
- uses: actions/upload-artifact@v5
5152
with:
5253
name: grafana-image-renderer-${{ matrix.GOOS }}-${{ matrix.GOARCH }}${{ matrix.SUFFIX || '' }}

Makefile

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
OUT_DIR = dist
22
BINARY ?= $(OUT_DIR)/grafana-image-renderer
3+
GO_BUILD_FLAGS = -buildvcs -ldflags '-s -w -extldflags "-static"'
34

45
.PHONY: check
56
check: lint test
@@ -25,16 +26,16 @@ fix:
2526

2627
.PHONY: build
2728
build: $(OUT_DIR)
28-
go build -buildvcs -o $(BINARY) .
29+
CGO_ENABLED=0 go build $(GO_BUILD_FLAGS) -o $(BINARY) .
2930

3031
.PHONY: build-all
3132
build-all: build $(OUT_DIR)
32-
GOOS=linux GOARCH=amd64 go build -buildvcs -o $(OUT_DIR)/grafana-image-renderer-linux-amd64 .
33-
GOOS=linux GOARCH=arm64 go build -buildvcs -o $(OUT_DIR)/grafana-image-renderer-linux-arm64 .
34-
GOOS=darwin GOARCH=amd64 go build -buildvcs -o $(OUT_DIR)/grafana-image-renderer-darwin-amd64 .
35-
GOOS=darwin GOARCH=arm64 go build -buildvcs -o $(OUT_DIR)/grafana-image-renderer-darwin-arm64 .
36-
GOOS=windows GOARCH=amd64 go build -buildvcs -o $(OUT_DIR)/grafana-image-renderer-windows-amd64.exe .
37-
GOOS=windows GOARCH=arm64 go build -buildvcs -o $(OUT_DIR)/grafana-image-renderer-windows-arm64.exe .
33+
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build $(GO_BUILD_FLAGS) -o $(OUT_DIR)/grafana-image-renderer-linux-amd64 .
34+
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build $(GO_BUILD_FLAGS) -o $(OUT_DIR)/grafana-image-renderer-linux-arm64 .
35+
CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build $(GO_BUILD_FLAGS) -o $(OUT_DIR)/grafana-image-renderer-darwin-amd64 .
36+
CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build $(GO_BUILD_FLAGS) -o $(OUT_DIR)/grafana-image-renderer-darwin-arm64 .
37+
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build $(GO_BUILD_FLAGS) -o $(OUT_DIR)/grafana-image-renderer-windows-amd64.exe .
38+
CGO_ENABLED=0 GOOS=windows GOARCH=arm64 go build $(GO_BUILD_FLAGS) -o $(OUT_DIR)/grafana-image-renderer-windows-arm64.exe .
3839

3940
.PHONY: clean
4041
clean:

0 commit comments

Comments
 (0)