Skip to content

Commit 5e76f77

Browse files
authored
Merge pull request #15 from pusher/new-build
New (Prow-enabled) build
2 parents 045d0bc + 7f20a96 commit 5e76f77

File tree

4 files changed

+204
-2
lines changed

4 files changed

+204
-2
lines changed

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,9 @@
1515

1616
# Vendored dependencies
1717
vendor/
18+
19+
# binary
20+
quack
21+
22+
# env file
23+
.env

Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
FROM golang:1.9 AS builder
1+
FROM golang:1.12 AS builder
22
WORKDIR /go/src/github.com/pusher/quack
33
RUN curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh
44

55
COPY . .
66
RUN dep ensure --vendor-only
77
RUN CGO_ENABLED=0 GOOS=linux go build -o /bin/quack github.com/pusher/quack/cmd/quack
88

9-
FROM alpine
9+
FROM alpine:3.10
1010
COPY --from=builder /bin/quack /bin/quack
1111

1212
ENTRYPOINT ["/bin/quack"]

Makefile

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
include .env
2+
BINARY := quack
3+
VERSION := $(shell git describe --always --dirty --tags 2>/dev/null || echo "undefined")
4+
5+
RED := \033[31m
6+
GREEN := \033[32m
7+
NC := \033[0m
8+
9+
IMG ?= quay.io/pusher/quack
10+
11+
.NOTPARALLEL:
12+
13+
.PHONY: all
14+
all: distclean test build
15+
16+
.PHONY: build
17+
build: clean $(BINARY)
18+
19+
.PHONY: clean
20+
clean:
21+
rm -f $(BINARY)
22+
23+
.PHONY: distclean
24+
distclean: clean
25+
rm -rf vendor
26+
rm -rf release
27+
28+
.PHONY: fmt
29+
fmt:
30+
$(GO) fmt ./cmd/... ./pkg/...
31+
32+
.PHONY: vet
33+
vet: vendor
34+
$(GO) vet ./cmd/... ./pkg/...
35+
36+
.PHONY: lint
37+
lint:
38+
@ echo -e "$(GREEN)Linting code$(NC)"
39+
$(LINTER) run --disable-all \
40+
--exclude-use-default=false \
41+
--enable=govet \
42+
--enable=ineffassign \
43+
--enable=deadcode \
44+
--enable=golint \
45+
--enable=goconst \
46+
--enable=gofmt \
47+
--enable=goimports \
48+
--deadline=120s \
49+
--tests ./...
50+
@ echo
51+
52+
vendor:
53+
@ echo -e "$(GREEN)Pulling dependencies$(NC)"
54+
$(DEP) ensure -v --vendor-only
55+
@ echo
56+
57+
.PHONY: test
58+
test: vendor
59+
@ echo -e "$(GREEN)Running test suite$(NC)"
60+
$(GO) test ./...
61+
@ echo
62+
63+
.PHONY: check
64+
check: fmt lint vet test
65+
66+
.PHONY: build
67+
build: clean $(BINARY)
68+
69+
$(BINARY): fmt vet
70+
CGO_ENABLED=0 $(GO) build -o $(BINARY) github.com/pusher/quack/cmd/quack
71+
72+
.PHONY: docker-build
73+
docker-build: check
74+
docker build . -t ${IMG}:${VERSION}
75+
@echo -e "$(GREEN)Built $(IMG):$(VERSION)$(NC)"
76+
77+
TAGS ?= latest
78+
.PHONY: docker-tag
79+
docker-tag: docker-build
80+
@IFS=","; tags=${TAGS}; for tag in $${tags}; do docker tag ${IMG}:${VERSION} ${IMG}:$${tag}; echo -e "$(GREEN)Tagged $(IMG):$(VERSION) as $${tag}$(NC)"; done
81+
82+
PUSH_TAGS ?= ${VERSION}, latest
83+
.PHONY: docker-push
84+
docker-push: docker-build docker-tag
85+
@IFS=","; tags=${PUSH_TAGS}; for tag in $${tags}; do docker push ${IMG}:$${tag}; echo -e "$(GREEN)Pushed $(IMG):$${tag}$(NC)"; done
86+
87+
TAGS ?= latest
88+
.PHONY: docker-clean
89+
docker-clean:
90+
@IFS=","; tags=${TAGS}; for tag in $${tags}; do docker rmi -f ${IMG}:${VERSION} ${IMG}:$${tag}; done

configure

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
#!/usr/bin/env bash
2+
3+
if (( ${BASH_VERSION:0:1} < 4 )); then
4+
echo "This configure script requires bash 4"
5+
exit 1
6+
fi
7+
8+
RED='\033[0;31m'
9+
GREEN='\033[0;32m'
10+
BLUE='\033[0;34m'
11+
NC='\033[0m'
12+
13+
declare -A tools=()
14+
15+
vercomp () {
16+
if [[ $1 == $2 ]]
17+
then
18+
return 0
19+
fi
20+
local IFS=.
21+
local i ver1=($1) ver2=($2)
22+
# fill empty fields in ver1 with zeros
23+
for ((i=${#ver1[@]}; i<${#ver2[@]}; i++))
24+
do
25+
ver1[i]=0
26+
done
27+
for ((i=0; i<${#ver1[@]}; i++))
28+
do
29+
if [[ -z ${ver2[i]} ]]
30+
then
31+
# fill empty fields in ver2 with zeros
32+
ver2[i]=0
33+
fi
34+
if ((10#${ver1[i]} > 10#${ver2[i]}))
35+
then
36+
return 1
37+
fi
38+
if ((10#${ver1[i]} < 10#${ver2[i]}))
39+
then
40+
return 2
41+
fi
42+
done
43+
return 0
44+
}
45+
46+
check_for() {
47+
echo -n "Checking for $1... "
48+
TOOL_PATH=$(command -v $1)
49+
if ! [ -x "$TOOL_PATH" -a -f "$TOOL_PATH" ]; then
50+
printf "${RED}not found${NC}\n"
51+
cd - > /dev/null
52+
exit 1
53+
else
54+
printf "${GREEN}found${NC}\n"
55+
tools[$1]=$TOOL_PATH
56+
fi
57+
}
58+
59+
check_go_env() {
60+
echo -n "Checking \$GOPATH... "
61+
if [ -z "$GOPATH" ]; then
62+
printf "${RED}invalid${NC} - GOPATH not set\n"
63+
exit 1
64+
fi
65+
printf "${GREEN}valid${NC} - $GOPATH\n"
66+
}
67+
68+
check_go_version() {
69+
echo -n "Checking go version... "
70+
GO_VERSION=$(${tools[go]} version | ${tools[awk]} '{where = match($0, /[0-9]\.[0-9]+[\.0-9]*/); if (where != 0) print substr($0, RSTART, RLENGTH)}')
71+
vercomp $GO_VERSION 1.10
72+
case $? in
73+
0) ;&
74+
1)
75+
printf "${GREEN}"
76+
echo $GO_VERSION
77+
printf "${NC}"
78+
;;
79+
2)
80+
printf "${RED}"
81+
echo "$GO_VERSION < 1.10"
82+
exit 1
83+
;;
84+
esac
85+
}
86+
87+
cd ${0%/*}
88+
89+
check_for make
90+
check_for awk
91+
check_for go
92+
check_for dep
93+
check_for golangci-lint
94+
check_go_env
95+
check_go_version
96+
97+
cat <<- EOF > .env
98+
MAKE := ${tools[make]}
99+
SHASUM := ${tools[shasum]}
100+
GO := ${tools[go]}
101+
GOVERSION := $GO_VERSION
102+
DEP := ${tools[dep]}
103+
LINTER := ${tools[golangci-lint]}
104+
EOF
105+
106+
echo "Environment configuration written to .env"

0 commit comments

Comments
 (0)