Skip to content
This repository has been archived by the owner on Jan 23, 2024. It is now read-only.

Commit

Permalink
Adapt Makefile to be similar to Gardener's Makefile
Browse files Browse the repository at this point in the history
  • Loading branch information
rfranzke authored and msohn committed Jan 17, 2018
1 parent dbdb9eb commit e7f9fa0
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 121 deletions.
50 changes: 23 additions & 27 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@ VCS := github.com
ORGANIZATION := gardener
PROJECT := aws-lb-readvertiser
REPOSITORY := $(VCS)/$(ORGANIZATION)/$(PROJECT)
VERSION := v0.0.2
VERSION := $(shell cat VERSION)
LD_FLAGS := "-w -X $(REPOSITORY)/pkg/version.Version=$(VERSION)"
PACKAGES := $(shell go list ./... | grep -v '/vendor/')
REGISTRY := eu.gcr.io/sap-cloud-platform-dev1
IMAGE_REPOSITORY := $(REGISTRY)/garden/$(PROJECT)
IMAGE_TAG := $(VERSION)

BIN_DIR := bin
GOBIN := $(PWD)/bin
PATH := $(GOBIN):$(PATH)
USER := $(shell id -u -n)
Expand All @@ -35,28 +36,25 @@ verify: vet fmt lint test

.PHONY: revendor
revendor:
@glide up -v
@glide-vc --use-lock-file --no-tests --only-code
@dep ensure -update
@dep prune


.PHONY: build
build: bin/aws-lb-readvertiser
build:
@go build -o $(BIN_DIR)/aws-lb-readvertiser $(GO_EXTRA_FLAGS) -ldflags $(LD_FLAGS) main.go

.PHONY: release
release: build docker-build docker-image docker-login docker-push rename-binaries clean

bin/aws-lb-readvertiser: check-go-version
@go install -v -ldflags $(LD_FLAGS) $(REPOSITORY)/
release: build docker-build docker-image docker-login docker-push rename-binaries

.PHONY: build-release
build-release:
@go build -o /go/bin/aws-lb-readvertiser -v -ldflags $(LD_FLAGS) $(REPOSITORY)/
@go build -o /go/bin/aws-lb-readvertiser $(GO_EXTRA_FLAGS) -ldflags $(LD_FLAGS) main.go

.PHONY: docker-build
docker-build: rel/bin/aws-lb-readvertiser

rel/bin/aws-lb-readvertiser:
@./scripts/build-release
@sudo chown $(user):$(group) rel/bin/aws-lb-readvertiser
docker-build:
@./hack/build-release
@sudo chown $(user):$(group) $(BIN_DIR)/rel/aws-lb-readvertiser

.PHONY: docker-image
docker-image:
Expand All @@ -74,8 +72,15 @@ docker-push:

.PHONY: rename-binaries
rename-binaries:
@cp bin/aws-lb-readvertiser aws-lb-readvertiser-darwin-amd64
@cp rel/bin/aws-lb-readvertiser aws-lb-readvertiser-linux-amd64
@if [[ -f $(BIN_DIR)/aws-lb-readvertiser ]]; then cp $(BIN_DIR)/aws-lb-readvertiser aws-lb-readvertiser-darwin-amd64; fi
@if [[ -f $(BIN_DIR)/rel/aws-lb-readvertiser ]]; then cp $(BIN_DIR)/rel/aws-lb-readvertiser aws-lb-readvertiser-linux-amd64; fi


.PHONY: clean
clean:
@rm -rf $(BIN_DIR)/
@rm -f *linux-amd64
@rm -f *darwin-amd64

.PHONY: fmt
fmt:
Expand All @@ -88,18 +93,9 @@ vet:
.PHONY: lint
lint:
@for package in $(PACKAGES); do \
golint -set_exit_status $$package $$i || exit 1; \
golint -set_exit_status $$(find $$package -maxdepth 1 -name "*.go" | grep -vE 'zz_generated|_test.go') || exit 1; \
done

.PHONY: test
test:
@go test $(PACKAGES)

.PHONY: check-go-version
check-go-version:
@./scripts/check-go-version

.PHONY: clean
clean:
@rm -rf bin/
@rm -rf rel/
@ginkgo -r pkg
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ The `kube-apiserver` deployment must reside in the same namespace as the Readver

## How to build it?

:warning: Please don't forget to update the `$VERSION` variable in the `Makefile` before creating a new release:
:warning: Please don't forget to update the content of the `VERSION` file before creating a new release:

```bash
$ make release
Expand Down
1 change: 1 addition & 0 deletions VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.0.2
17 changes: 9 additions & 8 deletions scripts/build-release → hack/build-release
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,20 @@
# See the License for the specific language governing permissions and
# limitations under the License.

mkdir -p rel/bin

BINARY="aws-lb-readvertiser"
REL_DIR="$(dirname $0)/../bin/rel"
REPOSITORY="github.com/gardener/aws-lb-readvertiser"
BINARY="aws-lb-readvertiser"

mkdir -p $REL_DIR

sudo docker run \
--cidfile=cid \
--cidfile=$BINARY-cid \
-v $PWD:/go/src/$REPOSITORY:ro \
-w /go/src/$REPOSITORY \
golang:1.8.0-alpine \
golang:1.9.2-alpine3.7 \
/bin/sh -x -c \
'apk add --no-cache --update alpine-sdk && make build-release'

sudo docker cp $(cat cid):/go/bin/$BINARY rel/bin/$BINARY
sudo docker rm $(cat cid)
sudo rm cid
sudo docker cp $(cat $BINARY-cid):/go/bin/$BINARY $REL_DIR/$BINARY
sudo docker rm $(cat $BINARY-cid)
sudo rm $BINARY-cid
46 changes: 0 additions & 46 deletions scripts/check-go-version

This file was deleted.

39 changes: 0 additions & 39 deletions scripts/git-version

This file was deleted.

0 comments on commit e7f9fa0

Please sign in to comment.