Skip to content

Commit

Permalink
Update makefiles to generate proper filenames
Browse files Browse the repository at this point in the history
I took this opportunity to overhaul them makefiles with other changes:

* get rid of *-runtime/*-client targets, now we just build the matrix
* quiet the clean target
* install using porter mixin install
* consolidate targets for the internal / external mixins
* moved code gen into the same makefile that handles building code
  • Loading branch information
carolynvs-msft committed Apr 16, 2019
1 parent 55d54d7 commit 2bfba65
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 104 deletions.
125 changes: 43 additions & 82 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,85 +24,46 @@ else
FILE_EXT=
endif

MIXIN_TAG ?= canary
HELM_MIXIN_URL = https://deislabs.blob.core.windows.net/porter/mixins/helm/$(MIXIN_TAG)/helm
AZURE_MIXIN_URL = https://deislabs.blob.core.windows.net/porter/mixins/azure/$(MIXIN_TAG)/azure
TERRAFORM_MIXIN_URL = https://deislabs.blob.core.windows.net/porter/mixins/terraform/$(MIXIN_TAG)/terraform

build: build-client build-runtime azure helm terraform

build-runtime: generate
$(MAKE) $(MAKE_OPTS) build-runtime MIXIN=porter -f mixin.mk BINDIR=bin
$(MAKE) $(MAKE_OPTS) build-runtime MIXIN=exec -f mixin.mk
$(MAKE) $(MAKE_OPTS) build-runtime MIXIN=kubernetes -f mixin.mk

build-client: generate
$(MAKE) $(MAKE_OPTS) build-client MIXIN=porter -f mixin.mk BINDIR=bin
$(MAKE) $(MAKE_OPTS) build-client MIXIN=exec -f mixin.mk
$(MAKE) $(MAKE_OPTS) build-client MIXIN=kubernetes -f mixin.mk

generate: packr2
go generate ./...

HAS_PACKR2 := $(shell command -v packr2)
packr2:
ifndef HAS_PACKR2
go get -u github.com/gobuffalo/packr/v2/packr2
endif
INT_MIXINS = exec kubernetes
EXT_MIXINS = helm azure terraform
MIXIN_TAG ?= canary
MIXINS_URL = https://deislabs.blob.core.windows.net/porter/mixins

.PHONY: build
build: build-porter build-mixins get-mixins

build-porter:
$(MAKE) $(MAKE_OPTS) build MIXIN=porter -f mixin.mk BINDIR=bin

xbuild-all:
build-mixins: $(addprefix build-mixin-,$(INT_MIXINS))
build-mixin-%:
$(MAKE) $(MAKE_OPTS) build MIXIN=$* -f mixin.mk

xbuild-all: xbuild-porter xbuild-mixins

xbuild-porter:
$(MAKE) $(MAKE_OPTS) xbuild-all MIXIN=porter -f mixin.mk BINDIR=bin
$(MAKE) $(MAKE_OPTS) xbuild-all MIXIN=exec -f mixin.mk
$(MAKE) $(MAKE_OPTS) xbuild-all MIXIN=kubernetes -f mixin.mk

xbuild-runtime:
$(MAKE) $(MAKE_OPTS) xbuild-runtime MIXIN=porter -f mixin.mk BINDIR=bin
$(MAKE) $(MAKE_OPTS) xbuild-runtime MIXIN=exec -f mixin.mk
$(MAKE) $(MAKE_OPTS) xbuild-runtime MIXIN=kubernetes -f mixin.mk

xbuild-client:
$(MAKE) $(MAKE_OPTS) xbuild-client MIXIN=porter -f mixin.mk BINDIR=bin
$(MAKE) $(MAKE_OPTS) xbuild-client MIXIN=exec -f mixin.mk
$(MAKE) $(MAKE_OPTS) xbuild-client MIXIN=kubernetes -f mixin.mk

bin/mixins/helm/helm:
mkdir -p bin/mixins/helm
curl -f -o bin/mixins/helm/helm $(HELM_MIXIN_URL)-$(CLIENT_PLATFORM)-$(CLIENT_ARCH)
chmod +x bin/mixins/helm/helm
bin/mixins/helm/helm version

bin/mixins/helm/helm-runtime:
mkdir -p bin/mixins/helm
curl -f -o bin/mixins/helm/helm-runtime $(HELM_MIXIN_URL)-runtime-$(RUNTIME_PLATFORM)-$(RUNTIME_ARCH)
chmod +x bin/mixins/helm/helm-runtime

helm: bin/mixins/helm/helm bin/mixins/helm/helm-runtime

bin/mixins/azure/azure:
mkdir -p bin/mixins/azure
curl -f -o bin/mixins/azure/azure $(AZURE_MIXIN_URL)-$(CLIENT_PLATFORM)-$(CLIENT_ARCH)
chmod +x bin/mixins/azure/azure
bin/mixins/azure/azure version

bin/mixins/azure/azure-runtime:
mkdir -p bin/mixins/azure
curl -f -o bin/mixins/azure/azure-runtime $(AZURE_MIXIN_URL)-runtime-$(RUNTIME_PLATFORM)-$(RUNTIME_ARCH)
chmod +x bin/mixins/azure/azure-runtime

azure: bin/mixins/azure/azure bin/mixins/azure/azure-runtime

bin/mixins/terraform/terraform:
mkdir -p bin/mixins/terraform
curl -f -o bin/mixins/terraform/terraform $(TERRAFORM_MIXIN_URL)-$(CLIENT_PLATFORM)-$(CLIENT_ARCH)
chmod +x bin/mixins/terraform/terraform
bin/mixins/terraform/terraform version

bin/mixins/terraform/terraform-runtime:
mkdir -p bin/mixins/terraform
curl -f -o bin/mixins/terraform/terraform-runtime $(TERRAFORM_MIXIN_URL)-runtime-$(RUNTIME_PLATFORM)-$(RUNTIME_ARCH)
chmod +x bin/mixins/terraform/terraform-runtime

terraform: bin/mixins/terraform/terraform bin/mixins/terraform/terraform-runtime

xbuild-mixins: $(addprefix xbuild-mixin-,$(INT_MIXINS))
xbuild-mixins-%:
$(MAKE) $(MAKE_OPTS) xbuild-all MIXIN=$* -f mixin.mk

get-mixins: $(addprefix get-mixin-,$(EXT_MIXINS))

bin/porter:
$(MAKE) build-porter

get-mixin-helm: bin/mixins/helm/helm
bin/mixins/helm/helm: bin/porter
bin/porter mixin install helm --version $(MIXIN_TAG) --url $(MIXINS_URL)/helm

get-mixin-azure: bin/mixins/azure/azure
bin/mixins/azure/azure: bin/porter
bin/porter mixin install azure --version $(MIXIN_TAG) --url $(MIXINS_URL)/azure

get-mixin-terraform: bin/mixins/terraform/terraform
bin/mixins/terraform/terraform: bin/porter
bin/porter mixin install terraform --version $(MIXIN_TAG) --url $(MIXINS_URL)/terraform

verify: verify-vendor

Expand Down Expand Up @@ -157,8 +118,8 @@ install: build
ln -f -s $(HOME)/.porter/porter /usr/local/bin/porter

clean:
-rm -fr bin/
-rm -fr cnab/
-rm porter.yaml Dockerfile bundle.json
-helm delete --purge porter-ci-mysql
-helm delete --purge porter-ci-wordpress
@-rm -fr bin/
@-rm -fr cnab/
@-rm porter.yaml Dockerfile bundle.json
@-helm delete --purge porter-ci-mysql
@-helm delete --purge porter-ci-wordpress
44 changes: 22 additions & 22 deletions mixin.mk
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,10 @@ LDFLAGS = -w -X $(PKG)/pkg.Version=$(VERSION) -X $(PKG)/pkg.Commit=$(COMMIT)
XBUILD = CGO_ENABLED=0 go build -a -tags netgo -ldflags '$(LDFLAGS)'
BINDIR ?= bin/mixins/$(MIXIN)

CLIENT_PLATFORM = $(shell go env GOOS)
CLIENT_ARCH = $(shell go env GOARCH)
RUNTIME_PLATFORM = linux
RUNTIME_ARCH = amd64
SUPPORTED_CLIENT_PLATFORMS = linux darwin windows
SUPPORTED_CLIENT_ARCHES = amd64 386
CLIENT_PLATFORM ?= $(shell go env GOOS)
CLIENT_ARCH ?= $(shell go env GOARCH)
SUPPORTED_PLATFORMS = linux darwin windows
SUPPORTED_ARCHES = amd64

ifeq ($(CLIENT_PLATFORM),windows)
FILE_EXT=.exe
Expand All @@ -27,29 +25,31 @@ else
FILE_EXT=
endif

build: build-client build-runtime

build-runtime:
mkdir -p $(BINDIR)
GOARCH=$(RUNTIME_ARCH) GOOS=$(RUNTIME_PLATFORM) go build -ldflags '$(LDFLAGS)' -o $(BINDIR)/$(MIXIN)-runtime$(FILE_EXT) ./cmd/$(MIXIN)

build-client:
.PHONY: build
build: generate
mkdir -p $(BINDIR)
go build -ldflags '$(LDFLAGS)' -o $(BINDIR)/$(MIXIN)$(FILE_EXT) ./cmd/$(MIXIN)

xbuild-all: xbuild-runtime $(addprefix xbuild-for-,$(SUPPORTED_CLIENT_PLATFORMS))

xbuild-for-%:
$(MAKE) $(MAKE_OPTS) CLIENT_PLATFORM=$* MIXIN=$(MIXIN) xbuild-client -f mixin.mk
xbuild-all:
$(foreach OS, $(SUPPORTED_PLATFORMS), \
$(foreach ARCH, $(SUPPORTED_ARCHES), \
$(MAKE) $(MAKE_OPTS) CLIENT_PLATFORM=$(OS) CLIENT_ARCH=$(ARCH) MIXIN=$(MIXIN) xbuild -f mixin.mk; \
))

xbuild-runtime:
GOARCH=$(RUNTIME_ARCH) GOOS=$(RUNTIME_PLATFORM) $(XBUILD) -o $(BINDIR)/$(VERSION)/$(MIXIN)-runtime-$(RUNTIME_PLATFORM)-$(RUNTIME_ARCH)$(FILE_EXT) ./cmd/$(MIXIN)

xbuild-client: $(BINDIR)/$(VERSION)/$(MIXIN)-$(CLIENT_PLATFORM)-$(CLIENT_ARCH)$(FILE_EXT)
$(BINDIR)/$(VERSION)/$(MIXIN)-$(CLIENT_PLATFORM)-$(CLIENT_ARCH)$(FILE_EXT):
xbuild: $(BINDIR)/$(VERSION)/$(MIXIN)-$(CLIENT_PLATFORM)-$(CLIENT_ARCH)$(FILE_EXT)
$(BINDIR)/$(VERSION)/$(MIXIN)-$(CLIENT_PLATFORM)-$(CLIENT_ARCH)$(FILE_EXT): generate
mkdir -p $(dir $@)
GOOS=$(CLIENT_PLATFORM) GOARCH=$(CLIENT_ARCH) $(XBUILD) -o $@ ./cmd/$(MIXIN)

generate: packr2
go generate ./...

HAS_PACKR2 := $(shell command -v packr2)
packr2:
ifndef HAS_PACKR2
go get -u github.com/gobuffalo/packr/v2/packr2
endif

publish:
# AZURE_STORAGE_CONNECTION_STRING will be used for auth in the following commands
if [[ "$(PERMALINK)" == "latest" ]]; then \
Expand Down

0 comments on commit 2bfba65

Please sign in to comment.