diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..013dc66 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,13 @@ +FROM golang:latest +ENV GOPATH="/go/" +ENV GO111MODULE="on" +WORKDIR /go/src/mark +COPY / . +RUN make get +RUN make build + +FROM alpine:latest +RUN apk --no-cache add ca-certificates bash +WORKDIR / +COPY --from=0 /go/src/mark/mark /bin/ +ENTRYPOINT ["/bin/mark"] diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..787083e --- /dev/null +++ b/Makefile @@ -0,0 +1,41 @@ +NAME = $(notdir $(PWD)) + +VERSION = $(shell printf "%s.%s" \ + $$(git rev-list --count HEAD) \ + $$(git rev-parse --short HEAD) \ +) + +GO111MODULE = off + +BRANCH = $(shell git rev-parse --abbrev-ref HEAD) + +REMOTE = kovetskiy + +version: + @echo $(VERSION) + +get: + go get -v -d + +build: + @echo :: building go binary $(VERSION) + CGO_ENABLED=0 GOOS=linux go build \ + -ldflags "-X main.version=$(VERSION)" \ + -gcflags "-trimpath $(GOPATH)/src" + +image: + @echo :: building image $(NAME):$(VERSION) + @docker build -t $(NAME):$(VERSION) -f Dockerfile . + docker tag $(NAME):$(VERSION) $(NAME):latest + +push: + $(if $(REMOTE),,$(error REMOTE is not set)) + $(eval VERSION ?= latest) + $(eval TAG ?= $(REMOTE)/$(NAME):$(VERSION)) + @echo :: pushing image $(TAG) + @docker tag $(NAME):$(VERSION) $(TAG) + @docker push $(TAG) + @docker push $(REMOTE)/$(NAME):latest + +clean: + rm -rf $(NAME) diff --git a/main.go b/main.go index 17f8623..db07e6f 100644 --- a/main.go +++ b/main.go @@ -67,25 +67,28 @@ Also, optional following headers are supported: Usage: mark [options] [-u ] [-p ] [-k] [-l ] -f + mark [options] [-u ] [-p ] [-k] [-b ] -f mark [options] [-u ] [-p ] [-k] [-n] -c mark -v | --version mark -h | --help Options: - -u Use specified username for updating Confluence page. - -p Use specified password for updating Confluence page. - -l Edit specified Confluence page. - If -l is not specified, file should contain metadata (see - above). - -f Use specified markdown file for converting to html. - -c Specify configuration file which should be used for reading - Confluence page URL and markdown file path. - -k Lock page editing to current user only to prevent accidental - manual edits over Confluence Web UI. - --dry-run Show resulting HTML and don't update Confluence page content. - --trace Enable trace logs. - -h --help Show this screen and call 911. - -v --version Show version. + -u Use specified username for updating Confluence page. + -p Use specified password for updating Confluence page. + -l Edit specified Confluence page. + If -l is not specified, file should contain metadata (see + above). + -b --base-url Base URL for Confluence. + Alternative option for base_url config field. + -f Use specified markdown file for converting to html. + -c Specify configuration file which should be used for reading + Confluence page URL and markdown file path. + -k Lock page editing to current user only to prevent accidental + manual edits over Confluence Web UI. + --dry-run Show resulting HTML and don't update Confluence page content. + --trace Enable trace logs. + -h --help Show this screen and call 911. + -v --version Show version. ` ) @@ -245,18 +248,22 @@ func main() { baseURL := url.Scheme + "://" + url.Host if url.Host == "" { - baseURL, err = config.GetString("base_url") - if err != nil { - if zhash.IsNotFound(err) { - logger.Fatal( - "Confluence base URL should be specified using -l " + - "flag or be stored in configuration file", + var ok bool + baseURL, ok = args["--base-url"].(string) + if !ok { + baseURL, err = config.GetString("base_url") + if err != nil { + if zhash.IsNotFound(err) { + logger.Fatal( + "Confluence base URL should be specified using -l " + + "flag or be stored in configuration file", + ) + } + + logger.Fatalf( + "can't read base_url configuration variable: %s", err, ) } - - logger.Fatalf( - "can't read base_url configuration variable: %s", err, - ) } }