github.com/docker/app@v0.9.1-beta3.0.20210611140623-a48f773ab002/docker.Makefile (about) 1 include vars.mk 2 3 LINT_IMAGE_NAME := $(BIN_NAME)-lint:$(BUILD_TAG) 4 DEV_IMAGE_NAME := $(BIN_NAME)-dev:$(BUILD_TAG) 5 BIN_IMAGE_NAME := $(BIN_NAME)-bin:$(BUILD_TAG) 6 CROSS_IMAGE_NAME := $(BIN_NAME)-cross:$(BUILD_TAG) 7 CLI_IMAGE_NAME := $(BIN_NAME)-cli:$(BUILD_TAG) 8 E2E_CROSS_IMAGE_NAME := $(BIN_NAME)-e2e-cross:$(BUILD_TAG) 9 10 BIN_CTNR_NAME := $(BIN_NAME)-bin-$(TAG) 11 CLI_CNTR_NAME := $(BIN_NAME)-cli-$(TAG) 12 CROSS_CTNR_NAME := $(BIN_NAME)-cross-$(TAG) 13 E2E_CROSS_CTNR_NAME := $(BIN_NAME)-e2e-cross-$(TAG) 14 COV_CTNR_NAME := $(BIN_NAME)-cov-$(TAG) 15 SCHEMAS_CTNR_NAME := $(BIN_NAME)-schemas-$(TAG) 16 17 BUILD_ARGS=--build-arg TAG=$(TAG) --build-arg COMMIT=$(COMMIT) --build-arg ALPINE_VERSION=$(ALPINE_VERSION) --build-arg GOPROXY=$(GOPROXY) 18 19 PKG_PATH := /go/src/$(PKG_NAME) 20 21 22 CNAB_BASE_INVOCATION_IMAGE_NAME := docker/cnab-app-base:$(BUILD_TAG) 23 CNAB_BASE_INVOCATION_IMAGE_PATH := _build/invocation-image 24 25 PUSH_CNAB_BASE_INVOCATION_IMAGE_NAME := docker/cnab-app-base:$(TAG) 26 27 .DEFAULT: all 28 all: cross test 29 30 create_bin: 31 @$(call mkdir,bin) 32 33 build_dev_image: 34 docker build $(BUILD_ARGS) --target=dev -t $(DEV_IMAGE_NAME) . 35 36 shell: build_dev_image ## run a shell in the docker build image 37 docker run -ti --rm $(DEV_IMAGE_NAME) bash 38 39 cross: create_bin ## cross-compile binaries (linux, darwin, windows) 40 docker build $(BUILD_ARGS) --output type=local,dest=./bin/ --target=cross -t $(CROSS_IMAGE_NAME) . 41 @$(call chmod,+x,bin/$(BIN_NAME)-linux) 42 @$(call chmod,+x,bin/$(BIN_NAME)-linux-arm64) 43 @$(call chmod,+x,bin/$(BIN_NAME)-linux-arm) 44 @$(call chmod,+x,bin/$(BIN_NAME)-darwin) 45 @$(call chmod,+x,bin/$(BIN_NAME)-windows.exe) 46 47 cli-cross: create_bin 48 docker build $(BUILD_ARGS) --output type=local,dest=./bin/ --target=cli -t $(CLI_IMAGE_NAME) . 49 @$(call chmod,+x,bin/docker-linux) 50 @$(call chmod,+x,bin/docker-darwin) 51 @$(call chmod,+x,bin/docker-windows.exe) 52 53 e2e-cross: create_bin 54 docker build $(BUILD_ARGS) --output type=local,dest=./bin/ --target=e2e-cross -t $(E2E_CROSS_IMAGE_NAME) . 55 @$(call chmod,+x,bin/$(BIN_NAME)-e2e-linux) 56 @$(call chmod,+x,bin/$(BIN_NAME)-e2e-darwin) 57 @$(call chmod,+x,bin/gotestsum-linux) 58 @$(call chmod,+x,bin/gotestsum-darwin) 59 @$(call chmod,+x,bin/test2json-linux) 60 @$(call chmod,+x,bin/test2json-darwin) 61 62 tars: 63 tar --transform='flags=r;s|$(BIN_NAME)-linux|$(BIN_NAME)-plugin-linux|' -czf bin/$(BIN_NAME)-linux.tar.gz -C bin $(BIN_NAME)-linux 64 tar czf bin/$(BIN_NAME)-e2e-linux.tar.gz -C bin $(BIN_NAME)-e2e-linux 65 tar --transform='flags=r;s|$(BIN_NAME)-linux-arm64|$(BIN_NAME)-plugin-linux-arm64|' -czf bin/$(BIN_NAME)-linux-arm64.tar.gz -C bin $(BIN_NAME)-linux-arm64 66 tar --transform='flags=r;s|$(BIN_NAME)-linux-arm|$(BIN_NAME)-plugin-linux-arm|' -czf bin/$(BIN_NAME)-linux-arm.tar.gz -C bin $(BIN_NAME)-linux-arm 67 tar --transform='flags=r;s|$(BIN_NAME)-darwin|$(BIN_NAME)-plugin-darwin|' -czf bin/$(BIN_NAME)-darwin.tar.gz -C bin $(BIN_NAME)-darwin 68 tar czf bin/$(BIN_NAME)-e2e-darwin.tar.gz -C bin $(BIN_NAME)-e2e-darwin 69 tar --transform='flags=r;s|$(BIN_NAME)-windows|$(BIN_NAME)-plugin-windows|' -czf bin/$(BIN_NAME)-windows.tar.gz -C bin $(BIN_NAME)-windows.exe 70 tar czf bin/$(BIN_NAME)-e2e-windows.tar.gz -C bin $(BIN_NAME)-e2e-windows.exe 71 72 test: test-unit test-e2e ## run all tests 73 74 test-unit: build_dev_image ## run unit tests 75 @$(call mkdir,_build/test-results) 76 docker run --rm -v $(CURDIR)/_build/test-results:/test-results $(DEV_IMAGE_NAME) make TEST_RESULTS_PREFIX=$(TEST_RESULTS_PREFIX) test-unit 77 78 test-e2e: build_dev_image invocation-image ## run end-to-end tests 79 docker run -v /var/run:/var/run:ro --rm --network="host" $(DEV_IMAGE_NAME) make TEST_RESULTS_PREFIX=$(TEST_RESULTS_PREFIX) bin/$(BIN_NAME) E2E_TESTS=$(E2E_TESTS) test-e2e 80 81 COV_LABEL := com.docker.app.cov-run=$(TAG) 82 coverage-run: build_dev_image ## run tests with coverage 83 @$(call mkdir,_build) 84 docker run -v /var/run:/var/run:ro --name $(COV_CTNR_NAME) --network="host" -t $(DEV_IMAGE_NAME) make COMMIT=${COMMIT} TAG=${TAG} TEST_RESULTS_PREFIX=$(TEST_RESULTS_PREFIX) coverage 85 coverage-results: 86 docker cp $(COV_CTNR_NAME):$(PKG_PATH)/_build/cov/ ./_build/ci-cov 87 docker cp $(COV_CTNR_NAME):$(PKG_PATH)/_build/test-results/ ./_build/test-results 88 docker rm $(COV_CTNR_NAME) 89 # coverage is split in two like this so that CI can extract the results even on failure (which will be detected via the junit) using the individual steps, but for end users running we want the overall failure. 90 coverage: coverage-run coverage-results 91 92 lint: ## run linter(s) 93 $(info Linting...) 94 docker build -t $(LINT_IMAGE_NAME) -f Dockerfile.lint . 95 docker run --rm $(LINT_IMAGE_NAME) make lint 96 97 vendor: build_dev_image 98 $(info Update Vendoring...) 99 docker rm -f docker-app-vendoring || true 100 # git bash, mingw and msys by default rewrite args that seems to be linux paths and try to expand that to a meaningful windows path 101 # we don't want that to happen when mounting paths referring to files located in the container. Thus we use the double "//" prefix that works 102 # both on windows, linux and macos 103 docker run -it --name docker-app-vendoring -v docker-app-vendor-cache://dep-cache -e DEPCACHEDIR=//dep-cache $(DEV_IMAGE_NAME) sh -c "rm -rf ./vendor && make vendor DEP_ARGS=\"$(DEP_ARGS)\"" 104 rm -rf ./vendor 105 docker cp docker-app-vendoring:/go/src/github.com/docker/app/vendor . 106 docker cp docker-app-vendoring:/go/src/github.com/docker/app/Gopkg.lock . 107 docker rm -f docker-app-vendoring 108 $(warning You may need to reset permissions on vendor/*) 109 110 clean-vendor-cache: 111 docker rm -f docker-app-vendoring || true 112 docker volume rm -f docker-app-vendor-cache 113 114 check-vendor: build_dev_image 115 $(info Check Vendoring...) 116 docker run --rm $(DEV_IMAGE_NAME) sh -c "make vendor && hack/check-git-diff vendor" 117 118 specification/bindata.go: specification/schemas/*.json build_dev_image 119 docker run --name $(SCHEMAS_CTNR_NAME) $(DEV_IMAGE_NAME) sh -c "make schemas" 120 docker cp $(SCHEMAS_CTNR_NAME):$(PKG_PATH)/specification/bindata.go ./specification/ 121 docker rm $(SCHEMAS_CTNR_NAME) 122 123 schemas: specification/bindata.go ## generate specification/bindata.go from json schemas 124 125 invocation-image: 126 docker build -f Dockerfile.invocation-image $(BUILD_ARGS) --target=invocation -t $(CNAB_BASE_INVOCATION_IMAGE_NAME) -t $(CNAB_BASE_INVOCATION_IMAGE_NAME)-amd64 --platform=amd64 . 127 128 invocation-image-arm64: 129 docker build -f Dockerfile.invocation-image $(BUILD_ARGS) --target=invocation -t $(CNAB_BASE_INVOCATION_IMAGE_NAME)-arm64 --platform=arm64 . 130 131 invocation-image-arm: 132 docker build -f Dockerfile.invocation-image $(BUILD_ARGS) --target=invocation -t $(CNAB_BASE_INVOCATION_IMAGE_NAME)-arm --platform=arm . 133 134 invocation-image-cross: invocation-image invocation-image-arm64 invocation-image-arm 135 136 save-invocation-image-tag: 137 docker tag $(CNAB_BASE_INVOCATION_IMAGE_NAME) docker/cnab-app-base:$(INVOCATION_IMAGE_TAG) 138 docker save docker/cnab-app-base:$(INVOCATION_IMAGE_TAG) -o _build/$(OUTPUT) 139 140 save-invocation-image: 141 @$(call mkdir,_build) 142 docker save $(CNAB_BASE_INVOCATION_IMAGE_NAME) -o $(CNAB_BASE_INVOCATION_IMAGE_PATH).tar 143 144 save-invocation-image-cross: save-invocation-image 145 docker save $(CNAB_BASE_INVOCATION_IMAGE_NAME)-arm64 -o $(CNAB_BASE_INVOCATION_IMAGE_PATH)-arm64.tar 146 docker save $(CNAB_BASE_INVOCATION_IMAGE_NAME)-arm -o $(CNAB_BASE_INVOCATION_IMAGE_PATH)-arm.tar 147 148 push-invocation-image: 149 # tag and push linux/amd64 150 docker tag $(CNAB_BASE_INVOCATION_IMAGE_NAME) $(PUSH_CNAB_BASE_INVOCATION_IMAGE_NAME) 151 docker push $(PUSH_CNAB_BASE_INVOCATION_IMAGE_NAME) 152 # tag and push linux/arm64 153 docker tag $(CNAB_BASE_INVOCATION_IMAGE_NAME)-arm64 $(PUSH_CNAB_BASE_INVOCATION_IMAGE_NAME)-arm64 154 docker push $(PUSH_CNAB_BASE_INVOCATION_IMAGE_NAME)-arm64 155 # tag and push linux/armhf 156 docker tag $(CNAB_BASE_INVOCATION_IMAGE_NAME)-arm $(PUSH_CNAB_BASE_INVOCATION_IMAGE_NAME)-arm 157 docker push $(PUSH_CNAB_BASE_INVOCATION_IMAGE_NAME)-arm 158 # create and push manifest list 159 DOCKER_CLI_EXPERIMENTAL=enabled docker manifest create $(PUSH_CNAB_BASE_INVOCATION_IMAGE_NAME) $(PUSH_CNAB_BASE_INVOCATION_IMAGE_NAME) $(PUSH_CNAB_BASE_INVOCATION_IMAGE_NAME)-arm64 $(PUSH_CNAB_BASE_INVOCATION_IMAGE_NAME)-arm 160 DOCKER_CLI_EXPERIMENTAL=enabled docker manifest push $(PUSH_CNAB_BASE_INVOCATION_IMAGE_NAME) 161 162 help: ## this help 163 @awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST) | sort 164 165 .PHONY: lint test-e2e test-unit test cli-cross cross e2e-cross coverage coverage-run coverage-results shell build_dev_image tars vendor check-vendor schemas help invocation-image invocation-image-arm invocation-image-arm64 invocation-image-cross save-invocation-image save-invocation-image-tag push-invocation-image