-
Notifications
You must be signed in to change notification settings - Fork 106
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
Add ability to export/launch Windows-based images #310
Changes from all commits
951f092
4f069b9
0bdce47
18c9b9f
ae3507e
539f081
79dc3ae
3474231
5981f5c
d7df44e
5c4d64f
4ee9527
5a8a481
0c5c2f1
77d86a0
a14a853
0386084
3c77d7f
bb8a894
c143b70
19f5009
78886b6
ba20c05
aabeb66
2324097
1af518a
a2a8e32
c808922
0880d8e
e2f9687
78787a3
79c6b3d
27587be
b62429e
5e2f700
eb421a1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
out |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,15 @@ | ||
ifeq ($(OS),Windows_NT) | ||
SHELL:=cmd.exe | ||
PWD?=$(subst /,\,${CURDIR}) | ||
LDFLAGS=-s -w | ||
BLANK:= | ||
/:=\$(BLANK) | ||
LIFECYCLE_VERSION?=$(shell type VERSION) | ||
else | ||
/:=/ | ||
LIFECYCLE_VERSION?=$(shell cat VERSION) | ||
endif | ||
|
||
GOCMD?=go | ||
GOARCH?=amd64 | ||
GOENV=GOARCH=$(GOARCH) CGO_ENABLED=0 | ||
|
@@ -8,38 +20,34 @@ LDFLAGS+=-X 'github.com/buildpacks/lifecycle/cmd.SCMCommit=$(SCM_COMMIT)' | |
LDFLAGS+=-X 'github.com/buildpacks/lifecycle/cmd.PlatformAPI=$(PLATFORM_API)' | ||
GOBUILD=go build $(GOFLAGS) -ldflags "$(LDFLAGS)" | ||
GOTEST=$(GOCMD) test $(GOFLAGS) | ||
LIFECYCLE_VERSION?=$(shell cat VERSION) | ||
PLATFORM_API?=0.3 | ||
BUILDPACK_API?=0.2 | ||
SCM_REPO?=github.com/buildpacks/lifecycle | ||
PARSED_COMMIT:=$(shell git rev-parse --short HEAD) | ||
SCM_COMMIT?=$(PARSED_COMMIT) | ||
BUILD_DIR?=$(PWD)/out | ||
COMPILATION_IMAGE?=golang:1.13-alpine | ||
|
||
define LIFECYCLE_DESCRIPTOR | ||
[api] | ||
platform = "$(PLATFORM_API)" | ||
buildpack = "$(BUILDPACK_API)" | ||
|
||
[lifecycle] | ||
version = "$(LIFECYCLE_VERSION)" | ||
endef | ||
BUILD_DIR?=$(PWD)$/out | ||
LINUX_COMPILATION_IMAGE?=golang:1.14-alpine | ||
WINDOWS_COMPILATION_IMAGE?=golang:1.14-windowsservercore-1809 | ||
SOURCE_COMPILATION_IMAGE?=lifecycle-img | ||
BUILD_CTR?=lifecycle-ctr | ||
DOCKER_CMD?=make test | ||
|
||
all: test build package | ||
|
||
build: build-linux build-windows | ||
|
||
build-linux: build-linux-lifecycle build-linux-symlinks build-linux-launcher | ||
build-windows: build-windows-lifecycle build-windows-symlinks build-windows-launcher | ||
|
||
build-linux-lifecycle: export GOOS:=linux | ||
build-linux-lifecycle: OUT_DIR:=$(BUILD_DIR)/$(GOOS)/lifecycle | ||
build-linux-lifecycle: GOENV:=GOARCH=$(GOARCH) CGO_ENABLED=1 | ||
build-linux-lifecycle: DOCKER_RUN=docker run --workdir=/lifecycle -v $(OUT_DIR):/out -v $(PWD):/lifecycle $(COMPILATION_IMAGE) | ||
build-linux-lifecycle: DOCKER_RUN=docker run --workdir=/lifecycle -v $(OUT_DIR):/out -v $(PWD):/lifecycle $(LINUX_COMPILATION_IMAGE) | ||
build-linux-lifecycle: | ||
@echo "> Building lifecycle/lifecycle for linux..." | ||
mkdir -p $(OUT_DIR) | ||
$(DOCKER_RUN) sh -c 'apk add build-base && $(GOENV) $(GOBUILD) -o /out/lifecycle -a ./cmd/lifecycle' | ||
|
||
|
||
build-linux-launcher: export GOOS:=linux | ||
build-linux-launcher: OUT_DIR?=$(BUILD_DIR)/$(GOOS)/lifecycle | ||
build-linux-launcher: | ||
|
@@ -60,30 +68,45 @@ build-linux-symlinks: | |
ln -sf lifecycle $(OUT_DIR)/rebaser | ||
ln -sf lifecycle $(OUT_DIR)/creator | ||
|
||
build-linux: build-linux-lifecycle build-linux-symlinks build-linux-launcher | ||
|
||
build-windows: export GOOS:=windows | ||
build-windows: OUT_DIR:=$(BUILD_DIR)/$(GOOS)/lifecycle | ||
build-windows: | ||
@echo "> Building for windows..." | ||
mkdir -p $(OUT_DIR) | ||
$(GOENV) $(GOBUILD) -o $(OUT_DIR)/launcher -a ./cmd/launcher | ||
test $$(du -m $(OUT_DIR)/launcher|cut -f 1) -le 3 | ||
$(GOENV) $(GOBUILD) -o $(OUT_DIR)/lifecycle.exe -a ./cmd/lifecycle | ||
ln -sf lifecycle.exe $(OUT_DIR)/analyzer.exe | ||
ln -sf lifecycle.exe $(OUT_DIR)/restorer.exe | ||
ln -sf lifecycle.exe $(OUT_DIR)/builder.exe | ||
ln -sf lifecycle.exe $(OUT_DIR)/exporter.exe | ||
ln -sf lifecycle.exe $(OUT_DIR)/rebaser.exe | ||
ln -sf lifecycle.exe $(OUT_DIR)/creator.exe | ||
build-windows-lifecycle: export GOOS:=windows | ||
build-windows-lifecycle: OUT_DIR?=$(BUILD_DIR)$/$(GOOS)$/lifecycle | ||
build-windows-lifecycle: | ||
@echo "> Building lifecycle/lifecycle for Windows..." | ||
$(GOBUILD) -o $(OUT_DIR)$/lifecycle.exe -a ./cmd/lifecycle | ||
|
||
build-windows-launcher: export GOOS:=windows | ||
build-windows-launcher: OUT_DIR?=$(BUILD_DIR)$/$(GOOS)$/lifecycle | ||
build-windows-launcher: | ||
@echo "> Building lifecycle/launcher for Windows..." | ||
$(GOBUILD) -o $(OUT_DIR)$/launcher.exe -a ./cmd/launcher | ||
|
||
build-windows-symlinks: export GOOS:=windows | ||
build-windows-symlinks: OUT_DIR?=$(BUILD_DIR)$/$(GOOS)$/lifecycle | ||
build-windows-symlinks: | ||
@echo "> Creating phase symlinks for Windows..." | ||
ifeq ($(OS),Windows_NT) | ||
call mklink $(OUT_DIR)$/detector.exe lifecycle.exe | ||
call mklink $(OUT_DIR)$/analyzer.exe lifecycle.exe | ||
call mklink $(OUT_DIR)$/restorer.exe lifecycle.exe | ||
call mklink $(OUT_DIR)$/builder.exe lifecycle.exe | ||
call mklink $(OUT_DIR)$/exporter.exe lifecycle.exe | ||
call mklink $(OUT_DIR)$/rebaser.exe lifecycle.exe | ||
else | ||
ln -sf lifecycle.exe $(OUT_DIR)$/detector.exe | ||
ln -sf lifecycle.exe $(OUT_DIR)$/analyzer.exe | ||
ln -sf lifecycle.exe $(OUT_DIR)$/restorer.exe | ||
ln -sf lifecycle.exe $(OUT_DIR)$/builder.exe | ||
ln -sf lifecycle.exe $(OUT_DIR)$/exporter.exe | ||
ln -sf lifecycle.exe $(OUT_DIR)$/rebaser.exe | ||
endif | ||
|
||
build-darwin: export GOOS:=darwin | ||
build-darwin: OUT_DIR:=$(BUILD_DIR)/$(GOOS)/lifecycle | ||
build-darwin: | ||
@echo "> Building for macos..." | ||
mkdir -p $(OUT_DIR) | ||
$(GOENV) $(GOBUILD) -o $(OUT_DIR)/launcher -a ./cmd/launcher | ||
test $$(du -m $(OUT_DIR)/launcher|cut -f 1) -le 3 | ||
test $$(du -m $(OUT_DIR)/launcher|cut -f 1) -le 4 | ||
$(GOENV) $(GOBUILD) -o $(OUT_DIR)/lifecycle -a ./cmd/lifecycle | ||
ln -sf lifecycle $(OUT_DIR)/detector | ||
ln -sf lifecycle $(OUT_DIR)/analyzer | ||
|
@@ -94,19 +117,19 @@ build-darwin: | |
|
||
install-goimports: | ||
@echo "> Installing goimports..." | ||
cd tools; $(GOCMD) install golang.org/x/tools/cmd/goimports | ||
cd tools && $(GOCMD) install golang.org/x/tools/cmd/goimports | ||
|
||
install-yj: | ||
@echo "> Installing yj..." | ||
cd tools; $(GOCMD) install github.com/sclevine/yj | ||
cd tools && $(GOCMD) install github.com/sclevine/yj | ||
|
||
install-mockgen: | ||
@echo "> Installing mockgen..." | ||
cd tools; $(GOCMD) install github.com/golang/mock/mockgen | ||
cd tools && $(GOCMD) install github.com/golang/mock/mockgen | ||
|
||
install-golangci-lint: | ||
@echo "> Installing golangci-lint..." | ||
cd tools; $(GOCMD) install github.com/golangci/golangci-lint/cmd/golangci-lint | ||
cd tools && $(GOCMD) install github.com/golangci/golangci-lint/cmd/golangci-lint | ||
|
||
lint: install-golangci-lint | ||
@echo "> Linting code..." | ||
|
@@ -119,23 +142,19 @@ generate: install-mockgen | |
|
||
format: install-goimports | ||
@echo "> Formating code..." | ||
test -z $$(goimports -l -w -local github.com/buildpacks/lifecycle .) | ||
|
||
verify-jq: | ||
ifeq (, $(shell which jq)) | ||
$(error "No jq in $$PATH, please install jq") | ||
endif | ||
$(if $(shell goimports -l -w -local github.com/buildpacks/lifecycle .), @echo Fixed formatting errors. Re-run && exit 1) | ||
|
||
test: unit acceptance | ||
|
||
unit: verify-jq format lint install-yj | ||
unit: UNIT_PACKAGES=$(shell $(GOCMD) list ./... | grep -v acceptance) | ||
unit: format lint install-yj | ||
@echo "> Running unit tests..." | ||
$(GOTEST) -v -count=1 $$($(GOCMD) list ./... | grep -v acceptance) | ||
$(GOTEST) -v -count=1 $(UNIT_PACKAGES) | ||
ameyer-pivotal marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
acceptance: format lint | ||
@echo "> Running acceptance tests..." | ||
$(GOTEST) -v -count=1 -tags=acceptance ./acceptance/... | ||
|
||
acceptance-darwin: format lint | ||
@echo "> Running acceptance tests..." | ||
$(GOTEST) -v -count=1 -tags=acceptance ./acceptance/... | ||
|
@@ -151,23 +170,24 @@ package-linux: GOOS:=linux | |
package-linux: GOOS_DIR:=$(BUILD_DIR)/$(GOOS) | ||
package-linux: ARCHIVE_NAME=lifecycle-v$(LIFECYCLE_VERSION)+$(GOOS).x86-64 | ||
package-linux: | ||
@echo "> Writing descriptor file for $(GOOS)..." | ||
mkdir -p $(GOOS_DIR) | ||
echo "$${LIFECYCLE_DESCRIPTOR}" > $(GOOS_DIR)/lifecycle.toml | ||
|
||
@echo "> Packaging lifecycle for $(GOOS)..." | ||
tar czf $(BUILD_DIR)/$(ARCHIVE_NAME).tgz -C $(GOOS_DIR) lifecycle.toml lifecycle | ||
$(GOCMD) run tools/packager/main.go -os $(GOOS) -launcherExePath $(GOOS_DIR)/lifecycle/launcher -lifecycleExePath $(GOOS_DIR)/lifecycle/lifecycle -lifecycleVersion $(LIFECYCLE_VERSION) -platformAPI $(PLATFORM_API) -buildpackAPI $(BUILDPACK_API) -outputPackagePath $(BUILD_DIR)/$(ARCHIVE_NAME).tgz | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using the
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not attached to |
||
|
||
package-windows: export LIFECYCLE_DESCRIPTOR:=$(LIFECYCLE_DESCRIPTOR) | ||
package-windows: GOOS:=windows | ||
package-windows: GOOS_DIR:=$(BUILD_DIR)/$(GOOS) | ||
package-windows: GOOS_DIR:=$(BUILD_DIR)$/$(GOOS) | ||
ameyer-pivotal marked this conversation as resolved.
Show resolved
Hide resolved
|
||
package-windows: ARCHIVE_NAME=lifecycle-v$(LIFECYCLE_VERSION)+$(GOOS).x86-64 | ||
package-windows: | ||
@echo "> Writing descriptor file for $(GOOS)..." | ||
mkdir -p $(GOOS_DIR) | ||
echo "$${LIFECYCLE_DESCRIPTOR}" > $(GOOS_DIR)/lifecycle.toml | ||
|
||
@echo "> Packaging lifecycle for $(GOOS)..." | ||
tar czf $(BUILD_DIR)/$(ARCHIVE_NAME).tgz -C $(GOOS_DIR) lifecycle.toml lifecycle | ||
$(GOCMD) run tools$/packager$/main.go -os $(GOOS) -launcherExePath $(GOOS_DIR)$/lifecycle$/launcher.exe -lifecycleExePath $(GOOS_DIR)$/lifecycle$/lifecycle.exe -lifecycleVersion $(LIFECYCLE_VERSION) -platformAPI $(PLATFORM_API) -buildpackAPI $(BUILDPACK_API) -outputPackagePath $(BUILD_DIR)$/$(ARCHIVE_NAME).tgz | ||
|
||
docker-build-source-image-windows: | ||
docker build -f tools/Dockerfile.windows --tag $(SOURCE_COMPILATION_IMAGE) --build-arg image_tag=$(WINDOWS_COMPILATION_IMAGE) --cache-from=$(SOURCE_COMPILATION_IMAGE) --isolation=process --quiet . | ||
|
||
docker-run-windows: docker-build-source-image-windows | ||
docker-run-windows: | ||
@echo "> Running '$(DOCKER_CMD)' in docker windows..." | ||
@docker volume rm -f lifecycle-out | ||
docker run -v lifecycle-out:c:/lifecycle/out -e LIFECYCLE_VERSION -e PLATFORM_API -e BUILDPACK_API -v gopathcache:c:/gopath -v '\\.\pipe\docker_engine:\\.\pipe\docker_engine' --isolation=process --rm $(SOURCE_COMPILATION_IMAGE) $(DOCKER_CMD) | ||
docker run -v lifecycle-out:c:/lifecycle/out --rm $(SOURCE_COMPILATION_IMAGE) tar -cf- out | tar -xf- | ||
@docker volume rm -f lifecycle-out | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This target is meant to be an easy and consistent wrapper for any Windows command (i.e. Our hope is to make building, running, and troubleshooting on Windows extremely consistent for any CNB contributor and CI by ensuring everyone's using an identical Dockerfile-based Windows environment w/o any manual setup. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. An alternative implementation we tried was |
||
.PHONY: verify-jq |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Windows jobs ends up simpler than Linux since dependencies are in the
tools/Dockerfile.windows
and it's run through themake docker-run-windows
target.The tradeoff is that Windows
build
is slower than Linux (~7 mins vs ~4 mins resp) but I feel the consistency/simplicity is worth it. More thoughts on theMakefile#docker-run-windows
target below