Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not encode -runtime into mixin download filename #272

Merged
merged 3 commits into from
Apr 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
104 changes: 33 additions & 71 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,23 @@ 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
INT_MIXINS = exec kubernetes
EXT_MIXINS = helm azure terraform
MIXIN_TAG ?= canary
MIXINS_URL = https://deislabs.blob.core.windows.net/porter/mixins

build: build-client build-runtime azure helm terraform
.PHONY: build
build: build-porter build-mixins get-mixins

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-porter: generate
$(MAKE) $(MAKE_OPTS) build MIXIN=porter -f mixin.mk BINDIR=bin

build-client: generate
build-porter-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

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

generate: packr2
go generate ./...
Expand All @@ -50,59 +51,19 @@ ifndef HAS_PACKR2
go get -u github.com/gobuffalo/packr/v2/packr2
endif

xbuild-all:
xbuild-all: xbuild-porter xbuild-mixins

xbuild-porter: generate
$(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-mixin-%: generate
$(MAKE) $(MAKE_OPTS) xbuild-all MIXIN=$* -f mixin.mk

get-mixins:
$(foreach MIXIN, $(EXT_MIXINS), \
bin/porter mixin install $(MIXIN) --version $(MIXIN_TAG) --url $(MIXINS_URL)/$(MIXIN); \
)

verify: verify-vendor

Expand All @@ -116,12 +77,12 @@ ifndef HAS_DEP
endif
dep version

test: clean test-unit test-cli
test: clean-last-testrun test-unit test-cli

test-unit: build
go test ./...

test-cli: clean build init-porter-home-for-ci
test-cli: clean-last-testrun build init-porter-home-for-ci
PORTER_HOME=$(PORTER_HOME) REGISTRY=$(REGISTRY) KUBECONFIG=$(KUBECONFIG) ./scripts/test/test-cli.sh

init-porter-home-for-ci:
Expand Down Expand Up @@ -156,9 +117,10 @@ install: build
cp -R bin/* $(HOME)/.porter/
ln -f -s $(HOME)/.porter/porter /usr/local/bin/porter

clean:
clean: clean-mixins clean-last-testrun

clean-mixins:
-rm -fr bin/
-rm -fr cnab/
-rm porter.yaml Dockerfile bundle.json
-helm delete --purge porter-ci-mysql
-helm delete --purge porter-ci-wordpress

clean-last-testrun:
-rm -fr cnab/ porter.yaml Dockerfile bundle.json
5 changes: 2 additions & 3 deletions docs/content/mixin-distribution.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ for our DeisLabs mixins helpful as a starting point.
Porter expects mixins to be published with a specific naming convention:

* client: `VERSION/MIXIN-GOOS-GOARCH[FILE-EXT]`
* runtime: `VERSION/MIXIN-runtime-linux-amd64`
* runtime: `VERSION/MIXIN-linux-amd64`

\* Note: Porter uses `GOOS` and `GOARCH` which are terms from the Go programming
language, because it is written in Go. You must use the same terms, for example
Expand All @@ -41,7 +41,6 @@ base url/
└── v0.4.0-ralpha.1+dubonnet
├── exec-darwin-amd64
├── exec-linux-amd64
├── exec-runtime-linux-amd64
└── exec-windows-amd64.exe
```

Expand All @@ -59,7 +58,7 @@ porter mixin install NAME --version VERSION --url URL
```

* client url: `URL/VERSION/NAME-GOOS-GOARCH[FILE_EXT]`
* runtime url: `URL/VERSION/NAME-runtime-linux-amd64`
* runtime url: `URL/VERSION/NAME-linux-amd64`

When `--version` is not specified, it is defaulted to `latest` which should
represent the most recent version of the mixin.
Expand Down
29 changes: 14 additions & 15 deletions mixin.mk
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ 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)
RUNTIME_PLATFORM ?= linux
RUNTIME_ARCH ?= amd64
SUPPORTED_PLATFORMS = linux darwin windows
SUPPORTED_ARCHES = amd64

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

.PHONY: build
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)
GOARCH=$(RUNTIME_ARCH) GOOS=$(RUNTIME_PLATFORM) $(XBUILD) -o $(BINDIR)/$(MIXIN)-runtime$(FILE_EXT) ./cmd/$(MIXIN)

build-client:
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-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-for-%:
$(MAKE) $(MAKE_OPTS) CLIENT_PLATFORM=$* MIXIN=$(MIXIN) xbuild-client -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)
xbuild: $(BINDIR)/$(VERSION)/$(MIXIN)-$(CLIENT_PLATFORM)-$(CLIENT_ARCH)$(FILE_EXT)
$(BINDIR)/$(VERSION)/$(MIXIN)-$(CLIENT_PLATFORM)-$(CLIENT_ARCH)$(FILE_EXT):
mkdir -p $(dir $@)
GOOS=$(CLIENT_PLATFORM) GOARCH=$(CLIENT_ARCH) $(XBUILD) -o $@ ./cmd/$(MIXIN)
Expand Down
2 changes: 1 addition & 1 deletion pkg/mixin/provider/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func (p *FileSystem) Install(opts mixin.InstallOptions) (mixin.Metadata, error)
}

runtimeUrl := opts.GetParsedURL()
runtimeUrl.Path = path.Join(runtimeUrl.Path, opts.Version, fmt.Sprintf("%s-runtime-linux-amd64", opts.Name))
runtimeUrl.Path = path.Join(runtimeUrl.Path, opts.Version, fmt.Sprintf("%s-linux-amd64", opts.Name))
runtimePath := filepath.Join(mixinDir, opts.Name+"-runtime")
err = p.downloadFile(runtimeUrl, runtimePath)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/mixin/provider/install_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func TestFileSystem_Install_RollbackBadDownload(t *testing.T) {
func TestFileSystem_Install_RollbackMissingRuntime(t *testing.T) {
// serve out a fake mixin
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if strings.Contains(r.RequestURI, "runtime") {
if strings.Contains(r.RequestURI, "linux-amd64") {
w.WriteHeader(400)
} else {
fmt.Fprintf(w, "#!/usr/bin/env bash\necho i am a client mixxin\n")
Expand Down