@@ -7,8 +7,13 @@ GOVERSION:=$(shell go version | awk '{print $$3 " " $$4}')
77GOOS: =$(shell go env GOOS)
88GOARCH: =$(shell go env GOARCH)
99
10+ BIN_NAME: =preflight
11+
1012DOCKER_IMAGE? =quay.io/jetstack/preflight
11- DOCKER_IMAGE_TAG? =$(DOCKER_IMAGE ) :$(VERSION )
13+ DOCKER_IMAGE_TAG? =$(DOCKER_IMAGE ) :$(COMMIT )
14+
15+ # BUILD_IN decides if the binaries will be built in `docker` or in the `host`.
16+ BUILD_IN? =docker
1217
1318# OAuth2 config for the agent to work with platform.jetstack.io
1419OAUTH_CLIENT_ID? =k3TrDbfLhCgnpAbOiiT2kIE1AbovKzjo
5257lint : vet
5358 cd $(ROOT_DIR ) && golint
5459
55- .PHONY : ./builds/preflight-$(GOOS ) -$(GOARCH )
56- ./builds/preflight-$(GOOS ) -$(GOARCH ) :
57- GOOS=$(GOOS ) GOARCH=$(GOARCH ) $(GO_BUILD ) -o ./builds/preflight-$(GOOS ) -$(GOARCH ) .
58-
59- build-all-platforms :
60- $(MAKE ) GOOS=linux GOARCH=amd64 ./builds/preflight-linux-amd64
61- $(MAKE ) GOOS=darwin GOARCH=amd64 ./builds/preflight-darwin-amd64
62- $(MAKE ) GOOS=windows GOARCH=amd64 ./builds/preflight-windows-amd64
6360
64- # Bundles
65-
66- ./bundles/preflight-bundle-$(GOOS ) -$(GOARCH ) .tgz : ./builds/preflight-$(GOOS ) -$(GOARCH )
67- cd $(ROOT_DIR ) && \
68- mkdir -p ./bundles && \
69- tar --transform " s/builds\/preflight-$( GOOS) -$( GOARCH) /preflight/" -rvf $@ .tmp $< && \
70- gzip < $@ .tmp > $@ && \
71- rm $@ .tmp
72-
73- bundle-all-platforms :
74- $(MAKE ) GOOS=linux GOARCH=amd64 ./bundles/preflight-bundle-linux-amd64.tgz
75- $(MAKE ) GOOS=darwin GOARCH=amd64 ./bundles/preflight-bundle-darwin-amd64.tgz
76- $(MAKE ) GOOS=windows GOARCH=amd64 ./bundles/preflight-bundle-windows-amd64.tgz
61+ .PHONY : ./builds/$(GOOS ) /$(GOARCH ) /$(BIN_NAME )
62+ ./builds/$(GOOS ) /$(GOARCH ) /$(BIN_NAME ) :
63+ GOOS=$(GOOS ) GOARCH=$(GOARCH ) $(GO_BUILD ) -o ./builds/$(GOOS ) /$(GOARCH ) /$(BIN_NAME ) .
64+ .PHONY : ./builds/$(GOOS ) /$(GOARCH ) /v$(GOARM ) /$(BIN_NAME )
65+ ./builds/$(GOOS ) /$(GOARCH ) /v$(GOARM ) /$(BIN_NAME ) :
66+ GOOS=$(GOOS ) GOARCH=$(GOARCH ) GOARM=$(GOARM ) $(GO_BUILD ) -o ./builds/$(GOOS ) /$(GOARCH ) /v$(GOARM ) /$(BIN_NAME ) .
67+
68+ build-all-platforms : build-all-platforms-in-$(BUILD_IN )
69+
70+ build-all-platforms-in-host :
71+ $(MAKE ) GOOS=linux GOARCH=amd64 ./builds/linux/amd64/$(BIN_NAME )
72+ $(MAKE ) GOOS=linux GOARCH=arm64 ./builds/linux/arm64/$(BIN_NAME )
73+ $(MAKE ) GOOS=linux GOARCH=arm GOARM=7 ./builds/linux/arm/v7/$(BIN_NAME )
74+ $(MAKE ) GOOS=darwin GOARCH=amd64 ./builds/darwin/amd64/$(BIN_NAME )
75+ $(MAKE ) GOOS=windows GOARCH=amd64 ./builds/windows/amd64/$(BIN_NAME )
76+
77+ build-all-platforms-in-docker :
78+ rm -rf ./builds
79+ docker build --rm -t preflight-bin -f ./builder.dockerfile \
80+ --build-arg oauth_client_id=$(OAUTH_CLIENT_ID ) \
81+ --build-arg oauth_client_secret=$(OAUTH_CLIENT_SECRET ) \
82+ --build-arg oauth_auth_server_domain=$(OAUTH_AUTH_SERVER_DOMAIN ) \
83+ .
84+ docker create --rm --name=preflight-bin-container preflight-bin
85+ docker cp preflight-bin-container:/go/github.com/jetstack/preflight/builds ./builds
86+ docker rm preflight-bin-container
87+ docker rmi preflight-bin
7788
7889# Docker image
79-
80- build-docker-image :
81- docker build --tag $(DOCKER_IMAGE_TAG ) \
82- --build-arg oauth_client_id=$(OAUTH_CLIENT_ID ) \
83- --build-arg oauth_client_secret=$(OAUTH_CLIENT_SECRET ) \
84- --build-arg oauth_auth_server_domain=$(OAUTH_AUTH_SERVER_DOMAIN ) \
90+ PLATFORMS? =linux/arm/v7,linux/arm64/v8,linux/amd64
91+ BUILDX_EXTRA_ARGS? =
92+
93+ push_buildx_args =--push $(BUILDX_EXTRA_ARGS )
94+ push-canary_buildx_args =--tag $(DOCKER_IMAGE ) :canary --push $(BUILDX_EXTRA_ARGS )
95+ build_buildx_args =$(BUILDX_EXTRA_ARGS )
96+
97+ .PHONY : _docker-%
98+ _docker-% : build-all-platforms
99+ docker buildx build --platform $(PLATFORMS ) \
100+ --tag $(DOCKER_IMAGE_TAG ) \
101+ $($* _buildx_args) \
85102 .
86103
87- push-docker-image :
88- docker tag $(DOCKER_IMAGE_TAG ) $(DOCKER_IMAGE ) :latest
89- docker push $(DOCKER_IMAGE_TAG )
90- docker push $(DOCKER_IMAGE ) :latest
104+ build-docker-image : _docker-build
105+ push-docker-image : _docker-push
91106
92- push-docker-image-canary :
93- docker tag $(DOCKER_IMAGE_TAG ) $(DOCKER_IMAGE ) :canary
94- docker push $(DOCKER_IMAGE_TAG )
95- docker push $(DOCKER_IMAGE ) :canary
107+ NEW_TAG? =latest
108+ create-docker-image-tag :
109+ docker buildx imagetools create $(DOCKER_IMAGE ) :$(COMMIT ) --tag $(DOCKER_IMAGE ) :$(NEW_TAG )
96110
97111# CI
98112
99113export PATH: =$(GOPATH ) /bin:$(PATH )
100114
101115ci-deps :
116+ echo " ci-deps is going to be disabled. We are adopting Github actions"
102117 go install golang.org/x/lint/golint
103118
104119ci-test : ci-deps test lint
105120
106121ci-build : ci-test build build-docker-image build-all-platforms bundle-all-platforms push-docker-image-canary
122+ echo " ci-build is going to be disabled. We are adopting Github actions"
107123
108124ci-publish : ci-build push-docker-image
125+ echo " ci-publish is going to be disabled. We are adopting Github actions"
0 commit comments