Skip to content

Commit

Permalink
Build static Go binary
Browse files Browse the repository at this point in the history
Signed-off-by: Tamal Saha <[email protected]>
  • Loading branch information
tamalsaha authored and knadh committed Apr 11, 2021
1 parent b060c75 commit a266027
Showing 1 changed file with 23 additions and 28 deletions.
51 changes: 23 additions & 28 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,38 +17,43 @@ deps:
go get -u github.com/knadh/stuffbin/...
cd frontend && yarn install

# Run the JS frontend server in dev mode.
.PHONY: run-frontend
run-frontend:
export VUE_APP_VERSION="${VERSION}" && cd frontend && yarn serve

# Build the JS frontend into frontend/dist.
.PHONY: build-frontend
build-frontend:
export VUE_APP_VERSION="${VERSION}" && cd frontend && yarn build
# Build the backend to ./listmonk.
.PHONY: build
build:
CGO_ENABLED=0 go build -o ${BIN} -ldflags="-s -w -X 'main.buildString=${BUILDSTR}' -X 'main.versionString=${VERSION}'" cmd/*.go

# Run the backend.
.PHONY: run
run: build
./${BIN}

# Build the backend to ./listmonk.
.PHONY: build
build:
go build -o ${BIN} -ldflags="-s -w -X 'main.buildString=${BUILDSTR}' -X 'main.versionString=${VERSION}'" cmd/*.go
# Build the JS frontend into frontend/dist.
.PHONY: build-frontend
build-frontend:
export VUE_APP_VERSION="${VERSION}" && cd frontend && yarn build

# pack-releases runns stuffbin packing on the given binary. This is used
# in the .goreleaser post-build hook.
.PHONY: pack-bin
pack-bin:
stuffbin -a stuff -in ${BIN} -out ${BIN} ${STATIC}
# Run the JS frontend server in dev mode.
.PHONY: run-frontend
run-frontend:
export VUE_APP_VERSION="${VERSION}" && cd frontend && yarn serve

# Run Go tests.
.PHONY: test
test:
go test ./...

# Bundle all static assets including the JS frontend into the ./listmonk binary
# using stuffbin (installed with make deps).
.PHONY: dist
dist: build build-frontend
stuffbin -a stuff -in ${BIN} -out ${BIN} ${STATIC}

# pack-releases runns stuffbin packing on the given binary. This is used
# in the .goreleaser post-build hook.
.PHONY: pack-bin
pack-bin:
stuffbin -a stuff -in ${BIN} -out ${BIN} ${STATIC}

# Use goreleaser to do a dry run producing local builds.
.PHONY: release-dry
release-dry:
Expand All @@ -58,13 +63,3 @@ release-dry:
.PHONY: release
release:
goreleaser --parallelism 1 --rm-dist --skip-validate

# Opens the cypress frontend tests UI.
.PHONY: open-frontend-tests
open-frontend-tests:
cd frontend && ./node_modules/cypress/bin/cypress open

# Run Go tests.
.PHONY: test
test:
go test ./...

0 comments on commit a266027

Please sign in to comment.