Skip to content

Commit 861bdb8

Browse files
committed
Version the CSI protobuf
This patch versions the generated CSI protobuf and provides a Travis-CI build step that verifies the protobuf is up-to-date before allowing any changes to be merged. Additionally this patch also adds minimal Go language bindings in order to verify the specification. Finally, scaffolding was put into place in order to support Cxx language bindings in the future as well.
1 parent 3ff71b1 commit 861bdb8

File tree

13 files changed

+7364
-212
lines changed

13 files changed

+7364
-212
lines changed

.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
csi.proto
2-
csi.pb.go
1+
/csi.proto.tmp
2+
.DS_Store

.travis.yml

Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,38 @@
1-
go_import_path: github.com/container-storage-interface/spec
1+
# Setting "sudo" to false forces Travis-CI to use its
2+
# container-based build infrastructure, which has shorter
3+
# queue times.
4+
sudo: false
25

3-
language: go
6+
# Use the newer Travis-CI build templates based on the
7+
# Debian Linux distribution "Trusty" release.
8+
dist: trusty
49

5-
go:
6-
- 1.8.x
10+
# Selecting C as the language keeps the container to a
11+
# minimum footprint.
12+
language: c
713

8-
before_install:
9-
- gem install gist
10-
- curl -LO https://github.com/google/protobuf/releases/download/v3.3.0/protoc-3.3.0-linux-x86_64.zip
11-
- unzip protoc-3.3.0-linux-x86_64.zip
12-
- chmod +x bin/protoc
13-
- export PATH="$(pwd)/bin:$PATH"
14+
jobs:
15+
include:
1416

15-
install:
16-
- go get -u github.com/golang/protobuf/proto
17-
- go get -u github.com/golang/protobuf/protoc-gen-go
18-
- go get -u google.golang.org/grpc
19-
- CSI_SPEC_FILE=spec.md make csi.proto
17+
# The test stage validates that the protobuf file was updated
18+
# correctly prior to being committed.
19+
- stage: test
20+
script: make
2021

21-
script:
22-
- make csi.pb.go
22+
# The lang stages validate the specification using
23+
# language-specific bindings.
2324

24-
after_success:
25-
- printf "%s" "$GITHUB_API_TOKEN" > "${HOME}/.gist"
26-
- gist -d "https://travis-ci.org/container-storage-interface/spec/jobs/${TRAVIS_BUILD_ID}" *.{proto,go}
25+
# Lang stage: Cxx
26+
- stage: lang
27+
script: make -C lib/cxx
28+
29+
# Lang stage: Go
30+
- stage: lang
31+
language: go
32+
go: 1.8.3
33+
go_import_path: github.com/container-storage-interface/spec
34+
install:
35+
- make -C lib/go protoc
36+
- make -C lib/go protoc-gen-go
37+
script:
38+
- make -C lib/go

CONTRIBUTING.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@ This also applies to the code snippets in the markdown files.
1717

1818
## Git commit
1919

20+
Prior to committing code please run `make` in order to update the protobuf file and any language bindings.
21+
2022
### Commit Style
2123

22-
Each commit should represent a single logical (atomic) change: this makes your changes easier to review.
24+
Each commit should represent a single logical (atomic) change: this makes your changes easier to review.
2325

2426
* Try to avoid unrelated cleanups (e.g., typo fixes or style nits) in the same commit that makes functional changes.
2527
While typo fixes are great, including them in the same commit as functional changes makes the commit history harder to read.

Makefile

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,47 @@
11
all: build
22

3-
include csi.mk
3+
CSI_SPEC := spec.md
4+
CSI_PROTO := csi.proto
45

5-
build: $(CSI_PROTO) $(CSI_GOSRC)
6+
# This is the target for building the temporary CSI protobuf file.
7+
#
8+
# The temporary file is not versioned, and thus will always be
9+
# built on Travis-CI.
10+
$(CSI_PROTO).tmp: $(CSI_SPEC)
11+
cat $? | \
12+
sed -n -e '/```protobuf$$/,/```$$/ p' | \
13+
sed -e 's@^```.*$$@////////@g' > $@
14+
15+
# This is the target for building the CSI protobuf file.
16+
#
17+
# This target depends on its temp file, which is not versioned.
18+
# Therefore when built on Travis-CI the temp file will always
19+
# be built and trigger this target. On Travis-CI the temp file
20+
# is compared with the real file, and if they differ the build
21+
# will fail.
22+
#
23+
# Locally the temp file is simply copied over the real file.
24+
$(CSI_PROTO): $(CSI_PROTO).tmp
25+
ifeq (true,$(TRAVIS))
26+
diff "$@" "$?"
27+
else
28+
diff "$@" "$?" > /dev/null 2>&1 || cp -f "$?" "$@"
29+
.PHONY: $(CSI_PROTO).tmp
30+
endif
31+
32+
build: $(CSI_PROTO)
33+
34+
# If this is not running on Travis-CI then for sake of convenience
35+
# go ahead and update the language bindings as well.
36+
ifneq (true,$(TRAVIS))
37+
build:
38+
$(MAKE) -C lib/go
39+
$(MAKE) -C lib/cxx
40+
endif
641

742
clean:
8-
rm -f $(CSI_PROTO) $(CSI_GOSRC)
43+
44+
clobber: clean
45+
rm -f $(CSI_PROTO) $(CSI_PROTO).tmp
46+
47+
.PHONY: clean clobber

README.md

Lines changed: 1 addition & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -2,49 +2,4 @@
22

33
![CSI Logo](logo.png)
44

5-
This project contains the CSI [specification](spec.md). Please see the
6-
[build reference](#build-reference) section for information on how to
7-
generate the protobuf or Go source files.
8-
9-
## Build Reference
10-
This section describes how to generate the CSI protobuf file, generate
11-
Go sources from the protobuf, and which environment variables can
12-
influence the build process.
13-
14-
### Generate Protobuf
15-
The CSI protobuf can be generated with the following command:
16-
17-
```bash
18-
$ make csi.proto
19-
```
20-
21-
In the above example the protobuf file is generated by parsing a `spec.md`
22-
from a remote git repository (this one in fact). However, it's also
23-
possible to generate the protobuf from a local spec file:
24-
25-
```bash
26-
$ CSI_SPEC_FILE=spec.md make csi.proto
27-
```
28-
29-
### Generate Go Source
30-
The following command generates the Go source file from the protobuf:
31-
32-
```bash
33-
$ make csi.pb.go
34-
```
35-
36-
### Build Options
37-
It's also possible to influence the location from which the CSI specification
38-
is retrieved with the following environment variables:
39-
40-
| Name | Description | Default |
41-
|------|-------------|---------|
42-
| `CSI_SPEC_FILE` | The path to a local spec file used to generate the protobuf | |
43-
| `CSI_GIT_OWNER` | The GitHub user or organization that owns the git repository that contains the CSI spec file | `container-storage-interface` |
44-
| `CSI_GIT_REPO` | The GitHub repository that contains the CSI spec file | `spec` |
45-
| `CSI_GIT_REF` | The git ref to use when getting the CSI spec file. This value can be a branch name, a tag, or a git commit ID | `master` |
46-
| `CSI_SPEC_NAME` | The name of the CSI spec markdown file | `spec.md` |
47-
| `CSI_SPEC_PATH` | The remote path of the CSI markdown file | |
48-
| `CSI_PROTO_NAME` | The name of the protobuf file to generate. This value should not include the file extension | `csi` |
49-
| `CSI_PROTO_DIR` | The path of the directory in which the protobuf and Go source files will be generated. If this directory does not exist it will be created. | `.` |
50-
| `CSI_PROTO_ADD` | A list of additional protobuf files used when building the Go source file | |
5+
This project contains the CSI [specification](spec.md) and [protobuf](csi.proto) files.

csi.mk

Lines changed: 0 additions & 140 deletions
This file was deleted.

0 commit comments

Comments
 (0)