Skip to content

Commit

Permalink
Fixes and Tag support. (#13)
Browse files Browse the repository at this point in the history
* move some builder pieces around. remove things and simplify
* add tag support
* add update check
* add os and arch to version
  • Loading branch information
davidnewhall authored Jan 7, 2021
1 parent 564c735 commit 28fd488
Show file tree
Hide file tree
Showing 20 changed files with 439 additions and 75 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ before_script:
- tar -xf .secret_files.tar
# - gpg --import gpg.signing.key
- rm -f gpg.signing.key .secret_files.tar
- source .metadata.sh
- source settings.sh
script:
# Test Go and Docker.
- make test
Expand Down
43 changes: 23 additions & 20 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
# This Makefile is written as generic as possible.
# Setting the variables in .metadata.sh and creating the paths in the repo makes this work.
# Setting the variables in settings.sh and creating the paths in the repo makes this work.
# See more: https://github.com/golift/application-builder

# Suck in our application information.
IGNORED:=$(shell bash -c "source .metadata.sh ; env | grep -v BASH_FUNC | sed 's/=/:=/;s/^/export /' > .metadata.make")
IGNORED:=$(shell bash -c "source settings.sh ; env | grep -v BASH_FUNC | sed 's/=/:=/;s/^/export /' > .metadata.make")

# md2roff turns markdown into man files and html files.
MD2ROFF_BIN=github.com/davidnewhall/md2roff

# rsrc adds an ico file to a Windows exe file.
RSRC_BIN=github.com/akavel/rsrc

# If upx is available, use it to compress the binaries.
UPX=$(shell which upx)

# Travis CI passes the version in. Local builds get it from the current git tag.
ifeq ($(VERSION),)
include .metadata.make
Expand All @@ -23,6 +26,7 @@ else
ITERATION:=$(_ITERATION)
endif


# rpm is wierd and changes - to _ in versions.
RPMVERSION:=$(shell echo $(VERSION) | tr -- - _)
# used for freebsd packages.
Expand All @@ -40,12 +44,12 @@ $(PACKAGE_SCRIPTS) \
--rpm-os linux \
--iteration $(ITERATION) \
--license $(LICENSE) \
--url $(URL) \
--url $(SOURCE_URL) \
--maintainer "$(MAINT)" \
--vendor "$(VENDOR)" \
--description "$(DESC)" \
--config-files "/etc/$(BINARY)/$(CONFIG_FILE)" \
--freebsd-origin "$(GHUSER)/$(REPO)/$(BINARY)"
--freebsd-origin "$(SOURCE_URL)"
endef

PLUGINS:=$(patsubst plugins/%/main.go,%,$(wildcard plugins/*/main.go))
Expand Down Expand Up @@ -124,39 +128,39 @@ $(shell go env GOPATH)/bin/rsrc:
build: $(BINARY)
$(BINARY): main.go
go build -o $(BINARY) -ldflags "-w -s $(VERSION_LDFLAGS) $(EXTRA_LDFLAGS) "
[ "$(COMPRESS)" != "true" ] || upx -q9 $@
[ "$(UPX)" == "" ] || upx -q9 $@

linux: $(BINARY).amd64.linux
$(BINARY).amd64.linux: main.go
# Building linux 64-bit x86 binary.
GOOS=linux GOARCH=amd64 go build -o $@ -ldflags "-w -s $(VERSION_LDFLAGS) $(EXTRA_LDFLAGS) "
[ "$(COMPRESS)" != "true" ] || upx -q9 $@
[ "$(UPX)" == ""] || upx -q9 $@

linux386: $(BINARY).i386.linux
$(BINARY).i386.linux: main.go
# Building linux 32-bit x86 binary.
GOOS=linux GOARCH=386 go build -o $@ -ldflags "-w -s $(VERSION_LDFLAGS) $(EXTRA_LDFLAGS) "
[ "$(COMPRESS)" != "true" ] || upx -q9 $@
[ "$(UPX)" == "" ] || upx -q9 $@

arm: arm64 armhf

arm64: $(BINARY).arm64.linux
$(BINARY).arm64.linux: main.go
# Building linux 64-bit ARM binary.
GOOS=linux GOARCH=arm64 go build -o $@ -ldflags "-w -s $(VERSION_LDFLAGS) $(EXTRA_LDFLAGS) "
[ "$(COMPRESS)" != "true" ] || upx -q9 $@
[ "$(UPX)" == "" ] || upx -q9 $@

armhf: $(BINARY).armhf.linux
$(BINARY).armhf.linux: main.go
# Building linux 32-bit ARM binary.
GOOS=linux GOARCH=arm GOARM=6 go build -o $@ -ldflags "-w -s $(VERSION_LDFLAGS) $(EXTRA_LDFLAGS) "
[ "$(COMPRESS)" != "true" ] || upx -q9 $@
[ "$(UPX)" == "" ] || upx -q9 $@

macos: $(BINARY).amd64.macos
$(BINARY).amd64.macos: main.go
# Building darwin 64-bit x86 binary.
GOOS=darwin GOARCH=amd64 go build -o $@ -ldflags "-w -s $(VERSION_LDFLAGS) $(EXTRA_LDFLAGS) "
[ "$(COMPRESS)" != "true" ] || upx -q9 $@
[ "$(UPX)" == "" ] || upx -q9 $@

freebsd: $(BINARY).amd64.freebsd
$(BINARY).amd64.freebsd: main.go
Expand All @@ -165,7 +169,7 @@ $(BINARY).amd64.freebsd: main.go
freebsd386: $(BINARY).i386.freebsd
$(BINARY).i386.freebsd: main.go
GOOS=freebsd GOARCH=386 go build -o $@ -ldflags "-w -s $(VERSION_LDFLAGS) $(EXTRA_LDFLAGS) "
[ "$(COMPRESS)" != "true" ] || upx -q9 $@ || true
[ "$(UPX)" == "" ] || upx -q9 $@ || true

freebsdarm: $(BINARY).armhf.freebsd
$(BINARY).armhf.freebsd: main.go
Expand All @@ -176,7 +180,7 @@ windows: $(BINARY).amd64.exe
$(BINARY).amd64.exe: rsrc.syso main.go
# Building windows 64-bit x86 binary.
GOOS=windows GOARCH=amd64 go build -o $@ -ldflags "-w -s $(VERSION_LDFLAGS) $(EXTRA_LDFLAGS) $(WINDOWS_LDFLAGS)"
[ "$(COMPRESS)" != "true" ] || upx -q9 $@
[ "$(UPX)" == "" ] || upx -q9 $@

####################
##### Packages #####
Expand All @@ -186,11 +190,12 @@ linux_packages: rpm deb rpm386 deb386 debarm rpmarm debarmhf rpmarmhf

freebsd_packages: freebsd_pkg freebsd386_pkg freebsdarm_pkg

macapp: $(MACAPP).app.zip
$(MACAPP).app.zip: macos
[ "$(MACAPP)" == "" ] || mkdir -p init/macos/$(MACAPP).app/Contents/MacOS
[ "$(MACAPP)" == "" ] || cp $(BINARY).amd64.macos init/macos/$(MACAPP).app/Contents/MacOS/$(MACAPP)
[ "$(MACAPP)" == "" ] || cp -rp init/macos/$(MACAPP).app $(MACAPP).app
macapp: $(MACAPP).app
$(MACAPP).app: macos
@[ "$(MACAPP)" != "" ] || (echo "Must set 'MACAPP' in settings.sh!" && exit 1)
mkdir -p init/macos/$(MACAPP).app/Contents/MacOS
cp $(BINARY).amd64.macos init/macos/$(MACAPP).app/Contents/MacOS/$(MACAPP)
cp -rp init/macos/$(MACAPP).app $(MACAPP).app

rpm: $(BINARY)-$(RPMVERSION)-$(ITERATION).x86_64.rpm
$(BINARY)-$(RPMVERSION)-$(ITERATION).x86_64.rpm: package_build_linux check_fpm
Expand Down Expand Up @@ -375,7 +380,6 @@ docker:
--build-arg "VERSION=$(VERSION)-$(ITERATION)" \
--build-arg "LICENSE=$(LICENSE)" \
--build-arg "DESC=$(DESC)" \
--build-arg "URL=$(URL)" \
--build-arg "VENDOR=$(VENDOR)" \
--build-arg "AUTHOR=$(MAINT)" \
--build-arg "BINARY=$(BINARY)" \
Expand All @@ -393,14 +397,13 @@ docker:
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 $@
curl -sL $(SOURCE_URL)/archive/v$(VERSION).tar.gz | openssl dgst -r -sha256 | tee $@
$(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%{{SOURCE_URL}}%$(SOURCE_URL)%g" \
-e "s%{{SOURCE_PATH}}%$(SOURCE_PATH)%g" \
-e "s%{{CONFIG_FILE}}%$(CONFIG_FILE)%g" \
Expand Down
5 changes: 3 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,17 @@ require (
github.com/getlantern/golog v0.0.0-20201105130739-9586b8bde3a9 // indirect
github.com/getlantern/ops v0.0.0-20200403153110-8476b16edcd6 // indirect
github.com/getlantern/systray v1.1.0
github.com/gopherjs/gopherjs v0.0.0-20200217142428-fce0ec30dd00 // indirect
github.com/gorilla/mux v1.8.0
github.com/hako/durafmt v0.0.0-20200710122514-c0fb7b4da026
github.com/lestrrat-go/apache-logformat v0.0.0-20200929122403-cd9b7dc018c7
github.com/lestrrat-go/strftime v1.0.4 // indirect
github.com/mitchellh/go-homedir v1.1.0
github.com/pkg/errors v0.9.1 // indirect
github.com/spf13/pflag v1.0.6-0.20201009195203-85dd5c8bc61c
golang.org/x/mod v0.4.0
golang.org/x/sys v0.0.0-20201223074533-0d417f636930 // indirect
golift.io/cnfg v0.0.7
golift.io/rotatorr v0.0.0-20201213130124-94efc0b9aff1
golift.io/starr v0.9.5-0.20210104053210-306f1822c914
golift.io/starr v0.9.5-0.20210106213634-edf8887280d5
golift.io/version v0.0.2
)
26 changes: 26 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,20 @@ github.com/getlantern/ops v0.0.0-20200403153110-8476b16edcd6 h1:QthAQCekS1YOeYWS
github.com/getlantern/ops v0.0.0-20200403153110-8476b16edcd6/go.mod h1:D5ao98qkA6pxftxoqzibIBBrLSUli+kYnJqrgBf9cIA=
github.com/getlantern/systray v1.1.0 h1:U0wCEqseLi2ok1fE6b88gJklzriavPJixZysZPkZd/Y=
github.com/getlantern/systray v1.1.0/go.mod h1:AecygODWIsBquJCJFop8MEQcJbWFfw/1yWbVabNgpCM=
github.com/github/hub v1.12.4 h1:ZMLV2JbeXTrKnoOT+i3Kerp+fCZb8zJzrrlWSFiTjOo=
github.com/github/hub v2.11.2+incompatible h1:H0wUQmNZVxF2+XyGPTsOxUVrRrFnTq133tezo6u4X4U=
github.com/github/hub v2.11.2+incompatible/go.mod h1:zQrzJEdze2hfWJDgktd/L6sROjAdCThFrzjbxw4keTs=
github.com/go-stack/stack v1.8.0 h1:5SgMzNM5HxrEjV0ww2lTmX6E2Izsfxas4+YHWRs3Lsk=
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
github.com/golang/mock v1.4.4/go.mod h1:l3mdAwkq5BuhzHwde/uurv3sEJeZMXNpwsxVWU71h+4=
github.com/gopherjs/gopherjs v0.0.0-20200217142428-fce0ec30dd00 h1:l5lAOZEym3oK3SQ2HBHWsJUfbNBiTXJDeW2QDxw9AQ0=
github.com/gopherjs/gopherjs v0.0.0-20200217142428-fce0ec30dd00/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI=
github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So=
github.com/hako/durafmt v0.0.0-20200710122514-c0fb7b4da026 h1:BpJ2o0OR5FV7vrkDYfXYVJQeMNWa8RhklZOpW2ITAIQ=
github.com/hako/durafmt v0.0.0-20200710122514-c0fb7b4da026/go.mod h1:5Scbynm8dF1XAPwIwkGPqzkM/shndPm79Jd1003hTjE=
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 h1:Z9n2FFNUXsshfwJMBgNA0RU6/i7WVaAegv3PtuIHPMs=
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51/go.mod h1:CzGEWj7cYgsdH8dAjBGEr58BoE7ScuLd+fwFZ44+/x8=
github.com/lestrrat-go/apache-logformat v0.0.0-20200929122403-cd9b7dc018c7 h1:7INtS8k7YsKH6PnPysHeu1cEvxah47k5kLzYvJXibF4=
github.com/lestrrat-go/apache-logformat v0.0.0-20200929122403-cd9b7dc018c7/go.mod h1:thy9OlWY26pQu7tUAL5Ox9HV/sZzlSwx/AW43yO4lSg=
github.com/lestrrat-go/apache-logformat v2.0.4+incompatible h1:UGhOtNoUfiDovk037iWsclR8qggymBW1DfHp97ZwCiY=
Expand All @@ -38,6 +45,10 @@ github.com/lestrrat-go/strftime v1.0.3 h1:qqOPU7y+TM8Y803I8fG9c/DyKG3xH/xkng6keC
github.com/lestrrat-go/strftime v1.0.3/go.mod h1:E1nN3pCbtMSu1yjSVeyuRFVm/U0xoR76fd03sz+Qz4g=
github.com/lestrrat-go/strftime v1.0.4 h1:T1Rb9EPkAhgxKqbcMIPguPq8glqXTA1koF8n9BHElA8=
github.com/lestrrat-go/strftime v1.0.4/go.mod h1:E1nN3pCbtMSu1yjSVeyuRFVm/U0xoR76fd03sz+Qz4g=
github.com/mattn/go-colorable v0.1.8 h1:c1ghPdyEDarC70ftn0y+A/Ee++9zz8ljHG1b13eJ0s8=
github.com/mattn/go-colorable v0.1.8/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY=
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y=
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c h1:rp5dCmg/yLR3mgFuSOe4oEnDDmGLROTvMragMUXpTQw=
Expand All @@ -54,14 +65,25 @@ github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UV
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.6.2-0.20201103103935-92707c0b2d50/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/mod v0.4.0 h1:8pl+sMODzuvGJkmj2W4kZihvVb5mKm8pB/X44PIQHv8=
golang.org/x/mod v0.4.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200515095857-1151b9dac4a9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201223074533-0d417f636930 h1:vRgIt+nup/B/BwIS0g2oC0haq0iqbV3ZA+u6+0TlNCo=
golang.org/x/sys v0.0.0-20201223074533-0d417f636930/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/tools v0.0.0-20190425150028-36563e24a262/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golift.io/cnfg v0.0.7 h1:qkNpP5Bq+5Gtoc6HcI8kapMD5zFOVan6qguxqBQF3OY=
golift.io/cnfg v0.0.7/go.mod h1:AsB0DJe7nv0bizKaoy3e3MjjOF7upTpMOMvsfv4CNNk=
golift.io/rotatorr v0.0.0-20201213130124-94efc0b9aff1 h1:8SDkFT5QpXyN24BCPw5Yux7SiMExnbL8o2hK1yfW3pk=
Expand All @@ -74,6 +96,10 @@ golift.io/starr v0.9.5-0.20210102172243-614fc1de1548 h1:10xWqUGL/yotNrEaJpquZ1pp
golift.io/starr v0.9.5-0.20210102172243-614fc1de1548/go.mod h1:EE8B7OlqZlE/EGmBP1bLsK1OHEgWwbNpyjDXX0B2f0Y=
golift.io/starr v0.9.5-0.20210104053210-306f1822c914 h1:gG2bli4+C6dCkl4Y/z2DUm4V7Ihwmd5pJn9CGA5V5G4=
golift.io/starr v0.9.5-0.20210104053210-306f1822c914/go.mod h1:EE8B7OlqZlE/EGmBP1bLsK1OHEgWwbNpyjDXX0B2f0Y=
golift.io/starr v0.9.5-0.20210106052616-b9672b29a15a h1:8HMszpaR/vYU3S7/ikA5B2ZAthARyG0d7Xje5xwCM2g=
golift.io/starr v0.9.5-0.20210106052616-b9672b29a15a/go.mod h1:EE8B7OlqZlE/EGmBP1bLsK1OHEgWwbNpyjDXX0B2f0Y=
golift.io/starr v0.9.5-0.20210106213634-edf8887280d5 h1:0fViTc9QBhSZsopWPmynIm+apX+r4k4Sc+9IYfRjAy8=
golift.io/starr v0.9.5-0.20210106213634-edf8887280d5/go.mod h1:EE8B7OlqZlE/EGmBP1bLsK1OHEgWwbNpyjDXX0B2f0Y=
golift.io/version v0.0.2 h1:i0gXRuSDHKs4O0sVDUg4+vNIuOxYoXhaxspftu2FRTE=
golift.io/version v0.0.2/go.mod h1:76aHNz8/Pm7CbuxIsDi97jABL5Zui3f2uZxDm4vB6hU=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
Expand Down
8 changes: 5 additions & 3 deletions init/buildinfo.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# This file is read in by metadata.sh.
# This file is read in by settings.sh.
# These values are not generally user configurable and this file is overwritten on upgrades.
# Override values in here by setting them in .metadata.sh; do not change this file.
# Override values in here by setting them in settings.sh; do not change this file.
##########

VENDOR="Go Lift <[email protected]>"

# Dynamic. Recommend not changing.
VVERSION=$(git describe --abbrev=0 --tags $(git rev-list --tags --max-count=1) 2>/dev/null)
VERSION="$(echo $VVERSION | tr -d v | grep -E '^\S+$' || echo development)"
Expand All @@ -17,4 +19,4 @@ BRANCH="${TRAVIS_BRANCH:-${GIT_BRANCH}}"
# Defines docker manifest/build types.
BUILDS="linux:armhf:arm linux:arm64:arm64 linux:amd64:amd64 linux:i386:386"

export VVERSION VERSION ITERATION DATE BRANCH COMMIT BUILDS
export VENDOR VVERSION VERSION ITERATION DATE BRANCH COMMIT BUILDS
3 changes: 1 addition & 2 deletions init/docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ ARG VERSION
ARG LICENSE=MIT
ARG BINARY
ARG SOURCE_URL=http://github.com/golift/application-builder
ARG URL=http://github.com/golift/application-builder
ARG DESC=application-builder
ARG VENDOR=golift
ARG AUTHOR=golift
Expand All @@ -43,7 +42,7 @@ LABEL org.opencontainers.image.created="${BUILD_DATE}" \
org.opencontainers.image.title="${BINARY}" \
org.opencontainers.image.documentation="${SOURCE_URL}/wiki/Docker" \
org.opencontainers.image.description="${DESC}" \
org.opencontainers.image.url="${URL}" \
org.opencontainers.image.url="${SOURCE_URL}" \
org.opencontainers.image.revision="${COMMIT}" \
org.opencontainers.image.source="${SOURCE_URL}" \
org.opencontainers.image.vendor="${VENDOR}" \
Expand Down
3 changes: 1 addition & 2 deletions init/docker/hooks/build
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ set -e -o pipefail
# This always run local to the Dockerfile folder, so the path is ../..
pushd ../..

source .metadata.sh
source settings.sh

# Build each configured image from Docker Cloud.
for build in $BUILDS; do
Expand All @@ -24,7 +24,6 @@ for build in $BUILDS; do
--build-arg "VERSION=${VERSION}-${ITERATION}" \
--build-arg "LICENSE=${LICENSE}" \
--build-arg "DESC=${DESC}" \
--build-arg "URL=${URL}" \
--build-arg "VENDOR=${VENDOR}" \
--build-arg "AUTHOR=${MAINT}" \
--build-arg "BINARY=${BINARY}" \
Expand Down
2 changes: 1 addition & 1 deletion init/docker/hooks/push
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# https://github.com/golift/application-builder

pushd ../..
source .metadata.sh
source settings.sh
popd

if [ "$BUILDS" != "" ]; then
Expand Down
53 changes: 28 additions & 25 deletions pkg/apps/apps.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,37 +84,40 @@ func (a *Apps) HandleAPIpath(app App, uri string, api APIHandler, method ...stri
// The purpose of this complicated monster is to keep API handler methods simple.
func (a *Apps) handleAPI(app App, api APIHandler) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
id, _ := strconv.Atoi(mux.Vars(r)["id"])

switch start := time.Now(); {
case app == Radarr && (id > len(a.Radarr) || id < 1):
a.Respond(w, http.StatusUnprocessableEntity, fmt.Errorf("%v: %w", id, ErrNoRadarr), time.Since(start))
case app == Lidarr && (id > len(a.Lidarr) || id < 1):
a.Respond(w, http.StatusUnprocessableEntity, fmt.Errorf("%v: %w", id, ErrNoLidarr), time.Since(start))
case app == Sonarr && (id > len(a.Sonarr) || id < 1):
a.Respond(w, http.StatusUnprocessableEntity, fmt.Errorf("%v: %w", id, ErrNoSonarr), time.Since(start))
case app == Readarr && (id > len(a.Readarr) || id < 1):
a.Respond(w, http.StatusUnprocessableEntity, fmt.Errorf("%v: %w", id, ErrNoReadarr), time.Since(start))
// These store the application configuration (starr) in a context then pass that into the api() method.
// They retrieve the return code and output, then send a response (a.Respond).
// disccordnotifier.com uses 1-indexes, so we subtract 1 from the ID (turn 1 into 0).
var (
msg interface{}
ctx = r.Context()
code = http.StatusUnprocessableEntity
id, _ = strconv.Atoi(mux.Vars(r)["id"])
start = time.Now()
)

// disccordnotifier.com uses 1-indexes; subtract 1 from the ID (turn 1 into 0 generally).
switch id--; {
// Make sure the id is within range of the available service.
case app == Radarr && (id >= len(a.Radarr) || id < 0):
msg = fmt.Errorf("%v: %w", id, ErrNoRadarr)
case app == Lidarr && (id >= len(a.Lidarr) || id < 0):
msg = fmt.Errorf("%v: %w", id, ErrNoLidarr)
case app == Sonarr && (id >= len(a.Sonarr) || id < 0):
msg = fmt.Errorf("%v: %w", id, ErrNoSonarr)
case app == Readarr && (id >= len(a.Readarr) || id < 0):
msg = fmt.Errorf("%v: %w", id, ErrNoReadarr)
// Store the application configuration (starr) in a context then pass that into the api() method.
// Retrieve the return code and output, and send a response via a.Respond().
case app == Radarr:
code, msg := api(r.WithContext(context.WithValue(r.Context(), Radarr, a.Radarr[id-1])))
a.Respond(w, code, msg, time.Since(start))
code, msg = api(r.WithContext(context.WithValue(ctx, Radarr, a.Radarr[id])))
case app == Lidarr:
code, msg := api(r.WithContext(context.WithValue(r.Context(), Lidarr, a.Lidarr[id-1])))
a.Respond(w, code, msg, time.Since(start))
code, msg = api(r.WithContext(context.WithValue(ctx, Lidarr, a.Lidarr[id])))
case app == Sonarr:
code, msg := api(r.WithContext(context.WithValue(r.Context(), Sonarr, a.Sonarr[id-1])))
a.Respond(w, code, msg, time.Since(start))
code, msg = api(r.WithContext(context.WithValue(ctx, Sonarr, a.Sonarr[id])))
case app == Readarr:
code, msg := api(r.WithContext(context.WithValue(r.Context(), Readarr, a.Readarr[id-1])))
a.Respond(w, code, msg, time.Since(start))
code, msg = api(r.WithContext(context.WithValue(ctx, Readarr, a.Readarr[id])))
default:
// unknown app, just run the handler.
code, msg := api(r)
a.Respond(w, code, msg, time.Since(start))
code, msg = api(r) // unknown app, just run the handler.
}

a.Respond(w, code, msg, time.Since(start))
}
}

Expand Down
Loading

0 comments on commit 28fd488

Please sign in to comment.