diff --git a/.metadata.sh b/.metadata.sh index b0c2a17d..2ae87146 100755 --- 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="${SOURCE_URL}" # 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/davidnewhall/unifi-poller/unifipoller.Version=1.3.3 +# 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,9 @@ 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} +# This is a custom download path for homebrew formula. +SOURCE_PATH=https://code.golift.io/${BINARY}/tar.gz/v${VERSION} + +export IMPORT_PATH SOURCE_URL URL VERSION_PATH VVERSION VERSION ITERATION DATE COMMIT SOURCE_PATH diff --git a/.secret_files.tar.enc b/.secret_files.tar.enc index 9a799392..be29d514 100644 Binary files a/.secret_files.tar.enc and b/.secret_files.tar.enc differ diff --git a/Makefile b/Makefile index 25349e1d..6fbf7b1b 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -# This Makefile is written as generic as possible. +# This Make# This Makefile is written as generic as possible. # Setting the variables in .metadata.sh and creating the paths in the repo makes this work. # See more: https://github.com/golift/application-builder @@ -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 $@/ @@ -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) . @@ -229,7 +230,8 @@ $(BINARY).rb: v$(VERSION).tar.gz.sha256 init/homebrew/$(FORMULA).rb.tmpl -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 @@ -260,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 57eeb331..0321c55f 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 051c164b..3eb4e50e 100755 --- 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 85427ebc..39efcc04 100644 --- a/init/homebrew/service.rb.tmpl +++ b/init/homebrew/service.rb.tmpl @@ -1,10 +1,11 @@ # Homebrew Formula Template. Built by Makefile: `make fomula` # This is part of Application Builder. # https://github.com/golift/application-builder +# This file is used when FORMULA is set to 'service'. class {{Class}} < Formula desc "{{Desc}}" homepage "{{URL}}" - url "{{URL}}/archive/v{{Version}}.tar.gz" + url "{{SOURCE_PATH}}" sha256 "{{SHA256}}" head "{{URL}}" @@ -14,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" @@ -49,7 +50,7 @@ class {{Class}} < Formula ProgramArguments #{bin}/#{name} - -c + --config #{etc}/#{name}/{{CONFIG_FILE}} RunAtLoad diff --git a/scripts/formula-deploy.sh b/scripts/formula-deploy.sh index a99b6521..843c5139 100755 --- a/scripts/formula-deploy.sh +++ b/scripts/formula-deploy.sh @@ -21,7 +21,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 \"\$(