Skip to content
This repository has been archived by the owner on Mar 22, 2023. It is now read-only.

Commit

Permalink
Merge pull request #3 from golift/dn2_bitly
Browse files Browse the repository at this point in the history
Build Updates
  • Loading branch information
davidnewhall authored Jul 15, 2019
2 parents d29abab + f53f5d8 commit 40f1a99
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 37 deletions.
15 changes: 11 additions & 4 deletions .metadata.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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
31 changes: 17 additions & 14 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 $@/
Expand Down Expand Up @@ -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)"

Expand Down Expand Up @@ -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) .

Expand All @@ -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

Expand All @@ -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.
Expand All @@ -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)
Expand Down
21 changes: 11 additions & 10 deletions init/docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand All @@ -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
Expand All @@ -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" ]
3 changes: 2 additions & 1 deletion init/docker/hooks/build
Original file line number Diff line number Diff line change
Expand Up @@ -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} .
Expand Down
6 changes: 3 additions & 3 deletions init/homebrew/service.rb.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -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}}"

Expand All @@ -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"
Expand Down
6 changes: 3 additions & 3 deletions init/homebrew/tool.rb.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -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}}"

Expand All @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion scripts/formula-deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 \"\$(<bitly_token)\" -d \"${JSON}\"")
# Extract link from reply.
Expand Down
2 changes: 1 addition & 1 deletion scripts/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ if [ "$CMD" = "" ]; then
fi

# Grab latest release file from github.
URL=$($CMD ${LATEST} | egrep "browser_download_url.*\.(${ARCH})\.${FILE}\"" | cut -d\" -f 4)
URL=$($CMD ${LATEST} | egrep "browser_download_url.*(${ARCH})\.${FILE}\"" | cut -d\" -f 4)

if [ "$?" != "0" ] || [ "$URL" = "" ]; then
echo "Error locating latest release at ${LATEST}"
Expand Down

0 comments on commit 40f1a99

Please sign in to comment.