-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
13 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
.makefiles | ||
.git |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
/artifacts | ||
/vendor | ||
/artifacts/ | ||
/.makefiles/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
FROM scratch | ||
COPY bin/echo-server /bin/echo-server | ||
COPY artifacts/build/release/linux/amd64/echo-server /bin/echo-server | ||
ENV PORT 8080 | ||
EXPOSE 8080 | ||
ENTRYPOINT ["/bin/echo-server"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,72 +1,11 @@ | ||
BUILD_OS := windows linux darwin | ||
BUILD_ARCH := amd64 | ||
BUILD_DEBUG_FLAGS := | ||
BUILD_RELEASE_FLAGS := -ldflags "-s -w" | ||
DOCKER_REPO = jmalloc/echo-server | ||
|
||
BUILD_PATH := artifacts/build | ||
COVERAGE_PATH := artifacts/tests/coverage | ||
GO_MATRIX_OS := windows linux darwin | ||
GO_MATRIX_ARCH := amd64 | ||
|
||
CURRENT_OS := $(shell uname | tr A-Z a-z) | ||
CURRENT_ARCH := amd64 | ||
-include .makefiles/Makefile | ||
-include .makefiles/pkg/go/v1/Makefile | ||
-include .makefiles/pkg/docker/v1/Makefile | ||
|
||
SOURCES := $(shell find . -name '*.go' -not -path './vendor/*') | ||
PACKAGES := $(sort $(dir $(SOURCES))) | ||
BINARIES := $(notdir $(shell find ./cmd -mindepth 1 -maxdepth 1 -type d)) | ||
TARGETS := $(foreach OS,$(BUILD_OS),$(foreach ARCH,$(BUILD_ARCH),$(foreach BIN,$(BINARIES),$(OS)/$(ARCH)/$(BIN)))) | ||
|
||
test: vendor | ||
go test $(PACKAGES) | ||
|
||
build: $(addprefix $(BUILD_PATH)/debug/$(CURRENT_OS)/$(CURRENT_ARCH)/,$(BINARIES)) | ||
|
||
debug: $(addprefix $(BUILD_PATH)/debug/,$(TARGETS)) | ||
|
||
release: $(addprefix $(BUILD_PATH)/release/,$(TARGETS)) | ||
|
||
docker: Dockerfile $(BUILD_PATH)/release/linux/amd64/echo-server | ||
@mkdir -p bin | ||
cp $(BUILD_PATH)/release/linux/amd64/echo-server bin/echo-server | ||
docker build -t jmalloc/echo-server:dev . | ||
|
||
clean: | ||
@git check-ignore ./* | grep -v ^./vendor | xargs -t -n1 rm -rf | ||
docker rmi $(docker images -qf dangling=true) | ||
|
||
clean-all: | ||
@git check-ignore ./* | xargs -t -n1 rm -rf | ||
docker rmi $(docker images -qf dangling=true) | ||
|
||
coverage: $(COVERAGE_PATH)/index.html | ||
|
||
open-coverage: $(COVERAGE_PATH)/index.html | ||
open $(COVERAGE_PATH)/index.html | ||
|
||
lint: vendor | ||
go vet $(PACKAGES) | ||
! go fmt $(PACKAGES) | grep ^ | ||
|
||
prepare: lint coverage | ||
|
||
ci: $(COVERAGE_PATH)/coverage.cov | ||
|
||
.PHONY: build test debug release docker clean clean-all coverage open-coverage lint prepare ci | ||
|
||
vendor: go.mod | ||
go mod vendor | ||
|
||
$(BUILD_PATH)/%: vendor $(SOURCES) | ||
$(eval PARTS := $(subst /, ,$*)) | ||
$(eval BUILD := $(word 1,$(PARTS))) | ||
$(eval OS := $(word 2,$(PARTS))) | ||
$(eval ARCH := $(word 3,$(PARTS))) | ||
$(eval PKG := ./cmd/$(word 4,$(PARTS))) | ||
$(eval FLAGS := $(if $(filter debug,$(BUILD)),$(BUILD_DEBUG_FLAGS),$(BUILD_RELEASE_FLAGS))) | ||
|
||
GOARCH=$(ARCH) GOOS=$(OS) go build $(FLAGS) -o "$@" "$(PKG)" | ||
|
||
$(COVERAGE_PATH)/index.html: $(COVERAGE_PATH)/coverage.cov | ||
go tool cover -html="$<" -o "$@" | ||
|
||
$(COVERAGE_PATH)/coverage.cov: vendor | ||
@mkdir -p "$(COVERAGE_PATH)" | ||
go test $(PACKAGES) -covermode=count -coverprofile="$(COVERAGE_PATH)/coverage.cov" | ||
.makefiles/%: | ||
@curl -sfL https://makefiles.dev/v1 | bash /dev/stdin "$@" |
Binary file not shown.