Skip to content

Commit c2bbbc3

Browse files
committed
stop using GB, convert to dep/gox/GOPATH model
GB seems semi-abandoned, and currently doesn't cross compile with either go-1.9.4 or go-1.10 ([bug][1]). Possibly due to the new cgo flag whitelisting (see: [go issue: 23739][2])? Instead: * require devs to put into GOPATH, as this seems unfortunately to be the convention the go community arrived at :( * use dep for vendoring * use gox for easy cross compilation [1]: constabulary/gb#733 [2]: golang/go#23739
1 parent 9d18382 commit c2bbbc3

File tree

189 files changed

+6833
-1170
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

189 files changed

+6833
-1170
lines changed

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ jobs:
55
- image: circleci/golang:1
66
steps:
77
- checkout
8-
- run: make build-setup test
8+
- run: make test

.gitignore

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1+
/build
12
/config.json
2-
/bin
3-
/pkg
4-
/tar
5-
/man/*.[1-9]
63
/prox.exe
74
/server.pem
85
/server.key

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
language: go
2-
script: make build-setup test
2+
script: make test
33
sudo: false
44
go:
5-
- 1.8
65
- 1.9
6+
- "1.10"

DEPS.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,8 @@ Portions of this software utilize third party libraries:
66
77
* Runtime dependencies:
88
├── https://github.com/cactus/mlog (MIT License)
9-
├── https://github.com/cactus/tai64 (MIT License)
109
└── https://github.com/jessevdk/go-flags (BSD License)
1110
1211
* Test only dependencies:
1312
└── https://github.com/stretchr/testify/assert (MIT License)
14-
├── https://github.com/davecgh/go-spew (ISC License)
15-
└── https://github.com/pmezard/go-difflib (BSD License)
1613
~~~

Gopkg.lock

Lines changed: 39 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Gopkg.toml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Gopkg.toml example
2+
#
3+
# Refer to https://github.com/golang/dep/blob/master/docs/Gopkg.toml.md
4+
# for detailed Gopkg.toml documentation.
5+
#
6+
# required = ["github.com/user/thing/cmd/thing"]
7+
# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"]
8+
#
9+
# [[constraint]]
10+
# name = "github.com/user/project"
11+
# version = "1.0.0"
12+
#
13+
# [[constraint]]
14+
# name = "github.com/user/project2"
15+
# branch = "dev"
16+
# source = "github.com/myfork/project2"
17+
#
18+
# [[override]]
19+
# name = "github.com/x/y"
20+
# version = "2.4.0"
21+
22+
23+
[[constraint]]
24+
name = "github.com/cactus/mlog"
25+
version = "1.0.0"
26+
27+
[[constraint]]
28+
name = "github.com/jessevdk/go-flags"
29+
version = "1.3.0"
30+
31+
[[constraint]]
32+
name = "github.com/stretchr/testify"
33+
version = "1.2.1"

Makefile

Lines changed: 52 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,28 @@
1-
2-
BUILDDIR := ${CURDIR}
1+
# environment
2+
BUILDDIR := ${CURDIR}/build
33
TARBUILDDIR := ${BUILDDIR}/tar
44
ARCH := $(shell go env GOHOSTARCH)
55
OS := $(shell go env GOHOSTOS)
66
GOVER := $(shell go version | awk '{print $$3}' | tr -d '.')
7+
8+
# app specific info
79
APP_NAME := go-camo
810
APP_VER := $(shell git describe --always --dirty --tags|sed 's/^v//')
911
VERSION_VAR := main.ServerVersion
12+
13+
# flags and build configuration
1014
GOTEST_FLAGS := -cpu=1,2
1115
GOBUILD_DEPFLAGS := -tags netgo
1216
GOBUILD_LDFLAGS ?= -s -w
1317
GOBUILD_FLAGS := ${GOBUILD_DEPFLAGS} -ldflags "${GOBUILD_LDFLAGS} -X ${VERSION_VAR}=${APP_VER}"
14-
GB := gb
18+
19+
# cross compile defs
20+
CC_BUILD_ARCHES = darwin/amd64 freebsd/amd64 linux/amd64
21+
CC_OUTPUT_TPL := ${BUILDDIR}/bin/{{.Dir}}.{{.OS}}-{{.Arch}}
22+
23+
# error messages
24+
GOX_ERR_MSG = 'gox' command not found.
25+
GOX_INSTALL_MSG = try 'go get github.com/mitchellh/gox'
1526

1627
define HELP_OUTPUT
1728
Available targets:
@@ -20,7 +31,6 @@ Available targets:
2031
all build binaries and man pages
2132
test run tests
2233
cover run tests with cover output
23-
build-setup fetch dependencies
2434
build build all binaries
2535
man build all man pages
2636
tar build release tarball
@@ -34,31 +44,31 @@ help:
3444
@echo "$$HELP_OUTPUT"
3545

3646
clean:
37-
@rm -rf "${BUILDDIR}/bin"
38-
@rm -rf "${BUILDDIR}/pkg"
39-
@rm -rf "${BUILDDIR}/tar"
40-
@rm -rf "${BUILDDIR}/man/"*.[1-9]
41-
42-
build-setup:
43-
@go get github.com/constabulary/gb/...
47+
@rm -rf "${BUILDDIR}"
4448

4549
build:
50+
@[ -d "${BUILDDIR}/bin" ] || mkdir -p "${BUILDDIR}/bin"
4651
@echo "Building..."
47-
@${GB} build ${GOBUILD_FLAGS} ...
52+
@echo "...go-camo..."
53+
@env CGO_ENABLED=0 go build ${GOBUILD_FLAGS} -o "${BUILDDIR}/bin/go-camo" .
54+
@echo "...url-tool..."
55+
@env CGO_ENABLED=0 go build ${GOBUILD_FLAGS} -o "${BUILDDIR}/bin/url-tool" ./url-tool
56+
@echo "done!"
4857

4958
test:
5059
@echo "Running tests..."
51-
@${GB} test ${GOTEST_FLAGS} ...
60+
@go test ${GOTEST_FLAGS} ./...
5261

5362
generate:
5463
@echo "Running generate..."
55-
@${GB} generate
64+
@go generate
5665

5766
cover:
5867
@echo "Running tests with coverage..."
59-
@${GB} test -cover ${GOTEST_FLAGS} ...
68+
@go test -cover ${GOTEST_FLAGS} ./...
6069

6170
${BUILDDIR}/man/%: man/%.mdoc
71+
@[ -d "${BUILDDIR}/man" ] || mkdir -p "${BUILDDIR}/man"
6272
@cat $< | sed -E "s#.Os (.*) VERSION#.Os \1 ${APP_VER}#" > $@
6373

6474
man: $(patsubst man/%.mdoc,${BUILDDIR}/man/%,$(wildcard man/*.1.mdoc))
@@ -67,28 +77,41 @@ tar: all
6777
@echo "Building tar..."
6878
@mkdir -p ${TARBUILDDIR}/${APP_NAME}-${APP_VER}/bin
6979
@mkdir -p ${TARBUILDDIR}/${APP_NAME}-${APP_VER}/man
70-
@cp ${BUILDDIR}/bin/${APP_NAME}-netgo ${TARBUILDDIR}/${APP_NAME}-${APP_VER}/bin/${APP_NAME}
71-
@cp ${BUILDDIR}/bin/url-tool-netgo ${TARBUILDDIR}/${APP_NAME}-${APP_VER}/bin/url-tool
80+
@cp ${BUILDDIR}/bin/${APP_NAME} ${TARBUILDDIR}/${APP_NAME}-${APP_VER}/bin/${APP_NAME}
81+
@cp ${BUILDDIR}/bin/url-tool ${TARBUILDDIR}/${APP_NAME}-${APP_VER}/bin/url-tool
7282
@cp ${BUILDDIR}/man/*.[1-9] ${TARBUILDDIR}/${APP_NAME}-${APP_VER}/man/
7383
@tar -C ${TARBUILDDIR} -czf ${TARBUILDDIR}/${APP_NAME}-${APP_VER}.${GOVER}.${OS}-${ARCH}.tar.gz ${APP_NAME}-${APP_VER}
84+
@rm -rf "${TARBUILDDIR}/${APP_NAME}-${APP_VER}"
7485

7586
cross-tar: man
76-
@echo "Making tar for ${APP_NAME}:darwin.amd64"
77-
@env GOOS=darwin GOARCH=amd64 ${GB} build ${GOBUILD_FLAGS} ...
78-
@env GOOS=freebsd GOARCH=amd64 ${GB} build ${GOBUILD_FLAGS} ...
79-
@env GOOS=linux GOARCH=amd64 ${GB} build ${GOBUILD_FLAGS} ...
80-
81-
@(for x in darwin-amd64 freebsd-amd64 linux-amd64; do \
82-
echo "Making tar for ${APP_NAME}.$${x}"; \
87+
$(if $(shell type -p gox),,$(error ${GOX_ERR_MSG} ${GOX_INSTALL_MSG}))
88+
89+
@echo "Building (cross-compile: ${CC_BUILD_ARCHES})..."
90+
@echo "...go-camo..."
91+
@env gox -output="${CC_OUTPUT_TPL}" -osarch="${CC_BUILD_ARCHES}" \
92+
${GOBUILD_FLAGS} .
93+
@echo
94+
95+
@echo "...url-tool..."
96+
@env gox -output="${CC_OUTPUT_TPL}" -osarch="${CC_BUILD_ARCHES}" \
97+
${GOBUILD_FLAGS} ./url-tool
98+
@echo
99+
100+
@echo "...creating tar files..."
101+
@(for x in $(subst /,-,${CC_BUILD_ARCHES}); do \
102+
echo "making tar for ${APP_NAME}.$${x}"; \
83103
XDIR="${GOVER}.$${x}"; \
84-
mkdir -p ${TARBUILDDIR}/$${XDIR}/${APP_NAME}-${APP_VER}/bin/; \
85-
mkdir -p ${TARBUILDDIR}/$${XDIR}/${APP_NAME}-${APP_VER}/man/; \
86-
cp bin/${APP_NAME}-$${x}-netgo ${TARBUILDDIR}/$${XDIR}/${APP_NAME}-${APP_VER}/bin/${APP_NAME}; \
87-
cp bin/url-tool-$${x}-netgo ${TARBUILDDIR}/$${XDIR}/${APP_NAME}-${APP_VER}/bin/url-tool; \
88-
cp ${BUILDDIR}/man/*.[1-9] ${TARBUILDDIR}/$${XDIR}/${APP_NAME}-${APP_VER}/man/; \
104+
ODIR="${TARBUILDDIR}/$${XDIR}/${APP_NAME}-${APP_VER}"; \
105+
mkdir -p $${ODIR}/{bin,man}/; \
106+
cp ${BUILDDIR}/bin/${APP_NAME}.$${x} $${ODIR}/bin/${APP_NAME}; \
107+
cp ${BUILDDIR}/bin/url-tool.$${x} $${ODIR}/bin/url-tool; \
108+
cp ${BUILDDIR}/man/*.[1-9] $${ODIR}/man/; \
89109
tar -C ${TARBUILDDIR}/$${XDIR} -czf ${TARBUILDDIR}/${APP_NAME}-${APP_VER}.$${XDIR}.tar.gz ${APP_NAME}-${APP_VER}; \
110+
rm -rf "${TARBUILDDIR}/$${XDIR}/"; \
90111
done)
91112

113+
@echo "done!"
114+
92115
release-sign:
93116
@echo "signing release tarballs"
94117
@(cd tar; shasum -a 256 go-camo-*.tar.gz > SHA256; \

README.md

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -118,12 +118,27 @@ Extract, and copy files to desired locations.
118118

119119
Building requires:
120120

121-
* git
122121
* make
123-
* go (version 1.8 recommended)
122+
* git
123+
* go (latest version recommended. At least version >= 1.9)
124+
125+
Additionally required, if cross compiling:
126+
127+
* [gox](https://github.com/mitchellh/gox)
124128

125129
Building:
126130

131+
First, make sure you check out the repository into the proper location
132+
in your GOPATH. This can be done manually, or with `go get`.
133+
134+
```
135+
$ export GOPATH=/tmp/go
136+
$ go get -d github.com/cactus/go-camo
137+
$ cd $GOPATH/src/github.com/cactus/go-camo
138+
```
139+
140+
Once that is done, you are ready to build!
141+
127142
```text
128143
# show make targets
129144
$ make
@@ -133,15 +148,11 @@ Available targets:
133148
all build binaries and man pages
134149
test run tests
135150
cover run tests with cover output
136-
build-setup fetch dependencies
137151
build build all
138152
man build all man pages
139153
tar build release tarball
140154
cross-tar cross compile and build release tarballs
141155
142-
# fetch vendor dependencies
143-
$ make build-setup
144-
145156
# build all binaries and man pages
146157
# strips debug symbols by default
147158
$ make all
@@ -150,12 +161,6 @@ $ make all
150161
$ make all GOBUILD_LDFLAGS=""
151162
```
152163

153-
By default, Go-Camo builds with `-tags netgo`. However, for Go versions
154-
older than 1.5, this may not result in Go-Camo using the netgo resolver unless
155-
your Go stdlib is also compiled with `-tags netgo`. For this reason, it is
156-
required to build with at least go-1.5. Building with the latest Go version is
157-
recommended.
158-
159164
## Running
160165

161166
```text
File renamed without changes.
File renamed without changes.

src/go-camo/camo/example_proxymetrics_test.go renamed to camo/example_proxymetrics_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import (
88
"fmt"
99
"os"
1010

11-
"go-camo/camo"
12-
"go-camo/stats"
11+
"github.com/cactus/go-camo/camo"
12+
"github.com/cactus/go-camo/stats"
1313
)
1414

1515
func ExampleProxyMetrics() {
File renamed without changes.

src/go-camo/camo/proxy.go renamed to camo/proxy.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import (
1616
"strings"
1717
"time"
1818

19-
"go-camo/camo/encoding"
19+
"github.com/cactus/go-camo/camo/encoding"
2020

2121
"github.com/cactus/mlog"
2222
)

src/go-camo/camo/proxy_test.go renamed to camo/proxy_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ import (
1111
"testing"
1212
"time"
1313

14-
"go-camo/camo/encoding"
15-
"go-camo/router"
14+
"github.com/cactus/go-camo/camo/encoding"
15+
"github.com/cactus/go-camo/router"
1616

1717
"github.com/stretchr/testify/assert"
1818
)
File renamed without changes.

diagrams/diagram.monopic

1.95 KB
Binary file not shown.

diagrams/diagram.txt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
+----------+ request +-------------+
2+
| |----------------------------->| |
3+
| | | |
4+
| | | web-app |
5+
| | img src=https://go-camo/url | |
6+
| |<-----------------------------| |
7+
| | +-------------+
8+
| client |
9+
| | https://go-camo/url +-------------+ http://some/img
10+
| |----------------------------->| |--------------->
11+
| | | |
12+
| | | go-camo |
13+
| | img data | | img data
14+
| |<-----------------------------| |<---------------
15+
| | +-------------+
16+
+----------+
17+

src/go-camo/main.go renamed to main.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// go-camo daemon (go-camod)
66
package main
77

8-
//go:generate go run ../../tools/genversion.go -pkg $GOPACKAGE -input ../../DEPS.md -output version_info_generated.go
8+
//go:generate go run tools/genversion.go -pkg $GOPACKAGE -input DEPS.md -output main_vers_gen.go
99

1010
import (
1111
"fmt"
@@ -17,9 +17,9 @@ import (
1717
"strings"
1818
"time"
1919

20-
"go-camo/camo"
21-
"go-camo/router"
22-
"go-camo/stats"
20+
"github.com/cactus/go-camo/camo"
21+
"github.com/cactus/go-camo/router"
22+
"github.com/cactus/go-camo/stats"
2323

2424
"github.com/cactus/mlog"
2525
flags "github.com/jessevdk/go-flags"

src/go-camo/version_info_generated.go renamed to main_vers_gen.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,8 @@ Portions of this software utilize third party libraries:
1414
1515
* Runtime dependencies:
1616
├── https://github.com/cactus/mlog (MIT License)
17-
├── https://github.com/cactus/tai64 (MIT License)
1817
└── https://github.com/jessevdk/go-flags (BSD License)
1918
2019
* Test only dependencies:
2120
└── https://github.com/stretchr/testify/assert (MIT License)
22-
├── https://github.com/davecgh/go-spew (ISC License)
23-
└── https://github.com/pmezard/go-difflib (BSD License)
2421
`
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)