Skip to content

Commit

Permalink
stop using GB, convert to dep/gox/GOPATH model
Browse files Browse the repository at this point in the history
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
  • Loading branch information
dropwhile committed Feb 18, 2018
1 parent 9d18382 commit ff00986
Show file tree
Hide file tree
Showing 190 changed files with 6,836 additions and 1,171 deletions.
3 changes: 2 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
version: 2
jobs:
build:
working_directory: /go/src/github.com/cactus/go-camo
docker:
- image: circleci/golang:1
steps:
- checkout
- run: make build-setup test
- run: make test
5 changes: 1 addition & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
/build
/config.json
/bin
/pkg
/tar
/man/*.[1-9]
/prox.exe
/server.pem
/server.key
Expand Down
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
language: go
script: make build-setup test
script: make test
sudo: false
go:
- 1.8
- 1.9
- "1.9.x"
- "1.10"
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ Changelog
=========

## HEAD
* change repo layout and build pipeline to dep/gox/GOPATH style

## 1.0.17 2018-01-25
* update dependency versions to current
Expand Down
3 changes: 0 additions & 3 deletions DEPS.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,8 @@ Portions of this software utilize third party libraries:
* Runtime dependencies:
├── https://github.com/cactus/mlog (MIT License)
├── https://github.com/cactus/tai64 (MIT License)
└── https://github.com/jessevdk/go-flags (BSD License)
* Test only dependencies:
└── https://github.com/stretchr/testify/assert (MIT License)
├── https://github.com/davecgh/go-spew (ISC License)
└── https://github.com/pmezard/go-difflib (BSD License)
~~~
39 changes: 39 additions & 0 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 33 additions & 0 deletions Gopkg.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Gopkg.toml example
#
# Refer to https://github.com/golang/dep/blob/master/docs/Gopkg.toml.md
# for detailed Gopkg.toml documentation.
#
# required = ["github.com/user/thing/cmd/thing"]
# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"]
#
# [[constraint]]
# name = "github.com/user/project"
# version = "1.0.0"
#
# [[constraint]]
# name = "github.com/user/project2"
# branch = "dev"
# source = "github.com/myfork/project2"
#
# [[override]]
# name = "github.com/x/y"
# version = "2.4.0"


[[constraint]]
name = "github.com/cactus/mlog"
version = "1.0.0"

[[constraint]]
name = "github.com/jessevdk/go-flags"
version = "1.3.0"

[[constraint]]
name = "github.com/stretchr/testify"
version = "1.2.1"
81 changes: 52 additions & 29 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,17 +1,28 @@

BUILDDIR := ${CURDIR}
# environment
BUILDDIR := ${CURDIR}/build
TARBUILDDIR := ${BUILDDIR}/tar
ARCH := $(shell go env GOHOSTARCH)
OS := $(shell go env GOHOSTOS)
GOVER := $(shell go version | awk '{print $$3}' | tr -d '.')

# app specific info
APP_NAME := go-camo
APP_VER := $(shell git describe --always --dirty --tags|sed 's/^v//')
VERSION_VAR := main.ServerVersion

# flags and build configuration
GOTEST_FLAGS := -cpu=1,2
GOBUILD_DEPFLAGS := -tags netgo
GOBUILD_LDFLAGS ?= -s -w
GOBUILD_FLAGS := ${GOBUILD_DEPFLAGS} -ldflags "${GOBUILD_LDFLAGS} -X ${VERSION_VAR}=${APP_VER}"
GB := gb

# cross compile defs
CC_BUILD_ARCHES = darwin/amd64 freebsd/amd64 linux/amd64
CC_OUTPUT_TPL := ${BUILDDIR}/bin/{{.Dir}}.{{.OS}}-{{.Arch}}

# error messages
GOX_ERR_MSG = 'gox' command not found.
GOX_INSTALL_MSG = try 'go get github.com/mitchellh/gox'

define HELP_OUTPUT
Available targets:
Expand All @@ -20,7 +31,6 @@ Available targets:
all build binaries and man pages
test run tests
cover run tests with cover output
build-setup fetch dependencies
build build all binaries
man build all man pages
tar build release tarball
Expand All @@ -34,31 +44,31 @@ help:
@echo "$$HELP_OUTPUT"

clean:
@rm -rf "${BUILDDIR}/bin"
@rm -rf "${BUILDDIR}/pkg"
@rm -rf "${BUILDDIR}/tar"
@rm -rf "${BUILDDIR}/man/"*.[1-9]

build-setup:
@go get github.com/constabulary/gb/...
@rm -rf "${BUILDDIR}"

build:
@[ -d "${BUILDDIR}/bin" ] || mkdir -p "${BUILDDIR}/bin"
@echo "Building..."
@${GB} build ${GOBUILD_FLAGS} ...
@echo "...go-camo..."
@env CGO_ENABLED=0 go build ${GOBUILD_FLAGS} -o "${BUILDDIR}/bin/go-camo" .
@echo "...url-tool..."
@env CGO_ENABLED=0 go build ${GOBUILD_FLAGS} -o "${BUILDDIR}/bin/url-tool" ./url-tool
@echo "done!"

test:
@echo "Running tests..."
@${GB} test ${GOTEST_FLAGS} ...
@go test ${GOTEST_FLAGS} ./...

generate:
@echo "Running generate..."
@${GB} generate
@go generate

cover:
@echo "Running tests with coverage..."
@${GB} test -cover ${GOTEST_FLAGS} ...
@go test -cover ${GOTEST_FLAGS} ./...

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

man: $(patsubst man/%.mdoc,${BUILDDIR}/man/%,$(wildcard man/*.1.mdoc))
Expand All @@ -67,28 +77,41 @@ tar: all
@echo "Building tar..."
@mkdir -p ${TARBUILDDIR}/${APP_NAME}-${APP_VER}/bin
@mkdir -p ${TARBUILDDIR}/${APP_NAME}-${APP_VER}/man
@cp ${BUILDDIR}/bin/${APP_NAME}-netgo ${TARBUILDDIR}/${APP_NAME}-${APP_VER}/bin/${APP_NAME}
@cp ${BUILDDIR}/bin/url-tool-netgo ${TARBUILDDIR}/${APP_NAME}-${APP_VER}/bin/url-tool
@cp ${BUILDDIR}/bin/${APP_NAME} ${TARBUILDDIR}/${APP_NAME}-${APP_VER}/bin/${APP_NAME}
@cp ${BUILDDIR}/bin/url-tool ${TARBUILDDIR}/${APP_NAME}-${APP_VER}/bin/url-tool
@cp ${BUILDDIR}/man/*.[1-9] ${TARBUILDDIR}/${APP_NAME}-${APP_VER}/man/
@tar -C ${TARBUILDDIR} -czf ${TARBUILDDIR}/${APP_NAME}-${APP_VER}.${GOVER}.${OS}-${ARCH}.tar.gz ${APP_NAME}-${APP_VER}
@rm -rf "${TARBUILDDIR}/${APP_NAME}-${APP_VER}"

cross-tar: man
@echo "Making tar for ${APP_NAME}:darwin.amd64"
@env GOOS=darwin GOARCH=amd64 ${GB} build ${GOBUILD_FLAGS} ...
@env GOOS=freebsd GOARCH=amd64 ${GB} build ${GOBUILD_FLAGS} ...
@env GOOS=linux GOARCH=amd64 ${GB} build ${GOBUILD_FLAGS} ...

@(for x in darwin-amd64 freebsd-amd64 linux-amd64; do \
echo "Making tar for ${APP_NAME}.$${x}"; \
$(if $(shell type -p gox),,$(error ${GOX_ERR_MSG} ${GOX_INSTALL_MSG}))

@echo "Building (cross-compile: ${CC_BUILD_ARCHES})..."
@echo "...go-camo..."
@env gox -output="${CC_OUTPUT_TPL}" -osarch="${CC_BUILD_ARCHES}" \
${GOBUILD_FLAGS} .
@echo

@echo "...url-tool..."
@env gox -output="${CC_OUTPUT_TPL}" -osarch="${CC_BUILD_ARCHES}" \
${GOBUILD_FLAGS} ./url-tool
@echo

@echo "...creating tar files..."
@(for x in $(subst /,-,${CC_BUILD_ARCHES}); do \
echo "making tar for ${APP_NAME}.$${x}"; \
XDIR="${GOVER}.$${x}"; \
mkdir -p ${TARBUILDDIR}/$${XDIR}/${APP_NAME}-${APP_VER}/bin/; \
mkdir -p ${TARBUILDDIR}/$${XDIR}/${APP_NAME}-${APP_VER}/man/; \
cp bin/${APP_NAME}-$${x}-netgo ${TARBUILDDIR}/$${XDIR}/${APP_NAME}-${APP_VER}/bin/${APP_NAME}; \
cp bin/url-tool-$${x}-netgo ${TARBUILDDIR}/$${XDIR}/${APP_NAME}-${APP_VER}/bin/url-tool; \
cp ${BUILDDIR}/man/*.[1-9] ${TARBUILDDIR}/$${XDIR}/${APP_NAME}-${APP_VER}/man/; \
ODIR="${TARBUILDDIR}/$${XDIR}/${APP_NAME}-${APP_VER}"; \
mkdir -p $${ODIR}/{bin,man}/; \
cp ${BUILDDIR}/bin/${APP_NAME}.$${x} $${ODIR}/bin/${APP_NAME}; \
cp ${BUILDDIR}/bin/url-tool.$${x} $${ODIR}/bin/url-tool; \
cp ${BUILDDIR}/man/*.[1-9] $${ODIR}/man/; \
tar -C ${TARBUILDDIR}/$${XDIR} -czf ${TARBUILDDIR}/${APP_NAME}-${APP_VER}.$${XDIR}.tar.gz ${APP_NAME}-${APP_VER}; \
rm -rf "${TARBUILDDIR}/$${XDIR}/"; \
done)

@echo "done!"

release-sign:
@echo "signing release tarballs"
@(cd tar; shasum -a 256 go-camo-*.tar.gz > SHA256; \
Expand Down
29 changes: 17 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,27 @@ Extract, and copy files to desired locations.

Building requires:

* git
* make
* go (version 1.8 recommended)
* git
* go (latest version recommended. At least version >= 1.9)

Additionally required, if cross compiling:

* [gox](https://github.com/mitchellh/gox)

Building:

First, make sure you check out the repository into the proper location
in your GOPATH. This can be done manually, or with `go get`.

```
$ export GOPATH=/tmp/go
$ go get -d github.com/cactus/go-camo
$ cd $GOPATH/src/github.com/cactus/go-camo
```

Once that is done, you are ready to build!

```text
# show make targets
$ make
Expand All @@ -133,15 +148,11 @@ Available targets:
all build binaries and man pages
test run tests
cover run tests with cover output
build-setup fetch dependencies
build build all
man build all man pages
tar build release tarball
cross-tar cross compile and build release tarballs
# fetch vendor dependencies
$ make build-setup
# build all binaries and man pages
# strips debug symbols by default
$ make all
Expand All @@ -150,12 +161,6 @@ $ make all
$ make all GOBUILD_LDFLAGS=""
```

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

## Running

```text
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (
"fmt"
"os"

"go-camo/camo"
"go-camo/stats"
"github.com/cactus/go-camo/camo"
"github.com/cactus/go-camo/stats"
)

func ExampleProxyMetrics() {
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion src/go-camo/camo/proxy.go → camo/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
"strings"
"time"

"go-camo/camo/encoding"
"github.com/cactus/go-camo/camo/encoding"

"github.com/cactus/mlog"
)
Expand Down
4 changes: 2 additions & 2 deletions src/go-camo/camo/proxy_test.go → camo/proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (
"testing"
"time"

"go-camo/camo/encoding"
"go-camo/router"
"github.com/cactus/go-camo/camo/encoding"
"github.com/cactus/go-camo/router"

"github.com/stretchr/testify/assert"
)
Expand Down
File renamed without changes.
Binary file added diagrams/diagram.monopic
Binary file not shown.
17 changes: 17 additions & 0 deletions diagrams/diagram.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
+----------+ request +-------------+
| |----------------------------->| |
| | | |
| | | web-app |
| | img src=https://go-camo/url | |
| |<-----------------------------| |
| | +-------------+
| client |
| | https://go-camo/url +-------------+ http://some/img
| |----------------------------->| |--------------->
| | | |
| | | go-camo |
| | img data | | img data
| |<-----------------------------| |<---------------
| | +-------------+
+----------+

8 changes: 4 additions & 4 deletions src/go-camo/main.go → main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// go-camo daemon (go-camod)
package main

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

import (
"fmt"
Expand All @@ -17,9 +17,9 @@ import (
"strings"
"time"

"go-camo/camo"
"go-camo/router"
"go-camo/stats"
"github.com/cactus/go-camo/camo"
"github.com/cactus/go-camo/router"
"github.com/cactus/go-camo/stats"

"github.com/cactus/mlog"
flags "github.com/jessevdk/go-flags"
Expand Down
Loading

0 comments on commit ff00986

Please sign in to comment.