Skip to content

Commit

Permalink
ci: Specify commit and build time via linker flags
Browse files Browse the repository at this point in the history
  • Loading branch information
ivov committed Jan 19, 2025
1 parent d48bde3 commit e9a1b29
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
4 changes: 3 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ COPY . ./
ENV CGO_ENABLED=1
RUN apk add --no-cache git build-base sqlite
RUN go mod download
RUN go build -o bin cmd/server/main.go
RUN BUILD_TIME=$(date +"%Y-%m-%dT%H:%M:%S%z") && \
GIT_COMMIT=$(git describe --always --dirty) && \
go build -ldflags="-s -X main.commitSha=$GIT_COMMIT -X main.buildTime=$BUILD_TIME" -o bin cmd/server/main.go

FROM alpine:latest
RUN mkdir /root/.n8n-shortlink
Expand Down
10 changes: 5 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
HOME_DIR := $(shell echo $$HOME)
DB_PATH := $(HOME_DIR)/.n8n-shortlink/n8n-shortlink.sqlite

CURRENT_TIME = $(shell date +"%Y-%m-%dT%H:%M:%S%z")
GIT_DESCRIPTION = $(shell git describe --always --dirty)
LINKER_FLAGS = '-s -X main.commitSha=${GIT_DESCRIPTION} -X main.buildTime=${CURRENT_TIME}'

help:
@echo "Commands:"
@sed -n 's/^##//p' $(MAKEFILE_LIST)
Expand All @@ -13,7 +17,7 @@ help:

## run: Build and run binary
run:
go run cmd/server/main.go
go run -ldflags=${LINKER_FLAGS} cmd/server/main.go
.PHONY: run

## live: Run binary with live reload
Expand Down Expand Up @@ -59,10 +63,6 @@ test/watch:
# build
# ------------

CURRENT_TIME = $(shell date +"%Y-%m-%dT%H:%M:%S%z")
GIT_DESCRIPTION = $(shell git describe --always --dirty)
LINKER_FLAGS = '-s -X main.commitSha=${GIT_DESCRIPTION} -X main.buildTime=${CURRENT_TIME}'

## build: Build binary, burning in commit SHA and build time
build:
go build -ldflags=${LINKER_FLAGS} -o bin cmd/server/main.go
Expand Down

0 comments on commit e9a1b29

Please sign in to comment.