diff --git a/.metadata.sh b/.metadata.sh index 062152c..4c3091f 100644 --- a/.metadata.sh +++ b/.metadata.sh @@ -25,13 +25,17 @@ export BINARY GHUSER HBREPO MAINT VENDOR DESC GOLANGCI_LINT_ARGS CONFIG_FILE LIC # Fix the repo if it doesn't match the binary name. # Provide a better URL if one exists. -GHREPO="${GHUSER}/${BINARY}" -URL="https://github.com/${GHREPO}" +# Used as go import path in docker and homebrew builds. +IMPORT_PATH="github.com/${GHUSER}/${BINARY}" +# Used for source links and wiki links. +SOURCE_URL="https://${IMPORT_PATH}" +# Used for documentation links. +URL="https://github.com/${GHUSER}/${BINARY}" # This parameter is passed in as -X to go build. Used to override the Version variable in a package. # This makes a path like github.com/user/hello-world/helloworld.Version=1.3.3 # Name the Version-containing library the same as the github repo, without dashes. -VERSION_PATH="github.com/${GHREPO}/$(echo ${BINARY} | tr -d -- -).Version" +VERSION_PATH="${IMPORT_PATH}/$(echo ${BINARY} | tr -d -- -).Version" # Dynamic. Recommend not changing. VVERSION=$(git describe --abbrev=0 --tags $(git rev-list --tags --max-count=1)) @@ -41,4 +45,7 @@ ITERATION=$(git rev-list --count --all || echo 0) DATE="$(date -u +%Y-%m-%dT%H:%M:%SZ)" COMMIT="$(git rev-parse --short HEAD || echo 0)" -export GHREPO URL VERSION_PATH VERSION ITERATION DATE COMMIT +# Used by homebrew downloads. +SOURCE_PATH=https://codeload.${IMPORT_PATH}/tar.gz/v${VERSION} + +export IMPORT_PATH SOURCE_URL URL VERSION_PATH VVERSION VERSION ITERATION DATE COMMIT SOURCE_PATH diff --git a/Makefile b/Makefile index 62ae72a..0f3e343 100644 --- a/Makefile +++ b/Makefile @@ -47,7 +47,7 @@ endef all: build # Prepare a release. Called in Travis CI. -release: clean macos arm windows linux_packages +release: clean macos windows linux_packages # Prepareing a release! mkdir -p $@ mv $(BINARY).*.macos $(BINARY).*.linux $@/ @@ -87,39 +87,39 @@ README.html: md2roff # Binaries build: $(BINARY) -$(BINARY): +$(BINARY): *.go */*.go go build -o $(BINARY) -ldflags "-w -s -X $(VERSION_PATH)=$(VERSION)-$(ITERATION)" linux: $(BINARY).amd64.linux -$(BINARY).amd64.linux: +$(BINARY).amd64.linux: *.go */*.go # Building linux 64-bit x86 binary. GOOS=linux GOARCH=amd64 go build -o $@ -ldflags "-w -s -X $(VERSION_PATH)=$(VERSION)-$(ITERATION)" linux386: $(BINARY).i386.linux -$(BINARY).i386.linux: +$(BINARY).i386.linux: *.go */*.go # Building linux 32-bit x86 binary. GOOS=linux GOARCH=386 go build -o $@ -ldflags "-w -s -X $(VERSION_PATH)=$(VERSION)-$(ITERATION)" arm: arm64 armhf arm64: $(BINARY).arm64.linux -$(BINARY).arm64.linux: +$(BINARY).arm64.linux: *.go */*.go # Building linux 64-bit ARM binary. GOOS=linux GOARCH=arm64 go build -o $@ -ldflags "-w -s -X $(VERSION_PATH)=$(VERSION)-$(ITERATION)" armhf: $(BINARY).armhf.linux -$(BINARY).armhf.linux: +$(BINARY).armhf.linux: *.go */*.go # Building linux 32-bit ARM binary. GOOS=linux GOARCH=arm GOARM=6 go build -o $@ -ldflags "-w -s -X $(VERSION_PATH)=$(VERSION)-$(ITERATION)" macos: $(BINARY).amd64.macos -$(BINARY).amd64.macos: +$(BINARY).amd64.macos: *.go */*.go # Building darwin 64-bit x86 binary. GOOS=darwin GOARCH=amd64 go build -o $@ -ldflags "-w -s -X $(VERSION_PATH)=$(VERSION)-$(ITERATION)" exe: $(BINARY).amd64.exe windows: $(BINARY).amd64.exe -$(BINARY).amd64.exe: +$(BINARY).amd64.exe: *.go */*.go # Building windows 64-bit x86 binary. GOOS=windows GOARCH=amd64 go build -o $@ -ldflags "-w -s -X $(VERSION_PATH)=$(VERSION)-$(ITERATION)" @@ -211,7 +211,8 @@ docker: --build-arg "VENDOR=$(VENDOR)" \ --build-arg "AUTHOR=$(MAINT)" \ --build-arg "BINARY=$(BINARY)" \ - --build-arg "GHREPO=$(GHREPO)" \ + --build-arg "IMPORT_PATH=$(IMPORT_PATH)" \ + --build-arg "SOURCE_URL=$(SOURCE_URL)" \ --build-arg "CONFIG_FILE=$(CONFIG_FILE)" \ --tag $(BINARY) . @@ -222,17 +223,19 @@ formula: $(BINARY).rb v$(VERSION).tar.gz.sha256: # Calculate the SHA from the Github source file. curl -sL $(URL)/archive/v$(VERSION).tar.gz | openssl dgst -r -sha256 | tee $@ -$(BINARY).rb: v$(VERSION).tar.gz.sha256 +$(BINARY).rb: v$(VERSION).tar.gz.sha256 init/homebrew/$(FORMULA).rb.tmpl # Creating formula from template using sed. sed -e "s/{{Version}}/$(VERSION)/g" \ -e "s/{{Iter}}/$(ITERATION)/g" \ -e "s/{{SHA256}}/$(shell head -c64 $<)/g" \ -e "s/{{Desc}}/$(DESC)/g" \ -e "s%{{URL}}%$(URL)%g" \ - -e "s%{{GHREPO}}%$(GHREPO)%g" \ + -e "s%{{IMPORT_PATH}}%$(IMPORT_PATH)%g" \ + -e "s%{{SOURCE_PATH}}%$(SOURCE_PATH)%g" \ -e "s%{{CONFIG_FILE}}%$(CONFIG_FILE)%g" \ -e "s%{{Class}}%$(shell echo $(BINARY) | perl -pe 's/(?:\b|-)(\p{Ll})/\u$$1/g')%g" \ init/homebrew/$(FORMULA).rb.tmpl | tee $(BINARY).rb + # That perl line turns hello-world into HelloWorld, etc. # Extras @@ -246,7 +249,7 @@ lint: # This is safe; recommended even. dep: vendor -vendor: +vendor: Gopkg.* dep ensure --vendor-only # Don't run this unless you're ready to debug untested vendored dependencies. @@ -259,9 +262,9 @@ deps: install: man readme $(BINARY) @echo - Done Building! - @echo - Local installation with the Makefile is only supported on macOS. - @echo If you wish to install the application manually on Linux, check out the wiki: https://github.com/$(GHREPO)/wiki/Installation + @echo If you wish to install the application manually on Linux, check out the wiki: https://$(SOURCE_URL)/wiki/Installation @echo - Otherwise, build and install a package: make rpm -or- make deb - @echo See the Package Install wiki for more info: https://github.com/$(GHREPO)/wiki/Package-Install + @echo See the Package Install wiki for more info: https://$(SOURCE_URL)/wiki/Package-Install @[ "$(shell uname)" = "Darwin" ] || (echo "Unable to continue, not a Mac." && false) @[ "$(PREFIX)" != "" ] || (echo "Unable to continue, PREFIX not set. Use: make install PREFIX=/usr/local ETC=/usr/local/etc" && false) @[ "$(ETC)" != "" ] || (echo "Unable to continue, ETC not set. Use: make install PREFIX=/usr/local ETC=/usr/local/etc" && false) diff --git a/init/docker/Dockerfile b/init/docker/Dockerfile index 57eeb33..0321c55 100644 --- a/init/docker/Dockerfile +++ b/init/docker/Dockerfile @@ -9,21 +9,21 @@ ARG BUILD_DATE=0 ARG COMMIT=0 ARG VERSION=unknown ARG BINARY=application-builder -ARG GHREPO=golift/application-builder +ARG IMPORT_PATH=github.com/golift/application-builder FROM golang:stretch as builder ARG ARCH ARG OS ARG BINARY -ARG GHREPO +ARG IMPORT_PATH -RUN mkdir -p $GOPATH/pkg/mod $GOPATH/bin $GOPATH/src/github.com/${GHREPO} +RUN mkdir -p $GOPATH/pkg/mod $GOPATH/bin $GOPATH/src/${IMPORT_PATH} RUN apt-get update \ && apt-get install -y curl \ && curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh -COPY . $GOPATH/src/github.com/${GHREPO} -WORKDIR $GOPATH/src/github.com/${GHREPO} +COPY . $GOPATH/src/${IMPORT_PATH} +WORKDIR $GOPATH/src/${IMPORT_PATH} RUN dep ensure --vendor-only \ && CGO_ENABLED=0 make ${BINARY}.${ARCH}.${OS} @@ -36,7 +36,8 @@ ARG COMMIT ARG VERSION ARG LICENSE=MIT ARG BINARY -ARG GHREPO +ARG IMPORT_PATH +ARG SOURCE_URL=http://github.com/golift/application-builder ARG URL=http://github.com/golift/application-builder ARG DESC=application-builder ARG VENDOR=golift @@ -46,19 +47,19 @@ ARG CONFIG_FILE=config.conf # Build-time metadata as defined at https://github.com/opencontainers/image-spec/blob/master/annotations.md LABEL org.opencontainers.image.created="${BUILD_DATE}" \ org.opencontainers.image.title="${BINARY}" \ - org.opencontainers.image.documentation="https://github.com/${GHREPO}/wiki/Docker" \ + org.opencontainers.image.documentation="${SOURCE_URL}/wiki/Docker" \ org.opencontainers.image.description="${DESC}" \ org.opencontainers.image.url="${URL}" \ org.opencontainers.image.revision="${COMMIT}" \ - org.opencontainers.image.source="https://github.com/${GHREPO}" \ + org.opencontainers.image.source="${SOURCE_URL}" \ org.opencontainers.image.vendor="${VENDOR}" \ org.opencontainers.image.authors="${AUTHOR}" \ org.opencontainers.image.architecture="${OS} ${ARCH}" \ org.opencontainers.image.licenses="${LICENSE}" \ org.opencontainers.image.version="${VERSION}" -COPY --from=builder /go/src/github.com/${GHREPO}/${BINARY}.${ARCH}.${OS} /image -COPY --from=builder /go/src/github.com/${GHREPO}/examples/${CONFIG_FILE}.example /etc/${BINARY}/${CONFIG_FILE} +COPY --from=builder /go/src/${IMPORT_PATH}/${BINARY}.${ARCH}.${OS} /image +COPY --from=builder /go/src/${IMPORT_PATH}/examples/${CONFIG_FILE}.example /etc/${BINARY}/${CONFIG_FILE} VOLUME [ "/etc/${BINARY}" ] ENTRYPOINT [ "/image" ] diff --git a/init/docker/hooks/build b/init/docker/hooks/build index 051c164..3eb4e50 100644 --- a/init/docker/hooks/build +++ b/init/docker/hooks/build @@ -28,7 +28,8 @@ for build in $BUILDS; do --build-arg "VENDOR=${VENDOR}" \ --build-arg "AUTHOR=${MAINT}" \ --build-arg "BINARY=${BINARY}" \ - --build-arg "GHREPO=${GHREPO}" \ + --build-arg "IMPORT_PATH=${IMPORT_PATH}" \ + --build-arg "SOURCE_URL=${SOURCE_URL}" \ --build-arg "CONFIG_FILE=${CONFIG_FILE}" \ --tag "${IMAGE_NAME}_${os}_${name}" \ --file ${DOCKERFILE_PATH} . diff --git a/init/homebrew/service.rb.tmpl b/init/homebrew/service.rb.tmpl index 94098db..39efcc0 100644 --- a/init/homebrew/service.rb.tmpl +++ b/init/homebrew/service.rb.tmpl @@ -5,7 +5,7 @@ class {{Class}} < Formula desc "{{Desc}}" homepage "{{URL}}" - url "{{URL}}/archive/v{{Version}}.tar.gz" + url "{{SOURCE_PATH}}" sha256 "{{SHA256}}" head "{{URL}}" @@ -15,9 +15,9 @@ class {{Class}} < Formula def install ENV["GOPATH"] = buildpath - bin_path = buildpath/"src/github.com/{{GHREPO}}" + bin_path = buildpath/"src/{{IMPORT_PATH}}" # Copy all files from their current location (GOPATH root) - # to $GOPATH/src/github.com/{{GHREPO}} + # to $GOPATH/src/{{IMPORT_PATH}} bin_path.install Dir["*",".??*"] cd bin_path do system "dep", "ensure", "--vendor-only" diff --git a/init/homebrew/tool.rb.tmpl b/init/homebrew/tool.rb.tmpl index afb8252..f0ab68c 100644 --- a/init/homebrew/tool.rb.tmpl +++ b/init/homebrew/tool.rb.tmpl @@ -5,7 +5,7 @@ class {{Class}} < Formula desc "{{Desc}}" homepage "{{URL}}" - url "{{URL}}/archive/v{{Version}}.tar.gz" + url "{{SOURCE_PATH}}" sha256 "{{SHA256}}" head "{{URL}}" @@ -15,9 +15,9 @@ class {{Class}} < Formula def install ENV["GOPATH"] = buildpath - bin_path = buildpath/"src/github.com/{{GHREPO}}" + bin_path = buildpath/"src/{{IMPORT_PATH}}" # Copy all files from their current location (GOPATH root) - # to $GOPATH/src/github.com/{{GHREPO}} + # to $GOPATH/src/{{IMPORT_PATH}} bin_path.install Dir["*",".??*"] cd bin_path do system "dep", "ensure", "--vendor-only" diff --git a/scripts/formula-deploy.sh b/scripts/formula-deploy.sh index 74ee030..65619bf 100755 --- a/scripts/formula-deploy.sh +++ b/scripts/formula-deploy.sh @@ -20,7 +20,7 @@ if [ -f "bitly_token" ]; then API=https://api-ssl.bitly.com/v4/bitlinks # Request payload. In single quotes with double quotes escaped. :see_no_evil: JSON='{\"domain\": \"bit.ly\",\"title\": \"${BINARY}.v${VERSION}-${ITERATION}.tgz\", \ - \"tags\": [\"${BINARY}\"], \"long_url\": \"https://codeload.github.com/${GHREPO}/tar.gz/v${VERSION}\"}' + \"tags\": [\"${BINARY}\"], \"long_url\": \"${SOURCE_PATH}\"}' # Request with headers and data. Using bash -c to hide token from bash -x in travis logs. OUT=$(bash -c "curl -s -X POST -H 'Content-type: application/json' ${API} -H \"\$(