github.com/opensuse/umoci@v0.4.2/Makefile (about) 1 # umoci: Umoci Modifies Open Containers' Images 2 # Copyright (C) 2016, 2017, 2018 SUSE LLC. 3 # 4 # Licensed under the Apache License, Version 2.0 (the "License"); 5 # you may not use this file except in compliance with the License. 6 # You may obtain a copy of the License at 7 # 8 # http://www.apache.org/licenses/LICENSE-2.0 9 # 10 # Unless required by applicable law or agreed to in writing, software 11 # distributed under the License is distributed on an "AS IS" BASIS, 12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 # See the License for the specific language governing permissions and 14 # limitations under the License. 15 16 # Use bash, so that we can do process substitution. 17 SHELL = /bin/bash 18 19 # Go tools. 20 GO ?= go 21 GO_MD2MAN ?= go-md2man 22 23 # Set up the ... lovely ... GOPATH hacks. 24 PROJECT := github.com/openSUSE/umoci 25 CMD := ${PROJECT}/cmd/umoci 26 27 # We use Docker because Go is just horrific to deal with. 28 UMOCI_IMAGE := umoci_dev 29 DOCKER_RUN := docker run --rm -it --security-opt apparmor:unconfined --security-opt label:disable -v ${PWD}:/go/src/${PROJECT} 30 31 # Output directory. 32 BUILD_DIR ?= . 33 34 # Release information. 35 GPG_KEYID ?= 36 37 # Version information. 38 VERSION := $(shell cat ./VERSION) 39 COMMIT_NO := $(shell git rev-parse HEAD 2> /dev/null || true) 40 COMMIT := $(if $(shell git status --porcelain --untracked-files=no),"${COMMIT_NO}-dirty","${COMMIT_NO}") 41 42 BUILD_FLAGS ?= 43 44 BASE_FLAGS := ${BUILD_FLAGS} -tags "${BUILDTAGS}" 45 BASE_LDFLAGS := -s -w -X main.gitCommit=${COMMIT} -X main.version=${VERSION} 46 47 DYN_BUILD_FLAGS := ${BASE_FLAGS} -buildmode=pie -ldflags "${BASE_LDFLAGS}" 48 TEST_BUILD_FLAGS := ${BASE_FLAGS} -buildmode=pie -ldflags "${BASE_LDFLAGS} -X ${PROJECT}/pkg/testutils.binaryType=test" 49 STATIC_BUILD_FLAGS := ${BASE_FLAGS} -ldflags "${BASE_LDFLAGS} -extldflags '-static'" 50 51 .DEFAULT: umoci 52 53 GO_SRC = $(shell find . -name \*.go) 54 55 # NOTE: If you change these make sure you also update local-validate-build. 56 57 umoci: $(GO_SRC) 58 $(GO) build ${DYN_BUILD_FLAGS} -o $(BUILD_DIR)/$@ ${CMD} 59 60 umoci.static: $(GO_SRC) 61 env CGO_ENABLED=0 $(GO) build ${STATIC_BUILD_FLAGS} -o $(BUILD_DIR)/$@ ${CMD} 62 63 umoci.cover: $(GO_SRC) 64 $(GO) test -c -cover -covermode=count -coverpkg=./... ${TEST_BUILD_FLAGS} -o $(BUILD_DIR)/$@ ${CMD} 65 66 .PHONY: release 67 release: 68 hack/release.sh -S "$(GPG_KEYID)" -r release/$(VERSION) -v $(VERSION) 69 70 .PHONY: install 71 install: $(GO_SRC) 72 $(GO) install -v ${DYN_BUILD_FLAGS} ${CMD} 73 74 .PHONY: install.static 75 install.static: $(GO_SRC) 76 $(GO) install -v ${STATIC_BUILD_FLAGS} ${CMD} 77 78 .PHONY: clean 79 clean: 80 rm -f umoci umoci.static umoci.cov* 81 rm -f $(MANPAGES) 82 83 .PHONY: validate 84 validate: umociimage 85 $(DOCKER_RUN) $(UMOCI_IMAGE) make local-validate 86 87 .PHONY: local-validate 88 local-validate: local-validate-git local-validate-go local-validate-reproducible local-validate-build 89 90 # TODO: Remove the special-case ignored system/* warnings. 91 .PHONY: local-validate-go 92 local-validate-go: 93 @type gofmt >/dev/null 2>/dev/null || (echo "ERROR: gofmt not found." && false) 94 test -z "$$(gofmt -s -l . | grep -vE '^vendor/|^third_party/' | tee /dev/stderr)" 95 @type golint >/dev/null 2>/dev/null || (echo "ERROR: golint not found." && false) 96 test -z "$$(golint $(PROJECT)/... | grep -vE '/vendor/|/third_party/' | tee /dev/stderr)" 97 @go doc cmd/vet >/dev/null 2>/dev/null || (echo "ERROR: go vet not found." && false) 98 test -z "$$($(GO) vet $$($(GO) list $(PROJECT)/... | grep -vE '/vendor/|/third_party/') 2>&1 | tee /dev/stderr)" 99 100 EPOCH_COMMIT ?= 97ecdbd53dcb72b7a0d62196df281f131dc9eb2f 101 .PHONY: local-validate-git 102 local-validate-git: 103 @type git-validation > /dev/null 2>/dev/null || (echo "ERROR: git-validation not found." && false) 104 ifdef TRAVIS_COMMIT_RANGE 105 git-validation -q -run DCO,short-subject 106 else 107 git-validation -q -run DCO,short-subject -range $(EPOCH_COMMIT)..HEAD 108 endif 109 110 # Make sure that our builds are reproducible even if you wait between them and 111 # the modified time of the files is different. 112 .PHONY: local-validate-reproducible 113 local-validate-reproducible: 114 mkdir -p .tmp-validate 115 make -B umoci && cp umoci .tmp-validate/umoci.a 116 @echo sleep 10s 117 @sleep 10s && touch $(GO_SRC) 118 make -B umoci && cp umoci .tmp-validate/umoci.b 119 diff -s .tmp-validate/umoci.{a,b} 120 sha256sum .tmp-validate/umoci.{a,b} 121 rm -r .tmp-validate/umoci.{a,b} 122 123 .PHONY: local-validate-build 124 local-validate-build: 125 $(GO) build ${DYN_BUILD_FLAGS} -o /dev/null ${CMD} 126 env CGO_ENABLED=0 $(GO) build ${STATIC_BUILD_FLAGS} -o /dev/null ${CMD} 127 $(GO) test -run nothing ${DYN_BUILD_FLAGS} $(PROJECT)/... 128 129 MANPAGES_MD := $(wildcard doc/man/*.md) 130 MANPAGES := $(MANPAGES_MD:%.md=%) 131 132 doc/man/%.1: doc/man/%.1.md 133 $(GO_MD2MAN) -in $< -out $@ 134 135 .PHONY: doc 136 doc: $(MANPAGES) 137 138 # Used for tests. 139 DOCKER_IMAGE :=opensuse/amd64:tumbleweed 140 141 .PHONY: umociimage 142 umociimage: 143 docker build -t $(UMOCI_IMAGE) --build-arg DOCKER_IMAGE=$(DOCKER_IMAGE) . 144 145 ifndef COVERAGE 146 COVERAGE := $(shell mktemp --dry-run umoci.cov.XXXXXX) 147 endif 148 149 .PHONY: test-unit 150 test-unit: umociimage 151 touch $(COVERAGE) && chmod a+rw $(COVERAGE) 152 $(DOCKER_RUN) -e COVERAGE=$(COVERAGE) --cap-add=SYS_ADMIN $(UMOCI_IMAGE) make local-test-unit 153 $(DOCKER_RUN) -e COVERAGE=$(COVERAGE) -u 1000:1000 --cap-drop=all $(UMOCI_IMAGE) make local-test-unit 154 155 .PHONY: local-test-unit 156 local-test-unit: 157 GO=$(GO) COVER=1 hack/test-unit.sh 158 159 .PHONY: test-integration 160 test-integration: umociimage 161 touch $(COVERAGE) && chmod a+rw $(COVERAGE) 162 $(DOCKER_RUN) -e COVERAGE=$(COVERAGE) $(UMOCI_IMAGE) make TESTS="${TESTS}" local-test-integration 163 $(DOCKER_RUN) -e COVERAGE=$(COVERAGE) -u 1000:1000 --cap-drop=all $(UMOCI_IMAGE) make TESTS="${TESTS}" local-test-integration 164 165 .PHONY: local-test-integration 166 local-test-integration: umoci.cover 167 TESTS="${TESTS}" COVER=1 hack/test-integration.sh 168 169 shell: umociimage 170 $(DOCKER_RUN) $(UMOCI_IMAGE) bash 171 172 .PHONY: ci 173 ci: umoci umoci.cover doc local-validate test-unit test-integration 174 hack/ci-coverage.sh $(COVERAGE)