This repository has been archived by the owner on Nov 17, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #57 from pusher/prow-migration
Migrate CI tasks to Makefile ready for Prow
- Loading branch information
Showing
8 changed files
with
243 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,3 +22,7 @@ vendor/ | |
# Kubernetes config | ||
kubeconfig | ||
credentials/ | ||
|
||
# Local environmental config | ||
.env | ||
k8s-spot-rescheduler |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,28 @@ | ||
FROM golang:1.10 AS builder | ||
ARG VERSION=undefined | ||
|
||
FROM golang:1.12 AS builder | ||
ARG VERSION | ||
|
||
RUN curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh | ||
|
||
WORKDIR /go/src/github.com/pusher/k8s-spot-rescheduler | ||
COPY . . | ||
RUN go get -u github.com/golang/dep/cmd/dep \ | ||
&& dep ensure -v \ | ||
&& env GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -o rescheduler | ||
|
||
FROM scratch | ||
COPY --from=builder /go/src/github.com/pusher/k8s-spot-rescheduler/rescheduler /bin/rescheduler | ||
COPY Gopkg.lock Gopkg.lock | ||
COPY Gopkg.toml Gopkg.toml | ||
|
||
RUN dep ensure --vendor-only | ||
|
||
COPY *.go ./ | ||
COPY deploy deploy/ | ||
COPY metrics metrics/ | ||
COPY nodes nodes/ | ||
COPY scaler scaler/ | ||
|
||
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-X main.VERSION=${VERSION}" -a -o k8s-spot-rescheduler github.com/pusher/k8s-spot-rescheduler | ||
|
||
FROM alpine:3.9 | ||
RUN apk --no-cache add ca-certificates | ||
WORKDIR /bin | ||
COPY --from=builder /go/src/github.com/pusher/k8s-spot-rescheduler/k8s-spot-rescheduler . | ||
|
||
ENTRYPOINT ["/bin/rescheduler"] | ||
ENTRYPOINT ["/bin/k8s-spot-rescheduler"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
include .env | ||
BINARY := k8s-spot-rescheduler | ||
VERSION := $(shell git describe --always --dirty --tags 2>/dev/null || echo "undefined") | ||
|
||
RED := \033[31m | ||
GREEN := \033[32m | ||
NC := \033[0m | ||
|
||
IMG ?= quay.io/pusher/k8s-spot-rescheduler | ||
|
||
.NOTPARALLEL: | ||
|
||
.PHONY: all | ||
all: distclean test build | ||
|
||
.PHONY: build | ||
build: clean $(BINARY) | ||
|
||
.PHONY: clean | ||
clean: | ||
rm -f $(BINARY) | ||
|
||
.PHONY: distclean | ||
distclean: clean | ||
rm -rf vendor | ||
rm -rf release | ||
|
||
.PHONY: fmt | ||
fmt: | ||
$(GO) fmt ./... | ||
|
||
.PHONY: vet | ||
vet: vendor | ||
$(GO) vet ./... | ||
|
||
.PHONY: lint | ||
lint: | ||
@ echo "$(GREEN)Linting code$(NC)" | ||
$(LINTER) run --disable-all \ | ||
--exclude-use-default=false \ | ||
--enable=govet \ | ||
--enable=ineffassign \ | ||
--enable=deadcode \ | ||
--enable=golint \ | ||
--enable=goconst \ | ||
--enable=gofmt \ | ||
--enable=goimports \ | ||
--skip-dirs=pkg/client/ \ | ||
--deadline=120s \ | ||
--tests ./... | ||
@ echo | ||
|
||
vendor: | ||
@ echo "$(GREEN)Pulling dependencies$(NC)" | ||
$(DEP) ensure --vendor-only | ||
@ echo | ||
|
||
.PHONY: test | ||
test: vendor | ||
@ echo "$(GREEN)Running test suite$(NC)" | ||
$(GO) test ./... | ||
@ echo | ||
|
||
.PHONY: check | ||
check: fmt lint vet test | ||
|
||
.PHONY: build | ||
build: clean $(BINARY) | ||
|
||
$(BINARY): fmt vet | ||
CGO_ENABLED=0 $(GO) build -o $(BINARY) -ldflags="-X main.VERSION=${VERSION}" github.com/pusher/k8s-spot-rescheduler | ||
|
||
.PHONY: docker-build | ||
docker-build: check | ||
docker build --build-arg VERSION=${VERSION} . -t ${IMG}:${VERSION} | ||
@echo "$(GREEN)Built $(IMG):$(VERSION)$(NC)" | ||
|
||
TAGS ?= latest | ||
.PHONY: docker-tag | ||
docker-tag: docker-build | ||
@IFS=","; tags=${TAGS}; for tag in $${tags}; do docker tag ${IMG}:${VERSION} ${IMG}:$${tag}; echo "$(GREEN)Tagged $(IMG):$(VERSION) as $${tag}$(NC)"; done | ||
|
||
PUSH_TAGS ?= ${VERSION}, latest | ||
.PHONY: docker-push | ||
docker-push: docker-build docker-tag | ||
@IFS=","; tags=${PUSH_TAGS}; for tag in $${tags}; do docker push ${IMG}:$${tag}; echo "$(GREEN)Pushed $(IMG):$${tag}$(NC)"; done | ||
|
||
TAGS ?= latest | ||
.PHONY: docker-clean | ||
docker-clean: | ||
@IFS=","; tags=${TAGS}; for tag in $${tags}; do docker rmi -f ${IMG}:${VERSION} ${IMG}:$${tag}; done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
#!/usr/bin/env bash | ||
|
||
if (( ${BASH_VERSION:0:1} < 4 )); then | ||
echo "This configure script requires bash 4" | ||
exit 1 | ||
fi | ||
|
||
RED='\033[0;31m' | ||
GREEN='\033[0;32m' | ||
BLUE='\033[0;34m' | ||
NC='\033[0m' | ||
|
||
declare -A tools=() | ||
|
||
vercomp () { | ||
if [[ $1 == $2 ]] | ||
then | ||
return 0 | ||
fi | ||
local IFS=. | ||
local i ver1=($1) ver2=($2) | ||
# fill empty fields in ver1 with zeros | ||
for ((i=${#ver1[@]}; i<${#ver2[@]}; i++)) | ||
do | ||
ver1[i]=0 | ||
done | ||
for ((i=0; i<${#ver1[@]}; i++)) | ||
do | ||
if [[ -z ${ver2[i]} ]] | ||
then | ||
# fill empty fields in ver2 with zeros | ||
ver2[i]=0 | ||
fi | ||
if ((10#${ver1[i]} > 10#${ver2[i]})) | ||
then | ||
return 1 | ||
fi | ||
if ((10#${ver1[i]} < 10#${ver2[i]})) | ||
then | ||
return 2 | ||
fi | ||
done | ||
return 0 | ||
} | ||
|
||
check_for() { | ||
echo -n "Checking for $1... " | ||
TOOL_PATH=$(command -v $1) | ||
if ! [ -x "$TOOL_PATH" -a -f "$TOOL_PATH" ]; then | ||
printf "${RED}not found${NC}\n" | ||
cd - > /dev/null | ||
exit 1 | ||
else | ||
printf "${GREEN}found${NC}\n" | ||
tools[$1]=$TOOL_PATH | ||
fi | ||
} | ||
|
||
check_go_env() { | ||
echo -n "Checking \$GOPATH... " | ||
if [ -z "$GOPATH" ]; then | ||
printf "${RED}invalid${NC} - GOPATH not set\n" | ||
exit 1 | ||
fi | ||
printf "${GREEN}valid${NC} - $GOPATH\n" | ||
} | ||
|
||
check_go_version() { | ||
echo -n "Checking go version... " | ||
GO_VERSION=$(${tools[go]} version | ${tools[awk]} '{where = match($0, /[0-9]\.[0-9]+[\.0-9]*/); if (where != 0) print substr($0, RSTART, RLENGTH)}') | ||
vercomp $GO_VERSION 1.10 | ||
case $? in | ||
0) ;& | ||
1) | ||
printf "${GREEN}" | ||
echo $GO_VERSION | ||
printf "${NC}" | ||
;; | ||
2) | ||
printf "${RED}" | ||
echo "$GO_VERSION < 1.10" | ||
exit 1 | ||
;; | ||
esac | ||
} | ||
|
||
cd ${0%/*} | ||
|
||
check_for make | ||
check_for awk | ||
check_for go | ||
check_for dep | ||
check_for golangci-lint | ||
check_for shasum | ||
check_go_env | ||
check_go_version | ||
|
||
cat <<- EOF > .env | ||
MAKE := ${tools[make]} | ||
SHASUM := ${tools[shasum]} | ||
GO := ${tools[go]} | ||
GOVERSION := $GO_VERSION | ||
DEP := ${tools[dep]} | ||
LINTER := ${tools[golangci-lint]} | ||
EOF | ||
|
||
echo "Environment configuration written to .env" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package main | ||
|
||
// VERSION contains injected version information | ||
var VERSION = "undefined" |
This file was deleted.
Oops, something went wrong.