Skip to content

Commit 610c1e7

Browse files
authored
Merge pull request kubernetes-csi#12 from pohly/release-tools
release tools
2 parents dc6d533 + 33d58fd commit 610c1e7

File tree

522 files changed

+244
-399534
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

522 files changed

+244
-399534
lines changed

Gopkg.lock

-122
This file was deleted.

Gopkg.toml

-7
This file was deleted.

Makefile

-35
This file was deleted.

OWNERS

+8-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
# See the OWNERS docs: https://git.k8s.io/community/contributors/guide/owners.md
22

33
approvers:
4-
- saad-ali
5-
- jsafrane
6-
- msau42
7-
- pohly
4+
- saad-ali
5+
- msau42
6+
- pohly
7+
8+
reviewers:
9+
- saad-ali
10+
- msau42
11+
- pohly

README.md

+51-19
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,51 @@
1-
# csi-lib-utils
2-
3-
TBD
4-
5-
## Community, discussion, contribution, and support
6-
7-
Learn how to engage with the Kubernetes community on the [community page](http://kubernetes.io/community/).
8-
9-
You can reach the maintainers of this project at:
10-
11-
- [Slack](http://slack.k8s.io/)
12-
- [Mailing List](https://groups.google.com/forum/#!forum/kubernetes-dev)
13-
14-
### Code of conduct
15-
16-
Participation in the Kubernetes community is governed by the [Kubernetes Code of Conduct](code-of-conduct.md).
17-
18-
[owners]: https://git.k8s.io/community/contributors/guide/owners.md
19-
[Creative Commons 4.0]: https://git.k8s.io/website/LICENSE
1+
# [csi-release-tools](https://github.com/kubernetes-csi/csi-release-tools)
2+
3+
These build and test rules can be shared between different Go projects
4+
without modifications. Customization for the different projects happen
5+
in the top-level Makefile.
6+
7+
The rules include support for building and pushing Docker images, with
8+
the following features:
9+
- one or more command and image per project
10+
- push canary and/or tagged release images
11+
- automatically derive the image tag(s) from repo tags
12+
- the source code revision is stored in a "revision" image label
13+
- never overwrites an existing release image
14+
15+
Usage
16+
-----
17+
18+
The expected repository layout is:
19+
- `cmd/*/*.go` - source code for each command
20+
- `cmd/*/Dockerfile` - docker file for each command or
21+
Dockerfile in the root when only building a single command
22+
- `Makefile` - includes `release-tools/build.make` and sets
23+
configuration variables
24+
- `.travis.yml` - a symlink to `release-tools/.travis.yml`
25+
26+
To create a release, tag a certain revision with a name that
27+
starts with `v`, for example `v1.0.0`, then `make push`
28+
while that commit is checked out.
29+
30+
It does not matter on which branch that revision exists, i.e. it is
31+
possible to create releases directly from master. A release branch can
32+
still be created for maintenance releases later if needed.
33+
34+
Release branches are expected to be named `release-x.y` for releases
35+
`x.y.z`. Building from such a branch creates `x.y-canary`
36+
images. Building from master creates the main `canary` image.
37+
38+
Sharing and updating
39+
--------------------
40+
41+
[`git subtree`](https://github.com/git/git/blob/master/contrib/subtree/git-subtree.txt)
42+
is the recommended way of maintaining a copy of the rules inside the
43+
`release-tools` directory of a project. This way, it is possible to make
44+
changes also locally, test them and then push them back to the shared
45+
repository at a later time.
46+
47+
Cheat sheet:
48+
49+
- `git subtree add --prefix=release-tools https://github.com/kubernetes-csi/csi-release-tools.git master` - add release tools to a repo which does not have them yet (only once)
50+
- `git subtree pull --prefix=release-tools https://github.com/kubernetes-csi/csi-release-tools.git master` - update local copy to latest upstream (whenever upstream changes)
51+
- edit, `git commit`, `git subtree push --prefix=release-tools [email protected]:<user>/csi-release-tools.git <my-new-or-existing-branch>` - push to a new branch before submitting a PR

RELEASE.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Release Process
2+
3+
No tagged releases are planned at this point. The intention is to keep
4+
the master branch in a state such that it can be used for all
5+
supported branches in downstream repos which use these files.

SECURITY_CONTACTS

+1
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@
1111
# INSTRUCTIONS AT https://kubernetes.io/security/
1212

1313
saad-ali
14+
msau42

build.make

+124
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
# Copyright 2019 The Kubernetes Authors.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
.PHONY: build-% build container-% container push-% push clean test
16+
17+
# A space-separated list of all commands in the repository, must be
18+
# set in main Makefile of a repository.
19+
# CMDS=
20+
21+
# This is the default. It can be overridden in the main Makefile after
22+
# including build.make.
23+
REGISTRY_NAME=quay.io/k8scsi
24+
25+
# Revision that gets built into each binary via the main.version
26+
# string. Uses the `git describe` output based on the most recent
27+
# version tag with a short revision suffix or, if nothing has been
28+
# tagged yet, just the revision.
29+
#
30+
# Beware that tags may also be missing in shallow clones as done by
31+
# some CI systems (like TravisCI, which pulls only 50 commits).
32+
REV=$(shell git describe --long --tags --match='v*' --dirty 2>/dev/null || git rev-list -n1 HEAD)
33+
34+
# A space-separated list of image tags under which the current build is to be pushed.
35+
# Determined dynamically.
36+
IMAGE_TAGS=
37+
38+
# A "canary" image gets built if the current commit is the head of the remote "master" branch.
39+
# That branch does not exist when building some other branch in TravisCI.
40+
IMAGE_TAGS+=$(shell if [ "$$(git rev-list -n1 HEAD)" = "$$(git rev-list -n1 origin/master 2>/dev/null)" ]; then echo "canary"; fi)
41+
42+
# A "X.Y.Z-canary" image gets built if the current commit is the head of a "origin/release-X.Y.Z" branch.
43+
# The actual suffix does not matter, only the "release-" prefix is checked.
44+
IMAGE_TAGS+=$(shell git branch -r --points-at=HEAD | grep 'origin/release-' | grep -v -e ' -> ' | sed -e 's;.*/release-\(.*\);\1-canary;')
45+
46+
# A release image "vX.Y.Z" gets built if there is a tag of that format for the current commit.
47+
# --abbrev=0 suppresses long format, only showing the closest tag.
48+
IMAGE_TAGS+=$(shell tagged="$$(git describe --tags --match='v*' --abbrev=0)"; if [ "$$tagged" ] && [ "$$(git rev-list -n1 HEAD)" = "$$(git rev-list -n1 $$tagged)" ]; then echo $$tagged; fi)
49+
50+
# Images are named after the command contained in them.
51+
IMAGE_NAME=$(REGISTRY_NAME)/$*
52+
53+
ifdef V
54+
# Adding "-alsologtostderr" assumes that all test binaries contain glog. This is not guaranteed.
55+
TESTARGS = -v -args -alsologtostderr -v 5
56+
else
57+
TESTARGS =
58+
endif
59+
60+
# Specific packages can be excluded from each of the tests below by setting the *_FILTER_CMD variables
61+
# to something like "| grep -v 'github.com/kubernetes-csi/project/pkg/foobar'". See usage below.
62+
63+
build-%:
64+
mkdir -p bin
65+
CGO_ENABLED=0 GOOS=linux go build -a -ldflags '-X main.version=$(REV) -extldflags "-static"' -o ./bin/$* ./cmd/$*
66+
67+
container-%: build-%
68+
docker build -t $*:latest -f $(shell if [ -e ./cmd/$*/Dockerfile ]; then echo ./cmd/$*/Dockerfile; else echo Dockerfile; fi) --label revision=$(REV) .
69+
70+
push-%: container-%
71+
set -ex; \
72+
push_image () { \
73+
docker tag $*:latest $(IMAGE_NAME):$$tag; \
74+
docker push $(IMAGE_NAME):$$tag; \
75+
}; \
76+
for tag in $(IMAGE_TAGS); do \
77+
if [ "$$tag" = "canary" ] || echo "$$tag" | grep -q -e '-canary$$'; then \
78+
: "creating or overwriting canary image"; \
79+
push_image; \
80+
elif docker pull $(IMAGE_NAME):$$tag 2>&1 | tee /dev/stderr | grep -q "manifest for $(IMAGE_NAME):$$tag not found"; then \
81+
: "creating release image"; \
82+
push_image; \
83+
else \
84+
: "release image $(IMAGE_NAME):$$tag already exists, skipping push"; \
85+
fi; \
86+
done
87+
88+
build: $(CMDS:%=build-%)
89+
container: $(CMDS:%=container-%)
90+
push: $(CMDS:%=push-%)
91+
92+
clean:
93+
-rm -rf bin
94+
95+
test:
96+
97+
.PHONY: test-go
98+
test: test-go
99+
test-go:
100+
@ echo; echo "### $@:"
101+
go test `go list ./... | grep -v 'vendor' $(TEST_GO_FILTER_CMD)` $(TESTARGS)
102+
103+
.PHONY: test-vet
104+
test: test-vet
105+
test-vet:
106+
@ echo; echo "### $@:"
107+
go vet `go list ./... | grep -v vendor $(TEST_VET_FILTER_CMD)`
108+
109+
.PHONY: test-fmt
110+
test: test-fmt
111+
test-fmt:
112+
@ echo; echo "### $@:"
113+
files=$$(find . -name '*.go' | grep -v './vendor' $(TEST_FMT_FILTER_CMD)); \
114+
if [ $$(gofmt -d $$files | wc -l) -ne 0 ]; then \
115+
echo "formatting errors:"; \
116+
gofmt -d $$files; \
117+
false; \
118+
fi
119+
120+
.PHONY: test-subtree
121+
test: test-subtree
122+
test-subtree:
123+
@ echo; echo "### $@:"
124+
./release-tools/verify-subtree.sh release-tools

0 commit comments

Comments
 (0)