Skip to content

Commit 7ee8de7

Browse files
goruhaosterman
authored andcommitted
Implement build-harness support (#11)
1 parent c9a0eb6 commit 7ee8de7

7 files changed

+57
-136
lines changed

.editorconfig

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Override for Makefile
2+
[{Makefile, makefile, GNUmakefile}]
3+
indent_style = tab
4+
indent_size = 4
5+
6+
[Makefile.*]
7+
indent_style = tab
8+
indent_size = 4

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ _cgo_export.*
2020
_testmain.go
2121

2222
*.exe
23-
*.test
2423
*.prof
2524

2625
.idea
@@ -39,3 +38,5 @@ github-authorized-keys
3938
glide.lock
4039
.glide
4140
vendor/
41+
42+
build-harness/

.travis.yml

+22-47
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
sudo: required
22
env:
3-
- DOCKER_IMAGE_NAME=cloudposse/github-authorized-keys
3+
global:
4+
- DOCKER_IMAGE_NAME=clo/udposse/github-authorized-keys
5+
- RUN_TESTS=1
6+
- TEST_GITHUB_API_TOKEN=${GITHUB_API_TOKEN}
7+
- TEST_GITHUB_ORGANIZATION=${GITHUB_ORGANIZATION}
8+
- TEST_GITHUB_TEAM=${GITHUB_TEAM}
9+
- TEST_GITHUB_TEAM_ID=${GITHUB_TEAM_ID}
10+
- TEST_GITHUB_USER=${GITHUB_USER}
11+
- TEST_ETCD_ENDPOINT=http://${ETCD_IP}:2379
412
services:
513
- docker
614
install:
7-
- |-
8-
docker login \
9-
--email="$DOCKER_HUB_EMAIL" \
10-
--username="$DOCKER_HUB_USERNAME" \
11-
--password="$DOCKER_HUB_PASSWORD"
12-
15+
- make init
16+
- make docker:login
1317
- pip install docker-compose
1418

1519
script:
@@ -19,45 +23,16 @@ script:
1923
- docker-compose -f docker-compose-test.yaml up -d
2024

2125
- |-
22-
docker build --tag test \
23-
--build-arg RUN_TESTS=1 \
24-
--build-arg TEST_GITHUB_API_TOKEN=${GITHUB_API_TOKEN} \
25-
--build-arg TEST_GITHUB_ORGANIZATION=${GITHUB_ORGANIZATION} \
26-
--build-arg TEST_GITHUB_TEAM=${GITHUB_TEAM} \
27-
--build-arg TEST_GITHUB_TEAM_ID=${GITHUB_TEAM_ID} \
28-
--build-arg TEST_GITHUB_USER=${GITHUB_USER} \
29-
--build-arg TEST_ETCD_ENDPOINT=http://${ETCD_IP}:2379 \
30-
./
26+
make docker:build \
27+
ARGS="RUN_TESTS \
28+
TEST_GITHUB_API_TOKEN \
29+
TEST_GITHUB_ORGANIZATION \
30+
TEST_GITHUB_TEAM \
31+
TEST_GITHUB_TEAM_ID \
32+
TEST_GITHUB_USER \
33+
TEST_ETCD_ENDPOINT \
34+
"
3135
3236
after_success:
33-
- docker build -t $DOCKER_IMAGE_NAME .
34-
35-
- |-
36-
if [ ! -z "$TRAVIS_TAG" ]; then \
37-
docker tag $DOCKER_IMAGE_NAME $DOCKER_IMAGE_NAME:$TRAVIS_TAG && \
38-
docker push $DOCKER_IMAGE_NAME:$TRAVIS_TAG; \
39-
fi
40-
41-
- |-
42-
if [ ! -z "$TRAVIS_PULL_REQUEST_BRANCH" ]; then \
43-
docker tag $DOCKER_IMAGE_NAME $DOCKER_IMAGE_NAME:pr-$TRAVIS_PULL_REQUEST_BRANCH && \
44-
docker push $DOCKER_IMAGE_NAME:pr-$TRAVIS_PULL_REQUEST_BRANCH; \
45-
fi
46-
47-
- |-
48-
if [[ -z "$TRAVIS_PULL_REQUEST_BRANCH" && ! -z "$TRAVIS_BRANCH" ]]; then \
49-
docker tag $DOCKER_IMAGE_NAME $DOCKER_IMAGE_NAME:$TRAVIS_BRANCH && \
50-
docker push $DOCKER_IMAGE_NAME:$TRAVIS_BRANCH; \
51-
fi
52-
53-
- |-
54-
if [[ -z "$TRAVIS_TAG" && -z "$TRAVIS_PULL_REQUEST_BRANCH" && -z "$TRAVIS_BRANCH" ]]; then \
55-
docker tag $DOCKER_IMAGE_NAME $DOCKER_IMAGE_NAME:latest && \
56-
docker push $DOCKER_IMAGE_NAME:latest; \
57-
fi
58-
59-
- |-
60-
if [[ -z "$TRAVIS_PULL_REQUEST_BRANCH" ]] && [[ "$TRAVIS_BRANCH" == "master" ]]; then \
61-
docker tag $DOCKER_IMAGE_NAME $DOCKER_IMAGE_NAME:latest && \
62-
docker push $DOCKER_IMAGE_NAME:latest; \
63-
fi
37+
- make docker:build
38+
- make travis:docker-tag-and-push

Dockerfile

+8-3
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,14 @@ RUN set -ex \
2626
git \
2727
make \
2828
curl \
29-
&& curl https://glide.sh/get | sh \
30-
&& make deps \
31-
&& ( [[ $RUN_TESTS -eq 0 ]] || make test; ) \
29+
bash \
30+
&& make init \
31+
&& make go:deps-dev \
32+
&& make go:lint \
33+
&& make go:deps-build \
34+
&& make go:deps \
35+
&& ( [[ $RUN_TESTS -eq 0 ]] || make go:test; ) \
36+
&& make go:build \
3237
&& go-wrapper install \
3338
&& rm -rf /go/src \
3439
&& apk del .build-deps

Makefile

+13-64
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,22 @@
1-
GO := $(shell which go)
2-
GLIDE := $(shell which glide)
3-
APP ?= github-authorized-keys
4-
INSTALL_DIR ?= /usr/local/sbin
1+
SHELL = /bin/bash
2+
export BUILD_HARNESS_PATH ?= $(shell until [ -d "build-harness" ] || [ "`pwd`" == '/' ]; do cd ..; done; pwd)/build-harness
3+
-include $(BUILD_HARNESS_PATH)/Makefile
54

6-
include Makefile.*
5+
APP:=github-authorized-keys
6+
COPYRIGHT_SOFTWARE:=Github Authorized Keys
7+
COPYRIGHT_SOFTWARE_DESCRIPTION:=Use GitHub teams to manage system user accounts and authorized_keys
78

8-
## Update table of contents in README.md
9-
.PHONY : update-docs
10-
update-docs:
11-
@doctoc --notitle --github README.md
9+
.PHONY : init
10+
## Init build-harness
11+
init:
12+
@curl --retry 5 --retry-delay 1 https://raw.githubusercontent.com/cloudposse/build-harness/master/bin/install.sh | bash
1213

13-
.PHONY: build
14-
## Build binary
15-
build: $(GO)
16-
$(GO) build -o $(APP)
17-
18-
.PHONY: test
19-
## Run tests
20-
test: $(GO)
21-
$(GO) test $(shell $(GO) list ./... | grep -v /vendor/)
22-
23-
.PHONY: deps
24-
## Install dependencies
25-
deps: $(GLIDE)
26-
$(GLIDE) install
27-
28-
## Clean compiled binary
14+
.PHONY : clean
15+
## Clean build-harness
2916
clean:
30-
rm -f $(APP)
31-
$(GLIDE) remove all
32-
33-
## Install cli
34-
install: $(APP)
35-
cp $(APP) $(INSTALL_DIR)
36-
chmod 755 $(INSTALL_DIR)/$(APP)
17+
@rm -rf $(BUILD_HARNESS_PATH)
3718

38-
.PHONY: lint
39-
## Lint code
40-
lint: $(GO) vet
41-
find . ! -path "*/vendor/*" ! -path "*/.glide/*" -type f -name '*.go' | xargs -n 1 golint
4219

43-
.PHONY: vet
44-
## Vet code
45-
vet: $(GO)
46-
find . ! -path "*/vendor/*" ! -path "*/.glide/*" -type f -name '*.go' | xargs -n 1 $(GO) vet -v
4720

48-
.PHONY: fmt
49-
## Format code according to Golang convention
50-
fmt: $(GO)
51-
find . ! -path "*/vendor/*" ! -path "*/.glide/*" -type f -name '*.go' | xargs -n 1 gofmt -w -l -s
5221

53-
.PHONY: deps-dev
54-
## Install development dependencies
55-
deps-dev: $(GO)
56-
$(GO) get -d -v "github.com/golang/lint"
57-
$(GO) install -v "github.com/golang/lint/golint"
5822

59-
## This help screen
60-
help:
61-
@printf "Available targets:\n\n"
62-
@awk '/^[a-zA-Z\-\_0-9%:\\]+:/ { \
63-
helpMessage = match(lastLine, /^## (.*)/); \
64-
if (helpMessage) { \
65-
helpCommand = $$1; \
66-
helpMessage = substr(lastLine, RSTART + 3, RLENGTH); \
67-
gsub("\\\\", "", helpCommand); \
68-
gsub(":+$$", "", helpCommand); \
69-
printf " \x1b[32;01m%-35s\x1b[0m %s\n", helpCommand, helpMessage; \
70-
} \
71-
} \
72-
{ lastLine = $$0 }' $(MAKEFILE_LIST) | sort -u
73-
@printf "\n"

Makefile.copyright

-21
This file was deleted.

glide.yaml

+4
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ import:
2222
version: v2.3.7
2323
subpackages:
2424
- client.v1
25+
- package: github.com/ugorji/go/codec
26+
version: f4485b318aadd133842532f841dc205a8e339d74
27+
subpackages:
28+
- codec
2529
- package: github.com/Sirupsen/logrus
2630
version: v0.11.0
2731
- package: github.com/valyala/fasttemplate

0 commit comments

Comments
 (0)