From b3d31a2f64f908ee881848360fd8a485dc1ea437 Mon Sep 17 00:00:00 2001 From: Massaki Archambault Date: Sat, 26 Dec 2020 14:36:09 -0500 Subject: [PATCH] go project setup --- .gitignore | 1 + Dockerfile | 6 ++++ Makefile | 102 +++++++++++++++++++++++++++++++++++++++++++++++++++++ go.mod | 3 ++ main.go | 7 ++++ 5 files changed, 119 insertions(+) create mode 100644 Dockerfile create mode 100644 Makefile create mode 100644 go.mod create mode 100644 main.go diff --git a/.gitignore b/.gitignore index 621d452..53e2045 100644 --- a/.gitignore +++ b/.gitignore @@ -15,6 +15,7 @@ *.dll *.so *.dylib +bin/ # Test binary, built with `go test -c` *.test diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..32cc1cb --- /dev/null +++ b/Dockerfile @@ -0,0 +1,6 @@ +FROM alpine + +COPY ./bin/gitlabfs /usr/bin/gitlabfs + +ENTRYPOINT ["gitlabfs"] + diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..8428783 --- /dev/null +++ b/Makefile @@ -0,0 +1,102 @@ +PROGRAM := gitlabfs +TARGET_DIR := ./bin +VERSION := $(shell git describe --tags --always) + +SRC := $(shell find -name '*.go' -not -name '*_test.go' -type f) +BIN := $(TARGET_DIR)/$(PROGRAM) + +# tests +ALL_SRC := $(shell find -name '*.go' -type f) +COVER_PROFILE := $(TARGET_DIR)/coverage.out +COVER_REPORT := $(TARGET_DIR)/coverage.html + +# go +GO := go +GOFMT := $(GO) fmt +GORUN := $(GO) run -race +GOCLEAN := $(GO) clean +GOTEST := $(GO) test +GOCOVER := $(GO) tool cover +GOBUILD := $(GO) build + +# docker +DOCKER := docker +DOCKERBUILD := $(DOCKER) build +DOCKERTAG := $(DOCKER) tag +DOCKERPUSH := $(DOCKER) push +DOCKER_TAGS := $(PROGRAM):$(VERSION) + +.PHONY: all +all: build + +.PHONY: help +help: + @echo "clean revert back to clean state" + @echo "lint lint and format the code" + @echo "run run without building" + @echo "prepare prepare environment for build" + @echo "test build and run short test suite" + @echo "coverage build and run full test suite and generate coverage report" + @echo "build build the binary" + @echo "build-docker build the docker image" + +# clean: revert back to initial state + +.PHONY: clean +clean: + $(GOCLEAN) + rm -r $(TARGET_DIR) + +# lint: lint and format the code + +.PHONY: lint +lint: + $(GOFMT) ./... + +# run: run without building with debug flags + +.PHONY: run +run: lint + $(GORUN) main.go + +# prepare: prepare environment for build + +$(TARGET_DIR): + mkdir $(TARGET_DIR) &>/dev/null || true + +.PHONY: prepare +prepare: $(TARGET_DIR) + +# test: run short test suite + +.PHONY: test +test: lint + $(GOTEST) -short ./... + +# coverage: run full test suite with coverage report + +$(COVER_PROFILE): $(TARGET_DIR) $(ALL_SRC) + $(GOTEST) -coverprofile=$(COVER_PROFILE) ./... + +$(COVER_REPORT): $(TARGET_DIR) $(COVER_PROFILE) + $(GOCOVER) -html=$(COVER_PROFILE) -o=$(COVER_REPORT) + +.PHONY: coverage +coverage: lint $(COVER_REPORT) + $(GOCOVER) -func=$(COVER_PROFILE) + +# build: build the program for release + +$(BIN): $(TARGET_DIR) $(SRC) + $(GOBUILD) -o=$(BIN) + +.PHONY: build +build: lint $(BIN) + +# build-docker: build the docker image + +.PHONY: build-docker +build-docker: $(BIN) + $(DOCKERBUILD) -t $(PROGRAM) . + $(foreach tag,$(DOCKER_TAGS),$(DOCKERTAG) $(PROGRAM) $(tag);) + diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..17b1df7 --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module github.com/badjware/gitlabfs + +go 1.15 diff --git a/main.go b/main.go new file mode 100644 index 0000000..70a7fe5 --- /dev/null +++ b/main.go @@ -0,0 +1,7 @@ +package main + +import "fmt" + +func main() { + fmt.Println("Hello world!") +}